背景:以下代碼實現瞭如何查看所有用戶的代碼
report z_hello.
tables:usr01.
data:fieldcat type slis_t_fieldcat_alv with header line, " THIS IS ALV usage
layout type slis_layout_alv.
data:begin of itab occurs 0, " This define a interal TABLE
bname type usr01-bname,
spld type usr01-spld,
end of itab.
selection-screen begin of block bk01 with frame title txt-01.
select-options: s_bname for usr01-bname no intervals .
selection-screen end of block bk01.
initialization.
start-of-selection.
perform get_data.
perform show_data.
end-of-selection.
* THIS IS A TEST PROGROM.
* WRITE 'Hello World!!!'." This is a text program
* WRITE 'Hello'.
*WRITE 'World'.
* select k~ebeln
* into corresponding fields of table itab
* from ekko as k
* where k~ebeln in ebeln1
* and k~bedat in bedat
* and k~ekgrp in ekgrp.
*
* loop at itab.
* select sum( menge ) into itab-menge
* from ekpo
* where ebeln eq itab-ebeln.
* modify itab.
* endloop.
*
* loop at itab.
* select sum( wemng ) into itab-wemng
* from eket
* where ebeln eq itab-ebeln.
* modify itab.
* endloop.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
select * from usr01 into corresponding fields of table itab where bname in s_bname and bname ne 'GUXL'.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form SHOW_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form show_data .
clear fieldcat.
define fieldcatset."宏定義
fieldcat-just = 'C'."字段居中顯示
fieldcat-outputlen = 10."自定義字段的長度
fieldcat-ref_tabname = 'BKPF'."調用透明表的數據結構
fieldcat-fieldname = &1."透明表字段名
fieldcat-seltext_l = &2."ALV列名
fieldcat-col_pos = &3."列位置
APPEND fieldcat.
end-of-definition.
fieldcatset 'BNAME' '用戶名' ''.
fieldcatset 'SPLD' '輸出設備' ''.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid "程序名稱
* i_callback_pf_status_set = 'FRM_SET_PF_STATUS'
* i_callback_user_command = 'ALV_USER_COMMAND' "對ALV操作的時候觸發所定義的子程序
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
i_grid_title = '會計憑證' "標題名
* I_GRID_SETTINGS =
is_layout = layout "程序所定義的layout名稱
it_fieldcat = fieldcat[] "定義fieldcat數據
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* 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
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = itab
exceptions "下面都是默認的
program_error = 1
others = 2.
if sy-subrc <> 0.
* Implement suitable error handling here
message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " SHOW_DATA
form frm_set_pf_status using pt_extab type slis_t_extab.
set pf-status 'ZHKALV1'.
endform.