AIF Interface Variant
What is the use of Interface Variant?
With AIF interface, when you receive the message, the action associated with the interface triggers and all the processing functions are executed. So for all the messages, the same action triggers. Now consider SAP delivered an AIF interface to the customer and it is works with its own Action. But the customer might be interested, to process this message in a slight different way( but not with the original interface action). In that sense, it is one of the use case where the customer can configure an interface variant for the already delivered SAP interface and assign a new action to it.
Now with interface and its interface variant we have two different actions(one for each) and they do things slightly different. Now the question is when a message reaches to AIF, which action has to be triggered, the original action associated with the Interface or the action associated with the interface variant. Some additional customizing needed which determines which action has to be triggered. The post describes one of the use case.
The previous post Processing First Message in AIF describes how to design an AIF interface and process the incoming message.
Here we have the AIF interface.
The AIF interface ZFLT_XML works with fields of SPFLI structure. The action takes this SPFLI data and tries to create a record in DB table SPFLI. If the record is already present then shows a error message.
With this interface variant, lets take the below case:
When we receive the values of SPFLI structure, if the COUNTRYFR = DE , then it has to be handled by the action of the interface variant and where COUNTRYFR <> DE, then the original interface action has to react.
Let’s start with the AIF customizing. Execute Tx- /AIF/CUST and choose define interface variant.
Provide namespace as ZDEMO and continue.
Provide interface variant name and description. Save and go back.
As we assumed that, when COUNTRYFR = DE then it has to be handled by the interface variant action.
So we need to capture this condition in a table and use this table in AIF customizing.
Here AIF provides a template VARIANT table. Just copy this table and create a new table in Tx- SE11.
All the fields copied.
As per our use case requirement, we need to add the field COUNTRYFR in this table and make as a KEY field. Activate this table.
So we need to create a record. Usually a Maint View needs to be created for this to set the customizing. Well for now, create entries.
Here provide the namespace, the AIF interface name and the interface variant name and the value as DE to the field – COUNTRYFR
Now we have to assign this interface variant table.
Choose option: Define Assigning Tables and provide namespace and continue.
Below screen appears. We have two different interfaces create before for the namespace.
For the use case we are working with interface, ZFLT_XML. So assign the interface variant table to it.
Now choose- Define Interface Key fields and provide the details and continue.
Provide Key field number as 10, from F4 choose values.
Choose: COUNTRYFR ( this field is coming from the interface variant table ( key field) that was created in the previous step.
It has to be mapped to the AIF structure field name-
This means when AIF receives SPLFI information in the ZDEMO_S_SPFLI_AIF_RAW structure, the field COUNTRYFR value is taken and would be checked against the values in the interface variant table: ZDEMo_FLIGHT_VAR . If it matches then the Interface variant is selected to process the message with its action.
Now we have to MAP the AIF interface with the above created interface variant. Choose Define variant mapping and provide the interface variant and continue.
Create new entries .
Map it to the AIF interface. Now we have to assign an action to the interface variant. Choose Assign Actions.
Select New Entries.
Provide action number. Before assigning an action we have to create an action and then later come back here to assign.
From Tx- /AIF/CUST choose – Define Actions.
we already have one action – ZCREATE_FLIGHT which is used by the AIF interface ZFLT_XML. Check what is the functions assigned to it.
It has a single processing FM.
Create a new action.
provide the action name and description. Choose Define functions to assign a processing Function.
So the new action is ready and assign it to the interface variant an save.
So far, all customizing is ready to work with AIF interface variant and the time is to test with SPFLI data.
DATA: ls_flight_data TYPE zdemo_s_spfli_aif_raw.
DATA: lv_msgguid TYPE /aif/sxmssmguid.
PARAMETERS: p_carr TYPE spfli-carrid OBLIGATORY DEFAULT ‘AA’.
SELECT SINGLE * FROM spfli INTO @DATA(ls_spfli) WHERE carrid = @p_carr.
ls_spfli-carrid = ‘AC’.
ls_flight_data = ls_spfli.
is_any_structure = ls_flight_data
* iv_cust_ns = ” Namespace
* iv_cust_type = ” Identifier for a Customer-Specific AIF Interface Type
iv_queue_ns = ‘ZDEMO’ ” AIF Namespace
iv_queue_name = ‘XML’
* iv_save = ‘X’ ” Save message to Queue
* iv_use_buffer = ” ” Use buffer for saving to persistency
* iv_create_run = ‘X’ ” Create Run for Queue
ev_msgguid = lv_msgguid ” GUID for Integration Engine Objects
* cr_pers_queue = ” AIF Enabler for XML Messages
WRITE:/ ‘Message Created in AIF:’, lv_msgguid .
WRITE:/ ‘AIF call error’.
MESSAGE ‘Not Found’ TYPE ‘E’.
The reports reads the SPFLI data with field CARRID and changes the CARRID to AC and sends to AIF.
Provide CARRID as AA. for carrid = AA the COUNTRYFR = US, so ideally the original interface action should trigger and its processing FM must be executed.
Here the FM of the AIF interface action is processed.
So a new Record with CARRID = AC created.
Just deleted the record with carrid = AC . now we have to provide carrid = UA where the countryfr =DE
Execute the report with carrid = UA
This time the AIF interface Variant action is executed and the assigned FM is triggered.
Now SPFLi have a new entry with CARRID = AC . 🙂