Skip to Content
0

how to delete default communication record using BAPI_ADDRESSORG_CHANGE

Apr 12, 2017 at 07:12 AM

80

avatar image

Hi Experts,

I've created a custom program for the purpose of updating the communication data, mainly the field for telephone and communication note, for the Plant address using the standard fm bapi_addressorg_change.

I manage to insert and update the communication record correctly but fail to make it works for the delete. Appreciate if I can get some advises or hints on what I've done wrong in my codes as follow.

.....

data: tmp_werks like bapi4001_1-objkey,

data: wk_bapiadtel    like bapiadtel occurs 0 with header line,
      wk_bapicomrem   like bapicomrem occurs 0 with header line,
      wk_bapiret2     like bapiret2 occurs 0 with header line,
      wk_bapiadtel_x  like bapiadtelx occurs 0 with header line,
      wk_bapicomre_x  like bapicomrex occurs 0 with header line.

.....

form update_plant_address.

data: tmp_flg(1).

  loop at alv_padr into walv_padr.
    loop at wk_padr into wk_padr_s where werks = walv_padr-werks
                                     and adrnr = walv_padr-adrnr.
      if walv_padr ne wk_padr_s.
        tmp_werks = walv_padr-werks.
        perform get_address using tmp_werks.
        if lines( wk_bapiret2 ) = 0.
          if lines( wk_bapiadtel ) = 0.
            if not ( walv_padr-tel_number is initial and 
                     walv_padr-remark is initial ).
              tmp_flg = 'I'.
            endif.
          elseif not ( walv_padr-tel_number is initial and 
                       walv_padr-remark is initial ).
            tmp_flg = 'U'.
          else.
            tmp_flg = 'D'.
          endif.
          perform update_address using tmp_werks tmp_flg.
        endif.
      endif.
    endloop.
  endloop.
endform.

form get_address using p_werks.

  call function 'BAPI_ADDRESSORG_GETDETAIL'
    exporting
      obj_type                   = 'BUS1069'
      obj_id                     = p_werks
    tables
      bapiadtel                  = wk_bapiadtel
      bapicomrem                 = wk_bapicomrem
      return                     = wk_bapiret2
          .
endform.

form update_address using p_werks p_flg.

  wk_bapiadtel_x-updateflag = p_flg.
  wk_bapicomre_x-updateflag = p_flg.

  if p_flg ne 'I'.
    loop at wk_bapiadtel .
      if wk_bapiadtel-std_no = 'X'.
        delete wk_bapicomrem where consnumber ne wk_bapiadtel-consnumber.
        wk_bapiadtel-telephone = walv_padr-tel_number.
        modify wk_bapiadtel.
      else.
        delete wk_bapiadtel.
      endif.
    endloop.

    loop at wk_bapicomrem.
      wk_bapicomrem-comm_notes = walv_padr-remark.
      modify wk_bapicomrem.
    endloop.

    wk_bapiadtel_x-telephone = 'X'.
    wk_bapicomre_x-comm_notes = 'X'.
  else.
    wk_bapiadtel-country = 'HK'.
    wk_bapiadtel-std_no = 'X'.
    wk_bapiadtel-telephone = walv_padr-tel_number.
    wk_bapicomrem-comm_type = 'TEL'.
    wk_bapicomrem-langu = sy-langu.
    wk_bapicomrem-comm_notes = walv_padr-remark.
    append: wk_bapiadtel, wk_bapicomrem.
  endif.

  append: wk_bapiadtel_x, wk_bapicomre_x.

  call function 'BAPI_ADDRESSORG_CHANGE'
    exporting
      obj_type                          = 'BUS1069'
      obj_id                            = p_werks
    tables
      bapiadtel                         = wk_bapiadtel
      bapicomrem                        = wk_bapicomrem
      bapiadtel_x                       = wk_bapiadtel_x
      bapicomre_x                       = wk_bapicomre_x
      return                            = wk_bapiret2
          .

  if lines( wk_bapiret2 ) = 0.
    commit work.
  endif.

endform.


Thanks.

10 |10000 characters needed characters left characters exceeded

Hi Francis

Did you got any message ? and what sy-subrc return ?

0

Also ref to link below and focus on delete option

https://archive.sap.com/discussions/thread/1561104

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Francis S.K. LUK Apr 13, 2017 at 01:46 AM
0

Hi John,

I've solved the problem. For delete, no need to specify anything in wk_bapicomrem and wk_bapicomre_x, only need to specify the consnumber of the record to be deleted in wk_bapiadtel and put a 'D' in the wk_bapiadtel-updateflag will get the job done.

Thanks.

Share
10 |10000 characters needed characters left characters exceeded