AIF: Interface Variant

light111AIF 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.

1

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.

2

Provide interface variant name and description. Save and go back.

4

3

5


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.

89

All the fields copied.

10

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.

11

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.

12

Here provide the namespace, the AIF interface name and the interface variant name and the value as DE to the field – COUNTRYFR

1314


Now we have to assign this interface variant table.

Choose option: Define Assigning Tables and provide namespace and continue.

6

Below screen appears. We have two different interfaces create before for the namespace.

7

For the use case we are working with interface, ZFLT_XML. So assign the interface variant table to it.

15

Now choose- Define Interface Key fields and provide the details and continue.

16

Provide Key field number as 10, from F4 choose values.

17

Choose: COUNTRYFR ( this field is coming from the interface variant table ( key field) that was created in the previous step.

18

It has to be mapped to the AIF structure field name- 

1920


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.

21

Create new entries .

22

Map it to the AIF interface. Now we have to assign an action to the interface variant. Choose Assign Actions.

23

Select New Entries.

24

Provide action number.  Before assigning an action we have to create an action and then later come back here to assign.

25


From Tx- /AIF/CUST choose – Define Actions.

26

we already have one action – ZCREATE_FLIGHT which is used by the AIF interface ZFLT_XML. Check what is the functions assigned to it.

27

It has a single processing FM.

28

FM.

34

Create a new action.

29

provide the action name and description. Choose Define functions to assign a processing Function.

3031

FM.

35


So the new action is ready and assign it to the interface variant an save.

3233


So far, all customizing is ready to work with AIF interface variant and the time is to test with SPFLI data.

36


REPORT zdemo_aif_flight_create.
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’.

START-OF-SELECTION.
SELECT SINGLE * FROM spfli INTO @DATA(ls_spfli) WHERE carrid = @p_carr.
CASE sy-subrc.
WHEN 0.
ls_spfli-carrid = ‘AC’.
ls_flight_data = ls_spfli.
TRY.
/aif/cl_enabler_xml=>transfer_to_aif(
        EXPORTING
             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
       IMPORTING
           ev_msgguid = lv_msgguid ” GUID for Integration Engine Objects
       * CHANGING
           * cr_pers_queue = ” AIF Enabler for XML Messages
              ).
WRITE:/ ‘Message Created in AIF:’, lv_msgguid .
CATCH /aif/cx_inf_det_base.
CATCH /aif/cx_enabler_base.
CATCH /aif/cx_aif_engine_not_found.
CATCH /aif/cx_error_handling_general.
CATCH /aif/cx_aif_engine_base.
WRITE:/ ‘AIF call error’.
ENDTRY.
WHEN OTHERS.
MESSAGE ‘Not Found’ TYPE ‘E’.
ENDCASE.


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.

37

Here the FM of the AIF interface action is processed.

3839

So a new Record with CARRID = AC created.

40

Just deleted the record with carrid = AC . now we have to provide carrid = UA where the countryfr =DE

41

Execute the report with carrid = UA

42

This time the AIF interface Variant action is executed and the assigned FM is triggered.

4344

Now SPFLi have a new entry with CARRID = AC . 🙂 

45


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s