REUSE_ALV_LIST_DISPLAY- 22

light11Creating own PF Status and using it in ALV

 

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 21  how to hide few buttons in the toolbar that uses standard PF status. This post shows how to create own PF status and use it in ALV.


It is possible to create a PF status in same program where ALV is displayed but it is also possible to create a PF status in a function group and use that pf status in any program. Here a pf status is created in a function group .


57


Code Snippet:


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight,
box.
INCLUDE STRUCTURE spfli.
TYPES: END OF ty_flight.
DATA: lt_spfli TYPE TABLE OF ty_flight.
DATA: ls_spfli TYPE ty_flight.
DATA: ls_layout TYPE slis_layout_alv.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.

———————————–

START-OF-SELECTION.
PERFORM build_data.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_list_alv.

&————————————————-
& Form BUILD_DATA
&————————————————-*
FORM build_data.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————
FORM build_fieldcatalog.
DATA: ls_fieldcat TYPE LINE OF slis_t_fieldcat_alv.
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-cprog
I_INTERNAL_TABNAME =
i_structure_name = ‘SPFLI’
* I_CLIENT_NEVER_DISPLAY = ‘X’
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

ENDFORM. ” BUILD_FIELDCATALOG

&————————————————–
& Form BUILD_LAYOUT
&————————————————–*
FORM build_layout.
ls_layout-zebra = ‘X’.
ls_layout-box_fieldname = ‘BOX’.
ENDFORM. ” BUILD_LAYOUT

&————————————————–
& Form OWN_PF_STATUS
&————————————————–
FORM own_pf_status USING lt_EXCLUDE TYPE slis_t_extab.
SET PF-STATUS ‘DEMO_ALV_STATUS’ OF PROGRAM ‘SAPLZDEMO_ALV’ EXCLUDING lt_exclude.
ENDFORM. ” BUILD_LAYOUT
&—————————————————
& Form DISPLAY_LIST_ALV
&—————————————————-
FORM display_list_alv.

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
i_callback_program = sy-cprog
i_callback_pf_status_set = ‘OWN_PF_STATUS’   
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = lt_spfli
EXCEPTIONS
program_error = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ‘Program Error’ TYPE ‘I’.
WHEN OTHERS.
ENDCASE.
ENDFORM. ” DISPLAY_LIST_ALV


Program Output:  All 3 buttons are shown.

89


It is also possible to hide few buttons of the used own pf status .


Code Snippet:


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight,
box.
INCLUDE STRUCTURE spfli.
TYPES: END OF ty_flight.
DATA: lt_spfli TYPE TABLE OF ty_flight.
DATA: ls_spfli TYPE ty_flight.
DATA: ls_layout TYPE slis_layout_alv.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.

———————————–

START-OF-SELECTION.
PERFORM build_data.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_list_alv.

&————————————————-
& Form BUILD_DATA
&————————————————-*
FORM build_data.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————
FORM build_fieldcatalog.
DATA: ls_fieldcat TYPE LINE OF slis_t_fieldcat_alv.
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-cprog
I_INTERNAL_TABNAME =
i_structure_name = ‘SPFLI’
* I_CLIENT_NEVER_DISPLAY = ‘X’
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

ENDFORM. ” BUILD_FIELDCATALOG

&————————————————–
& Form BUILD_LAYOUT
&————————————————–*
FORM build_layout.
ls_layout-zebra = ‘X’.
ls_layout-box_fieldname = ‘BOX’.
ENDFORM. ” BUILD_LAYOUT

&————————————————–
& Form OWN_PF_STATUS
&————————————————–*
FORM own_pf_status USING lt_exclude TYPE slis_t_extab.
DATA: ls_exclude TYPE slis_extab.

” fill the function code of the button that you want to exclude
ls_exclude-fcode = ‘&ETA’.
APPEND ls_exclude TO lt_exclude.
SET PF-STATUS ‘DEMO_ALV_STATUS’ OF PROGRAM ‘SAPLZDEMO_ALV’ EXCLUDING lt_exclude.
ENDFORM. ” BUILD_LAYOUT
&—————————————————
& Form DISPLAY_LIST_ALV
&—————————————————-*
FORM display_list_alv.

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
i_callback_program = sy-cprog
i_callback_pf_status_set = ‘OWN_PF_STATUS’
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = lt_spfli
EXCEPTIONS
program_error = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ‘Program Error’ TYPE ‘I’.
WHEN OTHERS.
ENDCASE.
ENDFORM. ” DISPLAY_LIST_ALV


Program Output: One button is hidden/excluded from display.

10.jpg


 

Advertisements

One thought on “REUSE_ALV_LIST_DISPLAY- 22

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s