Output:
Code:
___________________________________________________
**** Type pools for alv declarations ****
TYPE-POOLS: slis.
**** Display ALV Output ****
PERFORM display_alv
TABLES <Enter Block1 Final table name>
<Enter Block2 Final table name>.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* Display ALV Output
*----------------------------------------------------------------------*
* -->P_I_BLK1 Final Output Table for block1
* -->P_I_BLK2 Final Output Table for block2
*----------------------------------------------------------------------*
FORM display_alv TABLES p_i_blk1 STRUCTURE <Enter correct structure name>
p_i_blk2 STRUCTURE <Enter correct structure name>.
**** Data Declaration for ALV ****
DATA:
i_fcat_blk1 TYPE slis_t_fieldcat_alv, "Field catalog for blk1
i_fcat_blk2 TYPE slis_t_fieldcat_alv, "Field catalog for blk2
i_events_blk1 TYPE slis_t_event, "Events
i_events_blk2 TYPE slis_t_event, "Events
i_sort_blk1 TYPE slis_t_sortinfo_alv, "Sort block1
i_sort_blk2 TYPE slis_t_sortinfo_alv, "Sort block2
wa_layout_blk1 TYPE slis_layout_alv, "Block1 Layout
wa_layout_blk2 TYPE slis_layout_alv. "Block2 Layout
**** Initialize table & workarea ****
REFRESH: i_fcat_blk1, i_fcat_blk2, i_events_blk1, i_events_blk2.
REFRESH: i_sort_blk1, i_sort_blk2.
CLEAR : wa_layout_blk1, wa_layout_blk2.
**** Build Layout ****
* Build block1 layout
PERFORM layout_alv USING '1'
CHANGING wa_layout_blk1.
* Build block2 layout
PERFORM layout_alv USING '2'
CHANGING wa_layout_blk2.
**** Set Events ****
* Set events for block1
PERFORM set_events USING '1'
CHANGING i_events_blk1.
* Set events for block2
PERFORM set_events USING '2'
CHANGING i_events_blk2.
**** Build the field catalog ****
* Build Fcat for block1 using reference structure
PERFORM build_field_catalog_fm USING i_fcat_blk1
'P_I_BLK1'
'<Enter the Structure name>'.
* Build Fcat for block2
PERFORM build_field_catalog TABLES i_fcat_blk2 USING:
'P_I_BLK2' '<Enter Field1>' '<Enter Col1 description>' '<Enter 'X' if Total/Subtot reqd else ' '>' ,
'P_I_BLK2' '<Enter Field2>' '<Enter Col2 description>' '<Enter 'X' if Total/Subtot reqd else ' '>' .
**** Build sort table ****
PERFORM sort_table TABLES i_sort_blk1
USING: '<Enter Field Names in order of sorting>'
' '. "<Enter 'X' if subtotal should be calculated based on this field>
PERFORM sort_table TABLES i_sort_blk2
USING: '<Enter Field Names in order of sorting>'
' '. "<Enter 'X' if subtotal should be calculated based on this field>
**** Initialize Block List Output ****
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS_SET'
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
.
**** Append Simple List in Block Mode ****
* Append block1
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout_blk1
it_fieldcat = i_fcat_blk1
i_tabname = 'P_I_BLK1'
it_events = i_events_blk1
it_sort = i_sort_blk1
* I_TEXT = ' '
TABLES
t_outtab = p_i_blk1
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Append block1
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout_blk2
it_fieldcat = i_fcat_blk2
i_tabname = 'P_I_BLK2'
it_events = i_events_blk2
it_sort = i_sort_blk2
* I_TEXT = ' '
TABLES
t_outtab = p_i_blk2
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
**** Display block list ****
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form LAYOUT_ALV
*&---------------------------------------------------------------------*
* Set the layout
*----------------------------------------------------------------------*
* -->P_BLOCK block
* -->P_WA_LAYOUT layout
*----------------------------------------------------------------------*
FORM layout_alv USING p_block TYPE i
CHANGING p_wa_layout TYPE slis_layout_alv.
p_wa_layout-zebra = 'X'.
p_wa_layout-colwidth_optimize = 'X'.
p_wa_layout-totals_text = 'Total'.
p_wa_layout-subtotals_text = 'Sub Total'
IF p_block = '1'.
* Set Layout for block1
ELSEIF p_block = '2'.
* Set Layout for block2
ENDIF.
ENDFORM. " LAYOUT_ALV
*&---------------------------------------------------------------------*
*& Form SET_EVENTS
*&---------------------------------------------------------------------*
* Get the Events
*----------------------------------------------------------------------*
* -->P_BLOCK block
* -->P_I_EVENTS Events
*----------------------------------------------------------------------*
FORM set_events USING p_block TYPE i
CHANGING p_i_events TYPE slis_t_event.
**** Data Declaration ****
DATA : wa_events TYPE slis_alv_event.
CLEAR: wa_events.
**** Set Events ****
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
et_events = p_i_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.
IF sy-subrc EQ 0.
READ TABLE p_i_events INTO wa_events WITH KEY name = 'TOP_OF_LIST'.
IF sy-subrc = 0. "Set top-of-page Event
IF p_block = '1'.
wa_events-form = 'TOP_OF_LIST_BLK1'.
ELSEIF p_block = '2'.
wa_events-form = 'TOP_OF_LIST_BLK2'.
ENDIF.
MODIFY p_i_events FROM wa_events INDEX sy-tabix.
ENDIF.
READ TABLE p_i_events INTO wa_events WITH KEY name = 'USER_COMMAND'.
IF sy-subrc = 0. "Set user_command Event
IF p_block = '1'.
wa_events-form = 'USER_COMMAND_BLK1'.
ELSEIF p_block = '2'.
wa_events-form = 'USER_COMMAND_BLK2'.
ENDIF.
MODIFY p_i_events FROM wa_events INDEX sy-tabix.
ENDIF.
ENDIF.
ENDFORM. " SET_EVENTS
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG_FM
*&---------------------------------------------------------------------*
* Build the field catalog
*----------------------------------------------------------------------*
* -->p_i_fcat Field Catalog
* -->p_tabname Final table name
* -->p_struct Reference Structure name
*----------------------------------------------------------------------*
FORM build_field_catalog_fm USING p_i_fcat TYPE slis_t_fieldcat_alv
p_tabname TYPE slis_tabname
p_struct TYPE dd02l-tabname.
**** Data Declaration ****
DATA : wa_fcat TYPE slis_fieldcat_alv.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = p_tabname
i_structure_name = p_struct
* I_CLIENT_NEVER_DISPLAY = 'x'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = p_i_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT p_i_fcat INTO wa_fcat.
CASE wa_fcat-fieldname.
WHEN '<enter the field name for which total/subtotal is required>'.
wa_fcat-do_sum = 'X'.
WHEN '<enter the field name for which total/subtotal is required>'.
wa_fcat-do_sum = 'X'.
WHEN OTHERS.
ENDCASE.
MODIFY p_i_fcat FROM wa_fcat INDEX sy-tabix.
CLEAR wa_fcat.
ENDLOOP.
ENDFORM. " BUILD_FIELD_CATALOG_FM
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
* Build the field catalog
*----------------------------------------------------------------------*
* -->p_tabname Final table name
* -->p_fieldname Field name
* -->p_seltext_l Description
* -->p_i_fcat Field Catalog
* -->p_do_sum Sum up the field values
*----------------------------------------------------------------------*
FORM build_field_catalog TABLES p_i_fcat TYPE slis_t_fieldcat_alv
USING p_tabname TYPE slis_fieldcat_alv-tabname
p_fieldname TYPE slis_fieldcat_alv-fieldname
p_seltext_l TYPE slis_fieldcat_alv-seltext_l
p_do_sum TYPE c.
**** Data Declaration ****
DATA : wa_fcat TYPE slis_fieldcat_alv.
CLEAR: wa_fcat.
wa_fcat-tabname = p_tabname.
wa_fcat-fieldname = p_fieldname.
wa_fcat-seltext_l = p_seltext_l.
wa_fcat-do_sum = p_do_sum.
APPEND wa_fcat TO p_i_fcat.
CLEAR wa_fcat.
ENDFORM. " BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form SORT_TABLE
*&---------------------------------------------------------------------*
* Populate sort table
*----------------------------------------------------------------------*
* -->P_I_SORT sort table
* -->P_FIELD Field name; based on which the table is to be sorted
* -->P_SUBTOT If 'X', calculate subtotal based on P_FIELD
*----------------------------------------------------------------------*
FORM sort_table TABLES p_i_sort TYPE slis_t_sortinfo_alv
USING p_field TYPE slis_fieldname
p_subtot TYPE char1.
**** Data Declaration ****
DATA : wa_sort TYPE slis_sortinfo_alv.
STATICS: v_spos TYPE i.
CLEAR : wa_sort.
v_spos = v_spos + 1. "increment sort sequence
wa_sort-fieldname = p_field.
wa_sort-up = 'X'. "Sort in ascending order
wa_sort-spos = v_spos. "Sort Sequence
wa_sort-subtot = p_subtot. "Consider for subtotal
APPEND wa_sort TO p_i_sort.
ENDFORM. " SORT_TABLE
*&---------------------------------------------------------------------*
*& Form TOP_OF_LIST_BLK1
*&---------------------------------------------------------------------*
* populate the header
*----------------------------------------------------------------------*
FORM top_of_list_blk1 .
**** Data Declaration ****
DATA:
i_header TYPE slis_t_listheader, "Header
wa_header TYPE slis_listheader.
**** Initialize table & workarea ****
REFRESH: i_header.
CLEAR : wa_header.
* Populate Title
wa_header-typ = 'H'.
wa_header-info = sy-title. "Program Title.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Populate Current date
wa_header-typ = 'S'.
wa_header-key = 'Date :'.
CONCATENATE sy-datum+6(2) '.' sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info.
APPEND wa_header TO i_header.
CLEAR: wa_header.
* Populate Program name
wa_header-typ = 'S'.
wa_header-key = 'Program Name:'.
wa_header-info = sy-repid.
APPEND wa_header TO i_header.
CLEAR: wa_header.
* Populate User name
wa_header-typ = 'S'.
wa_header-key = 'User Name:'.
wa_header-info = sy-uname.
APPEND wa_header TO i_header.
CLEAR: wa_header.
* Display the header
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
REFRESH: i_header.
* Blank Line
wa_header-typ = 'H'.
wa_header-info = ' '.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Populate Block1 Description
wa_header-typ = 'H'.
wa_header-info = '<Enter Block1 Description>'.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Display the header
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
**** Free table memory ****
REFRESH: i_header.
ENDFORM. " TOP_OF_LIST_BLK1
*&---------------------------------------------------------------------*
*& Form TOP_OF_LIST_BLK2
*&---------------------------------------------------------------------*
* populate the header
*----------------------------------------------------------------------*
FORM top_of_list_blk2 .
**** Data Declaration ****
DATA:
i_header TYPE slis_t_listheader, "Header
wa_header TYPE slis_listheader.
**** Initialize table & workarea ****
REFRESH: i_header.
CLEAR : wa_header.
* Populate Block2 Description
wa_header-typ = 'H'.
wa_header-info = '<Enter Block2 Description>'.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Display the header
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
**** Free table memory ****
REFRESH: i_header.
ENDFORM. " TOP_OF_LIST_BLK2
*&---------------------------------------------------------------------*
*& Form USER_COMMAND_BLK1
*&---------------------------------------------------------------------*
* Perform User Command
*----------------------------------------------------------------------*
* -->P_V_UCOMM user command
* -->P_V_FIELD field name
*----------------------------------------------------------------------*
FORM user_command_blk1 USING p_v_ucomm TYPE sy-ucomm
p_v_field TYPE slis_selfield.
CASE p_v_ucomm.
WHEN '&IC1'. "User Command for Double Click
CASE p_v_field-fieldname. "check which ALV field was selected
WHEN '<Enter Field1 Name>'.
"<Enter/Write the logic to be performed when <Field1> is double clicked>
WHEN '<Enter Field2 Name>'.
"<Enter/Write the logic to be performed when <Field2> is double clicked>
WHEN OTHERS.
ENDCASE.
WHEN '<Enter User Command>'.
"<Enter/Write the logic to be performed at user command <User Command>>
WHEN OTHERS.
ENDCASE.
ENDFORM. " USER_COMMAND_BLK1
*&---------------------------------------------------------------------*
*& Form USER_COMMAND_BLK2
*&---------------------------------------------------------------------*
* Perform User Command
*----------------------------------------------------------------------*
* -->P_V_UCOMM user command
* -->P_V_FIELD field name
*----------------------------------------------------------------------*
FORM user_command_blk2 USING p_v_ucomm TYPE sy-ucomm
p_v_field TYPE slis_selfield.
CASE p_v_ucomm.
WHEN '&IC1'. "User Command for Double Click
CASE p_v_field-fieldname. "check which ALV field was selected
WHEN '<Enter Field1 Name>'.
"<Enter/Write the logic to be performed when <Field1> is double clicked>
WHEN '<Enter Field2 Name>'.
"<Enter/Write the logic to be performed when <Field2> is double clicked>
WHEN OTHERS.
ENDCASE.
WHEN '<Enter User Command>'.
"<Enter/Write the logic to be performed at user command <User Command>>
WHEN OTHERS.
ENDCASE.
ENDFORM. " USER_COMMAND_BLK2
*&---------------------------------------------------------------------*
*& Form PF_STATUS_SET
*&---------------------------------------------------------------------*
* Set PF Status
*----------------------------------------------------------------------*
* -->P_I_EXTAB exculding table (Function Codes)
*----------------------------------------------------------------------*
FORM pf_status_set USING p_i_extab TYPE slis_t_extab.
SET PF-STATUS '<Enter the status name>'
EXCLUDING p_i_extab.
ENDFORM. " PF_
TYPE-POOLS: slis.
**** Display ALV Output ****
PERFORM display_alv
TABLES <Enter Block1 Final table name>
<Enter Block2 Final table name>.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* Display ALV Output
*----------------------------------------------------------------------*
* -->P_I_BLK1 Final Output Table for block1
* -->P_I_BLK2 Final Output Table for block2
*----------------------------------------------------------------------*
FORM display_alv TABLES p_i_blk1 STRUCTURE <Enter correct structure name>
p_i_blk2 STRUCTURE <Enter correct structure name>.
**** Data Declaration for ALV ****
DATA:
i_fcat_blk1 TYPE slis_t_fieldcat_alv, "Field catalog for blk1
i_fcat_blk2 TYPE slis_t_fieldcat_alv, "Field catalog for blk2
i_events_blk1 TYPE slis_t_event, "Events
i_events_blk2 TYPE slis_t_event, "Events
i_sort_blk1 TYPE slis_t_sortinfo_alv, "Sort block1
i_sort_blk2 TYPE slis_t_sortinfo_alv, "Sort block2
wa_layout_blk1 TYPE slis_layout_alv, "Block1 Layout
wa_layout_blk2 TYPE slis_layout_alv. "Block2 Layout
**** Initialize table & workarea ****
REFRESH: i_fcat_blk1, i_fcat_blk2, i_events_blk1, i_events_blk2.
REFRESH: i_sort_blk1, i_sort_blk2.
CLEAR : wa_layout_blk1, wa_layout_blk2.
**** Build Layout ****
* Build block1 layout
PERFORM layout_alv USING '1'
CHANGING wa_layout_blk1.
* Build block2 layout
PERFORM layout_alv USING '2'
CHANGING wa_layout_blk2.
**** Set Events ****
* Set events for block1
PERFORM set_events USING '1'
CHANGING i_events_blk1.
* Set events for block2
PERFORM set_events USING '2'
CHANGING i_events_blk2.
**** Build the field catalog ****
* Build Fcat for block1 using reference structure
PERFORM build_field_catalog_fm USING i_fcat_blk1
'P_I_BLK1'
'<Enter the Structure name>'.
* Build Fcat for block2
PERFORM build_field_catalog TABLES i_fcat_blk2 USING:
'P_I_BLK2' '<Enter Field1>' '<Enter Col1 description>' '<Enter 'X' if Total/Subtot reqd else ' '>' ,
'P_I_BLK2' '<Enter Field2>' '<Enter Col2 description>' '<Enter 'X' if Total/Subtot reqd else ' '>' .
**** Build sort table ****
PERFORM sort_table TABLES i_sort_blk1
USING: '<Enter Field Names in order of sorting>'
' '. "<Enter 'X' if subtotal should be calculated based on this field>
PERFORM sort_table TABLES i_sort_blk2
USING: '<Enter Field Names in order of sorting>'
' '. "<Enter 'X' if subtotal should be calculated based on this field>
**** Initialize Block List Output ****
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS_SET'
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
.
**** Append Simple List in Block Mode ****
* Append block1
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout_blk1
it_fieldcat = i_fcat_blk1
i_tabname = 'P_I_BLK1'
it_events = i_events_blk1
it_sort = i_sort_blk1
* I_TEXT = ' '
TABLES
t_outtab = p_i_blk1
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Append block1
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout_blk2
it_fieldcat = i_fcat_blk2
i_tabname = 'P_I_BLK2'
it_events = i_events_blk2
it_sort = i_sort_blk2
* I_TEXT = ' '
TABLES
t_outtab = p_i_blk2
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
**** Display block list ****
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form LAYOUT_ALV
*&---------------------------------------------------------------------*
* Set the layout
*----------------------------------------------------------------------*
* -->P_BLOCK block
* -->P_WA_LAYOUT layout
*----------------------------------------------------------------------*
FORM layout_alv USING p_block TYPE i
CHANGING p_wa_layout TYPE slis_layout_alv.
p_wa_layout-zebra = 'X'.
p_wa_layout-colwidth_optimize = 'X'.
p_wa_layout-totals_text = 'Total'.
p_wa_layout-subtotals_text = 'Sub Total'
IF p_block = '1'.
* Set Layout for block1
ELSEIF p_block = '2'.
* Set Layout for block2
ENDIF.
ENDFORM. " LAYOUT_ALV
*&---------------------------------------------------------------------*
*& Form SET_EVENTS
*&---------------------------------------------------------------------*
* Get the Events
*----------------------------------------------------------------------*
* -->P_BLOCK block
* -->P_I_EVENTS Events
*----------------------------------------------------------------------*
FORM set_events USING p_block TYPE i
CHANGING p_i_events TYPE slis_t_event.
**** Data Declaration ****
DATA : wa_events TYPE slis_alv_event.
CLEAR: wa_events.
**** Set Events ****
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
et_events = p_i_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.
IF sy-subrc EQ 0.
READ TABLE p_i_events INTO wa_events WITH KEY name = 'TOP_OF_LIST'.
IF sy-subrc = 0. "Set top-of-page Event
IF p_block = '1'.
wa_events-form = 'TOP_OF_LIST_BLK1'.
ELSEIF p_block = '2'.
wa_events-form = 'TOP_OF_LIST_BLK2'.
ENDIF.
MODIFY p_i_events FROM wa_events INDEX sy-tabix.
ENDIF.
READ TABLE p_i_events INTO wa_events WITH KEY name = 'USER_COMMAND'.
IF sy-subrc = 0. "Set user_command Event
IF p_block = '1'.
wa_events-form = 'USER_COMMAND_BLK1'.
ELSEIF p_block = '2'.
wa_events-form = 'USER_COMMAND_BLK2'.
ENDIF.
MODIFY p_i_events FROM wa_events INDEX sy-tabix.
ENDIF.
ENDIF.
ENDFORM. " SET_EVENTS
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG_FM
*&---------------------------------------------------------------------*
* Build the field catalog
*----------------------------------------------------------------------*
* -->p_i_fcat Field Catalog
* -->p_tabname Final table name
* -->p_struct Reference Structure name
*----------------------------------------------------------------------*
FORM build_field_catalog_fm USING p_i_fcat TYPE slis_t_fieldcat_alv
p_tabname TYPE slis_tabname
p_struct TYPE dd02l-tabname.
**** Data Declaration ****
DATA : wa_fcat TYPE slis_fieldcat_alv.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = p_tabname
i_structure_name = p_struct
* I_CLIENT_NEVER_DISPLAY = 'x'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = p_i_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT p_i_fcat INTO wa_fcat.
CASE wa_fcat-fieldname.
WHEN '<enter the field name for which total/subtotal is required>'.
wa_fcat-do_sum = 'X'.
WHEN '<enter the field name for which total/subtotal is required>'.
wa_fcat-do_sum = 'X'.
WHEN OTHERS.
ENDCASE.
MODIFY p_i_fcat FROM wa_fcat INDEX sy-tabix.
CLEAR wa_fcat.
ENDLOOP.
ENDFORM. " BUILD_FIELD_CATALOG_FM
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
* Build the field catalog
*----------------------------------------------------------------------*
* -->p_tabname Final table name
* -->p_fieldname Field name
* -->p_seltext_l Description
* -->p_i_fcat Field Catalog
* -->p_do_sum Sum up the field values
*----------------------------------------------------------------------*
FORM build_field_catalog TABLES p_i_fcat TYPE slis_t_fieldcat_alv
USING p_tabname TYPE slis_fieldcat_alv-tabname
p_fieldname TYPE slis_fieldcat_alv-fieldname
p_seltext_l TYPE slis_fieldcat_alv-seltext_l
p_do_sum TYPE c.
**** Data Declaration ****
DATA : wa_fcat TYPE slis_fieldcat_alv.
CLEAR: wa_fcat.
wa_fcat-tabname = p_tabname.
wa_fcat-fieldname = p_fieldname.
wa_fcat-seltext_l = p_seltext_l.
wa_fcat-do_sum = p_do_sum.
APPEND wa_fcat TO p_i_fcat.
CLEAR wa_fcat.
ENDFORM. " BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form SORT_TABLE
*&---------------------------------------------------------------------*
* Populate sort table
*----------------------------------------------------------------------*
* -->P_I_SORT sort table
* -->P_FIELD Field name; based on which the table is to be sorted
* -->P_SUBTOT If 'X', calculate subtotal based on P_FIELD
*----------------------------------------------------------------------*
FORM sort_table TABLES p_i_sort TYPE slis_t_sortinfo_alv
USING p_field TYPE slis_fieldname
p_subtot TYPE char1.
**** Data Declaration ****
DATA : wa_sort TYPE slis_sortinfo_alv.
STATICS: v_spos TYPE i.
CLEAR : wa_sort.
v_spos = v_spos + 1. "increment sort sequence
wa_sort-fieldname = p_field.
wa_sort-up = 'X'. "Sort in ascending order
wa_sort-spos = v_spos. "Sort Sequence
wa_sort-subtot = p_subtot. "Consider for subtotal
APPEND wa_sort TO p_i_sort.
ENDFORM. " SORT_TABLE
*&---------------------------------------------------------------------*
*& Form TOP_OF_LIST_BLK1
*&---------------------------------------------------------------------*
* populate the header
*----------------------------------------------------------------------*
FORM top_of_list_blk1 .
**** Data Declaration ****
DATA:
i_header TYPE slis_t_listheader, "Header
wa_header TYPE slis_listheader.
**** Initialize table & workarea ****
REFRESH: i_header.
CLEAR : wa_header.
* Populate Title
wa_header-typ = 'H'.
wa_header-info = sy-title. "Program Title.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Populate Current date
wa_header-typ = 'S'.
wa_header-key = 'Date :'.
CONCATENATE sy-datum+6(2) '.' sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info.
APPEND wa_header TO i_header.
CLEAR: wa_header.
* Populate Program name
wa_header-typ = 'S'.
wa_header-key = 'Program Name:'.
wa_header-info = sy-repid.
APPEND wa_header TO i_header.
CLEAR: wa_header.
* Populate User name
wa_header-typ = 'S'.
wa_header-key = 'User Name:'.
wa_header-info = sy-uname.
APPEND wa_header TO i_header.
CLEAR: wa_header.
* Display the header
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
REFRESH: i_header.
* Blank Line
wa_header-typ = 'H'.
wa_header-info = ' '.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Populate Block1 Description
wa_header-typ = 'H'.
wa_header-info = '<Enter Block1 Description>'.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Display the header
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
**** Free table memory ****
REFRESH: i_header.
ENDFORM. " TOP_OF_LIST_BLK1
*&---------------------------------------------------------------------*
*& Form TOP_OF_LIST_BLK2
*&---------------------------------------------------------------------*
* populate the header
*----------------------------------------------------------------------*
FORM top_of_list_blk2 .
**** Data Declaration ****
DATA:
i_header TYPE slis_t_listheader, "Header
wa_header TYPE slis_listheader.
**** Initialize table & workarea ****
REFRESH: i_header.
CLEAR : wa_header.
* Populate Block2 Description
wa_header-typ = 'H'.
wa_header-info = '<Enter Block2 Description>'.
APPEND wa_header TO i_header.
CLEAR wa_header.
* Display the header
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
**** Free table memory ****
REFRESH: i_header.
ENDFORM. " TOP_OF_LIST_BLK2
*&---------------------------------------------------------------------*
*& Form USER_COMMAND_BLK1
*&---------------------------------------------------------------------*
* Perform User Command
*----------------------------------------------------------------------*
* -->P_V_UCOMM user command
* -->P_V_FIELD field name
*----------------------------------------------------------------------*
FORM user_command_blk1 USING p_v_ucomm TYPE sy-ucomm
p_v_field TYPE slis_selfield.
CASE p_v_ucomm.
WHEN '&IC1'. "User Command for Double Click
CASE p_v_field-fieldname. "check which ALV field was selected
WHEN '<Enter Field1 Name>'.
"<Enter/Write the logic to be performed when <Field1> is double clicked>
WHEN '<Enter Field2 Name>'.
"<Enter/Write the logic to be performed when <Field2> is double clicked>
WHEN OTHERS.
ENDCASE.
WHEN '<Enter User Command>'.
"<Enter/Write the logic to be performed at user command <User Command>>
WHEN OTHERS.
ENDCASE.
ENDFORM. " USER_COMMAND_BLK1
*&---------------------------------------------------------------------*
*& Form USER_COMMAND_BLK2
*&---------------------------------------------------------------------*
* Perform User Command
*----------------------------------------------------------------------*
* -->P_V_UCOMM user command
* -->P_V_FIELD field name
*----------------------------------------------------------------------*
FORM user_command_blk2 USING p_v_ucomm TYPE sy-ucomm
p_v_field TYPE slis_selfield.
CASE p_v_ucomm.
WHEN '&IC1'. "User Command for Double Click
CASE p_v_field-fieldname. "check which ALV field was selected
WHEN '<Enter Field1 Name>'.
"<Enter/Write the logic to be performed when <Field1> is double clicked>
WHEN '<Enter Field2 Name>'.
"<Enter/Write the logic to be performed when <Field2> is double clicked>
WHEN OTHERS.
ENDCASE.
WHEN '<Enter User Command>'.
"<Enter/Write the logic to be performed at user command <User Command>>
WHEN OTHERS.
ENDCASE.
ENDFORM. " USER_COMMAND_BLK2
*&---------------------------------------------------------------------*
*& Form PF_STATUS_SET
*&---------------------------------------------------------------------*
* Set PF Status
*----------------------------------------------------------------------*
* -->P_I_EXTAB exculding table (Function Codes)
*----------------------------------------------------------------------*
FORM pf_status_set USING p_i_extab TYPE slis_t_extab.
SET PF-STATUS '<Enter the status name>'
EXCLUDING p_i_extab.
ENDFORM. " PF_
Click here to Continue.