下拉选择联动
作者:互联网
REPORT zv_exec_r_019a.
TYPE-POOLS :vrm . " ListBox使用
DATA: name TYPE vrm_id,
list TYPE vrm_values,
list1 TYPE vrm_values,
list2 TYPE vrm_values,
value LIKE LINE OF list.
TABLES: sscrfields.
DATA: g_code TYPE sscrfields-ucomm.
DATA :num TYPE i . "根据PRODH字段长度判断 某行属于哪一级
DATA :loaded TYPE c LENGTH 1 . "控制不重复查询数据库和不反复append数据 to WA1[]
DATA:BEGIN OF ls_tvko,
vkorg TYPE tvko-vkorg, "销售机构(公司)
vtext TYPE tvkot-vtext, "销售机构描述
END OF ls_tvko.
DATA:lt_tvko LIKE TABLE OF ls_tvko.
DATA:BEGIN OF ls_tvkbt,
vkorg TYPE tvkbz-vkorg, "销售组织
vkbur TYPE tvkbz-vkbur, "板块
bezei TYPE tvkbt-bezei,
END OF ls_tvkbt.
DATA:lt_tvkbt LIKE TABLE OF ls_tvkbt.
DATA:BEGIN OF ls_tvgrt,
vkgrp TYPE tvbvk-vkgrp, "销售组
vkbur TYPE tvbvk-vkbur, "板块
bezei TYPE tvgrt-bezei,
END OF ls_tvgrt.
DATA:lt_tvgrt LIKE TABLE OF ls_tvgrt.
DATA: g_alv_ref TYPE REF TO cl_gui_alv_grid .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY AS LISTBOX VISIBLE LENGTH 15 USER-COMMAND p1,
p_vkbur TYPE vkbur AS LISTBOX VISIBLE LENGTH 15 USER-COMMAND p2,
p_vkgrp TYPE vkgrp AS LISTBOX VISIBLE LENGTH 15,
i_ld TYPE name.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION .
AT SELECTION-SCREEN OUTPUT .
name = 'P_VKORG' .
"""""* 销售部门
CLEAR:list.
SELECT vkorg vtext INTO CORRESPONDING FIELDS OF TABLE lt_tvko FROM tvkot WHERE spras = '1' .
LOOP AT lt_tvko INTO ls_tvko.
value-key = ls_tvko-vkorg.
value-text = ls_tvko-vtext.
APPEND value TO list.
CLEAR: ls_tvko.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_VKORG'
values = list.
""""销售组织
CLEAR:list1.
SELECT a~vkorg
a~vkbur
b~bezei
INTO CORRESPONDING FIELDS OF TABLE lt_tvkbt
FROM tvkbz AS a INNER JOIN tvkbt AS b ON a~vkbur = b~vkbur
WHERE b~spras = '1'.
SORT lt_tvkbt BY vkorg vkbur bezei.
DELETE ADJACENT DUPLICATES FROM lt_tvkbt.
""""""销售组
CLEAR:list2.
SELECT a~vkgrp
a~vkbur
b~bezei
INTO CORRESPONDING FIELDS OF TABLE lt_tvgrt
FROM tvbvk AS a INNER JOIN tvgrt AS b ON a~vkgrp = b~vkgrp
WHERE b~spras = '1'.
SORT lt_tvgrt BY vkgrp vkbur bezei.
DELETE ADJACENT DUPLICATES FROM lt_tvgrt.
AT SELECTION-SCREEN .
g_code = sscrfields-ucomm.
CASE g_code.
WHEN 'P1' .
CLEAR : p_vkbur ,p_vkgrp .
"清空2、3级下拉空默认值,当用户在选择屏幕上重新选择时需要清除
CLEAR :list1 .
"清空2级下拉内表对应的值,当用户在选择屏幕上重新选择时需要清除
CLEAR num .
LOOP AT lt_tvkbt INTO ls_tvkbt WHERE vkorg = p_vkorg.
value-key = ls_tvkbt-vkbur.
value-text = ls_tvkbt-bezei.
APPEND value TO list1.
IF sy-tabix EQ 1.
p_vkbur = ls_tvkbt-vkbur.
ENDIF.
CLEAR:ls_tvkbt.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_VKBUR'
values = list1.
WHEN 'P2' .
CLEAR p_vkgrp .
"清空3级下拉空默认值,当用户在选择屏幕上重新选择时需要清除
CLEAR :list2 .
"清空3级下拉内表对应的值,当用户在选择屏幕上重新选择时需要清除
CLEAR num .
LOOP AT lt_tvgrt INTO ls_tvgrt WHERE vkbur = p_vkbur.
value-key = ls_tvgrt-vkgrp.
value-text = ls_tvgrt-bezei.
APPEND value TO list2.
IF sy-tabix EQ 1.
p_vkgrp = ls_tvgrt-vkgrp.
ENDIF.
CLEAR:ls_tvgrt.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_VKGRP'
values = list2.
ENDCASE .
*&---------------------------------------------------------------------*
*& Form f_set_alv_status
*&---------------------------------------------------------------------*
* 设置GUI状态
*----------------------------------------------------------------------*
FORM f_set_alv_status USING pi_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS_100' EXCLUDING pi_extab.
ENDFORM. " f_set_alv_status
*&---------------------------------------------------------------------*
*& Form f_alv_user_command
*&---------------------------------------------------------------------*
* 响应ALV的事件
*----------------------------------------------------------------------*
FORM f_alv_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* 响应屏幕按钮的动作
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = g_alv_ref.
CASE r_ucomm.
WHEN 'PUSHT'."新增
WHEN OTHERS.
ENDCASE.
rs_selfield-refresh = 'X'.
CALL METHOD g_alv_ref->refresh_table_display.
ENDFORM. " f_alv_user_command
*&---------------------------------------------------------------------*
标签:tvkbt,vkbur,选择,lt,ls,联动,tvgrt,TYPE 来源: https://www.cnblogs.com/cl5lc/p/16104891.html