Problem Statement:
In some situation, there will be a requirement to add custom button in application tool bar of ALV output. In this tutorial we will see the step by step procedure to add new button to application tool bar.
Step-1: Create the report ‘ZAPP_BUTTTON_RPT’ from SE38 transaction and copy paste the below code.
*&---------------------------------------------------------------------*
*& Report ZAPP_BUTTTON_RPT
*&---------------------------------------------------------------------*
REPORT zapp_buttton_rpt.
TYPE-POOLS: slis. " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: t_sbook TYPE TABLE OF sbook.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
x_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*--Fetch the required data from databaase table
SELECT * FROM sbook INTO TABLE t_sbook.
*--Build field catalog
x_fieldcat-fieldname = 'CARRID'. " Fieldname in the data table
x_fieldcat-seltext_m = 'Airline Name'." Column description
APPEND x_fieldcat TO t_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'CONNID'.
x_fieldcat-seltext_m = 'Con. No.'.
APPEND x_fieldcat TO t_fieldcat.
CLEAR x_fieldcat.
*--Call FM to disaplay data in ALV GRID format
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* i_callback_program =
* i_callback_pf_status_set = ''
* i_callback_user_command = ''
it_fieldcat = t_fieldcat
TABLES
t_outtab = t_sbook
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE 'Error in displaying output.' TYPE 'E'.
ENDIF.
Step-2: Save, Activate and Execute the above program. Output of the program looks like as follows.
Step-3: Now go to SE90 transaction.
Expand the Objects from the left 'Repository Information System' section as follows.
i.e. Repository Information System >> Program Library >> Program Subobjects >> GUI Status
Double click on GUI Status, and enter Program Name as 'SAPLKKBL' and Extcute.
The screen looks as follows.
Upon executing, we will see the list of available GUI Status
Step-3:
Select the CHECKBOX corresponds to STANDARD.
From Menu, go to GUI Status >> Copy (Click On COPY)
Step-4: Popup window appears, fill the details as follows and click on 'COPY'.
Step-5: Below window will appears, click on 'COPY'.
Step-6: Now the GUI status is copied to your program. This can be seen as below.
Step-7: Double click on the 'ZSTANDARD' GUI Status. It will take you to below screen.
Step-8: Enter the function code as '&BUT' as shown above and double click on the same to proceed further.
Upon double clicking following screen appears, select 'Static Text' Radio Button and press OK.
Step-9: Below screen appears, enter Function text, Icon Name and Information Text as show below and press OK.
As you can see in the above figure, we have selected "Folder Icon". You select the icon of your interest by F4 help on Icon name field.
Step-9: Assign Function to function key. In our example we have selected "Shift-F1", then press OK.
Step-10: Below screen appears, now validate the data entered and press OK.
Step-11: Upon pressing OK it will take you to below screen.
Save the changes to GUI status and Activate.
Step-12: Now go back to your program. Copy and Paste the below code. SAVE and ACTIVATE the program.
*&---------------------------------------------------------------------*
*& Report ZAPP_BUTTTON_RPT
*&---------------------------------------------------------------------*
REPORT zapp_buttton_rpt.
TYPE-POOLS: slis. " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: t_sbook TYPE TABLE OF sbook.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
x_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*--Fetch the required data from databaase table
SELECT * FROM sbook INTO TABLE t_sbook.
*--Build field catalog
x_fieldcat-fieldname = 'CARRID'. " Fieldname in the data table
x_fieldcat-seltext_m = 'Airline Name'." Column description
APPEND x_fieldcat TO t_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'CONNID'.
x_fieldcat-seltext_m = 'Con. No.'.
APPEND x_fieldcat TO t_fieldcat.
CLEAR x_fieldcat.
DATA: l_repid TYPE sy-repid.
l_repid = sy-repid.
*--Call FM to disaplay data in ALV GRID format
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
i_callback_pf_status_set = 'SUB_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = t_fieldcat
TABLES
t_outtab = t_sbook
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE 'Error in displaying output.' TYPE 'E'.
ENDIF.
*&---------------------------------------------------------------------*
*& Form sub_pf_status
*&---------------------------------------------------------------------*
* Sub-Routine to Set the PF status
*----------------------------------------------------------------------*
FORM sub_pf_status USING rt_extab TYPE slis_t_extab..
SET PF-STATUS 'ZSTANDARD'.
ENDFORM. "sub_pf_status
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* Sub-Routine to handle the click on the ALV aoutput
*----------------------------------------------------------------------*
FORM user_command USING r_ ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
IF r_ucomm EQ '&BUT'.
MESSAGE 'Custom button is clicked.' TYPE 'S'.
ENDIF.
ENDFORM. "User_command
Step-13: Execute(F8) the program. Now we can see the newly added BUTTON in application toolbar.
Click on the button to see the success message written in the code.
Conclusion:
Thus we have learnt the procedure to add the Button in Application Toolbar in ALV Output.
Regards,
Venugopal M N