0% found this document useful (0 votes)
892 views9 pages

11-Menu Painter in SAP

The document describes how to create a custom GUI for an ABAP report using Menu Painter in SAP. Key points: - Menu Painter (transaction code SE41) allows creating custom menus, toolbar buttons, and function keys for an ABAP program - A report is created to display material details based on a material type - The SET PF-STATUS command is used to define a custom menu for the program - Menu items like "Download" are created using Menu Painter - Double clicking the menu name generates code to handle user commands - An AT USER-COMMAND check downloads the material data table to an Excel file when user clicks the download menu

Uploaded by

KIRAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
892 views9 pages

11-Menu Painter in SAP

The document describes how to create a custom GUI for an ABAP report using Menu Painter in SAP. Key points: - Menu Painter (transaction code SE41) allows creating custom menus, toolbar buttons, and function keys for an ABAP program - A report is created to display material details based on a material type - The SET PF-STATUS command is used to define a custom menu for the program - Menu items like "Download" are created using Menu Painter - Double clicking the menu name generates code to handle user commands - An AT USER-COMMAND check downloads the material data table to an Excel file when user clicks the download menu

Uploaded by

KIRAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Menu painter in SAP

Create a custom GUI using SAP menu painter, create custom toolbar buttons,
custom menu
Menu painter is used to create custom GUI with custom buttons, custom toolbar and custom
menu for a specific ABAP program.
The t-code for menu painter is SE41, we can create menu using SET PF-STATUS keyword from
ABAP program .
Syntax: SET PF-STATUS '<MENU NAME>' .

Create a custom GUI for a SAP ABAP program


Create an ABAP program ZSAPN_MENU_PAINTER in SE38.
Add the below code and double click on menu name to create menu.
SET PF-STATUS 'ZSAPN_MENU'. " Double click on ZSAPN_MENU to create

Click on Yes and provide short description, enter.

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 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 custon GUI,save and double click on
menu name to create custon GUI.
SET PF-STATUS 'ZSAPN_MENU'. "double click on ZSAPN_MENU to create menu

Click Yes

Provide short text and enter.

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

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.

Go back to 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 modules 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 provides 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

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

= 'X'

*
*

FIELDNAMES

EXCEPTIONS

FILE_WRITE_ERROR

=1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER

INVALID_TYPE

NO_AUTHORITY

UNKNOWN_ERROR

HEADER_NOT_ALLOWED

SEPARATOR_NOT_ALLOWED

FILESIZE_NOT_ALLOWED

HEADER_TOO_LONG

DP_ERROR_CREATE

DP_ERROR_SEND

= 12

DP_ERROR_WRITE

= 13

UNKNOWN_DP_ERROR

ACCESS_DENIED

DP_OUT_OF_MEMORY

DISK_FULL

DP_TIMEOUT

FILE_NOT_FOUND

DATAPROVIDER_EXCEPTION

CONTROL_FLUSH_ERROR

OTHERS = 22

=3

=4
=5
=6
=7
=8
=9
= 10
= 11

= 14
= 15
= 16
= 17
= 18
= 19
= 20
= 21

.
IF SY-SUBRC = 0.
MESSAGE 'Data downloaded successfully' TYPE 'S'.
ENDIF.

ENDIF.

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

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

*
*

=''
=''

=''
=''

=''
= 'X'

=''
=''
=''
=''

= '/SCET/GUI_DOWNLOAD'

IMPORTING
FILELENGTH

TABLES
DATA_TAB = IT_MARA
*
*

FIELDNAMES

EXCEPTIONS

FILE_WRITE_ERROR

=1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER

INVALID_TYPE

NO_AUTHORITY

UNKNOWN_ERROR

HEADER_NOT_ALLOWED

SEPARATOR_NOT_ALLOWED

FILESIZE_NOT_ALLOWED

HEADER_TOO_LONG

DP_ERROR_CREATE

DP_ERROR_SEND

= 12

DP_ERROR_WRITE

= 13

=3

=4
=5
=6
=7
=8
=9
= 10
= 11

UNKNOWN_DP_ERROR

= 14

ACCESS_DENIED

DP_OUT_OF_MEMORY

DISK_FULL

DP_TIMEOUT

FILE_NOT_FOUND

DATAPROVIDER_EXCEPTION

CONTROL_FLUSH_ERROR

OTHERS = 22

= 15
= 16
= 17
= 18
= 19
= 20
= 21

.
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
donloaded into C:\MARA.XLS, check it (when ever you are testing please close the excel filw or
else it will get a run time error ).

You might also like