Skip to Content

*&———————————————————————
*& Report  BUPA_TEST_DELETE                                            *
*&                                                                     *
*&———————————————————————*
*&                                                                     *
*&                                                                     *
*&———————————————————————*

REPORT  BUPA_TEST_DELETE                        .

********* Data definitions ****************************************
tables: but000.

types: begin of ty_partner,
           partner type bu_partner,
           end of ty_partner.

DATAgv_cursor TYPE cursor,
       lv_partner type bu_partner,
       gt_partners type sorted table of ty_partner with unique key
       partner,
       lv_message type char80,
       lv_answer,
       lv_dele1_check type boole_d,
       lt_results type bapiret2_t,
       ls_result  type bapiret2,
       lt_partner_range type standard table of bus0range,
       ls_partner_range type bus0range,
       lt_partners_deleted type standard table of BUSSDELYES,
       ls_partner like line of lt_partners_deleted,
       lv_counter type i,
       lv_error   type boole_d.

*changes to implement the authorisation check

DATALS_RETURN                LIKE BAPIRET2,
        LV_MSGV1                 LIKE SYMSGV1,
        LV_RC                    LIKE SYSUBRC,
        LV_AUTH_CHECK_SUPPRESSED LIKE BOOLEBOOLE,
        IV_AKTYP                 LIKE TBZ0KAKTYP,
        IV_AUTHORIZATIONGROUP    like BUT000AUGRP.

*end of changes to implement the authorisation check

constants: gc_X type boole_d value ‘X’,
                 gc_max_commit type i value ‘750’.

*********** Selection screen ***************************************
select-options: partner for but000partner obligatory.

parameters:     xdele   type boole_d as checkbox default ‘ ‘,
                       statd   type boole_d as checkbox default ‘X’,
                      test    type boole_d as checkbox default ‘X’.


parameters: nodial type boole_d default ‘ ‘ nodisplay.

CLEAR: lv_counter, lv_error.

******** Main program *********************************************
if test is initial and sybatch is initial and nodial is initial.
*changes are done to implement the authorisation check

    IV_AKTYP = ’06’.
    IV_AUTHORIZATIONGROUP = ‘DEL’.
    AUTHORITY-CHECK OBJECT ‘B_BUPA_GRP’
            ID ‘ACTVT’ FIELD IV_AKTYP
            ID ‘BEGRU’ FIELD IV_AUTHORIZATIONGROUP.
       LV_RC = SYSUBRC.

  IF NOT LV_RC IS INITIAL.
        MESSAGE E777(R11) WITH IV_AUTHORIZATIONGROUP.
        EXIT.
  ELSE.

*end of changes to implement the authorisation check

  CALL FUNCTION ‘POPUP_TO_CONFIRM’
    EXPORTING
      TITLEBAR              = textp00
      TEXT_QUESTION         = textp01
      TEXT_BUTTON_1         = textp02
      ICON_BUTTON_1         = ‘ICON_CHECKED’
      TEXT_BUTTON_2         = textp04
      ICON_BUTTON_2         = ‘ICON_INCOMPLETE’
      DEFAULT_BUTTON        = ‘2’
      DISPLAY_CANCEL_BUTTON = ‘ ‘
      START_COLUMN          = 25
      START_ROW             = 6
    IMPORTING
      ANSWER                = lv_answer
    EXCEPTIONS
      TEXT_NOT_FOUND        = 1
      OTHERS                = 2.
  IF SYSUBRC <> 0 .
    MESSAGE ID SYMSGID TYPE SYMSGTY NUMBER SYMSGNO
            WITH SYMSGV1 SYMSGV2 SYMSGV3 SYMSGV4.
    exit.
  ENDIF.
  if lv_answer = ‘A’ or lv_answer = ‘2’.
    exit.
  endif.
endif.
endif.

if xdele = gc_X and statd = ‘ ‘.
* OPEN CURSOR WITH HOLD gv_cursor FOR
     SELECT  partner FROM  BUT000
        INTO TABLE gt_partners
        WHERE  PARTNER  in partner
        AND    XDELE    = gc_X.
elseif xdele = ‘ ‘ and statd = gc_X.

*  OPEN CURSOR WITH HOLD gv_CURSOR FOR
           SELECT t3~partner
                 INTO TABLE gt_partners
                 from  CRM_JSTO AS t1
                       inner join CRM_JEST as t2
                             on t1~OBJNR = t2~OBJNR
                       inner join BUT000 as t3
                             on t3~PARTNER_GUID = t2~OBJNR
                 WHERE ( t2~STAT    = ‘I1102’   “deleted
                         or t2~STAT = ‘I0812’ )
                                 “as long as I1102 is not in ABA
                   and t2~INACT = ‘ ‘
                   and t3~partner in partner.
elseif  xdele = gc_X and statd = gc_X.

*  OPEN CURSOR WITH HOLD gv_CURSOR FOR
           SELECT t3~partner
                 INTO TABLE gt_partners
                 from  CRM_JSTO AS t1
                       inner join CRM_JEST as t2
                             on t1~OBJNR = t2~OBJNR
                       inner join BUT000 as t3
                             on t3~PARTNER_GUID = t2~OBJNR
                 WHERE ( t2~STAT     = ‘I1102’   “deleted
                         OR t2~STAT  = ‘I0812’ )
                                 “as long as I1102 is not in ABA
                   and t2~INACT = ‘ ‘
                   and t3~partner in partner
                   and t3~xdele = gc_X.
else.

* OPEN CURSOR WITH HOLD gv_cursor FOR
     SELECT  partner FROM  BUT000
        INTO TABLE gt_partners
        WHERE  PARTNER  in partner.
endif.

if statd = ‘ ‘.
  lv_dele1_check = gc_X.
endif.

IF gt_partners IS INITIAL.
* nothing was selected
  write:/ textt04.
ELSE.
refresh: lt_partner_range.

LOOP AT gt_partners INTO lv_partner.

  ls_partner_rangetname  = ‘BUT000’.
  ls_partner_rangefname  = ‘PARTNER’.
  ls_partner_rangeoption = ‘EQ’.
  ls_partner_rangesign   = ‘I’.
  ls_partner_rangelow = lv_partner.
  append ls_partner_range to lt_partner_range.

  lv_counter = lv_counter + 1.
* Don’t commit changes until package size reached
  IF lv_counter LT gc_max_commit.
*  commit changes on DB
  ELSE.
    PERFORM commit_changes TABLES
                             lt_partner_range
                           USING
                             test
                             xdele
                             lv_dele1_check
                           CHANGING
                             lv_error.
    IF NOT lv_error is INITIAL.
       EXIT.
    ENDIF.

*   refresh structures for new run
    refresh lt_partner_range.
    MOVE 0 TO lv_counter.
  ENDIF.
ENDLOOP.

* delete remaining BP’s
IF NOT lt_partner_range IS INITIAL.
   PERFORM commit_changes TABLES
                            lt_partner_range
                          USING
                            test
                            xdele
                            lv_dele1_check
                          CHANGING
                            lv_error.
ENDIF.
ENDIF.

*&———————————————————————*
*&      Form  commit_changes
*&———————————————————————*
*       Delete package of business partner on DB
*———————————————————————-*
*      –>LT_PARTNER_RANGE  partners to be deleted
*      –>TEST              test mode
*      –>XDELE             only partners with XDELE set
*      –>LV_DELE1_CHECK    check deletion allowed
*———————————————————————-*

form commit_changes  tables
                       LT_PARTNER_RANGE structure bus0range
                     using
                       test           type boole_d
                       xdele          type boole_d
                       lv_dele1_check type boole_d
                     changing
                       lv_error       type boole_d.

*  delete given block of business partners
   CALL FUNCTION ‘BUP_BUPA_MASS_DELETE’
    EXPORTING
      IV_TESTRUN           = test
      IV_XDELE             = xdele
      iv_with_check        = lv_dele1_check
    TABLES
      IT_PARTNERS          = lt_partner_range
      ET_PARTNERS_DELETED  = lt_partners_deleted
      ET_RESULTS           = lt_results
    EXCEPTIONS
      DELETION_NOT_ALLOWED = 1
      FATAL_ERROR          = 2
      OTHERS               = 3.
  IF SYSUBRC <> 0.
    Case sysubrc“NOTE 732410
      When 1.
        write: / textt05.
        uline.
        write:/ textt04.
        refresh: lt_partner_range.
      When 2.
        write: / textt06.
        uline.
        write:/ textt04.
        refresh: lt_partner_range.
        lv_error = ‘X’.
        exit.
      When 3.
        write: / textt07.
        uline.
        write:/ textt04.
        refresh: lt_partner_range.
        lv_error = ‘X’.
        exit.
    EndCase.
  ENDIF.

* no error occured, but message was returned
  IF NOT lt_results IS INTIAL.
      loop at lt_results into ls_result.
        IF ls_resultmessage is INITIAL.
           MESSAGE ID ls_resultID TYPE ls_resultTYPE NUMBER ls_resultNUMBER
                   into ls_resultmessage
            WITH ls_resultMESSAGE_V1 ls_resultMESSAGE_V2 ls_resultMESSAGE_V3 ls_resultMESSAGE_V4.
        ENDIF.
        write: / ls_resultTYPE, ls_resultID, ls_resultNUMBER,
                 ls_resultmessage.
      endloop.
      uline.
  ENDIF.

  loop at lt_partners_deleted into ls_partner.
    if test is initial.
      write: / ls_partnervalue, textt01.
    else.
      write: / ls_partnervalue, textt02.
    endif.
  endloop.

  if test is initial.
    commit work.
  endif.

endform.                    ” commit_changes

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply