Michal’s tips: Application Interface Framework (AIF) – IDOC processing with AIF actions
In my previous article on Application Interface Framework (AIF) Michal’s PI tips: Application Interface Framework (AIF) 2.0 – monitoring existing IDOCs I’ve described how to monitor IDOCs in the Monitoring and Error Handling transaction of AIF without any changes to the existing IDOC scenario. This is fine if you want to start doing AIF scenarios but if you want to unleash the full potential of AIF (using indexed tables for searching, creating alerts or using Interface Monitor) you need to change your IDOC scenarios a bit so they will be using the full AIF flow configuration. This article will show a step by step solution on how to achive that.
How will the process look like when IDOCs will flow via AIF ?
IDOCs will be processed via an AIF generic function module which will start the AIF flow and at the end of the AIF processing the standard IDOC function module will be called again.
What are the steps necessary for receiving an IDOCs via AIF ?
1. You need to generate a raw data structure (which is the same as SAP data structure).
2. You need to configure a new interface in AIF.
3. You need to create a new IDOC process code which will be using the AIF generic function module.
4. You need to attach the new process code to the partner profile of the IDOC.
5. You need to set up the AIF interface engine details. This can also be done by /AIF/IDOC_GEN where you need to select variant 02.
6. You need to create a new AIF action which will start the AIF function module that will convert the raw SAP IDOC structure back to the IDOC data and call the standard IDOC function module. With note 1769872/SP1 a new function module was delivered that makes this step easier.
7. You need to define a structure mapping where you can assign the action to your interface.
8. You need to create an interface determination for the IDOC so it will know which interface should get started.
9. Now you will be ready to monitor your IDOC flow in AIF.
I will stick to the example from you previous article Michal’s PI tips: Application Interface Framework (AIF) 2.0 – monitoring existing IDOCs and show how to process STATUS IDOC via the AIF.
Step 1 and Step 2 that is generating an SAP structure for the standard IDOC and configuring a new interface in AIF are exactly the same as in the previous article so there is no need to copy the configuration once more.
In order to start the AIF with the IDOC we need to create a new process code in transaction WE42 but before you do that you should assign the AIF function module to the IDOC which you want to process with AIF in transaction WE57 – the module that we will be using is – /AIF/IDOC_INBOUND_PROCESS_FUNC and the config in WE57 can look like shown in Figure below.
Then you need to assign the message type to the function module in transaction BD51 as shown in Figure below (please note that you can create your own message type as well).
Next you can create a new process code in transaction WE42 and assign the function module – /AIF/IDOC_INBOUND_PROCESS_FUNC to this new process code.
Once you create a new process code you need to configure it in the partner profile for your inbound IDOC in transaction WE20.
The engine details will be a bit different that in case of the previous article as this time we want to use AIF log and in the next article AIF index tables so the engine configuration, transaction – /AIF/CUST_IF – Interface Development – Additional Interface Properties – Specify Interface Engines, will look like below. If you use the /AIF/IDOC_GEN report with an appropriate variant this step can be generated as well.
– Application Engine = IDOC
– Persistence Engine = IDOC
– Selection Engine = AIF index tables
– Logging Engine = AIF application log
AIF action is a place where business logic is being executed in a form of function modules which are responsible to process the data in AIF. They can do all sort of things like invoking BAPIs and other function modules. In our case we need build a function module which will change the SAP data back into IDOC data (as it was changed from IDOC data to raw data structure in the first AIF module – /AIF/IDOC_INBOUND_PROCESS_FUNC) and we need to call the standard IDOC function module. We need to start with creating a function module like – ZMICHAL_KRAWCZYK_01 but make a copy from /AIF/FILE_TEMPL_PROCESS to copy the interface of the module. Code for the module – ZMICHAL_KRAWCZYK_01 can be found in the listing below – please have a look at the comments in the code.
|ZMICHAL_KRAWCZYK01 – function module code
*” REFERENCE(TESTRUN) TYPE C
*” REFERENCE(SENDING_SYSTEM) TYPE /AIF/AIF_BUSINESS_SYSTEM_KEY
*” RETURN_TAB STRUCTURE BAPIRET2
*” REFERENCE(SUCCESS) TYPE /AIF/SUCCESSFLAG
*” REFERENCE(OLD_MESSAGES) TYPE /AIF/BAL_T_MSG
LT_IDOC_CONTRL type table of EDIDC,
LS_IDOC_CONTRL type EDIDC,
LT_IDOC_DATA type table of EDIDD,
LT_IDOC_STATUS type table of BDIDOCSTAT,
LT_RETURN_VARIABLES type table of BDWFRETVAR,
LT_SERIALIZATION_INFO type table of BDI_SER,
LR_REF type ref to data.
GET REFERENCE OF DATA into LR_REF.
*convert the RAW IDOC data to IDOC data again
CALL FUNCTION ‘/AIF/IDOC_CONVERT_SAP_STRUCT’
SAP_STRUCT = LR_REF
IV_TYPENAME = ‘ZAIFSYSTAT01’
ES_EDIDC = LS_IDOC_CONTRL
ET_EDIDD = LT_IDOC_DATA
APPEND LS_IDOC_CONTRL to LT_IDOC_CONTRL.
*call the standard function module for your IDOC
CALL FUNCTION ‘IDOC_INPUT_STATUS’
INPUT_METHOD = ‘ ‘
MASS_PROCESSING = ‘ ‘
IDOC_CONTRL = LT_IDOC_CONTRL
IDOC_DATA = LT_IDOC_DATA
IDOC_STATUS = LT_IDOC_STATUS
RETURN_VARIABLES = LT_RETURN_VARIABLES
SERIALIZATION_INFO = LT_SERIALIZATION_INFO
WRONG_FUNCTION_CALLED = 1
OTHERS = 2
IF SY-SUBRC 0.
*TODO Implement suitable error handling here
*move all IDOC status errors into AIF
CALL FUNCTION ‘/AIF/IDOC_CONVERT_STATREC’
RETURN_TAB = RETURN_TAB
IDOC_STATUS = LT_IDOC_STATUS
Once the function module is ready you can create a new action in Transaction – /AIF/CUST – Interface Development – Define Actions as shown in Figure below.
Then you can assign the new function module as shown in Figure below.
Now your action should be completed and ready to use.
In order to use the action you need to create a new structure mapping for your AIF interface – in Transaction – /AIF/CUST – Interface Development – Define Structure Mappings. Once you specify your interface in the selection screen you can assign a new action in it. You need to put your action name (record type is not necessary as we use the whole record) which it this case will be the IDOC record of the SYSTAT01 IDOC.
Process code from Step 3 does not determine which interface should get started with this IDOC. If we have multiple Interface using the same IDOC type we need to maintain interface determination in AIF in Transaction – /AIF/CUST_IF – System Configuration – Interface Determination – Interface Determination for IDOC interfaces (please note that this step is not necessary if we use the IDOC type for only once interface). At first we need to define the IDOC determination key which will be our IDOC – SYSTAT01 and message type – STATUS and in the details specify that we will be using IDOC data record and the field from the record – STATUS for example.
Then we can define the field’s value and interface which needs to be started when those values arrive to SAP.
Finally we can start the flow (either from IDOC test transaction – WE19 or a real one) and we can monitor that in AIF’s Monitoring and Error Handling application. Transaction – /AIF/ERR. We should be able to see all AIF interface specific details like the start of Structure Mapping, start of the action and the function module within it. In this case we also see the IDOC errors propagated to the AIF log from the IDOC status (due to the function /AIF/IDOC_CONVERT_STATREC used in the action’s function module)
Futher info and next articles:
Some info on AIF and IDOC processing can be found in help.sap.com.
In the next articles I will try to show you how to create AIF index tables to be able to search for messages on the basis of freely definable fields, how to create alerts to see messages in the Interface Monitor tool and how to change message content and reprocess IDOC messages in AIF.
Michal’s PI tips: Application Interface Framework (AIF) – IDOC with custom selection criteria (index tables)
Michal’s PI tips: Application Interface Framework (AIF) – IDOC with real time Interface Monitor