Delete CKMLCR Record without CKMLPP Records

2021-08-31 12:05发布


          点击此处--->   EasySAP.com 群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)

SE38 program: MLHELP_DEL_CR_NO_PP


*&---------------------------------------------------------------------*
*& Report  MLHELP_DEL_CR_NO_PP                                         *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  mlhelp_del_cr_no_pp                     .

TABLES:
  ckmlhdckmlppckmlcrsscrfields.

SELECT-OPTIONS:
  s_matnr FOR ckmlhd-matnr,
  s_bwkey FOR ckmlhd-bwkey.

PARAMETERS:
  p_bdatj LIKE ckmlpp-bdatj OBLIGATORY DEFAULT '2006',
  p_poper LIKE ckmlpp-poper OBLIGATORY DEFAULT '009',
  p_test AS CHECKBOX DEFAULT 'X'.

TYPE-POOLS:
  slis.

DATA:  gd_master TYPE boole-boole.
DATA:  gd_dontpanic LIKE sy-datlo.

DATA:
  lt_ckmlhd LIKE ckmlhd OCCURS WITH HEADER LINE,
  lt_ckmlpp LIKE ckmlpp OCCURS WITH HEADER LINE,
  lt_ckmlcr LIKE ckmlcr OCCURS WITH HEADER LINE.

*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
*----------------------------------------------------------------------*
  LOOP AT SCREEN.
    CASE screen-name.
      WHEN 'P_TEST'.
        IF gd_master 'X'.
          screen-input '1'.
        ELSE.
          IF sy-batch IS INITIAL.
            p_test 'X'.
            screen-input '0'.
          ENDIF.
        ENDIF.
        MODIFY SCREEN.
      WHEN OTHERS.
    ENDCASE.
  ENDLOOP.


*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
  IF sscrfields-ucomm '42'.
*   Sitzt der Benutzerparameter?
    GET PARAMETER ID 'DONTPANIC' FIELD gd_dontpanic.
    IF gd_dontpanic EQ sy-datlo.
      gd_master 'X'.
    ENDIF.
  ENDIF.



*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*

  SELECT FROM ckmlhd INTO TABLE lt_ckmlhd
   WHERE matnr IN s_matnr
     AND bwkey IN s_bwkey.

  SELECT FROM ckmlpp INTO TABLE lt_ckmlpp
   FOR ALL ENTRIES IN lt_ckmlhd
   WHERE kalnr lt_ckmlhd-kalnr
     AND bdatj p_bdatj
     AND poper p_poper
     AND untper '000'.

  SELECT FROM ckmlcr INTO TABLE lt_ckmlcr
   FOR ALL ENTRIES IN lt_ckmlhd
   WHERE kalnr  lt_ckmlhd-kalnr
     AND bdatj p_bdatj
     AND poper  p_poper
     AND untper '000'.

  SORT lt_ckmlpp BY kalnr.

  LOOP AT lt_ckmlcr.
    READ TABLE lt_ckmlpp
      WITH KEY kalnr lt_ckmlcr-kalnr
      BINARY SEARCH.
    IF sy-subrc 0.
      DELETE lt_ckmlcr.
    ENDIF.
  ENDLOOP.

  WRITE'Records to delete:'.

  LOOP AT lt_ckmlcr.
    WRITE/ lt_ckmlcr-kalnrlt_ckmlcr-salk3.
  ENDLOOP.

  IF p_test IS INITIAL AND NOT lt_ckmlcr[] IS INITIAL.
    DELETE ckmlcr FROM TABLE lt_ckmlcr.
    WRITE/ sy-dbcnt'Records deleted from CKMLCR'.
  ENDIF.


赞赏支持