Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
mickaelquesnot
Active Participant
2,582
Using extension fields in migration objects (Customer Open Items) in SAP S/4HANA On premise

 



Download pdf version : https://icedrive.net/s/APyBWPS1tfDC5XRWt6wgj4DwAWhV

In this tutorial I explain how to extend migration objects and provide data to the extension structure of BAPIs.
Scenario
Some BAPIs support extension for customer added fields by structure R_EXTENSION1 (Container for 'Customer Exit' Parameter) in their interface.

In my example I will extend the migration object Customer Open Items for 2 fields via the structure EXTENSION to the function module ZZ_INTERFACE_RWBAPI01.
The interface of this BAPI has the extension fields:

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = documentheader
customercpd = customercpd
contractheader = contractheader
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = lt_gl
accountreceivable = accountreceivable
accountpayable = accountpayable
accounttax = accounttax
currencyamount = currencyamount
criteria = lt_criteria
valuefield = valuefield
extension1 = extension1
return = return
paymentcard = paymentcard
contractitem = contractitem
extension2 = lt_ext
realestate = realestate
accountwt = accountwt.

 

 

The parameters are defined like structure BAPIACEXTC:

So, you must provide the data of all fields of the structure BAPIACEXTC in the component FIELD1 to FIELD5 :
Prerequisites
This tutorial is based on S/4HANA 2021 and should be valid for higher versions as well.
The creation of additional source structures was introduced in LTMOM with S/4HANA 1610 FPS2, hence, this approach does not work in older versions.
(For versions between 1610 FPS2 to 1709 FPS1 I can’t tell if it works or not.)
I performed the necessary steps for a file upload project and a staging project. The screenshots are taken from the file-based project.
Extending the Object in Migration Object Modeler
In Migration Cockpit the object Customer Open Items has several source structures as you can see in the view Source Structures in Migration Object Modeler (transaction LTMOM):

 

 

 

 

Remark
If you prefer the technical view which displays the names of fields and structures instead of the descriptions. The view can be switched in the menu Settings à Technical Names On/Off.

The target structure EXTENSION of the BAPI is a structure; hence we must add a new source structure below the source structure S_BSID.

Switch to change mode, then right-click on S_BSID, select Append Structure to Lower Level:

Enter name and description of the additional structure and confirm. I name the structure S_EXTENSIONIN and use description “Extension Fields”:

Now add the required fields:
0 XREF1_HD CHAR 250 0 Reference Key 1 Internal for Document He Extension 1 0 1
0 XREF2_HD CHAR 250 0 Reference Key 2 Internal for Document He Extension 1 0 1

Remark
Some Fields are necessary for the migration cockpit to link the entries in this structure to the Accounts Receivable (Customer) Open Items in the upper level structure.

1 BUKRS CHAR 60 0 Company Code Extension 1 S_BSID 0 1
1 XBLNR CHAR 16 0 Reference Document Number Extension 1 S_BSID 0 1
1 BLDAT DATS 8 0 Document Date Basic Data S_BSID 0 1
The other fields are entered as they are defined in structure EXTENSIONIN of the function module.
Now we need to link the structure to the parent structure S_BSID by foreign key relationship:

MWB: Name of foreign key field/ literal
This field either contains the field in the check table or a literal.
You use foreign keys to define relationships between tables. You can establish a foreign key relationship between two fields, or between a field and a literal.

Confirm and save the changes.

 

In Target Structures we don’t have to change anything.

In Structure Mapping we need to map our new structure S_EXTENSIONIN to the structure EXTENSIONIN by drag and drop:

 

 

Save the changes.

In Field Mapping we need to map the fields of the source structure to the corresponding fields in the target structure by drag and drop:

 

 

Save the changes.

Generate the object:

Role of BTE process RWBAPI01 in BAPI_ACC_DOCUMENT_POST in Migrate your data (Extension)
Introduction
BAPI_ACC_DOCUMENT_POST is use for creating/posting accounting document for AP, AR and GL documents. This is an alternate solution in place of BDC which is used for posting documents through transactions like FB01 and FBB1. This BAPI can take input from legacy system and convert data into accounting document.
A BTE has a predefined interface and it help us in adding custom functionality with help of a function module. This gets triggered after the BAPI calls and before the accounting document post, logics written in its FM executed and later reflected in the posted accounting document.
This document explains the scenarios where implementation of BTE (Business Transaction Events) is required to populate certain fields in the posted accounting document, which are not possible to populate directly through standard BAPI ‘BAPI_ACC_DOCUMENT_POST’.
Steps to populate XREF1_HD and XREF2_HD
To get the XREF1_HD & XREF2_HD populated in the posted accounting document we need to implement BTE (Business Transaction Events). So, we will discuss the flow to achieve the same.
• Here, we need to enable extension1 to get our XREF1_HD/ XREF2_HD populated in the accounting document.

 

FUNCTION bapi_acc_document_post.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(DOCUMENTHEADER) LIKE BAPIACHE09 STRUCTURE BAPIACHE09
*" VALUE(CUSTOMERCPD) LIKE BAPIACPA09 STRUCTURE BAPIACPA09
*" OPTIONAL
*" VALUE(CONTRACTHEADER) LIKE BAPIACCAHD STRUCTURE BAPIACCAHD
*" OPTIONAL
*" EXPORTING
*" VALUE(OBJ_TYPE) LIKE BAPIACHE09-OBJ_TYPE
*" VALUE(OBJ_KEY) LIKE BAPIACHE09-OBJ_KEY
*" VALUE(OBJ_SYS) LIKE BAPIACHE09-OBJ_SYS
*" TABLES
*" ACCOUNTGL STRUCTURE BAPIACGL09 OPTIONAL
*" ACCOUNTRECEIVABLE STRUCTURE BAPIACAR09 OPTIONAL
*" ACCOUNTPAYABLE STRUCTURE BAPIACAP09 OPTIONAL
*" ACCOUNTTAX STRUCTURE BAPIACTX09 OPTIONAL
*" CURRENCYAMOUNT STRUCTURE BAPIACCR09
*" CRITERIA STRUCTURE BAPIACKEC9 OPTIONAL
*" VALUEFIELD STRUCTURE BAPIACKEV9 OPTIONAL
*" EXTENSION1 STRUCTURE BAPIACEXTC OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*" PAYMENTCARD STRUCTURE BAPIACPC09 OPTIONAL
*" CONTRACTITEM STRUCTURE BAPIACCAIT OPTIONAL
*" EXTENSION2 STRUCTURE BAPIPAREX OPTIONAL
*" REALESTATE STRUCTURE BAPIACRE09 OPTIONAL
*" ACCOUNTWT STRUCTURE BAPIACWT09 OPTIONAL
*"----------------------------------------------------------------------

Extension1

Now, we will proceed with implementation of BTE.
Why BTE?
When the BAPI is executed, Code written in the BTE – function module will be executed, and the reason code of related line item will be changed/added before posting the documents.
How to implement?
Step1
• Go to transaction FIBF, blank screen will appear with application tool bar, as shown below.

 

• Hit on Settings tab and select ‘Process Modules’ -> …of a customer

Below screen will appear.
• Here functional team need to add/configure process RWBAPI01.

 

From Partner Enhancements tab, reference of process RWBAPI01 can be found, and Z Function module needs to be created taking reference of standard Function module SAMPLE_INTERFACE_RWBAPI01 (reference in below snap).

• Once the process (RWBAPI01) is enabled in process module of a customer, create A Function Group and later create one Function Module assigning this to created Function Group.

• Assign Z Function module (here ZZ_INTERFACE_RWBAPI01) to newly created Process.

 

 

FUNCTION ZZ_INTERFACE_RWBAPI01.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" IT_ACCIT STRUCTURE ACCIT
*" IT_ACCCR STRUCTURE ACCCR
*" RETURN STRUCTURE BAPIRET2
*" EXTENSION STRUCTURE BAPIACEXTC
*" IT_ACCWT STRUCTURE ACCIT_WT
*" IT_ACCTX STRUCTURE ACCBSET
*" CHANGING
*" VALUE(DOCUMENT_HEADER) LIKE ACCHD STRUCTURE ACCHD
*"----------------------------------------------------------------------

DATA GS_EXTENSION TYPE BAPIACEXTC.

IF NOT EXTENSION[] IS INITIAL.

CLEAR GS_EXTENSION.
READ TABLE EXTENSION INTO GS_EXTENSION INDEX 1.

IF NOT GS_EXTENSION-FIELD1 IS INITIAL.
IT_ACCIT-XREF1_HD = GS_EXTENSION-FIELD1.
ENDIF.

IF NOT GS_EXTENSION-FIELD2 IS INITIAL.
IT_ACCIT-XREF2_HD = GS_EXTENSION-FIELD2.
ENDIF.

MODIFY IT_ACCIT INDEX 1 TRANSPORTING XREF1_HD XREF2_HD.

ENDIF.

ENDFUNCTION.

 

Testing the object
Now you can jump to Migration Cockpit (App migration your data) and test your extension:
After you downloaded the new xml template you see a new sheet Extension Fields; the screenshots show some sample data:

 

 

 

Here you fill the fields of the extension structure and its values.

Debugging the migration object shows that the values are correctly passed to the BAPI:

 

 

 

 

 

 

 

 

 

 

 

Content of EXTENSION structure:

 

 

 

 

 

 

 

 

 

 

result

 

 

 

 

 
Labels in this area