Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update Z fields with BAPI_OUTB_DELIVERY_CHANGE using EXTENSION2

0 Kudos
5,613

How to update Z fields with BAPI_OUTB_DELIVERY_CHANGE using EXTENSION2.

I tried to update some Z fields in LIKP table using the BAPI to update deliveries but after call it any changes wasn't made.

Some one know about it?

2 REPLIES 2

former_member593648
Active Participant
1,510

You can refer to the following blog. It is for another scenario but this will be a good reference

https://blogs.sap.com/2014/06/24/bapi-extension-for-customer-added-fields/

1,510

I found the BAdI - SMOD_V50B0001. I made an enhancement implementaction and in the method EXIT_SAPLV50I_010 (User Exit BAPI for Changes to Outbound Delivery) set the follow code.

 METHOD if_ex_smod_v50b0001~exit_saplv50i_010.

    CONSTANTS: lc_vbkok    TYPE char5  VALUE 'VBKOK',           "Enhance the structure for more z fields in LIKP
               lc_vbpok    TYPE char5  VALUE 'VBPOK',           "Enhance the structure for more z fields in LIPS
               lc_cs_vbkok TYPE char8  VALUE 'CS_VBKOK'.

    DATA: lv_item TYPE posnr_vl.
    FIELD-SYMBOLS: <lfs_fieldname> TYPE any.

    LOOP AT extension2 INTO DATA(lw_extension2).

      CASE lw_extension2-param.
          "As a structure in row 0
        WHEN lc_vbkok. "Fields for LIKP
          IF lw_extension2-value IS NOT INITIAL.
            ASSIGN (lc_cs_vbkok) TO FIELD-SYMBOL(<lfs_vbkok>).
            IF <lfs_vbkok> IS ASSIGNED.
              ASSIGN COMPONENT lw_extension2-field OF STRUCTURE <lfs_vbkok> TO <lfs_fieldname>.
              IF <lfs_fieldname> IS ASSIGNED.
                <lfs_fieldname> = lw_extension2-value.
              ENDIF.
            ENDIF.
          ENDIF.

          "As a table from row 1 to n
        WHEN lc_vbpok. "Fields for LIPS
          IF lw_extension2-value IS NOT INITIAL.
            MOVE lw_extension2-row TO lv_item.
            READ TABLE ct_vbpok ASSIGNING FIELD-SYMBOL(<lfs_vbpok>) WITH KEY posnr_vl = lv_item.
            IF sy-subrc = 0.
              ASSIGN COMPONENT lw_extension2-field OF STRUCTURE <lfs_vbpok> TO <lfs_fieldname>.
              IF <lfs_fieldname> IS ASSIGNED.
                <lfs_fieldname> = lw_extension2-value.
              ENDIF.
            ENDIF.
          ENDIF.

      ENDCASE.

    ENDLOOP.

  ENDMETHOD.

Enhace the structures VBKOK as well LIKP with appen structures to add new z fields and enhance the structure VBPOK as well LIPS for the same purpose.

Also take a look to the program LV50LF01 and would need to implement an additional enhancement point to keep the values.

After this a think that I got it.

METHOD m_update_delivery.

    DATA: lw_header_data    TYPE bapiobdlvhdrchg,
          lw_header_control TYPE bapiobdlvhdrctrlchg,
          lw_extension2     TYPE bapiext.

    DATA: li_extension2 TYPE TABLE OF bapiext,
          li_return     TYPE TABLE OF bapiret2.

    DATA: lv_delivery TYPE bapiobdlvhdrchg-deliv_numb.

    lw_header_data-deliv_numb = p_w_output-delivery.
    lw_header_control-deliv_numb = p_w_output-delivery.
    lv_delivery = p_w_output-delivery.

    lw_extension2-param = 'VBKOK'.
    lw_extension2-field = 'ZZEXIDV'.

    lw_extension2-value = p_w_output-value.
    APPEND lw_extension2 TO li_extension2.

    " Call BAPI to update delivery
    CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
      EXPORTING
        header_data    = lw_header_data
        header_control = lw_header_control
        delivery       = lv_delivery
      TABLES
        extension2     = li_extension2
        return         = li_return.

    READ TABLE li_return INTO DATA(lw_return)
                         WITH KEY type = c_e.
    IF sy-subrc <> 0.
      COMMIT WORK AND WAIT.
    ENDIF.

  ENDMETHOD.