- 选择合适事件
FORM frm_check_data ##CALLED .
DATA:ls_klah TYPE klah,
lt_klah TYPE TABLE OF klah.
DATA:ls_tmp TYPE zmmt0013d,
lt_tmp TYPE TABLE OF zmmt0013d.
DATA:lv_flg TYPE char1,
lv_msg TYPE char25.
* 整理需检查的数据
LOOP AT total.
IF <action> EQ 'N' OR <action> EQ 'U' .
MOVE-CORRESPONDING <vim_total_struc> TO ls_tmp.
* 必输校验
IF ls_tmp-zcpxh IS INITIAL OR ls_tmp-zclass1 IS INITIAL OR ls_tmp-zclass1t IS INITIAL
OR ls_tmp-zclass2 IS INITIAL OR ls_tmp-zclass2t IS INITIAL.
lv_flg = '1'.
ELSE.
APPEND ls_tmp TO lt_tmp.
CLEAR:ls_tmp.
ENDIF.
ENDIF.
ENDLOOP.
* 校验分类是否在klah中存在
SELECT a~*
FROM klah AS a
WHERE a~klart = '001'
AND a~klagr = 'CLASS-03'
INTO TABLE @DATA(lt_data).
IF sy-subrc = 0.
SORT lt_data BY class.
ENDIF.
* 校验产品型号是否在klah中存在
SELECT a~*
FROM klah AS a
WHERE a~klart = '001'
AND a~klagr = 'PRD_MODEL'
INTO TABLE @DATA(lt_data1).
IF sy-subrc = 0.
SORT lt_data1 BY class.
ENDIF.
LOOP AT lt_tmp INTO ls_tmp.
* 检验一级分类
READ TABLE lt_data INTO DATA(ls_data) WITH KEY class = ls_tmp-zclass1 BINARY SEARCH.
IF sy-subrc <> 0.
lv_flg = '2'.
CLEAR:ls_data.
ENDIF.
* 检验二级分类
READ TABLE lt_data INTO ls_data WITH KEY class = ls_tmp-zclass2 BINARY SEARCH.
IF sy-subrc <> 0.
lv_flg = '2'.
CLEAR:ls_data.
ENDIF.
* 校验产品型号
READ TABLE lt_data1 INTO ls_data WITH KEY class = ls_tmp-zcpxh BINARY SEARCH.
IF sy-subrc <> 0.
lv_flg = '3'.
CLEAR:ls_data.
ENDIF.
CLEAR:ls_tmp.
ENDLOOP.
* 必输
IF lv_flg = '1'.
MESSAGE '请检查必输字段!' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = abap_true."c_abrt_save.
sy-subrc = 4.
ELSEIF lv_flg = '2'.
* 分类
MESSAGE '表中暂无该分类' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = abap_true."c_abrt_save.
sy-subrc = 4.
ELSEIF lv_flg = '3'.
* 产品型号
MESSAGE '表中暂无该产品型号' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = abap_true."c_abrt_save.
sy-subrc = 4.
ELSE.
* vim_abort_saving = abap_true."c_abrt_save.
sy-subrc = 0.
ENDIF.
ENDFORM.
添加Tcode