This document will show you how to use AIF Customizing to define multiple conditional checks. Additionally the alternative with an ABAP function module will also be presented.

In SAP AIF you have the possibility to use checks to verify if the content of the specified field matches a certain condition. When a checks fails, you can stop processing and don’t have to wait for a SAP BAPI message.

Checks can be located in Define Checks and defined by entering the namespace for which you want to create the check.

/wp-content/uploads/2015/11/sap_aif_define_checks_834589.png

For certain business cases it is required that a certain field matches more conditions. In order to exemplify this, the following scenario will be used.

In order to process an Order IDoc the material number used by vendor in E1EDP19 -> IDTNR for qualifier QUALF “002” should meet the following criteria:

  • If the material number doesn’t exist in table ZAIF_MVKE_TBL then everything is ok and the order IDoc should be processed;
  • For QUALF “002” if the material number exists in table ZAIF_MVKE_TBL, the sales organization VKORG is “ZUS2”, the system-date sy-date is newer as the date from which distr.-chain-spec. material status is valid VMSTD and the distribution-chain-specific material status VMSTA is “02”, “03” or “04”, then the IDoc processing should be stopped, an error message outputted and the causing field(s) IDTNR marked in red.

In order to illustrate the use case better the following diagram was used:

/wp-content/uploads/2015/11/sap_aif_decison_tree_834689.jpg

In SAP AIF you can use customizing or you can define your own function module for your desired check. In this article both solutions will be presented.

Because only some data needs to be checked the preprocessing mode will be used. In this mode SAP AIF will execute the mapping logic on top of IDoc raw message data and there is limited maintenance effort in Customizing.

For this functionality you have to configure the ALE runtime to call the generic inbound process function of the SAP AIF. In this document http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/e0f445c1-deb8-3110-7ebf-9665f7c1ed94&overridelayout=true you will find a good description on how you can do this.

To activate preprocessing, select the Preprocessing checkbox in Customizing for SAP Application Interface Framework under Interface Development -> Define Interfaces, like in the figure below:

/wp-content/uploads/2015/11/sap_aif_define_interfaces_834690.png

For this check, you will need fields from the second structure level, so you have to define a  structure mapping like shown below.


sap_aif_define_structure_I.pngsap_aif_define_structure_II.png

In AIF you have the possibility to use checks to verify if the content of the specified field matches a certain condition. There are several places where checks can be used, for example in structure mappings or assigned to a function in an action.
Checks can be located in Define Checks and defined by entering the namespace for which you want to create the check.

sap_aif_define_structure_IV.pngsap_aif_define_structure_V.pngsap_aif_define_structure_III.png

Customizing solution


Now you can define checks for any field of the structure E1EDP19.
For that go to Assign checks. Here you can use the diagram above in order to follow the logic flow of the checks.

The first step is to check if the qualifier QUALF is 002. If this is the case then the next step will be processed.


/wp-content/uploads/2015/11/sap_aif_first_check_834696.png


/wp-content/uploads/2015/11/sap_aif_second_check_834697.png


In the figure below you can see how the check CHECK_MAT_EXIST is defined.


/wp-content/uploads/2015/11/sap_aif_second_check_details_834698.png


For the last step the check CHECK_MAT_COND was used which will give an error if for the defined condition:
material status VMSTA is “02”, “03” or “04”.


/wp-content/uploads/2015/11/sap_aif_third_check_834699.png


For the check an error msg. class was defined which raises a certain message in case of an error. For the error message the value of the field IDTNR will be used dynamically in the message.


sap_aif_third_check_details_II.pngsap_aif_third_check_details_I.png


These are all the necessary steps required for this check to work. At the end you can test the development with a large variety of options in order to see if you achieve the desired results.


Testing:


In the following figure you can see the entries in the table ZAIF_MVKE_TBL.      


ZAIF_MVKE_TBL.png


Based on the content of the table ZAIF_MVKE_TBL we can see that multiple checks – defined in AIF customizing – fulfill the specified requirements.


sap_error_handling_II.pngsap_error_handling_I.png


Function module solution:


If you want to develop a check function module then the function module should have the same signature as the template /AIF/FILE_TEMPL_CHECK. Then you can write your own code in order tosolve the problem by using only one check. For the specified use case, the following ABAP-Code was used in order to solve the problem.


FUNCTION ZAIF_MATNR_CHECK .

data: lv_vmsta type VMSTA.

if VALUE2 = ‘002’.

select VMSTA into lv_vmsta from ZAIF_MVKE_TBL
where MATNR = VALUE1 and VKORG = ‘ZUS2’ and VMSTD <= SYDATUM.
if sysubrc = 0.
ERROR
= ABAP_TRUE.
else.
endif.
endselect.

endif.

ENDFUNCTION.


When you develop the code you should consider which fields from the IDoc you will use for your check. You can define up to five fields from Fieldname 1 to Fieldname 5 which will correspond to VALUE1 from VALUE5 in the function module with the specified template.


sap_error_handling_I.png


sap_error_handling_II.png


Then you go to the structure and assign the check like in the picture below. Here is important to enter the fields corresponding to the variables in the function module. With other words IDTNR comes in Fieldname 1 and QUALF in Fieldname 2. In order to check the raw data, select Check Raw data


/wp-content/uploads/2015/11/sap_aif_check_raw_data_834728.png

Testing:


In order to compare the results from the function module with the results from the multiple checks the entries in the table weren’t modified and the order IDoc contains the same material numbers.


Based on the content of the table ZAIF_MVKE_TBL we can see that the function module fulfills the specified requirements and delivers the same result as the multiple checks.


/wp-content/uploads/2015/11/sap_aif_test_1_834729.png/wp-content/uploads/2015/11/sap_aif_test_2_834730.png

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply