3. 程序代码: 层级显示(hierarchical display)
此程序将层级显示PO(purchasing order)的细节(MM模块)。
TABLES : ekko,
ekpo.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
TYPE-POOLS: slis.
DATA: BEGIN OF headertab OCCURS 0,
ebeln LIKE ekko-ebeln,
bstyp LIKE ekko-bstyp,
bsart LIKE ekko-bsart,
statu LIKE ekko-statu,
END OF headertab.
DATA: BEGIN OF itemtab OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
peinh LIKE ekpo-peinh,
netwr LIKE ekpo-netwr,
END OF itemtab.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: v_repid LIKE sy-repid.
DATA: g_tabname_header TYPE slis_tabname,
g_tabname_item TYPE slis_tabname,
gs_keyinfo TYPE slis_keyinfo_alv.
START-OF-SELECTION.
v_repid = sy-repid.
SELECT ebeln bstyp bsart statu
INTO TABLE headertab
FROM ekko
WHERE ebeln IN s_ebeln.
IF NOT headertab[] IS INITIAL.
SELECT ebeln ebelp matnr werks menge netpr peinh netwr
INTO TABLE itemtab
FROM ekpo
FOR ALL ENTRIES IN headertab
WHERE ebeln = headertab-ebeln.
ENDIF.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'HEADERTAB'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
i_bypassing_buffer = 'X'
i_buffer_active = ' '
CHANGING
ct_fieldcat = i_fieldcat
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.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'ITEMTAB'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
i_bypassing_buffer = 'X'
i_buffer_active = ' '
CHANGING
ct_fieldcat = i_fieldcat
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.
gs_keyinfo-header01 = 'EBELN'.
gs_keyinfo-item01 = 'EBELN'.
g_tabname_header = 'HEADERTAB'.
g_tabname_item = 'ITEMTAB'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = v_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IS_LAYOUT =
IT_FIELDCAT = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = 'X'
I_SAVE = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
i_tabname_header = g_tabname_header
i_tabname_item = g_tabname_item
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
is_keyinfo = gs_keyinfo
* IS_PRINT =
* IS_REPREP_ID =
I_BYPASSING_BUFFER = 'X'
I_BUFFER_ACTIVE = ' '
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab_header = headertab
t_outtab_item = itemtab
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.
4. 程序代码: 多内表的ALV显示(display more than one internal table in ALV)
此程序将通过ALV显示两张内表的数据(MM模块)。
TABLES : ekko,
ekpo.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
TYPE-POOLS: slis.
DATA: BEGIN OF headertab OCCURS 0,
ebeln LIKE ekko-ebeln,
bstyp LIKE ekko-bstyp,
bsart LIKE ekko-bsart,
statu LIKE ekko-statu,
END OF headertab.
DATA: BEGIN OF itemtab OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
peinh LIKE ekpo-peinh,
netwr LIKE ekpo-netwr,
END OF itemtab.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_fieldcat1 TYPE slis_t_fieldcat_alv.
DATA: v_repid LIKE sy-repid,
v_layout TYPE slis_layout_alv,
v_events TYPE slis_t_event,
v_print TYPE slis_print_alv.
START-OF-SELECTION.
v_repid = sy-repid.
SELECT ebeln bstyp bsart statu
INTO TABLE headertab
FROM ekko
WHERE ebeln IN s_ebeln.
IF NOT headertab[] IS INITIAL.
SELECT ebeln ebelp matnr werks menge netpr peinh netwr
INTO TABLE itemtab
FROM ekpo
FOR ALL ENTRIES IN headertab
WHERE ebeln = headertab-ebeln.
ENDIF.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'HEADERTAB'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
i_bypassing_buffer = 'X'
i_buffer_active = ' '
CHANGING
ct_fieldcat = i_fieldcat
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.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'ITEMTAB'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
i_bypassing_buffer = 'X'
i_buffer_active = ' '
CHANGING
ct_fieldcat = i_fieldcat1
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.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = v_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
.
IF NOT headertab[] IS INITIAL.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = v_layout
it_fieldcat = i_fieldcat
i_tabname = 'HEADERTAB'
it_events = v_events
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = headertab
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.
ENDIF.
IF NOT itemtab[] IS INITIAL.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = v_layout
it_fieldcat = i_fieldcat1
i_tabname = 'ITEMTAB'
it_events = v_events
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = itemtab
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.
ENDIF.
IF NOT headertab[] IS INITIAL OR
NOT itemtab[] IS INITIAL.
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.
ENDIF.
5. 程序代码: ALV中的交互报表程序(interactive reporting in ALV)
此程序首先显示PO(Purchasing Order)的表头数据,点击PO的Number将展示相应的PO细节(MM模块)。
TABLES : ekko,
ekpo.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
TYPE-POOLS: slis.
DATA: BEGIN OF headertab OCCURS 0,
ebeln LIKE ekko-ebeln,
bstyp LIKE ekko-bstyp,
bsart LIKE ekko-bsart,
statu LIKE ekko-statu,
END OF headertab.
DATA: BEGIN OF itemtab OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
peinh LIKE ekpo-peinh,
netwr LIKE ekpo-netwr,
END OF itemtab.
DATA: BEGIN OF level2 OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
peinh LIKE ekpo-peinh,
netwr LIKE ekpo-netwr,
END OF level2.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_fieldcat1 TYPE slis_t_fieldcat_alv.
DATA: v_repid LIKE sy-repid,
v_layout TYPE slis_layout_alv,
v_events TYPE slis_t_event,
v_print TYPE slis_print_alv,
l_fieldcat TYPE slis_fieldcat_alv.
START-OF-SELECTION.
v_repid = sy-repid.
SELECT ebeln bstyp bsart statu
INTO TABLE headertab
FROM ekko
WHERE ebeln IN s_ebeln.
IF NOT headertab[] IS INITIAL.
SELECT ebeln ebelp matnr werks menge netpr peinh netwr
INTO TABLE itemtab
FROM ekpo
FOR ALL ENTRIES IN headertab
WHERE ebeln = headertab-ebeln.
ENDIF.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'HEADERTAB'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
i_bypassing_buffer = 'X'
i_buffer_active = ' '
CHANGING
ct_fieldcat = i_fieldcat
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 i_fieldcat INTO l_fieldcat.
CASE l_fieldcat-fieldname.
WHEN 'EBELN'.
l_fieldcat-hotspot = 'X'.
MODIFY i_fieldcat FROM l_fieldcat.
ENDCASE.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
i_bypassing_buffer = 'X'
i_buffer_active = ' '
i_callback_program = v_repid
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'USER_COMMAND'
* I_STRUCTURE_NAME =
* IS_LAYOUT =
it_fieldcat = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* 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 =
TABLES
t_outtab = headertab
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.
*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
IF rs_selfield-fieldname EQ 'EBELN'.
CASE r_ucomm.
WHEN '&IC1'.
READ TABLE headertab INDEX rs_selfield-tabindex.
REFRESH level2.
CLEAR level2.
LOOP AT itemtab WHERE ebeln = headertab-ebeln.
APPEND itemtab TO level2.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'LEVEL2'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
i_bypassing_buffer = 'X'
i_buffer_active = ' '
CHANGING
ct_fieldcat = i_fieldcat1
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.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
i_bypassing_buffer = 'X'
i_buffer_active = ' '
i_callback_program = v_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND =
* I_STRUCTURE_NAME =
* IS_LAYOUT =
it_fieldcat = i_fieldcat1
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* 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 =
TABLES
t_outtab = level2
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.
ENDCASE.
ENDIF.
ENDFORM. "USER_COMMAND
转自: