Develop a Classical Report to display list of materials for a material input range(select-Options) and for a material type (screen input) with validations, search help and value help, the report can be able to download into excel sheet.
Input elements : Select-options for matnr ( material no for MARA table), parameter mtart( Material type from MARA), a check box and a parameter limit for limiting no of results.
When ever we click on download data, select file to download field will be enabled otherwise this should be disabled.
Input Screen.
REPORT ZCLASSICAL_REPORT_EVENTS LINE-COUNT 20(3). "20 lines are for report space and 3 lines are for footer space
TABLES : MARA.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA. "material out put internal table
DATA : WA_MARA TYPE TY_MARA. " work area
DATA : LV_MTART TYPE MARA-MTART.
DATA : LV_START_TIME TYPE SY-UZEIT .
DATA : LV_END_TIME TYPE SY-UZEIT .
TABLES : MARA.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA. "material out put internal table
DATA : WA_MARA TYPE TY_MARA. " work area
DATA : LV_MTART TYPE MARA-MTART.
DATA : LV_START_TIME TYPE SY-UZEIT .
DATA : LV_END_TIME TYPE SY-UZEIT .
DATA : LV_SKIP TYPE I.
DATA : LV_LINNO TYPE SY-LINNO. "To get the number of current line in list
DATA : LV_LINCT TYPE SY-LINCT. "To get the declared line count (Page length of list)
DATA : LV_LINNO TYPE SY-LINNO. "To get the number of current line in list
DATA : LV_LINCT TYPE SY-LINCT. "To get the declared line count (Page length of list)
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. "designs a block just for design double click on TEXT-001 to add text
SELECT-OPTIONS : S_MATNR FOR MARA-MATNR. " Material range input
PARAMETERS : P_MTART TYPE MARA-MTART. "material type input
SELECTION-SCREEN END OF BLOCK B1.
PARAMETERS P_DLOAD AS CHECKBOX USER-COMMAND UC1.
PARAMETERS P_FILE TYPE RLGRAP-FILENAME MODIF ID DLD .
PARAMETERS P_LIMIT TYPE I . "Limit no of rows to display to avoid burden on database
LOAD-OF-PROGRAM. "loads program into memory (1)
LV_START_TIME = SY-UZEIT .
INITIALIZATION. "triggers second (2)
P_MTART = 'FERT'. "MATERIAL TYPE DEFAULT VALUE
P_LIMIT = '50'. "Limit rows to 50
AT SELECTION-SCREEN OUTPUT . "for dynamic modifications (3)
IF P_DLOAD IS INITIAL .
LOOP AT SCREEN.
CHECK SCREEN-GROUP1 = 'DLD'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN ON P_MTART . " Validate single input field at selection-screen(4)
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_MTART . " Validate single input field(5)
PERFORM MTART_VALUE_HELP.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE .
PERFORM FILE_VALUE_HELP .
AT SELECTION-SCREEN ON HELP-REQUEST FOR P_MTART . " Provide help request F1 help(6)
PERFORM MTART_HELP.
AT SELECTION-SCREEN. " At selection screen(7)
PERFORM VALIDATE_INPUTS.
START-OF-SELECTION. " Start of selection(8)
PERFORM GET_MATERIALS .
END-OF-SELECTION. " End of selection(9)
LV_END_TIME = SY-UZEIT .
PERFORM DISPLAY_OUTPUT.
IF P_DLOAD = 'X'.
PERFORM DOWNLOAD_DATA.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE .
PERFORM FILE_VALUE_HELP .
AT SELECTION-SCREEN ON HELP-REQUEST FOR P_MTART . " Provide help request F1 help(6)
PERFORM MTART_HELP.
AT SELECTION-SCREEN. " At selection screen(7)
PERFORM VALIDATE_INPUTS.
START-OF-SELECTION. " Start of selection(8)
PERFORM GET_MATERIALS .
END-OF-SELECTION. " End of selection(9)
LV_END_TIME = SY-UZEIT .
PERFORM DISPLAY_OUTPUT.
IF P_DLOAD = 'X'.
PERFORM DOWNLOAD_DATA.
ENDIF.
"To trigger End-of-page event (Begin)
lv_linno = sy-linno.
lv_linct = sy-linct.
lv_skip = lv_linct - lv_linno.
lv_skip = lv_skip - 1.
SKIP lv_skip.
"To trigger End-of-page event (End)
lv_linno = sy-linno.
lv_linct = sy-linct.
lv_skip = lv_linct - lv_linno.
lv_skip = lv_skip - 1.
SKIP lv_skip.
"To trigger End-of-page event (End)
TOP-OF-PAGE. " Top of page(10)
WRITE : 'Material Details ' COLOR 2.
END-OF-PAGE. " End of page(11)
WRITE : 'The above materials are active materials available in database' COLOR 3.
WRITE : 'Start time' .
WRITE : LV_START_TIME .
WRITE : 'End time' .
WRITE : LV_END_TIME .
FORM VALIDATE_INPUTS .
IF S_MATNR IS INITIAL OR P_MTART IS INITIAL.
MESSAGE 'Please enter required inputs' TYPE 'E'.
ELSE.
***Validate material type is valid or not
SELECT MTART FROM MARA INTO LV_MTART
UP TO 1 ROWS WHERE MTART = P_MTART .
ENDSELECT.
IF LV_MTART IS INITIAL.
MESSAGE 'Material type is not available in MARA' TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_INPUTS
FORM GET_MATERIALS .
SELECT MATNR ERSDA MTART MBRSH MATKL MEINS FROM MARA
INTO TABLE IT_MARA
UP TO P_LIMIT ROWS
WHERE MATNR IN S_MATNR AND MTART = P_MTART .
ENDFORM. " GET_MATERIALS
FORM DISPLAY_OUTPUT .
IF IT_MARA IS NOT INITIAL.
LOOP AT IT_MARA INTO WA_MARA.
WRITE :/ WA_MARA-MATNR, WA_MARA-ERSDA, WA_MARA-MTART, WA_MARA-MBRSH, WA_MARA-MATKL, WA_MARA-MEINS .
ENDLOOP.
ELSE.
WRITE : 'No Data Found for your Query'.
ENDIF.
ENDFORM. " DISPLAY_OUTPUT
FORM MTART_HELP .
MESSAGE 'Enter a Material Type ' TYPE 'I'.
ENDFORM. " MTART_HELP
FORM MTART_VALUE_HELP .
MESSAGE 'Material type input ex: FERT' TYPE 'I'.
ENDFORM. " MTART_VSLUE_HELP
FORM DOWNLOAD_DATA .
DATA : LV_FILE TYPE STRING .
LV_FILE = P_FILE .
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LV_FILE
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT_MARA
.
IF SY-SUBRC = 0.
WRITE :/ 'Data downloaded to'.
WRITE : P_FILE.
ENDIF.
ENDFORM. " DOWNLOAD_DATA
FORM FILE_VALUE_HELP .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE.
ENDFORM. " FILE_VALUE_HELP