SM30 保存校验事件 加Tcode

  •  选择合适事件

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

​​​​​​​

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值