SAP ABAP 实现动态下拉框
自己用的小功能
REPORT z_matinal.
TYPE-POOLS:vrm.
DATA: name TYPE vrm_id.
DATA:num TYPE i. "内表判断字段长度的变量
TYPES: BEGIN OF wa ,
key(40),
text(80) TYPE c,
END OF wa.
DATA:gt LIKE t179t OCCURS 0 WITH HEADER LINE.
DATA:wa1 TYPE TABLE OF wa WITH HEADER LINE. "111
DATA:wa2 TYPE TABLE OF wa WITH HEADER LINE . "111222
DATA:wa3 TYPE TABLE OF wa WITH HEADER LINE. "111222333
DATA:itab LIKE t179t OCCURS 0 WITH HEADER LINE.
DATA: ps_t(15) TYPE c.
SELECTION-SCREEN BEGIN OF BLOCK t1 WITH FRAME TITLE title1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) TEXT-003.
PARAMETERS: pl1 LIKE ps_t AS LISTBOX VISIBLE LENGTH 15 USER-COMMAND p1 ."一级类
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) TEXT-004.
PARAMETERS: pl2 LIKE ps_t AS LISTBOX VISIBLE LENGTH 15 USER-COMMAND p2."二级类
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) TEXT-005.
PARAMETERS: pl3 LIKE ps_t AS LISTBOX VISIBLE LENGTH 15."三级类
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK t1.
INITIALIZATION.
gt-vtext = '1'.
gt-prodh = 'YI111'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI222'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI11145678'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI11198765'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI11112345'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI11156789'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI1114567812345678'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI1114567887654321'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI1115678123456789'.
APPEND gt .
gt-vtext = '1'.
gt-prodh = 'YI1115678987654321'.
APPEND gt .
AT SELECTION-SCREEN OUTPUT.
CLEAR:wa1,wa1[].
name = 'PL1'.
LOOP AT gt.
num = strlen( gt-prodh ).
IF num = 5.
wa1-text = gt-vtext.
wa1-key = gt-prodh.
APPEND: wa1.
ENDIF.
CLEAR: gt,num,wa1.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = name
values = wa1[].
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'P1'.
CLEAR: pl2,pl3. "清空2、3级下拉空默认值,当用户在选择屏幕上重新选择时需要清除
CLEAR:wa2,wa2[]. "清空2级下拉内表对应的值,当用户在选择屏幕上重新选择时需要清除
CLEAR num.
LOOP AT gt .
num = strlen( gt-prodh ).
IF num = 10 AND gt-prodh+0(5) = pl1.
wa2-text = gt-vtext.
wa2-key = gt-prodh.
APPEND: wa2.
ENDIF.
CLEAR:gt,num,wa2.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'PL2'
values = wa2[].
CLEAR pl2.
WHEN 'P2'.
CLEAR pl3. "清空3级下拉空默认值,当用户在选择屏幕上重新选择时需要清除
CLEAR:wa3,wa3[]. "清空3级下拉内表对应的值,当用户在选择屏幕上重新选择时需要清除
CLEAR num.
LOOP AT gt .
num = strlen( gt-prodh ).
IF num = 18 AND gt-prodh+0(10) = pl2.
wa3-text = gt-vtext.
wa3-key = gt-prodh.
APPEND: wa3.
ENDIF.
CLEAR:gt,num,wa3.
ENDLOOP.
* 公众号:matinal
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'PL3'
values = wa3[].
CLEAR pl3.
ENDCASE.