Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Commit for Asynchronous Function Module

Former Member
0 Likes
2,542

Halo Experts,

I am working on an Perfomance Optimization project . I am trying to optimize the program by scehduling the individual methods inside the program via asynchronous function modules . By this way I can run this independent methods parallely ( and not sequentailly) . for eg

if the program has

 
 me->m1( ).
 
me->m2( ).
 
me->m3( )
 


if m2 and m3 are independent of each other I schedule them parallely by

me->run_m2_m3_parallely( ) see the below code

 

CALL FUNCTION 'ZM2'
    STARTING NEW TASK 'FUNC1'
    DESTINATION 'NONE'
    CALLING ZCLASS=>set_flag_4_m2 ON END OF TASK.
 
CALL FUNCTION 'ZM3'
    STARTING NEW TASK 'FUNC2'
    DESTINATION 'NONE'
    CALLING ZCLASS=>set_flag_4_m3 ON END OF TASK.
 
 
 
 
  WAIT UNTIL l_m2_flag = 'X' AND
             l_m3_flag = 'X'.
 
  

the FMs ZM2 and ZM3 are updating Z Database tables( say ZM2 and ZM3 ) . Do I need an explicit commit work for Individual FMs or a single commit work for both the FMs.

How can I roll back both the updates to the database if a dump occurs ?

How should the commit work statement be in this case ?

Regards

Arshad

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,557

Hello Arshad,

When you're using asynch-RFC(aRFC) they are run in separate RFC contexts which don't share a common LUW. You need to maintain an explicit commit to store the data in the DB tables.

How can I roll back both the updates to the database if a dump occurs?

What exactly is your requirement, can you elaborate?

BR,

Suhas

PS: If you're using a transactioncal RFC(tRFC), they are registed in a common LUW.

8 REPLIES 8
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,558

Hello Arshad,

When you're using asynch-RFC(aRFC) they are run in separate RFC contexts which don't share a common LUW. You need to maintain an explicit commit to store the data in the DB tables.

How can I roll back both the updates to the database if a dump occurs?

What exactly is your requirement, can you elaborate?

BR,

Suhas

PS: If you're using a transactioncal RFC(tRFC), they are registed in a common LUW.

Read only

Former Member
0 Likes
1,557

Halo Suhas,

My aim is to run independent methods parallely so that I can optimise the perfomance of the program

My question regarding roll back was if some exception happens and dumps in Zm3 , will the M2 update be rolled back also?( because we are having individual commits inside Zm2 and Zm3 )

I tried this parallel execution , it is succesfully updating table m2 ( same as the number of entries of sequential run ) and table m3 it is not updating.

But the strange thing is if I put user defined break point in Zm3 and executing the program it is correctly updating m3 table .

Regards

Arshad

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,557

Hello Arshad,

My question regarding roll back was if some exception happens and dumps in Zm3 , will the M2 update be rolled back also?( because we are having individual commits inside Zm2 and Zm3 )

No, because you're running the updates in parallel, if you want to achieve this requirement you'll have to bundle the updates in a single LUW.

I tried this parallel execution , it is succesfully updating table m2 ( same as the number of entries of sequential run ) and table m3 it is not updating.

Are you issuing a COMMIT WORK in the asych task 'M3'?

BR,

Suhas

Read only

Former Member
0 Likes
1,557

Yes I am using commit work inside task M3 also.

Regards

Arshad

Read only

arseni_gallardo
Active Participant
0 Likes
1,557

I think you can solve your issue by using the KEEPING TASK addition.

In your ZCLASS=>set_flag_4_m2 method try this:


METHOD set_flag_4_m2.
  RECEIVE RESULTS FROM FUNCTION 'ZM2 ' KEEPING TASK.
 
ENDMETHOD.
METHOD set_flag_4_m3.
  RECEIVE RESULTS FROM FUNCTION 'ZM3 ' KEEPING TASK.
ENDMETHOD.

And after your wait you can try to do this:


WAIT UNTIL l_m2_flag = 'X' AND
             l_m3_flag = 'X'.

* In set_func2_commited you must receive results from BAPI_tRANSACTION_COMMIT and set global flag g_func2_commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    STARTING NEW TASK 'FUNC2'
    DESTINATION 'NONE'
    CALLING ZCLASS=>set_func2_commited ON END OF TASK.

* In set_func3_commited you must receive results from BAPI_tRANSACTION_COMMIT and set global flag g_func3_commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    STARTING NEW TASK 'FUNC3'
    DESTINATION 'NONE'
    CALLING ZCLASS=>set_func3_commited ON END OF TASK.
WAIT UNTIL g_func3_commit EQ 'X' and g_func2_commit EQ 'X'.

Read only

0 Likes
1,557

Halo Arseni,

Thanks for your reply . I tried the same but still the table M3 is not updated . While going in debugging its still updated . Dont know what really is the issue here ?

Regards

Arshad

Read only

Former Member
0 Likes
1,557

Hi,

As said by Suhas, bundle into one LUW. then it will work..

Instead of upadating tables directly in FM Z2 , and Z3 , recieve the results back to main internal session and use UPDATE Function module to update the tables..

RECEIVE RESULTS FROM FUNCTION z2 
                parameter_list 

RECEIVE RESULTS FROM FUNCTION z3 
                parameter_list

Regards,

Ravi.

Read only

0 Likes
1,557

Halo rshankar,

I cant change the existing logic of the program . So the table updates takes place in method m2 and m3 . and I need to put the same inside Async FM ZM2 and ZM3

Regards

Arshad