0% found this document useful (0 votes)
47 views11 pages

BAPI Extension for Custom Fields

Uploaded by

pandavidyasp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views11 pages

BAPI Extension for Custom Fields

Uploaded by

pandavidyasp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Bapi Extension:

Bapi Extension is used to add customs or user defined fields for the standard table as per
requirement through Bapi.

In The Bapi Function Module we have Two Parameter as

 Extensionin.
 Extensioninx.

You Assign Customs Field to the Parameters.

Ex: ‘Bapi_material_savedata’.

Go to Bapi FM Click ‘Goto’ in the Menu

In the Global data Contain default Structure, select the structure based on the table,now I
Want to Insert The field to, Mara Table So I select the Structure.
 “BAPI_TE_MARA’ - This Structure For Extensionin.
 “BAPI_TE_MARAX’-This Structure for Extensioninx.

Go to Se11 and select The radiobutton as data type and give structure name and click display.
Create append structure in the default structure ,add the customs fields to the append
structure ,here I add two fields ’zmjsystem’ and ‘zmjmtyp’.
Create append structure in the default structure ,add the customs fields to the append
structure ,here I add two fields ’zmjsystem’ and ‘zmjmtyp’.
 Go to program.
 Create Work area for the structure.
"Wa For Bapi_te_mara
ls_bapi_te_mara TYPE bapi_te_mara,
"Wa For Bapi_te_Marax
ls_bapi_te_marax TYPE bapi_te_marax,

 And Assign The Value For The Customs Fields.

"Assign Customs Field Record To The Structure (ls_bapi_te_mara).


ls_bapi_te_mara-material = gt_mara-material_no. “Mat123
ls_bapi_te_mara-zmjsystem = gt_mara-legacyfile. “Ls1
ls_bapi_te_mara-zmjmtyp = gt_mara-matstatus. “Valid

"Assign Customs Field Record To the Structure (ls_bapi_te_marax).


ls_bapi_te_marax-material = gt_mara-material_no. “Mat123
ls_bapi_te_marax-zmjsystem = 'X'.
ls_bapi_te_marax-zmjmtyp = 'X'.

 And Create Internal and Work Area For Extensionin and


Extensioninx.
lt_extension TYPE TABLE OF bapiparex WITH HEADER LINE,
lt_extensionx TYPE TABLE OF bapiparexx WITH HEADER LINE.

Bapiparex and Bapiparexx Contain Field as.

 Structure.
 Valuepart1.
 Valuepart2.
 Valuepart3.
 Valuepart4.

 Assign the Structure name and Structure value to the bapiparex


Fields.
"Assign Structure Name And Structure Value To the Extensionin
lt_extension- -structure = 'BAPI_TE_MARA'.
lt_extension-valuepart1 = ls_bapi_te_mara.
APPEND lt_extension.
CLEAR : lt_extension.
"Assign Structure Name And Structure Value To the Extensioninx
lt_extensionx-structure = 'BAPI_TE_MARAX'.
lt_extensionx-valuepart1 = ls_bapi_te_marax.
APPEND lt_extensionx.
CLEAR lt_extensionx.

 Finally Assign lt_extennsion and lt_extensionx to the Parameter.

Example Program :-
Add User Define fields To Mara table Using
‘Bapi_Create_Savedata’.
*&--------------------------------------------------------------------
-*
*& Report ZMJ_RP_MARA_BAPI_EXTENSION
*&

*&--------------------------------------------------------------------
-*
*& User : Sapuser14.(ECC)
*& Package : zmj_package
*&--------------------------------------------------------------------
-*

REPORT zmj_rp_mara_bapi_extension.
PARAMETERS : p_fpath(128) TYPE c.
TYPES : BEGIN OF ty_mara,
material_no TYPE matnr,
material_type TYPE mtart,
industry_sector TYPE mbrsh,
matl_group TYPE matkl,
unit TYPE meins,
mat_desc TYPE maktx,
legacyfile TYPE zdesystem,
matstatus TYPE zdemtyp,
END OF ty_mara.
DATA : lt_raw_data TYPE truxs_t_text_data.

DATA : gs_headdata TYPE bapimathead,


gs_mara TYPE bapi_mara,
gs_marax TYPE bapi_marax,
"I_Tab For Material Description
gt_des TYPE TABLE OF bapi_makt WITH HEADER LINE ,
"I_Tab For ty_mara
gt_mara TYPE TABLE OF ty_mara WITH HEADER LINE,
"Wa For Bapi_te_mara
ls_bapi_te_mara TYPE bapi_te_mara,
"Wa For Bapi_te_Marax
ls_bapi_te_marax TYPE bapi_te_marax,
lt_extension TYPE TABLE OF bapiparex WITH HEADER LINE,
lt_extensionx TYPE TABLE OF bapiparexx WITH HEADER LINE,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fpath.


CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = p_fpath.

START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = lt_raw_data
i_filename = p_fpath
TABLES
i_tab_converted_data = gt_mara
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

LOOP AT gt_mara.
"Headdata Work Area
gs_headdata-basic_view = 'X'.
gs_headdata-matl_type = gt_mara-material_type."'FERT'.
gs_headdata-ind_sector = gt_mara-industry_sector."'M' .
gs_headdata-material = gt_mara-material_no.
"Client data Work Area
gs_mara-matl_group = gt_mara-matl_group.
gs_mara-base_uom = gt_mara-unit."'EA'.
gs_mara-gtin_variant = 'NORM'.
"Client Datax Work Area
gs_marax-base_uom = 'X'.
"Tables : Material Description
gt_des-langu = sy-langu.
gt_des-matl_desc = gt_mara-mat_desc .
APPEND gt_des.
CLEAR gt_des.

"Logic For Extension bapi


"Assign Customs Field Record To The Structure (ls_bapi_te_mara).
ls_bapi_te_mara-material = gt_mara-material_no.
ls_bapi_te_mara-zmjsystem = gt_mara-legacyfile.
ls_bapi_te_mara-zmjmtyp = gt_mara-matstatus.
"Assign Customs Field Record To the Structure (ls_bapi_te_marax).
ls_bapi_te_marax-material = gt_mara-material_no.
ls_bapi_te_marax-zmjsystem = 'X'.
ls_bapi_te_marax-zmjmtyp = 'X'.
"Assign Structure Name And Structure Value To the Extensionin
lt_extension-structure = 'BAPI_TE_MARA'.
lt_extension-valuepart1 = ls_bapi_te_mara.
APPEND lt_extension.
CLEAR : lt_extension.
"Assign Structure Name And Structure Value To the Extensioninx
lt_extensionx-structure = 'BAPI_TE_MARAX'.
lt_extensionx-valuepart1 = ls_bapi_te_marax.
APPEND lt_extensionx.
CLEAR lt_extensionx.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'


EXPORTING
headdata = gs_headdata
clientdata = gs_mara
clientdatax = gs_marax
* PLANTDATA =
* PLANTDATAX =
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
* NO_ROLLBACK_WORK = ' '
IMPORTING
RETURN = lt_return
TABLES
materialdescription = gt_des
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
extensionin = lt_extension[]
extensioninx = lt_extensionx[]
.
APPEND lt_return.
clear : lt_return.
clear :
lt_extension[],lt_extensionx[],gt_des[],gs_headdata,gs_mara,gs_marax.
ENDLOOP.

LOOP at lt_return.
WRITE : / lt_return-message.
ENDLOOP.

Note:-
In the Bapi Fm put Dynamic Break Point for (loop at
it_extensionin) While debugg you can See how The field Go to
Add the Standard Table.

Common questions

Powered by AI

Work areas like 'ls_bapi_te_mara' are used as temporary storage structures that facilitate data handling during BAPI processes. They are significant because they allow for organized and structured manipulation of data before it is assigned to extension tables like 'lt_extension'. This enables developers to ensure that the correct data is processed and transformed before being appended to the extension parameters of the BAPI. By using defined work areas, developers can apply logic on a per-record basis, ensuring data integrity, type safety, and accurate mapping of legacy systems' data to new extensions. Hence, work areas are critical in structuring and organizing the customization logic within BAPI implementations .

When using the 'TEXT_CONVERT_XLS_TO_SAP' function in BAPI implementations, error handling mechanisms include checks of the return code 'sy-subrc' after the function call. If 'sy-subrc' is not equal to zero, signifying conversion failure or another exception, suitable error handling procedures need to be implemented. This could include displaying error messages, logging the error, or inhibiting further processing to ensure data accuracy and integrity are maintained without propagating erroneous data or states further in the application process .

The tables 'lt_extension' and 'lt_extensionx' play significant roles in BAPI material save operations by holding the customized data required for processing. 'lt_extension' is used for data passed into the 'Extensionin' parameter and 'lt_extensionx' for 'Extensioninx'. They contain the extended structure and carry custom field values from the modified record structures ('ls_bapi_te_mara' and 'ls_bapi_te_marax') to the BAPI call. Their role is crucial in ensuring that additional fields defined by the user can be integrated into the standard data processing of BAPI operations like 'BAPI_MATERIAL_SAVEDATA', thereby facilitating the utilization of custom business requirements in SAP processes .

Bapi Extension is used to add custom or user-defined fields to standard tables through BAPI. In the BAPI function module 'BAPI_MATERIAL_SAVEDATA', Bapi Extension allows customization by including additional fields not originally part of the standard structure through the parameters 'Extensionin' and 'Extensioninx'. This is achieved by creating append structures for the default structure, such as 'BAPI_TE_MARA' for Extensionin and 'BAPI_TE_MARAX' for Extensioninx, and assigning the custom field values to these structures, which are then appended to the parameters .

Data conversions are handled through the 'TEXT_CONVERT_XLS_TO_SAP' function module, which facilitates the reading of data from Excel files and converting them into internal SAP table formats. This function module requires specifying the input parameters such as 'i_filename' for the Excel file path and 'i_tab_raw_data' for the raw text data obtained from the file. Additionally, the 'i_tab_converted_data' table parameter is essential as it stores the converted data. Any conversion errors are indicated by the 'sy-subrc' error code, prompting suitable error handling to manage exceptions and ensure data integrity .

Assigning custom field values in the 'BAPI_MATERIAL_SAVEDATA' involves several crucial steps: creating work areas for the structures 'ls_bapi_te_mara' and 'ls_bapi_te_marax', defining custom fields within these structures, and assigning values to the custom fields from source tables such as 'gt_mara'. These work areas are then used to update the table extensions 'lt_extension' and 'lt_extensionx' by appending them to the respective 'Extensionin' and 'Extensioninx' structures in the BAPI call. The structures have to be correctly defined and related field values accurately assigned to ensure precise data integration and avoid runtime errors .

The structures 'ls_bapi_te_mara' and 'ls_bapi_te_marax' act as intermediate storage for extending standard material data tables in BAPI operations. They are defined to hold additional custom fields apart from standard SAP fields provided in tables such as MARA. These structures are filled with data from defined source tables, e.g., 'gt_mara', which includes material numbers and additional custom fields such as 'zmjsystem' and 'zmjmtyp'. These filled structures are then used to populate 'lt_extension' and 'lt_extensionx' tables, which integrate with the 'extensionin' and 'extensioninx' parameters in the BAPI call. This process enables the inclusion of custom-defined fields in the SAP data update mechanism, ensuring that extended data gets processed alongside standard material data .

'BAPI_TE_MARA' and 'BAPI_TE_MARAX' are structures that facilitate customization by serving as template structures for extensions in BAPI function modules. 'BAPI_TE_MARA' is used to define the additional fields that can be added under 'Extensionin', while 'BAPI_TE_MARAX' is used for 'Extensioninx'. By appending custom fields to these extension structures, developers can pass additional data into the BAPI process. The custom field records are assigned to these structures and ultimately appended to form part of the BAPI call, allowing for extended customization beyond the standard SAP provided fields .

The Bapi Extension mechanism maintains compatibility with standard SAP upgrades or patches through its non-invasive design. By using append structures to add fields to standard tables, Bapi Extensions function independently of the core SAP code. This separation means that standard tables and their original structures remain unchanged, preventing conflicts during upgrades or patches. As a result, the custom fields introduced via Bapi Extensions continue to work seamlessly post-upgrade, providing a flexible and maintainable system for incorporating bespoke business requirements without affecting the stability and integrity of the standard SAP systems .

Creating append structures for Bapi Extensions involves several steps: 1) Accessing transaction SE11 and selecting the radio button for data type; 2) Giving the structure name (e.g., 'BAPI_TE_MARA') for which the append structure is to be created; 3) Clicking display to open the structure; 4) Creating an append structure within this default structure to define new custom fields such as 'zmjsystem' and 'zmjmtyp'. These steps are important because append structures extend standard SAP structures non-invasively, enabling custom fields to be integrated into SAP BAPIs without disrupting the standard SAP codebase. This modularity allows for upgrades and patches in SAP environments without losing customizations .

You might also like