This blog demonstrates how to create a PO document using BAPI BAPI_PO_CREATE1, along with populating custom field values via the table/changing parameter EXTENSIONIN in BAPI.
We know that the EXTENSION parameter in BAPI is used to pass values of PO's custom fields; however, its structure, bapiparex, is so generic that we are unsure what values to pass as inputs, and we lack detailed information from BAPI's documentation.
Upon raising the SAP ticket, we got the solution to refer document of BAPI_CONTRACT_CREATE. Let's follow the steps below:
1. EXTENSION parameter values can be an XML-structured input if we have extended the PO via custom fields and a logic app.
2. It's Input values should be in the auxiliary structure ‘Custom Extension data’; the data can only be passed in an XML format.
Custom Extension data structures:
3. To convert this structure into an XML format, we can use the class CL_CFD_BAPI_MAPPING and methods IF_CFD_BAPI_MAPPING~MAP_TO_BAPIPAREX_SINGLE (for header data) and IF_CFD_BAPI_MAPPING~MAP_TO_BAPIPAREX_MULTI (for item data).
4. Refer to the code snippet for header data:
DATA ls_extensionin TYPE bapiparex.
DATA extensionin TYPE TABLE OF bapiparex.
DATA ls_po_bapi_header_ext TYPE mmpur_po_bapi_header_ext.
DATA ls_bapi_header_ext_data TYPE mmpur_po_bapi_header_ext-data.
DATA ls_bapi_header_ext_datax TYPE mmpur_po_bapi_header_ext-datax.
DATA lo_descr_struct TYPE REF TO cl_abap_structdescr.
DATA lo_descr_structx TYPE REF TO cl_abap_structdescr.
DATA lo_bapi_mapping TYPE REF TO if_cfd_bapi_mapping.
FIELD-SYMBOLS: <fs_comp_data> TYPE abap_compdescr,
<fs_comp_datax> TYPE abap_compdescr,
<fs_data> TYPE any,
<fs_datax> TYPE any,
<ls_data> TYPE any.
CLEAR extensionin.
lo_descr_struct ?= cl_abap_structdescr=>describe_by_data( ls_bapi_header_ext_data ).
lo_descr_structx ?= cl_abap_structdescr=>describe_by_data( ls_bapi_header_ext_datax ).
ls_bapi_header_ext_data-zz1_custom_pdh = 'value'.
LOOP AT lo_descr_struct->components ASSIGNING <fs_comp_data>.
ASSIGN COMPONENT <fs_comp_data>-name OF STRUCTURE ls_bapi_header_ext_data TO <fs_data>.
IF <fs_data> IS ASSIGNED AND <fs_data> IS NOT INITIAL.
ASSIGN COMPONENT <fs_comp_data>-name OF STRUCTURE ls_bapi_header_ext_datax TO <fs_datax>.
IF <fs_datax> IS ASSIGNED.
<fs_datax> = abap_true.
ENDIF.
ENDIF.
ENDLOOP.
ls_po_bapi_header_ext = VALUE #( key = lv_EBELN "PO value
data = ls_bapi_header_ext_data
datax = ls_bapi_header_ext_datax ).
TRY.
lo_bapi_mapping = cl_cfd_bapi_mapping=>get_instance( ).
lo_bapi_mapping->map_to_bapiparex_single(
EXPORTING
ir_source_structure = REF #( ls_po_bapi_header_ext )
CHANGING
ct_bapiparex = extensionin ).
CATCH cx_cfd_bapi_mapping. " Custom Fields: BAPI Mapping Exception
ENDTRY.Note : In S4 HANA 2022 FPS01
We observe that CI_EKKODBX is not included in the structure EKKO_INCL_EEW_X (which is used for updating the change indicator for custom fields)
We are using the MMPUR_PO_BAPI_HEADER_EXT structure to update the PO header custom fields, which consist of EKKO_INCL_EEW_PS (to update the actual data) and EKKO_INCL_EEW_X (to update the change indicator).
EKKO_INCL_EEW_PS has all the custom fields, which are enhanced via exit MM06E005 (EXIT_SAPMM06E_006, EXIT_SAPMM06E_008) and via Fiori app Custom fields and logic.
But fields that are enhanced via exit are missing in the structure EKKO_INCL_EEW_X because CI_EKKODBX is not included.
Without updating the change bar, we can't populate the values for these fields via BAPI_PO_CREATE1, extensionin.
To resolve this, we have implemented the SAP Note 3334975.
Use this method to fill extensionin parameter in BAPI_PO_CREATE1, to pass the values of the PO's custom field to create the Purchase order along with its custom fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 13 | |
| 12 | |
| 12 | |
| 10 | |
| 10 | |
| 9 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |