Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
akmal1216
Employee
Employee
6,715
Dear All,

I would like to share one interesting case related to AIF Automatic Reprocessing in this blog. It made my life easier, so I decided to share it with you 😊

Requirement


Recently I had requirement to make some enhancements in Sales Order change VA02 Tcode. So, to be more exact, in case of adding new item positions the same item position should be created in respective outbound delivery. It could be specific requirement regarding the customer, but customer is always right 😊

Problem area:


So, nothing is special here to do the above requirement. You can easily find include to do the enhancements in VA02 and use standard BAPI or BDC to insert the new item position to the respective outbound delivery. Some selects and mapping data to BAPI structures. Voila... it is done.

But in the real life not everything is as easy as it sounds. During process I came across with error VL045 - The sales order &1 is currently being processed by user &2.

So, it showed the current sales order is locked by my own user while doing changes in VL02N.


Yes, that’s correct since both processes are interconnected, inserting the new item position to outbound delivery checks if Sales Order transaction is locked or not.

Solution area:


Then I understood that I need a tool which can save the current payload and re-process it after some time. Besides, user can do some extra changes in VA02, in that case my solution should be triggered until I don't get error message VL045 - The sales order &1 is currently being processed by user &2.

So, tool should include number of counters to set how many times my logic should be triggered and amount of time ( minutes/seconds ) to set time interval to the logic triggering.

Additionally, logic should be triggered only and only having VL045 error message.


And… I found out AIF automatic reprocessing is the best fit here.

So, what’s AIF automatic reprocessing and how to use it in my case. According to the official documentation:

In the SAP Application Interface Framework, a reprocessing action is the technical representation of a function module that is called by a batch job. A reprocessing action contains the appropriate AIF runtime configuration group and the function module that is called by the reprocessing job.

The AIF runtime schedules a reprocessing action for registered error messages according to your settings in the following configuration tables:

  • AIF Automatic Reprocessing: Define Reprocessing Action(transaction code /AIF/REP_AC_DEF )

  • AIF Automatic Reprocessing: Assign Reprocessing Action(transaction code /AIF/REP_AC_ASGN)


 

Firstly, execute /AIF/CUST transaction to create namespace via Define Namespace and assign the interface to your namespace via Define Interfaces. So, here is the result in my case:


Don’t forget to check the Move Corresponding Structures.

As for the SAP Data Structure and Raw Data Structure, they should have the structure which keeps payload, and it will be used later in FM. In my case, I have created structure which includes three main fields to insert new position to the existing outbound delivery:


As the next step, expand Additional Interface Properties in /AIF/CUST and execute Specify Interface Engines and set Structured Persistence to the following three fields:


Now we need to create action and FM by executing Define Actions. As for the FM


As for the FM, choose Define functions and insert FM name, by clicking SAVE or ENTER, pop-up asks you copy FM from AIF template. Just click COPY and that’s it.


So far so good. We have already created some basic AIF staff like namespace, interface, persistence structure and action. It is time to do structure and action mapping. To do this, execute Define Structure Mappings insert your namespace, interface, and version number. Then in the source structure set your structure which you created in previous steps and do the same with Assign Actions.


Hugh, finally it is time to create the main objects to implement automatic re-processing. First step here is to create runtime group configuration via Tcode  /AIF/PERS_CGR


Attention !!! Don’t forget to check Runtime Cfg Active and Run Scheduled checkboxes.

Now let’s define reprocessing action, using Tcode /AIF/REP_AC_DEF


Pay attention that /AIF/RESTART_MSG is set.

The SAP Application Interface Framework delivers the /AIF/RESTART_MSG function module to automatically restart registered error messages.

Finally, as the last step in AIF, we need to assign error message and reprocessing action in Tcode /AIF/REP_AC_ASGN.


So now, in case of error message VL045, AIF will trigger my logic inside generated FM ten times within every 10 seconds, until it gets successfully processed.

Now let’s add piece of logic to the generated FM and call FM in VA02 enhancement.

First, let’s add necessary logic to insert the new item to the outbound delivery in the generated FM ZAKB_FM_INSERTITEMOBD.

FM has changing parameters and there is one called CURR_LINE, change it is type to your persistence structure:


Here, I found two ways to insert new item to the outbound delivery:

  1. using BAPI BAPI_DELIVERYPROCESSING_EXEC

  2. using BDC to copy the new item from VA02 to VL02N


I just used BDC way to illustrate in this blog. And here is sample source code:
FUNCTION zakb_fm_insertitemobd .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(TESTRUN) TYPE C
*" REFERENCE(SENDING_SYSTEM) TYPE /AIF/AIF_BUSINESS_SYSTEM_KEY
*" OPTIONAL
*" TABLES
*" RETURN_TAB STRUCTURE BAPIRET2
*" CHANGING
*" REFERENCE(DATA)
*" REFERENCE(CURR_LINE) TYPE ZAKB_S_OBD_PAYLOAD
*" REFERENCE(SUCCESS) TYPE /AIF/SUCCESSFLAG
*" REFERENCE(OLD_MESSAGES) TYPE /AIF/BAL_T_MSG
*"----------------------------------------------------------------------
BREAK-POINT. "#EC NOBREAK

DATA lt_bdcdata TYPE TABLE OF bdcdata.
DATA lt_messtab TYPE TABLE OF bdcmsgcoll.

CLEAR: lt_bdcdata,
lt_messtab.

"1st Screen
APPEND INITIAL LINE TO lt_bdcdata ASSIGNING FIELD-SYMBOL(<ls_bdcdata>).
<ls_bdcdata>-program = 'SAPMV50A'.
<ls_bdcdata>-dynpro = '4004'.
<ls_bdcdata>-dynbegin = 'X'.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'LIKP-VBELN'.
<ls_bdcdata>-fval = curr_line-delivery.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'BDC_OKCODE'.
<ls_bdcdata>-fval = '=ENT2'.


APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-program = 'SAPMV50A'.
<ls_bdcdata>-dynpro = '1000'.
<ls_bdcdata>-dynbegin = 'X'.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'BDC_OKCODE'.
<ls_bdcdata>-fval = '=RAUF_T'.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-program = 'SAPMV50A'.
<ls_bdcdata>-dynpro = '0105'.
<ls_bdcdata>-dynbegin = 'X'.


APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'LV50C-DATBI'.
<ls_bdcdata>-fval = sy-datum+6(2) && '.' && sy-datum+4(2) && '.' && sy-datum(4).

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'LV50C-VBELN'.
<ls_bdcdata>-fval = curr_line-salesdocument.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'LV50C-ABPOS'.
<ls_bdcdata>-fval = curr_line-salesdocumentitem.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'LV50C-BIPOS'.
<ls_bdcdata>-fval = curr_line-salesdocumentitem.

DATA: lv_datum TYPE dats.
lv_datum = sy-datum + 30.
APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'LV50C-DATBI'.
<ls_bdcdata>-fval = lv_datum+6(2) && '.' && lv_datum+4(2) && '.' && lv_datum(4). .


APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'BDC_OKCODE'.
<ls_bdcdata>-fval = '=ENT1'.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'BDC_OKCODE'.
<ls_bdcdata>-fval = '=ENT1'.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'BDC_OKCODE'.
<ls_bdcdata>-fval = '=BACK_T'.

IF lt_bdcdata[] IS NOT INITIAL.
"Last Screen (Save)
APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-program = 'SAPMV50A'.
<ls_bdcdata>-dynpro = '1000'.
<ls_bdcdata>-dynbegin = 'X'.

APPEND INITIAL LINE TO lt_bdcdata ASSIGNING <ls_bdcdata>.
<ls_bdcdata>-fnam = 'BDC_OKCODE'.
<ls_bdcdata>-fval = '=SICH_T'.
ENDIF.

DATA(lv_mode) = 'N'.
CALL TRANSACTION 'VL02N' USING lt_bdcdata
MODE lv_mode
UPDATE 'S'
MESSAGES INTO return_tab.
ENDFUNCTION.

Now we need to register the call to FM, in case of new item insertion in the Sales Order, use include MV45AFZZ and subroutine userexit_save_document_prepare, it is triggered when clicking the SAVE button in VA02 Tcode.

Here is source code to call AIF re-processing event with out namespace and runtime configuration ID:
" Call AIF automatic re-processing
TRY.
/aif/cl_enabler_xml=>transfer_to_aif( is_any_structure = ls_new_itemobd " Persistence structure type to keep payload
iv_queue_ns = 'ZIFTST' " AIF Namespace
iv_queue_name = 'ZRC' ). " Runtime group configuration ID

CATCH /aif/cx_aif_engine_not_found INTO DATA(lx_engine_not_found).
CATCH /aif/cx_enabler_base INTO DATA(lx_enabler_base).
CATCH /aif/cx_aif_engine_base INTO DATA(lx_engine_base).
CATCH /aif/cx_error_handling_general INTO DATA(lx_error_handling).
CATCH /aif/cx_inf_det_base INTO DATA(lx_inf_det_base).
ENDTRY.

Yuuhuu, that’s it, we did it. Now we have automatic reprocessing which will be triggered in every 10 seconds in case of VL045 error message, while inserting new item in Sales Order.

Some useful tips.

  1. You can check if process is really registered in automatic reprocessing or process is successfully finished in /AIF/ERR. Insert your namespace, interface, and interface version number. Choose Today in Generic selection and select all statuses in Status selection sections.

  2. If reprocessing is not registered, then double check if assigned message is correct.

  3. If you want to see payload data that’s processed, generate AIF persistence table via /AIF/PERS_TBL_GEN Tcode. After generating you see all the payloads via SE16N, and it is good to analyzing purpose.

  4. Unfortunately, you can’t debug your AIF FM directly. But you can do it by generating the test data in /AIF/ERR in Technical Mode. Then go to Tcode /AIF/IFTEST, choose your generated test file. Then choose RAW file and click Analyze button. By this it will execute generated FM with payload in debug mode.


 

To sum up:

In the SAP AIF automatic re-processing easily generates background job and you can easily set counters and time to retry process again. Another important and usefull point is process it will create background job only when triggered by error messages you have registered.

 

Usefull documents:

 

If you find blog insightful and interesting, please follow my profile for further interesting technical topics.

I will be gratefull for you comments and feedbacks.

Till then happy coding 😊
2 Comments
Labels in this area