• February 17, 2026
  • Kishore Thutaram
  • 0

Update Sales Order Custom Fields Using BAPI_SALESORDER_CHANGE in SAP

Business Scenario:

“Update the Sales order custom fields data using BAPI Extension Parameter”

Steps: Enhance the structures below by creating “Append structures” with the custom fields.

for the sales order header – BAPE_VBAK (with actual field), BAPE_VBAKX (Same field name with char 1 length)

for the sales order item – BAPE_VBAP (with actual field), BAPE_VBAPX (Same field name with char 1 length)


lv_vbeln =  vbeln. "Sales order number
      it_salesheadx-updateflag = 'U'.
      ls_bape_vbak-vbeln = lv_vbeln.
      ls_bape_vbak-zz1_credit =  'X'. "Custom field
      ls_extensionin-structure = 'BAPE_VBAK'.
      ls_extensionin-valuepart1 = ls_bape_vbak.
      APPEND ls_extensionin TO lt_extensionin.

      ls_bape_vbakx-vbeln = lv_vbeln.
      ls_bape_vbakx-zz1_credit = 'X'. "Custom field flag
      ls_extensionin-structure = 'BAPE_VBAKX'.
      ls_extensionin-valuepart1 = ls_bape_vbakx.
      APPEND ls_extensionin TO lt_extensionin.
      CLEAR: ls_extensionin.
* call sales order change bapi
      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument    = lv_vbeln
          order_header_in  = it_saleshead
          order_header_inx = it_salesheadx
        TABLES
          return           = return
          extensionin      = lt_extensionin.
      LOOP AT return WHERE type = 'E'.
        EXIT.
      ENDLOOP.
      IF sy-subrc NE 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ENDIF.
   
    

Kishore Thutaram

"SAP solution architect with a strong problem-solving mindset, sharing practical SAP S/4HANA and ABAP insights from real-world projects."

https://fiowelt.com