Skip to Content

EWM Code to Add "Process Code" to ODO Item

Does anyone know of a function module or method I can use to duplicate the actions executed when I add a process code (O002 - Warehouse Difference, Adj. Doc. + Qty / Adjustment of Delivery Quantity and Del. Quant. Transferred) to an ODO item and save? I know its calling method ACTION_EXECUTE (/SCDL/CL_SP) with action = SC_ADJUST_QUANTITY, to zero the quantity, but after that I'm not sure how the new delivery is created. I'm hoping there's some easy way to code this so I don't have to figure out the whole process!

Thanks for any help anyone can provide,

Mike

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    May 03, 2018 at 02:11 PM

    I figured it out. In case anyone searches and finds this question, here's the code for the solution...

      DATA: ls_sp_k_head   TYPE /scdl/s_sp_k_head,
            lt_sp_k_head   TYPE /scdl/t_sp_k_head,
            ls_prcodes_in  TYPE /scdl/s_sp_a_item_prcodes,
            lt_prcodes_in  TYPE /scdl/t_sp_a_item_prcodes,
            lt_prcodes_out TYPE /scdl/t_sp_a_item_prcodes.
    
      FIELD-SYMBOLS: <ls_prcodes_in>  TYPE /scdl/s_sp_a_item_prcodes.
    
      TRY.
          CREATE OBJECT lo_message_box.
          CREATE OBJECT lo_sp
            EXPORTING
              io_message_box = lo_message_box
              iv_doccat      = /scdl/if_dl_doc_c=>sc_doccat_out_prd
              iv_mode        = /scdl/cl_sp=>sc_mode_classic.
        CATCH /scdl/cx_sp_message_box.
          pv_error = 'X'.
          EXIT.
      ENDTRY.
    
      SELECT docid itemid qty uom
        FROM /scdl/db_proci_o
        INTO CORRESPONDING FIELDS OF TABLE lt_prcodes_in
         FOR ALL ENTRIES IN pt_data
       WHERE doccat = 'PDO'
         AND docno  = pt_data-docno    " 1 docno
         AND itemno = pt_data-itemno   " Could have multiple items we're splitting off
         AND qty   GT 0.               " Just in case the user tries to reprocess the same data twice!
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
    
    * Lock the ODO
      READ TABLE lt_prcodes_in INTO ls_prcodes_in INDEX 1.
      ls_sp_k_head-docid = ls_prcodes_in-docid.
      APPEND ls_sp_k_head TO lt_sp_k_head.
      CLEAR:  lt_return_codes, lv_rejected.
      lo_sp->lock(
        EXPORTING
          inkeys       = lt_sp_k_head
          aspect       = /scdl/if_sp_c=>sc_asp_head
          lockmode     = /scdl/if_sp1_locking=>sc_exclusive_lock
        IMPORTING
          rejected     = lv_rejected
          return_codes = lt_return_codes ).
      READ TABLE lt_return_codes TRANSPORTING NO FIELDS WITH KEY failed = abap_true.
      IF sy-subrc = 0 OR lv_rejected = abap_true.
        pv_error = abap_true.
        MESSAGE s999 WITH 'Unable to Lock ODO' ls_data-docno DISPLAY LIKE 'E'.
        EXIT.
      ENDIF.
    
    * Add the process code(s) and update!
      LOOP AT lt_prcodes_in ASSIGNING <ls_prcodes_in>.
        <ls_prcodes_in>-prcode  = 'O002'.
        <ls_prcodes_in>-qty    = -1 * <ls_prcodes_in>-qty.
      ENDLOOP.
    
      CLEAR: lt_return_codes, lv_rejected.
      lo_sp->update(
        EXPORTING
          inrecords    = lt_prcodes_in
          aspect       = /scdl/if_sp_c=>sc_asp_item_prcodes
        IMPORTING
          outrecords   = lt_prcodes_out
          rejected     = lv_rejected
          return_codes = lt_return_codes ).
      READ TABLE lt_return_codes TRANSPORTING NO FIELDS WITH KEY failed = abap_true.
      IF sy-subrc = 0 OR lv_rejected = abap_true.
        pv_error = abap_true.
        MESSAGE s999 WITH 'ODO Update Error'  DISPLAY LIKE 'E'.
        EXIT.
      ENDIF.
    
    * Save the data (we still need a commit, but that will happen all or none at the end)
      lo_sp->save( IMPORTING rejected = lv_rejected ).
      IF lv_rejected = abap_true.
        MESSAGE s999 WITH 'ODO Save Error'.
        pv_error = abap_true.
      ENDIF.
    
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 25, 2018 at 10:44 AM

    Hi Mike,

    not sure what you want to achieve. The creation of the new delivery is done during the transition service from the ODR (outbound delivery request) to the ODO.

    If you adjust the quantity you will see that on the ODR on the PPF tab there is a new entry for the transition service. Inside it is decided whether there is an open quantity and if a new delivery has to be created. So there is basically no "simple" action that does this.

    Therefore I wanted to ask what you are trying to do. E.g. if you call the adjust quantity action with the correct process code this will be done automatically. Therefore I do not know why you want to know the details how and where the delivery is created.

    Best regards

    Markus



    Add comment
    10|10000 characters needed characters exceeded

    • Hi Markus,

      We have an interface with a 3rd party shipper which can dictate if and when a delivery must be split for shipping. At times the shipper, via the interface, can tell us to split the ODO into two ODO's. My functional analyst told me the way he would do that in /SCWM/PRDO would be to hi-light the items that must be split off and click Process Codes -> Adjust Delivery Quantity, then select process code O002, and save - and now I need to code that within the interface.

      I don't really understand the ODR -> ODO part of what you said, but I'm going to try to do what you said... "if you call the adjust quantity action with the correct process code this will be done automatically", and see if that works.

      Let me know if you have any additional thoughts now that you know (hopefully, I explained it correctly) what I want. Otherwise, I'm going to write a test program and see if it works.

      Mike

  • Feb 06 at 03:41 PM

    I made a short program that will allow a user to enter Delivery number and perform Process Code update using the code provided above.

    It works.

    *&---------------------------------------------------------------------*
    *& Report ZUPDATE_PRCODE_QTY
    *&---------------------------------------------------------------------*
    *&
    *&---------------------------------------------------------------------*
    report zupdate_prcode_qty message-id 28.
    
    parameters: p_docno type /scdl/db_proci_o-docno obligatory.
    
    data pt_data type /scdl/db_proci_o occurs 0.
    data: ls_data type /scdl/db_proci_o.
    data:
      lo_sp                   type ref to /scdl/cl_sp_prd_out,
      lo_message_box          type ref to /scdl/cl_sp_message_box,
      ls_action               type /scdl/s_sp_act_action,
      lt_a_head               type /scdl/t_sp_a_head,
      lt_a_head_incoterms_out type /scdl/t_sp_a_head_incoterms,
      lt_a_head_incoterms     type /scdl/t_sp_a_head_incoterms,
      ls_a_head_incoterms     type /scdl/s_sp_a_head_incoterms,
      lt_a_item               type /scdl/t_sp_a_item,
      lv_rejected             type boole_d,
      lt_return_codes         type /scdl/t_sp_return_code,
      lt_messages             type /scdl/dm_message_tab.
    
    data: ls_sp_k_head   type /scdl/s_sp_k_head,
          lt_sp_k_head   type /scdl/t_sp_k_head,
          ls_prcodes_in  type /scdl/s_sp_a_item_prcodes,
          lt_prcodes_in  type /scdl/t_sp_a_item_prcodes,
          lt_prcodes_out type /scdl/t_sp_a_item_prcodes.
    
    field-symbols: <ls_prcodes_in>  type /scdl/s_sp_a_item_prcodes.
    
    data pv_error(1) type c.
    
    start-of-selection.
    
      if not ( p_docno is initial ).
    
        refresh pt_data.
        select * into table pt_data
          from /scdl/db_proci_o
          where docno = p_docno.
    
        clear pv_error.
        try.
            create object lo_message_box.
            create object lo_sp
              exporting
                io_message_box = lo_message_box
                iv_doccat      = /scdl/if_dl_doc_c=>sc_doccat_out_prd
                iv_mode        = /scdl/cl_sp=>sc_mode_classic.
    
          catch /scdl/cx_sp_message_box.
            pv_error = 'X'.
            exit.
        endtry.
    
        select docid itemid qty uom
          from /scdl/db_proci_o
          into corresponding fields of table lt_prcodes_in
           for all entries in pt_data
    
         where doccat = 'PDO'
           and docno  = pt_data-docno    " 1 docno
           and itemno = pt_data-itemno   " Could have multiple items we're splitting off
           and qty   gt 0.               " Just in case the user tries to reprocess the same data twice!
    
        if sy-subrc ne 0.
          exit.
        endif.
    
    * Lock the ODO
    
        read table lt_prcodes_in into ls_prcodes_in index 1.
        ls_sp_k_head-docid = ls_prcodes_in-docid.
        append ls_sp_k_head to lt_sp_k_head.
    
        clear:  lt_return_codes, lv_rejected.
    
        lo_sp->lock(
          exporting
            inkeys       = lt_sp_k_head
            aspect       = /scdl/if_sp_c=>sc_asp_head
            lockmode     = /scdl/if_sp1_locking=>sc_exclusive_lock
          importing
            rejected     = lv_rejected
            return_codes = lt_return_codes ).
    
        read table lt_return_codes transporting no fields with key failed = abap_true.
        if sy-subrc = 0 or lv_rejected = abap_true.
          pv_error = abap_true.
          message s999 with 'Unable to Lock ODO' ls_data-docno display like 'E'.
          exit.
        endif.
    
    * Add the process code(s) and update!
    
        loop at lt_prcodes_in assigning <ls_prcodes_in>.
          <ls_prcodes_in>-prcode  = 'O001'.
          <ls_prcodes_in>-qty    = -1 * <ls_prcodes_in>-qty.
        endloop.
    
        clear: lt_return_codes, lv_rejected.
    
        lo_sp->update(
          exporting
            inrecords    = lt_prcodes_in
            aspect       = /scdl/if_sp_c=>sc_asp_item_prcodes
          importing
            outrecords   = lt_prcodes_out
            rejected     = lv_rejected
            return_codes = lt_return_codes ).
    
        read table lt_return_codes transporting no fields with key failed = abap_true.
    
        if sy-subrc = 0 or lv_rejected = abap_true.
          pv_error = abap_true.
          message s999 with 'ODO Update Error'  display like 'E'.
          exit.
        endif.
    
    * Save the data (we still need a commit, but that will happen all or none at the end)
    
        lo_sp->save( importing rejected = lv_rejected ).
        if lv_rejected = abap_true.
          message s999 with 'ODO Save Error'.
          pv_error = abap_true.
        else.
          commit work.
        endif.
      else.
        message i999 with 'Doc Number Required'.
      endif.
    Add comment
    10|10000 characters needed characters exceeded