最近在写程序调用SM30时出现部分数据维护时报错,最终发现是调用时限制条件出错的原因。
程序要求是对工厂和库存地进行限制,当选择界面工厂和库存地不输入时无需做条件限制。
附程序部分代码:
FORM frm_call_sm30 .
DATA: lt_vimsellist LIKE vimsellist OCCURS 0 WITH HEADER LINE.
DATA: lt_vimexclfun LIKE vimexclfun OCCURS 0 WITH HEADER LINE.
DATA lv_line TYPE i.
DATA lv_xh TYPE i VALUE 0.
"清空数据
CLEAR lt_vimsellist[].
CLEAR lt_vimsellist.
"赋值数据
* IF s_werks-high IS INITIAL.
CLEAR : gt_werks ,gw_werks.
SELECT werks lgort_1
FROM ztmm_location
INTO CORRESPONDING FIELDS OF TABLE gt_werks
WHERE werks IN s_werks
AND lgort_1 IN s_lgort.
SORT gt_werks BY werks.
* DELETE ADJACENT DUPLICATES FROM gt_werks COMPARING werks.
DESCRIBE TABLE gt_werks LINES lv_line.
IF gt_werks IS NOT INITIAL.
CLEAR lv_xh.
IF s_werks IS NOT INITIAL AND
gt_werks[] IS NOT INITIAL.
LOOP AT gt_werks INTO gw_werks.
lv_xh = lv_xh + 1.
lt_vimsellist-viewfield = 'WERKS'.
lt_vimsellist-operator = 'EQ'.
lt_vimsellist-value = gw_werks-werks.
lt_vimsellist-and_or = 'OR'.
IF lv_xh = lv_line.
lt_vimsellist-and_or = 'AND'.
ENDIF.
APPEND lt_vimsellist.
ENDLOOP.
SORT lt_vimsellist BY viewfield value ASCENDING and_or DESCENDING.
DELETE ADJACENT DUPLICATES FROM lt_vimsellist COMPARING ALL FIELDS.
ENDIF.
IF s_lgort IS NOT INITIAL AND
gt_werks[] IS NOT INITIAL.
CLEAR lv_xh.
LOOP AT gt_werks INTO gw_werks.
lv_xh = lv_xh + 1.
lt_vimsellist-viewfield = 'LGORT_1'.
lt_vimsellist-operator = 'EQ'.
lt_vimsellist-value = gw_werks-lgort_1.
lt_vimsellist-and_or = 'OR'.
IF lv_xh = lv_line.
lt_vimsellist-and_or = 'AND'.
ENDIF.
APPEND lt_vimsellist.
ENDLOOP.
SORT lt_vimsellist BY viewfield and_or DESCENDING value ASCENDING.
DELETE ADJACENT DUPLICATES FROM lt_vimsellist COMPARING ALL FIELDS.
ENDIF.
IF p_active IS NOT INITIAL.
lt_vimsellist-viewfield = 'ACTIVE'.
lt_vimsellist-operator = 'EQ'.
lt_vimsellist-value = p_active.
* lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
ENDIF.
lt_vimexclfun-function = 'ANZG'."NEWL 新建 ANZG 修改显示切换 KOPE 复制权限
APPEND lt_vimexclfun .
lt_vimexclfun-function = 'KOPE'.
APPEND lt_vimexclfun.
ELSE.
IF s_werks-high IS NOT INITIAL.
lt_vimsellist-viewfield = 'WERKS'.
lt_vimsellist-operator = 'BT'.
lt_vimsellist-value = s_werks-low.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
lt_vimsellist-viewfield = 'WERKS'.
lt_vimsellist-operator = 'BT'.
lt_vimsellist-value = s_werks-high.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
IF s_lgort IS NOT INITIAL.
IF s_lgort-high IS NOT INITIAL.
lt_vimsellist-viewfield = 'LGORT_1'.
lt_vimsellist-operator = 'BT'.
lt_vimsellist-value = s_lgort-low.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
lt_vimsellist-viewfield = 'WERKS'.
lt_vimsellist-operator = 'BT'.
lt_vimsellist-value = s_lgort-high.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
ENDIF.
ELSE.
LOOP AT s_lgort.
lt_vimsellist-viewfield = 'LGORT_1'.
lt_vimsellist-operator = 'EQ'.
lt_vimsellist-value = s_lgort-low.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
ENDLOOP.
ENDIF.
ELSE.
LOOP AT s_werks.
lt_vimsellist-viewfield = 'WERKS'.
lt_vimsellist-operator = 'EQ'.
lt_vimsellist-value = s_werks-low.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
ENDLOOP.
IF s_lgort IS NOT INITIAL.
IF s_lgort-high IS NOT INITIAL.
lt_vimsellist-viewfield = 'LGORT_1'.
lt_vimsellist-operator = 'BT'.
lt_vimsellist-value = s_lgort-low.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
lt_vimsellist-viewfield = 'WERKS'.
lt_vimsellist-operator = 'BT'.
lt_vimsellist-value = s_lgort-high.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
ENDIF.
ELSE.
LOOP AT s_lgort.
lt_vimsellist-viewfield = 'LGORT_1'.
lt_vimsellist-operator = 'EQ'.
lt_vimsellist-value = s_lgort-low.
lt_vimsellist-and_or = 'AND'.
APPEND lt_vimsellist.
ENDLOOP.
ENDIF.
ENDIF.
lt_vimexclfun-function = 'ANZG'."NEWL 新建 ANZG 修改显示切换 KOPE 复制权限
APPEND lt_vimexclfun.
lt_vimexclfun-function = 'KOPE'.
APPEND lt_vimexclfun .
ENDIF.
"视图维护调用
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = 'U'
view_name = 'ZTMM_LOCATION'
TABLES
dba_sellist = lt_vimsellist
excl_cua_funct = lt_vimexclfun
EXCEPTIONS
client_reference = 1
foreign_lock = 2
invalid_action = 3
no_clientindependent_auth = 4
no_database_function = 5
no_editor_function = 6
no_show_auth = 7
no_tvdir_entry = 8
no_upd_auth = 9
only_show_allowed = 10
system_failure = 11
unknown_field_in_dba_sellist = 12
view_not_found = 13
maintenance_prohibited = 14
OTHERS = 15.
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.
只有符合lt_vimsellist内表中限制的条件的数据才会在SM30中查询和维护 。