*&---------------------------------------------------------------------*
*& Report ZCOOIS_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZCOOIS_REPORT.
TABLES: aufk,afru,afvc.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES : BEGIN OF ty_afko,
AUFNR TYPE afko-AUFNR,
aufpl TYPE afko-aufpl,
plnbez TYPE afko-plnbez,
PLNME TYPE AFKO-PLNME,
END OF ty_afko.
TYPES : BEGIN OF ty_afru,
aufpl TYPE afru-aufpl,
rueck TYPE afru-rueck,
gmnga TYPE afru-gmnga,
vornr TYPE afru-vornr,
ernam TYPE afru-ernam,
arbid TYPE afru-arbid,
END OF ty_afru.
TYPES : BEGIN OF ty_crhd,
arbpl TYPE crhd-arbpl,
END OF ty_crhd.
* afko~aufnr afko~aufpl afko~plnbez afko~plnme afru~aufpl afru~rueck afru~gmnga afru~vornr afru~ernam afru~arbid
TYPES : BEGIN OF ty_join,
AUFNR TYPE afko-AUFNR,
aufpl TYPE afko-aufpl,
plnbez TYPE afko-plnbez,
PLNME TYPE AFKO-PLNME,
aufpl1 TYPE afru-aufpl,
rueck TYPE afru-rueck,
gmnga TYPE afru-gmnga,
vornr TYPE afru-vornr,
ernam TYPE afru-ernam,
arbid TYPE afru-arbid,
END OF ty_join.
TYPES : BEGIN OF ty_final,
aufnr TYPE afko-aufnr,
plnbez TYPE afko-plnbez,
PLNME TYPE AFKO-PLNME,
aufpl TYPE afru-aufpl,
rueck TYPE afru-rueck,
gmnga TYPE afru-gmnga,
vornr TYPE afru-vornr,
ernam TYPE afru-ernam,
* ile03 TYPE afru-ile03,
arbpl TYPE crhd-arbpl,
END OF ty_final.
DATA : it_afko TYPE STANDARD TABLE OF ty_afko,
wa_afko TYPE ty_afko,
it_afru TYPE STANDARD TABLE OF ty_afru,
wa_afru TYPE ty_afru,
it_crhd TYPE STANDARD TABLE OF ty_crhd,
wa_crhd TYPE ty_crhd,
it_JOIN TYPE STANDARD TABLE OF ty_JOIN,
wa_JOIN TYPE ty_JOIN,
it_final TYPE STANDARD TABLE OF ty_final,
wa_final TYPE ty_final.
*
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv,
wa_event TYPE slis_alv_event.
DATA: t_fcat TYPE lvc_t_fcat,
fs_fcat TYPE lvc_s_fcat.
DATA: t_sort TYPE lvc_t_sort,
fs_sort TYPE lvc_s_sort.
fs_fcat-fieldname = 'GMNGA'.
fs_fcat-do_sum = 'X'.
APPEND fs_fcat TO t_fcat.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
BREAK 10115.
perform data_retrieval.
* if it_final[] IS INITIAL.
* MESSAGE 'Data is not found' TYPE 'I'.
* LEAVE LIST-PROCESSING.
* ENDIF.
perform build_FS_FCAT.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001 .
* SELECT-OPTIONS s_purch for ekbe-ebeln. ""Purchase Document
SELECT-OPTIONS s_afnr FOR wa_afko-AUFNR OBLIGATORY. "Posting Date
SELECTION-SCREEN END OF BLOCK a1.
*&---------------------------------------------------------------------*
*& Form BUILD_FS_FCAT
*&---------------------------------------------------------------------*
* Build FS_FCAT for ALV Report
*----------------------------------------------------------------------*
form build_FS_FCAT.
*
*aufnr TYPE afko-aufnr,
* aufpl TYPE afru-aufpl,
* rueck TYPE afru-rueck,
* gmnga TYPE afru-gmnga,
* vornr
DATA : RS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
fieldcatalog-fieldname = 'AUFNR'.
fieldcatalog-seltext_m = 'Order'.
fieldcatalog-col_pos = 1.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'RUECK'.
fieldcatalog-seltext_M = 'CONEFERMATION'.
fieldcatalog-col_pos = 2.
fieldcatalog-emphasize = 'X'.
APPEND fieldcatalog TO fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'GMNGA'.
fieldcatalog-seltexT_M = 'YIELD'.
fieldcatalog-col_pos = 3.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ARBPL'.
fieldcatalog-seltext_M = 'WORK CENTER'.
fieldcatalog-col_pos = 4.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'VORNR'.
fieldcatalog-seltext_M = 'OP. ACTIVITY'.
fieldcatalog-col_pos = 5.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PLNBEZ'.
fieldcatalog-seltext_M = 'MATERIAL'.
fieldcatalog-col_pos = 6.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PLNME'.
fieldcatalog-seltext_M = 'UNIT'.
fieldcatalog-col_pos = 7.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_M = 'ENTERED BY'.
fieldcatalog-col_pos = 8.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FS_FCAT
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
wa_event-name = slis_ev_top_of_page.
wa_event-form = 'TOP_OF_PAGE'.
APPEND wa_event TO gt_events.
CLEAR wa_event.
wa_event-name = slis_ev_user_command.
wa_event-form = 'USER_COMMAND'.
APPEND wa_event TO gt_events.
CLEAR wa_event.
gd_layout-colwidth_optimize = 'X'.
gd_layout-zebra = 'X'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
* i_callback_pf_status_set = 'SET_PF_STATUS'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_final
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*----------------------------------------------------------*
* FORM SET_PF_STATUS *
*----------------------------------------------------------*
*FORM set_pf_status USING rt_extab TYPE slis_t_extab.
* SET PF-STATUS 'SAVE'.
* "Copy of 'STANDARD' pf_status from fgroup SALV
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
BREAK 10115.
* SELECT aufnr
* aufpl
* plnbez
* PLNME
* FROM afko
* INTO TABLE it_afko
* WHERE aufnr in s_afnr.
* aufpl TYPE afru-aufpl,
* rueck TYPE afru-rueck,
* gmnga TYPE afru-gmnga,
* vornr TYPE afru-vornr,
**select a~datum a~mblnr a~mjahr a~zeile a~werk a~lagerort a~bwart
** b~sernr b~matnr
** into table it_sernr
** from ser03 as a inner join objk as b
** on a~obknr = b~obknr
*** for all entries in it_mseg
*** where a~mblnr = it_mseg-mblnr
** WHERE a~datum in s_dat
** AND a~bwart = '101'
** AND a~werk in s_code
** AND a~lagerort IN S_strg
** AND b~matnr in s_mat.
SELECT a~aufnr a~aufpl a~plnbez a~plnme
b~aufpl b~rueck b~gmnga b~vornr b~ernam b~arbid INTO TABLE it_join
FROM AFko as a INNER JOIN afru AS b on a~aufpl = b~aufpl
* join afKO on afko~aufpl eq afru~aufpl
where a~aufnr in s_afnr.
*SELECT aufpl
* rueck
* gmnga
* vornr
* ernam
* arbid
* FROM afru
* INTO TABLE it_afru
* FOR ALL ENTRIES IN it_afko
* WHERE aufpl = it_afko-aufpl.
SELECT arbpl
FROM crhd
INTO TABLE it_crhd
FOR ALL ENTRIES IN it_join
WHERE objid = it_join-arbid.
*BREAK 10115.
*LOOP AT it_afru INTO wa_afru.
* wa_afru-gmnga = wa_afru-gmnga + wa_afru-gmnga.
* ENDLOOP.
LOOP AT IT_join INTO WA_join.
MOVE WA_join-AUFNR TO WA_FINAL-AUFNR.
MOVE WA_join-AUFPL TO WA_FINAL-AUFPL.
MOVE wa_join-plnbez to wa_final-plnbez.
MOVE WA_join-PLNME TO WA_FINAL-PLNME.
* READ TABLE IT_AFru INTO WA_AFru INDEX SY-TABIX.
MOVE WA_join-AUFPL TO WA_FINAL-AUFPL.
MOVE WA_join-RUECK TO WA_FINAL-RUECK.
MOVE WA_join-GMNGA TO WA_FINAL-GMNGA.
MOVE WA_join-VORNR TO WA_FINAL-VORNR.
MOVE WA_join-ERNAM TO WA_FINAL-ERNAM.
READ TABLE it_crhd INTO wa_crhd INDEX sy-tabix.
MOVE wa_crhd-arbpl to wa_final-arbpl.
APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.
*LOOP AT it_mseg INTO wa_mseg.
* wa_final-mblnr = wa_mseg-mblnr.
* wa_final-matnr = wa_mseg-matnr.
* wa_final-werks = wa_mseg-werks.
* wa_final-lgort = wa_mseg-lgort.
* wa_final-bwart = wa_mseg-bwart.
* wa_final-zeile = wa_mseg-zeile.
* wa_final-erfmg = wa_mseg-erfmg.
* wa_final-aufnr = wa_final-aufnr.
* READ TABLE it_mara INTO wa_mara WITH key matnr = wa_final-matnr.
* wa_final-matkl = wa_mara-matkl.
* APPEND wa_final to it_final.
** ENDLOOP.
*LOOP AT it_mkpf INTO wa_mkpf.
* wa_final-CPUDT = wa_mkpf-CPUDT.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING CPUDT.
* APPEND wa_final to it_final.
* ENDLOOP.
*LOOP AT it_makt INTO wa_makt.
* wa_final-maktx = wa_makt-maktx.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING maktx.
* APPEND wa_final to it_final.
* ENDLOOP.
*BREAK 10115.
*LOOP AT it_objk INTO wa_objk.
* wa_final-sernr = wa_objk-sernr.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING sernr.
** APPEND wa_final to it_final.
* ENDLOOP.
*LOOP AT it_mara INTO wa_mara.
* wa_final-matkl = wa_mara-matkl.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING matkl.
* APPEND wa_final to it_final.
* ENDLOOP.
endform. " DATA_RETRIEVAL
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'Daily Production Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_final lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform. "top-of-page
*------------------------------------------------------------------*
* FORM USER_COMMAND *
*------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*------------------------------------------------------------------*
*************************Double click Event**************************
*********************************************************************
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
* Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'AWKEY'.
BREAK 10115.
data: r_belnr type range of awkey,
r_belnr_l like line of r_belnr.
*now in the code replace1 your loop by this:
*loop at it_final into wa_final.
* r_belnr_l-sign = 'I'.
* r_belnr_l-OPTION = 'EQ'.
* r_belnr_l-LOW = wa_final-awkey.
* r_belnr_l-high = ' '.
* append r_belnr_l to r_belnr.
*endloop.
*SUBMIT RM08RELEASE VIA SELECTION-SCREEN WITH SO_BELNR IN r_belnr AND RETURN.
* LOOP AT it_final INTO wa_final.
ENDIF.
ENDCASE.
ENDFORM.
** Check field clicked on within ALVgrid report
* IF rs_selfield-fieldname = 'AWKEY'.
** Read data table, using index of row user clicked on
* READ TABLE it_final INTO wa_final INDEX rs_selfield-tabindex.
* BREAK 10115.
** Set parameter ID for transaction screen field
* SET PARAMETER ID 'AWK' FIELD wa_final-AWKEY.
* SET PARAMETER ID 'AWK' FIELD wa_final-AWKEY.
** Sxecute transaction MRBR, and skip initial data entry screen
* CALL TRANSACTION 'MRBR' AND SKIP FIRST SCREEN.
* ENDIF.
"user_command
*&---------------------------------------------------------------------*
*& Form BUILD_EVENTS
*&---------------------------------------------------------------------*
* Build events table
*----------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*&---------------------------------------------------------------------*
*& Form BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
* Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*& Form END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_PAGE
*&---------------------------------------------------------------------*
*& Form END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_LIST
*& Report ZCOOIS_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZCOOIS_REPORT.
TABLES: aufk,afru,afvc.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES : BEGIN OF ty_afko,
AUFNR TYPE afko-AUFNR,
aufpl TYPE afko-aufpl,
plnbez TYPE afko-plnbez,
PLNME TYPE AFKO-PLNME,
END OF ty_afko.
TYPES : BEGIN OF ty_afru,
aufpl TYPE afru-aufpl,
rueck TYPE afru-rueck,
gmnga TYPE afru-gmnga,
vornr TYPE afru-vornr,
ernam TYPE afru-ernam,
arbid TYPE afru-arbid,
END OF ty_afru.
TYPES : BEGIN OF ty_crhd,
arbpl TYPE crhd-arbpl,
END OF ty_crhd.
* afko~aufnr afko~aufpl afko~plnbez afko~plnme afru~aufpl afru~rueck afru~gmnga afru~vornr afru~ernam afru~arbid
TYPES : BEGIN OF ty_join,
AUFNR TYPE afko-AUFNR,
aufpl TYPE afko-aufpl,
plnbez TYPE afko-plnbez,
PLNME TYPE AFKO-PLNME,
aufpl1 TYPE afru-aufpl,
rueck TYPE afru-rueck,
gmnga TYPE afru-gmnga,
vornr TYPE afru-vornr,
ernam TYPE afru-ernam,
arbid TYPE afru-arbid,
END OF ty_join.
TYPES : BEGIN OF ty_final,
aufnr TYPE afko-aufnr,
plnbez TYPE afko-plnbez,
PLNME TYPE AFKO-PLNME,
aufpl TYPE afru-aufpl,
rueck TYPE afru-rueck,
gmnga TYPE afru-gmnga,
vornr TYPE afru-vornr,
ernam TYPE afru-ernam,
* ile03 TYPE afru-ile03,
arbpl TYPE crhd-arbpl,
END OF ty_final.
DATA : it_afko TYPE STANDARD TABLE OF ty_afko,
wa_afko TYPE ty_afko,
it_afru TYPE STANDARD TABLE OF ty_afru,
wa_afru TYPE ty_afru,
it_crhd TYPE STANDARD TABLE OF ty_crhd,
wa_crhd TYPE ty_crhd,
it_JOIN TYPE STANDARD TABLE OF ty_JOIN,
wa_JOIN TYPE ty_JOIN,
it_final TYPE STANDARD TABLE OF ty_final,
wa_final TYPE ty_final.
*
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv,
wa_event TYPE slis_alv_event.
DATA: t_fcat TYPE lvc_t_fcat,
fs_fcat TYPE lvc_s_fcat.
DATA: t_sort TYPE lvc_t_sort,
fs_sort TYPE lvc_s_sort.
fs_fcat-fieldname = 'GMNGA'.
fs_fcat-do_sum = 'X'.
APPEND fs_fcat TO t_fcat.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
BREAK 10115.
perform data_retrieval.
* if it_final[] IS INITIAL.
* MESSAGE 'Data is not found' TYPE 'I'.
* LEAVE LIST-PROCESSING.
* ENDIF.
perform build_FS_FCAT.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001 .
* SELECT-OPTIONS s_purch for ekbe-ebeln. ""Purchase Document
SELECT-OPTIONS s_afnr FOR wa_afko-AUFNR OBLIGATORY. "Posting Date
SELECTION-SCREEN END OF BLOCK a1.
*&---------------------------------------------------------------------*
*& Form BUILD_FS_FCAT
*&---------------------------------------------------------------------*
* Build FS_FCAT for ALV Report
*----------------------------------------------------------------------*
form build_FS_FCAT.
*
*aufnr TYPE afko-aufnr,
* aufpl TYPE afru-aufpl,
* rueck TYPE afru-rueck,
* gmnga TYPE afru-gmnga,
* vornr
DATA : RS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
fieldcatalog-fieldname = 'AUFNR'.
fieldcatalog-seltext_m = 'Order'.
fieldcatalog-col_pos = 1.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'RUECK'.
fieldcatalog-seltext_M = 'CONEFERMATION'.
fieldcatalog-col_pos = 2.
fieldcatalog-emphasize = 'X'.
APPEND fieldcatalog TO fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'GMNGA'.
fieldcatalog-seltexT_M = 'YIELD'.
fieldcatalog-col_pos = 3.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ARBPL'.
fieldcatalog-seltext_M = 'WORK CENTER'.
fieldcatalog-col_pos = 4.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'VORNR'.
fieldcatalog-seltext_M = 'OP. ACTIVITY'.
fieldcatalog-col_pos = 5.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PLNBEZ'.
fieldcatalog-seltext_M = 'MATERIAL'.
fieldcatalog-col_pos = 6.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PLNME'.
fieldcatalog-seltext_M = 'UNIT'.
fieldcatalog-col_pos = 7.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_M = 'ENTERED BY'.
fieldcatalog-col_pos = 8.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FS_FCAT
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
wa_event-name = slis_ev_top_of_page.
wa_event-form = 'TOP_OF_PAGE'.
APPEND wa_event TO gt_events.
CLEAR wa_event.
wa_event-name = slis_ev_user_command.
wa_event-form = 'USER_COMMAND'.
APPEND wa_event TO gt_events.
CLEAR wa_event.
gd_layout-colwidth_optimize = 'X'.
gd_layout-zebra = 'X'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
* i_callback_pf_status_set = 'SET_PF_STATUS'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_final
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*----------------------------------------------------------*
* FORM SET_PF_STATUS *
*----------------------------------------------------------*
*FORM set_pf_status USING rt_extab TYPE slis_t_extab.
* SET PF-STATUS 'SAVE'.
* "Copy of 'STANDARD' pf_status from fgroup SALV
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
BREAK 10115.
* SELECT aufnr
* aufpl
* plnbez
* PLNME
* FROM afko
* INTO TABLE it_afko
* WHERE aufnr in s_afnr.
* aufpl TYPE afru-aufpl,
* rueck TYPE afru-rueck,
* gmnga TYPE afru-gmnga,
* vornr TYPE afru-vornr,
**select a~datum a~mblnr a~mjahr a~zeile a~werk a~lagerort a~bwart
** b~sernr b~matnr
** into table it_sernr
** from ser03 as a inner join objk as b
** on a~obknr = b~obknr
*** for all entries in it_mseg
*** where a~mblnr = it_mseg-mblnr
** WHERE a~datum in s_dat
** AND a~bwart = '101'
** AND a~werk in s_code
** AND a~lagerort IN S_strg
** AND b~matnr in s_mat.
SELECT a~aufnr a~aufpl a~plnbez a~plnme
b~aufpl b~rueck b~gmnga b~vornr b~ernam b~arbid INTO TABLE it_join
FROM AFko as a INNER JOIN afru AS b on a~aufpl = b~aufpl
* join afKO on afko~aufpl eq afru~aufpl
where a~aufnr in s_afnr.
*SELECT aufpl
* rueck
* gmnga
* vornr
* ernam
* arbid
* FROM afru
* INTO TABLE it_afru
* FOR ALL ENTRIES IN it_afko
* WHERE aufpl = it_afko-aufpl.
SELECT arbpl
FROM crhd
INTO TABLE it_crhd
FOR ALL ENTRIES IN it_join
WHERE objid = it_join-arbid.
*BREAK 10115.
*LOOP AT it_afru INTO wa_afru.
* wa_afru-gmnga = wa_afru-gmnga + wa_afru-gmnga.
* ENDLOOP.
LOOP AT IT_join INTO WA_join.
MOVE WA_join-AUFNR TO WA_FINAL-AUFNR.
MOVE WA_join-AUFPL TO WA_FINAL-AUFPL.
MOVE wa_join-plnbez to wa_final-plnbez.
MOVE WA_join-PLNME TO WA_FINAL-PLNME.
* READ TABLE IT_AFru INTO WA_AFru INDEX SY-TABIX.
MOVE WA_join-AUFPL TO WA_FINAL-AUFPL.
MOVE WA_join-RUECK TO WA_FINAL-RUECK.
MOVE WA_join-GMNGA TO WA_FINAL-GMNGA.
MOVE WA_join-VORNR TO WA_FINAL-VORNR.
MOVE WA_join-ERNAM TO WA_FINAL-ERNAM.
READ TABLE it_crhd INTO wa_crhd INDEX sy-tabix.
MOVE wa_crhd-arbpl to wa_final-arbpl.
APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.
*LOOP AT it_mseg INTO wa_mseg.
* wa_final-mblnr = wa_mseg-mblnr.
* wa_final-matnr = wa_mseg-matnr.
* wa_final-werks = wa_mseg-werks.
* wa_final-lgort = wa_mseg-lgort.
* wa_final-bwart = wa_mseg-bwart.
* wa_final-zeile = wa_mseg-zeile.
* wa_final-erfmg = wa_mseg-erfmg.
* wa_final-aufnr = wa_final-aufnr.
* READ TABLE it_mara INTO wa_mara WITH key matnr = wa_final-matnr.
* wa_final-matkl = wa_mara-matkl.
* APPEND wa_final to it_final.
** ENDLOOP.
*LOOP AT it_mkpf INTO wa_mkpf.
* wa_final-CPUDT = wa_mkpf-CPUDT.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING CPUDT.
* APPEND wa_final to it_final.
* ENDLOOP.
*LOOP AT it_makt INTO wa_makt.
* wa_final-maktx = wa_makt-maktx.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING maktx.
* APPEND wa_final to it_final.
* ENDLOOP.
*BREAK 10115.
*LOOP AT it_objk INTO wa_objk.
* wa_final-sernr = wa_objk-sernr.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING sernr.
** APPEND wa_final to it_final.
* ENDLOOP.
*LOOP AT it_mara INTO wa_mara.
* wa_final-matkl = wa_mara-matkl.
* MODIFY it_final INDEX sy-tabix FROM wa_final
* TRANSPORTING matkl.
* APPEND wa_final to it_final.
* ENDLOOP.
endform. " DATA_RETRIEVAL
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'Daily Production Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_final lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform. "top-of-page
*------------------------------------------------------------------*
* FORM USER_COMMAND *
*------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*------------------------------------------------------------------*
*************************Double click Event**************************
*********************************************************************
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
* Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'AWKEY'.
BREAK 10115.
data: r_belnr type range of awkey,
r_belnr_l like line of r_belnr.
*now in the code replace1 your loop by this:
*loop at it_final into wa_final.
* r_belnr_l-sign = 'I'.
* r_belnr_l-OPTION = 'EQ'.
* r_belnr_l-LOW = wa_final-awkey.
* r_belnr_l-high = ' '.
* append r_belnr_l to r_belnr.
*endloop.
*SUBMIT RM08RELEASE VIA SELECTION-SCREEN WITH SO_BELNR IN r_belnr AND RETURN.
* LOOP AT it_final INTO wa_final.
ENDIF.
ENDCASE.
ENDFORM.
** Check field clicked on within ALVgrid report
* IF rs_selfield-fieldname = 'AWKEY'.
** Read data table, using index of row user clicked on
* READ TABLE it_final INTO wa_final INDEX rs_selfield-tabindex.
* BREAK 10115.
** Set parameter ID for transaction screen field
* SET PARAMETER ID 'AWK' FIELD wa_final-AWKEY.
* SET PARAMETER ID 'AWK' FIELD wa_final-AWKEY.
** Sxecute transaction MRBR, and skip initial data entry screen
* CALL TRANSACTION 'MRBR' AND SKIP FIRST SCREEN.
* ENDIF.
"user_command
*&---------------------------------------------------------------------*
*& Form BUILD_EVENTS
*&---------------------------------------------------------------------*
* Build events table
*----------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*&---------------------------------------------------------------------*
*& Form BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
* Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*& Form END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_PAGE
*&---------------------------------------------------------------------*
*& Form END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_LIST
SELECT sum( gamng ) AS gamng
ReplyDeleteFROM afko
INTO wa_afko-gamng
WHERE plnbez = wa_aufk-plnbez
and aufnr <>''.