Hello,
There is no API readily avaliable to map user specified enhanced fields into extension data to be passed into standard BAPI's for creation of either quotation / sales order or PO documents.
Taking example of customer quotation creation scenario.Specific customer requirement needs enhancement of standard SD tables like VBAK, VBAP, VBEP and VBKD.These enhancements are done using Include Structure in respective tables.Now, customer requirement could be maintaining these enhanced fields
using BAPI.BAPI provides a flexibility to update these enhanced fields using EXTENSION Structure and system automatically continues processing it.Structure
of this extension field is BAPIPAREX which contains Include Structure name and four value parts each of length CHAR240.Now, mapping of any structure to
extension data for BAPI input is a tedious task as individual fields needs to be mapped to BAPIPAREX.This API shall solve this problem of mapping any structure to Extension Data.It takes any structure and its name as input and converts it into BAPIPAREX structure which can be directly passed in BAPI. No other processing shall be required.For a typical quotation creation, we use BAPI BAPI_QUOTATION_CREATEFROMDATA2. This BAPI has table type EXTENSIONIN as input for enhancement fields.Similarly this API can be used in any BAPI which supports user-specific enhancments and take BAPIPAREX as input.
Code:
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IR_DATA) TYPE ANY
*" REFERENCE(IV_TAB) TYPE TABNAME
*" EXPORTING
*" REFERENCE(ES_EXTENSION_OUT) TYPE BAPIPAREX
*" REFERENCE(ET_RETURN) TYPE BAPIRET2_T
*"----------------------------------------------------------------------
DATA : lref_data TYPE REF TO data,
lv_length TYPE i,
ls_return TYPE bapiret2,
ls_extensionout TYPE bapiparex.
FIELD-SYMBOLS : <fs_data> TYPE any.
CONSTANTS: lc_len TYPE i VALUE 30.
"Get Input reference
GET REFERENCE OF ir_data INTO lref_data.
ASSIGN lref_data->* TO <fs_data>.
"Get length of bapiparex
DESCRIBE FIELD <fs_data> LENGTH lv_length IN BYTE MODE.
"Fill valuepart(s)
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = <fs_data>
IMPORTING
ex_container = ls_extensionout+lc_len(lv_length)
EXCEPTIONS
illegal_parameter_type = 1
OTHERS = 2.
IF sy-subrc <> 0.
"Return Error message
ls_return-type = 'E'.
ls_return-id = 'MSG_CLASS'.
ls_return-number = '021'.
MESSAGE ID 'MSG_CLASS'
TYPE 'E'
NUMBER '021'
INTO ls_return-message.
APPEND ls_return TO et_return.
CLEAR ls_return.
ELSE.
"Move Structure name to extension
ls_extensionout-structure = iv_tab.
MOVE ls_extensionout TO es_extension_out.
ENDIF.
Enjoy