Skip to Content
avatar image
Former Member

Change/Delete production order components from ABAP-Code

Hi all,

can anybody show me how to change btw. delete production order components e.g. for report-usage.

I already found the BAPIS

CO_MK_IBAPI_COMPONENT_CHANGE

CO_MK_IBAPI_COMPONENT_REMOVE

, but could not found a direction how to use them, so SAP dumps with an unknown error everytime :/

Additionally, i got the BAPIs

BAPI_RESERVATION_CHANGE

BAPI_RESERVATION_DELETE

I executed them correctly, but as report message i get the information, that automatic reservation can't be changed...

Thanks for your help!

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

8 Answers

  • Best Answer
    Aug 01, 2013 at 03:11 AM

    Hi. You have to make use of BDC to edit/delete production order components.

    The BAPIs(BAPI_RESERVATION_CHANGE and BAPI_RESERVATION_DELETE) can only be used for reservations created directly via MB21 tcode.

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      I also think BDC for CO02 is the best option. I had similiar issue some years ago and all function modules tested for production order operations failed at the end. Internally SAP is using function modules with global data which are bad encapsulated for usage in own programs.

      One option might be the function module CLOI_CHANGES_UPL_45. This is part of the POI interface.

      By means of this FM can be changed some data in operations and components I suppose parameter CLOI_PLORD_RESBU_IMP is for components. Here is a sample program for calling the FM, in this case for changing one field in operation:

      *&---------------------------------------------------------------------*
      *& Report ZMB_PO_OPER_CREATE
      *&
      REPORT zmb_po_oper_change_cloi.

      PARAMETERS: p_aufnr TYPE char12 MEMORY ID anr OBLIGATORY DEFAULT '001000000944',
      p_act_n(4) TYPE c DEFAULT '0040',
      p_wc_o TYPE arbpl DEFAULT '2000',
      p_wc_n TYPE arbpl DEFAULT '2641'.

      DATA: ls_cloi_if_par_v2 TYPE cloiifpar,
      lt_opu TYPE TABLE OF cloioperu,
      lw_opu TYPE cloioperu,
      lt_cloi_methods_exp TYPE STANDARD TABLE OF cloimetlog,
      lt_cloi_messages_exp TYPE STANDARD TABLE OF cloimsglog,
      lt_cloi_msg_obj_log_exp TYPE STANDARD TABLE OF cloimoblog,
      lv_aplfl(6) TYPE c,
      lv_cloi_ret_val TYPE cloiretval,
      lw_cloi_messages_exp TYPE cloimsglog.

      CLEAR: ls_cloi_if_par_v2.

      ls_cloi_if_par_v2-commitflg = 'C'.
      ls_cloi_if_par_v2-r3_version = '60'.
      ls_cloi_if_par_v2-metlog_req = 'X'.
      ls_cloi_if_par_v2-msglog_req = 'X'.
      ls_cloi_if_par_v2-msgobj_req = 'X'.
      ls_cloi_if_par_v2-ord_req = 'X'.
      ls_cloi_if_par_v2-ordseq_req = 'X'.
      ls_cloi_if_par_v2-ordopr_req = 'X'.

      lw_opu-aufnr = p_aufnr.
      lw_opu-extaufnr = p_aufnr.
      lw_opu-aplfl = '000000'.
      lw_opu-vornr = p_act_n.
      *lw_opu-aplfl = lv_aplfl.
      lw_opu-field = 'ARBPL'.
      lw_opu-value = p_wc_n.
      APPEND lw_opu TO lt_opu.

      CALL FUNCTION 'CLOI_CHANGES_UPL_31'
      EXPORTING
      cloi_if_par = ls_cloi_if_par_v2
      IMPORTING
      cloi_ret_val = lv_cloi_ret_val
      TABLES
      * CLOI_PLORDI_IMP =
      * CLOI_PLORDU_IMP =
      * CLOI_PLORDD_IMP =
      * CLOI_ORDI_IMP =
      * CLOI_ORDU_IMP =
      * CLOI_PLORD_OPRU_IMP =
      cloi_ord_opru_imp = lt_opu
      * CLOI_MAP_EXP =
      cloi_method_log_exp = lt_cloi_methods_exp
      cloi_message_log_exp = lt_cloi_messages_exp
      cloi_msg_obj_log_exp = lt_cloi_msg_obj_log_exp
      * CLOI_PLORD_EXP =
      * CLOI_ORD_EXP =
      * CLOI_PLORD_OPR_EXP =
      * CLOI_ORD_OPR_EXP =
      * CLOI_ORD_SEQ_EXP =
      .
      WRITE: / 'Retval:', lv_cloi_ret_val.

      It was working in prototype phase but I ended up with using BDC (CALL TRANSACTION 'CO02').

      /Michael

  • avatar image
    Former Member
    Aug 01, 2013 at 02:54 PM

    Using the FM CLOI_CHANGES_UPL_45, this is my Code this far, trying to change the quantity of position #0050.There are no syntaxerror and i got returncode "5C", but there is no change in my database.

    *&---------------------------------------------------------------------*
    *& Report Z_CLOI_CHANGES_UPL_45
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*

    REPORT z_cloi_changes_upl_45.

    DATA: lv_aufnr TYPE aufnr.

    DATA: lt_cloi_plord_resbu_imp TYPE TABLE OF cloiplresbu,
    wa_cloi_plord_resbu_imp LIKE LINE OF lt_cloi_plord_resbu_imp.

    DATA: ls_cloi_if_par_v2 TYPE cloiifpar,
    lv_cloi_ret_val TYPE cloiretval. "Returnparameter

    DATA: lt_cloi_methods_exp TYPE STANDARD TABLE OF cloimetlog,
    lt_cloi_messages_exp TYPE STANDARD TABLE OF cloimsglog,
    lt_cloi_msg_obj_log_exp TYPE STANDARD TABLE OF cloimoblog.

    lv_aufnr = '000100004180'.

    CLEAR: ls_cloi_if_par_v2.
    ls_cloi_if_par_v2-commitflg = 'C'.
    ls_cloi_if_par_v2-r3_version = '60'.
    ls_cloi_if_par_v2-metlog_req = 'X'.
    ls_cloi_if_par_v2-msglog_req = 'X'.
    ls_cloi_if_par_v2-msgobj_req = 'X'.
    ls_cloi_if_par_v2-ord_req = 'X'.
    ls_cloi_if_par_v2-ordseq_req = 'X'.
    ls_cloi_if_par_v2-ordopr_req = 'X'.


    wa_cloi_plord_resbu_imp-plnum = lv_aufnr.
    wa_cloi_plord_resbu_imp-EXTPLNUM = lv_aufnr.
    wa_cloi_plord_resbu_imp-posnr = '0050'.
    wa_cloi_plord_resbu_imp-field = 'MENGE'.
    wa_cloi_plord_resbu_imp-value = '30'.
    APPEND wa_cloi_plord_resbu_imp TO lt_cloi_plord_resbu_imp.

    CALL FUNCTION 'CLOI_CHANGES_UPL_45'
    EXPORTING
    cloi_if_par = ls_cloi_if_par_v2
    IMPORTING
    cloi_ret_val = lv_cloi_ret_val
    TABLES
    * CLOI_PLORDI_IMP =
    * CLOI_PLORDU_IMP =
    * CLOI_PLORDD_IMP =
    * CLOI_ORDI_IMP =
    * CLOI_ORDU_IMP =
    * CLOI_PLORD_OPRU_IMP =
    * CLOI_ORD_OPRU_IMP =
    cloi_plord_resbu_imp = lt_cloi_plord_resbu_imp
    * CLOI_ORD_RESBU_IMP =
    * CLOI_EBAN_IMP =
    * CLOI_EKPO_IMP =
    * CLOI_MAP_EXP =
    cloi_method_log_exp = lt_cloi_methods_exp
    cloi_message_log_exp = lt_cloi_messages_exp
    cloi_msg_obj_log_exp = lt_cloi_msg_obj_log_exp
    * CLOI_PLORD_EXP =
    * CLOI_ORD_EXP =
    * CLOI_PLORD_OPR_EXP =
    * CLOI_ORD_OPR_EXP =
    * CLOI_ORD_SEQ_EXP =
    .

    WRITE: / 'Returninfo:', lv_cloi_ret_val.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I have not found good solution, but it's possible to modify POSNR via ASSIGN before DB update. Implement this just before COMMIT:


      TYPES: BEGIN OF ts_resb_bt.

      INCLUDE STRUCTURE resbb. TYPES:

      indold LIKE sy-tabix,

      no_req_upd LIKE sy-datar,

      END OF ts_resb_bt.

      TYPES tt_resb_bt TYPE TABLE OF ts_resb_bt.

      FIELD-SYMBOLS <lt_resb_bt> TYPE tt_resb_bt.

      FIELD-SYMBOLS <ls_resb_bt> TYPE ts_resb_bt.

      DATA lf_numc TYPE numc4.


      ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <lt_resb_bt>.

      LOOP AT <lt_resb_bt> ASSIGNING <ls_resb_bt>.

      lf_numc = sy-tabix * 10.

      <ls_resb_bt>-posnr = lf_numc.

      ENDLOOP.

  • avatar image
    Former Member
    Sep 03, 2013 at 07:10 AM

    Since I tried these function modules some years ago dealing with a similiar requirement I know how much effort you probably spent by trying and debugging to find out the way hou to use these SAP internal and not documented function modules of group COXT.

    Although you are deservedly happy now because it is working you should not forget one thing which finally stopped me in the past using it.

    These function modules are not released by SAP. This means they can be changed with every new release, enhancement or support package. SAP does not guarantee to keep parameters and functionallity. From this point of view they are not better then using CALL TRANSACTION.

    I know that it is practise to use SAP internal function modules in own programs and I do not condemn it but I recommend to consider it at least. Some companies have got policies not to use unreleased function modules. Again not released in this context means not released for usage in customer programs.

    You can see the status within the attributes tab. Compare it with any of a released FM like CONVERSION_EXIT_ALPHA_INPUT. There you'll find a Released on date.

    /Michael

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 01, 2013 at 09:53 AM

    First off, thanks for your answers!

    If i use BDC for CO02, i can't delete a variable position in the component overview, can i?

    Problem background is comparing data receiving from iDOC with the component overview.

    If the material fits, i update the positions' quantity etc...

    If not, i delete the position and create a new one based on the iDOC-Information.

    Can i estimate the position dynamicly using BDC?


    pastedImage_0.png (13.5 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • Record BDC by making use of a manual filter to get to the desired component and then perform your activity.

      Then in the program,pass the production order and material value (AUFNR,MATNR) to RESB table and get its position (POSNR) for performing desired activity.

      OR

      a.jpg (163.5 kB)
  • avatar image
    Former Member
    Aug 01, 2013 at 11:21 AM

    Hi,

    Here is a sample where I deleted operations within the overview screen. The components should also work in a similiar way:

    *&---------------------------------------------------------------------*
    *& Form POST_DELETIONS
    *&---------------------------------------------------------------------*
    * Remove operations from production order
    *----------------------------------------------------------------------*
    * -->PFD_NEW_OP Flag if new operations to be inserted.
    *----------------------------------------------------------------------*
    FORM post_deletions USING pfd_new_op TYPE char1.

    DATA: lwa_ct_params TYPE ctu_params,
    lfd_ctmode TYPE char1,
    lfd_mode TYPE char1,
    lfd_count TYPE i,
    lfd_oper_comp TYPE bapi_alm_order_operation-activity,
    lfd_string TYPE string,
    lfd_spo1flg TYPE char1,
    lfd_dumps TYPE resb-dumps,
    lfd_aufst TYPE resb-aufst,
    lfd_aufwg TYPE resb-aufwg.

    CLEAR: pfd_new_op.

    GET PARAMETER ID '/SIE/1I_CT_MODE' FIELD lfd_ctmode.
    IF lfd_ctmode CA 'AENP'.
    lfd_mode = lfd_ctmode.
    ELSE.
    lfd_mode = 'E'.
    ENDIF.
    *
    REFRESH git_bdcdata.
    REFRESH git_bdcmess.
    *
    * Find first possible operation for component reassgnment
    *
    LOOP AT git_alv INTO gwa_alv
    WHERE proc <> 'D'
    AND ampel = '3'
    AND po_vornr <> ''.
    lfd_oper_comp = gwa_alv-po_vornr.
    EXIT.
    ENDLOOP.
    *
    * Process actions
    *
    PERFORM bdc_dynpro USING 'SAPLCOKO1' '0110'.
    PERFORM bdc_field USING 'BDC_CURSOR' 'R62CLORD-FLG_KNOT'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=VGUE'.
    PERFORM bdc_field USING 'CAUFVD-AUFNR' gwa_ctrl-aufnr.
    PERFORM bdc_field USING 'R62CLORD-FLG_KNOT' c_x.
    PERFORM bdc_field USING 'R62CLORD-FLG_OVIEW' ''.

    LOOP AT git_alv INTO gwa_alv
    WHERE proc = 'D'
    OR proc = 'A'.
    CASE gwa_alv-proc.
    WHEN 'D'. "Delete Operations
    IF gwa_alv-comp = c_x.
    * Reassign components
    IF lfd_oper_comp IS INITIAL.
    CONCATENATE text-e11 gwa_alv-po_vornr INTO lfd_string
    SEPARATED BY space.
    CALL FUNCTION 'POPUP_TO_INFORM'
    EXPORTING
    titel = text-t06
    txt1 = text-e10
    txt2 = lfd_string.
    CONTINUE.
    ELSE.
    PERFORM bdc_dynpro USING 'SAPLCOVG' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=KPU2'.
    LOOP AT git_po_comp INTO gwa_po_comp
    WHERE operation = gwa_alv-po_vornr.
    * check if deletion flag is set
    * if so do not reassign but an additional dynpro will occur during deletion
    IF NOT gwa_po_comp-deletion_indicator IS INITIAL.
    lfd_spo1flg = c_x.
    CONTINUE.
    ENDIF.
    * check if component is part of a dummy assembly
    * If so ignore, because reassignment is done with the level above
    SELECT SINGLE dumps aufst aufwg FROM resb
    INTO (lfd_dumps, lfd_aufst, lfd_aufwg)
    WHERE rsnum = gwa_po_comp-reservation_number
    AND rspos = gwa_po_comp-reservation_item
    AND rsart = gwa_po_comp-reservation_type.
    IF sy-subrc = 0.
    IF lfd_dumps IS INITIAL AND NOT lfd_aufst IS INITIAL AND NOT lfd_aufst IS INITIAL.
    CONTINUE.
    ENDIF.
    ENDIF.

    PERFORM bdc_dynpro USING 'SAPLCOMK' '0120'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=P--'.

    PERFORM bdc_dynpro USING 'SAPLCOMK' '0120'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=AUFS'.

    PERFORM bdc_dynpro USING 'SAPLCO05' '0110'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=MORE'.
    PERFORM bdc_field USING 'BDC_CURSOR' 'RCOSU-POSNR'.
    PERFORM bdc_field USING 'RCOSU-POSNR' gwa_po_comp-item_number.
    PERFORM bdc_field USING 'RCOSU-VORNR' gwa_alv-po_vornr.
    PERFORM bdc_field USING 'RCOSU-MATNR' gwa_po_comp-material.

    PERFORM bdc_dynpro USING 'SAPLCOMK' '0120'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=SWAP'.
    PERFORM bdc_field USING 'RC27X-FLG_SEL(01)' c_x.

    PERFORM bdc_dynpro USING 'SAPLCOMP' '1040'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=GOON'.
    PERFORM bdc_field USING 'RCM01-VORNR' lfd_oper_comp.
    ENDLOOP.
    PERFORM bdc_dynpro USING 'SAPLCOMK' '0120'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.

    PERFORM bdc_dynpro USING 'SAPLCOKO1' '0115'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=VGUE'.
    ENDIF.
    ENDIF.
    * Delete operation
    lfd_count = lfd_count + 1.
    PERFORM bdc_dynpro USING 'SAPLCOVG' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=P--'.

    PERFORM bdc_dynpro USING 'SAPLCOVG' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=AUFS'.

    PERFORM bdc_dynpro USING 'SAPLCO05' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=MORE'.
    PERFORM bdc_field USING 'BDC_CURSOR' 'RCOSU-VORNR'.
    PERFORM bdc_field USING 'RCOSU-VORNR' gwa_alv-po_vornr.

    PERFORM bdc_dynpro USING 'SAPLCOVG' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=LOE'.
    PERFORM bdc_field USING 'RC27X-FLG_SEL(01)' c_x.

    IF gwa_alv-prt IS INITIAL AND lfd_spo1flg IS INITIAL.
    PERFORM bdc_dynpro USING 'SAPLSPO2' '0200'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=OPT1'.
    ELSE.
    PERFORM bdc_dynpro USING 'SAPLSPO2' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=OPT1'.
    ENDIF.

    WHEN 'A'. "Add Operations
    pfd_new_op = c_x.
    ENDCASE.
    ENDLOOP.
    * Post data
    IF lfd_count > 0.
    PERFORM bdc_dynpro USING 'SAPLCOVG' '0100'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
    PERFORM bdc_field USING 'BDC_CURSOR' 'PSFC_DISP-AUFNR'.

    lwa_ct_params-dismode = lfd_mode.
    lwa_ct_params-updmode = 'S'.
    lwa_ct_params-defsize = c_x.
    lwa_ct_params-cattmode = space.
    * lwa_ct_params-nobinpt = c_x. " This would leed to popup of error messages
    " But side effect is that long text won't work
    lwa_ct_params-nobiend = space.
    lwa_ct_params-racommit = c_x.
    CALL TRANSACTION 'CO02'
    USING git_bdcdata
    OPTIONS FROM lwa_ct_params
    MESSAGES INTO git_bdcmess.
    DESCRIBE TABLE git_bdcmess LINES lfd_count.
    READ TABLE git_bdcmess INDEX lfd_count INTO gwa_bdcmess.
    IF sy-subrc = 0.
    gwa_ctrl-refresh = c_n.
    MESSAGE ID gwa_bdcmess-msgid TYPE gwa_bdcmess-msgtyp NUMBER gwa_bdcmess-msgnr
    WITH gwa_bdcmess-msgv1 gwa_bdcmess-msgv2 gwa_bdcmess-msgv3.
    ENDIF.
    COMMIT WORK AND WAIT.
    ENDIF.

    ENDFORM. " POST_DELETIONS

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 03, 2013 at 12:29 PM

    Thanks for the Information, Michael!

    I think using the "unofficial" FMs is way better than using BDC in my case.

    K.Arun, where can i put down the document? I will do this after the "CO_XT_COMPONENT_ADD"-FM is working perfect. DId you try to implement this FM? I always get the bug posted on top....

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 06, 2013 at 12:06 PM

    Does anybody know how the posnr of the production orders components is composed of?

    I found a way to assign the posnr, but i got no idea which values are the right ones...

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Could you tell us how you passed the posnr to the component? I haven't managed to get that to work.

      And thanks for sharing your findings about the CO_XT_COMPONENT... functions!

      They're a great step forward compared to BDC!

  • avatar image
    Former Member
    Sep 17, 2013 at 11:51 AM

    Another problem appeared in my programm:

    If i first add and then delete a component, there is an error not founding CAUFVD(FM CO_BT_CAUFV_READ_WITH_KEY).,

    Is there the need to fill the document tables, additional to the database?

    If i add a component by transaction CO02 and then delete by using the Delete-FM, there is no error.

    Regards.

    Add comment
    10|10000 characters needed characters exceeded