Using Menu Painter in SAP ABAP

+ -
Requirement: Develop a report to display material details for a material type, create a custom GUI to provide user to download the data into an excel sheet, provide back button only. Go to se38, create a program to display material details for a material type.
REPORT ZSAPN_MENU.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        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.
DATA : WA_MARA TYPE TY_MARA.

PARAMETERS : P_MTART TYPE MARA-MTART.

START-OF-SELECTION.

  SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA
    INTO TABLE IT_MARA
    WHERE MTART = P_MTART.

  LOOP AT IT_MARA INTO WA_MARA.
    WRITE : WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MBRSH, WA_MARA-MATKL, WA_MARA-MEINS.
  ENDLOOP.
Add below code after START-OF-SELECTION to create custom GUI,save and double click on the menu name to create custom GUI.
SET PF-STATUS 'ZSAPN_MENU'. "Double click on ZSAPN_MENU to create menu

Using menu painter in SAP ABAP reports

Click Yes

Using menu painter in SAP ABAP reports

Provide short text and enter.

Using menu painter in SAP ABAP reports

You can create menus, toolbar buttons, function keys by using menu painter.

Using menu painter in SAP ABAP reports

In this lesson we learn to create menu item ( download).

Expand Menu Bar, provide name as Download, double click on Download, provide code as DLOD and text as Download, save and activate.

Using menu painter in SAP ABAP reports

Go back to the program and add below code to download (when ever user click on download).

AT USER-COMMAND

This is a event which is used to implement user actions, it will trigger whenever a function button is pressed or a function code is pressed.

SY-UCOMM

SY-UCOMM is a system variable which stores the function code of the current action.

GUI_DOWNLOAD

GUI_DOWNLOAD is the function module which is used to download data from an internal table to local computer.

In order to implement the download functionality, we have to use AT USER-COMMAND event and SY-UCOMM system variable, here function code is DLOD, which we have provided in menu painter.

AT USER-COMMAND .
  IF SY-UCOMM = 'DLOD'.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*       BIN_FILESIZE                    =
        FILENAME = 'C:\MARA.XLS'
        FILETYPE = 'ASC'
*       APPEND   = ' '
*       WRITE_FIELD_SEPARATOR           = ' '
*       HEADER   = '00'
*       TRUNC_TRAILING_BLANKS           = ' '
*       WRITE_LF = 'X'
*       COL_SELECT                      = ' '
*       COL_SELECT_MASK                 = ' '
*       DAT_MODE = ' '
*       CONFIRM_OVERWRITE               = ' '
*       NO_AUTH_CHECK                   = ' '
*       CODEPAGE = ' '
*       IGNORE_CERR                     = ABAP_TRUE
*       REPLACEMENT                     = '#'
*       WRITE_BOM                       = ' '
*       TRUNC_TRAILING_BLANKS_EOL       = 'X'
*       WK1_N_FORMAT                    = ' '
*       WK1_N_SIZE                      = ' '
*       WK1_T_FORMAT                    = ' '
*       WK1_T_SIZE                      = ' '
*       WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*       SHOW_TRANSFER_STATUS            = ABAP_TRUE
*       VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'
*     IMPORTING
*       FILELENGTH                      =
      TABLES
        DATA_TAB = IT_MARA
*       FIELDNAMES                      =
*     EXCEPTIONS
*       FILE_WRITE_ERROR                = 1
*       NO_BATCH = 2
*       GUI_REFUSE_FILETRANSFER         = 3
*       INVALID_TYPE                    = 4
*       NO_AUTHORITY                    = 5
*       UNKNOWN_ERROR                   = 6
*       HEADER_NOT_ALLOWED              = 7
*       SEPARATOR_NOT_ALLOWED           = 8
*       FILESIZE_NOT_ALLOWED            = 9
*       HEADER_TOO_LONG                 = 10
*       DP_ERROR_CREATE                 = 11
*       DP_ERROR_SEND                   = 12
*       DP_ERROR_WRITE                  = 13
*       UNKNOWN_DP_ERROR                = 14
*       ACCESS_DENIED                   = 15
*       DP_OUT_OF_MEMORY                = 16
*       DISK_FULL                       = 17
*       DP_TIMEOUT                      = 18
*       FILE_NOT_FOUND                  = 19
*       DATAPROVIDER_EXCEPTION          = 20
*       CONTROL_FLUSH_ERROR             = 21
*       OTHERS   = 22
      .
    IF SY-SUBRC = 0.
      MESSAGE 'Data downloaded successfully' TYPE 'S'.
    ENDIF.


  ENDIF.

The final program code will be

REPORT ZSAPN_MENU.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        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.
DATA : WA_MARA TYPE TY_MARA.

PARAMETERS : P_MTART TYPE MARA-MTART.

START-OF-SELECTION.

  SET PF-STATUS 'ZSAPN_MENU'. "double click on ZSAPN_MENU to create menu

  SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA
    INTO TABLE IT_MARA UP TO 50 ROWS
    WHERE MTART = P_MTART .

  LOOP AT IT_MARA INTO WA_MARA.
    WRITE :/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MBRSH, WA_MARA-MATKL, WA_MARA-MEINS.
  ENDLOOP.

AT USER-COMMAND .
  IF SY-UCOMM = 'DLOD'.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*       BIN_FILESIZE                    =
        FILENAME = 'C:\MARA.XLS'
        FILETYPE = 'ASC'
*       APPEND   = ' '
*       WRITE_FIELD_SEPARATOR           = ' '
*       HEADER   = '00'
*       TRUNC_TRAILING_BLANKS           = ' '
*       WRITE_LF = 'X'
*       COL_SELECT                      = ' '
*       COL_SELECT_MASK                 = ' '
*       DAT_MODE = ' '
*       CONFIRM_OVERWRITE               = ' '
*       NO_AUTH_CHECK                   = ' '
*       CODEPAGE = ' '
*       IGNORE_CERR                     = ABAP_TRUE
*       REPLACEMENT                     = '#'
*       WRITE_BOM                       = ' '
*       TRUNC_TRAILING_BLANKS_EOL       = 'X'
*       WK1_N_FORMAT                    = ' '
*       WK1_N_SIZE                      = ' '
*       WK1_T_FORMAT                    = ' '
*       WK1_T_SIZE                      = ' '
*       WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*       SHOW_TRANSFER_STATUS            = ABAP_TRUE
*       VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'
*     IMPORTING
*       FILELENGTH                      =
      TABLES
        DATA_TAB = IT_MARA
*       FIELDNAMES                      =
*     EXCEPTIONS
*       FILE_WRITE_ERROR                = 1
*       NO_BATCH = 2
*       GUI_REFUSE_FILETRANSFER         = 3
*       INVALID_TYPE                    = 4
*       NO_AUTHORITY                    = 5
*       UNKNOWN_ERROR                   = 6
*       HEADER_NOT_ALLOWED              = 7
*       SEPARATOR_NOT_ALLOWED           = 8
*       FILESIZE_NOT_ALLOWED            = 9
*       HEADER_TOO_LONG                 = 10
*       DP_ERROR_CREATE                 = 11
*       DP_ERROR_SEND                   = 12
*       DP_ERROR_WRITE                  = 13
*       UNKNOWN_DP_ERROR                = 14
*       ACCESS_DENIED                   = 15
*       DP_OUT_OF_MEMORY                = 16
*       DISK_FULL                       = 17
*       DP_TIMEOUT                      = 18
*       FILE_NOT_FOUND                  = 19
*       DATAPROVIDER_EXCEPTION          = 20
*       CONTROL_FLUSH_ERROR             = 21
*       OTHERS   = 22
      .
    IF SY-SUBRC = 0.
      MESSAGE 'Data downloaded successfully' TYPE 'S'.
    ENDIF.
  ENDIF.
Provide a material type, execute the report, click on 'Download' link from menu, the data will be downloaded into C:\MARA.XLS, check it (when ever you are testing please close the excel file or else it will get a run time error ).

Using menu painter in SAP ABAP reports

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 62 People out of 64 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Lesson → ALV Reports