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

Call a subroutine from a Method in background mode

former_member201275
Active Contributor
0 Likes
3,864

I have a method which calls a subroutine 'USER_COMMAND' in Program 'MYPROGAM'. In foreground this works fine the code in the subroutine is executed. Is there a way to do this in background? When I run in background the code in the subroutine is not executed.

All help greatly appreciated.

1 ACCEPTED SOLUTION
Read only

former_member201275
Active Contributor
3,501

I have solved this using the advice of Raymond Giuseppi i.e. rewrite the whole Code. For some reason I cannot 'accept' his answer. All of the other answers though also helped me a lot!

I have a method which calls a subroutine 'USER_COMMAND' in Program 'MYPROGAM'. In foreground this works fine the code in the subroutine is executed. Is there a way to do this in background? When I run in background the code in the subroutine is not executed.

All help greatly appreciated.

12 REPLIES 12
Read only

ThomasZloch
Active Contributor
3,501

Handling user commands in background does not make sense, does it?

Read only

former_member201275
Active Contributor
0 Likes
3,501

Hi Thomas,

sorry, left out the part where i force the user_command:

Read only

RaymondGiuseppi
Active Contributor
3,501

IMHO setting the status doesn't make more sense, could you consider executing the form in your main code before calling FM (even do not call the FM if spool not required, and then convert to OO) you could check if sy-batch is not initial or use a print event and not a screen event.

Read only

former_member201275
Active Contributor
0 Likes
3,501

Hi Raymond,

I have commented that out but it doesn't work either.

What I would like to do is execute the code in subroutine 'USER_COMMAND' of program 'MYPROGAM' when the program is run in background. Not sure if this can be called from a method in background mode?

At the moment when the program is run in foreground, the USER_COMMAND subroutine is called and the user can then click on a button called 'BOOK' to make a booking. I want to change the program so that it runs in background and forces the booking.

Read only

RaymondGiuseppi
Active Contributor
3,501

Assertion 'At the moment when the program is run in foreground, the USER_COMMAND subroutine is called and the user can then click on a button called 'BOOK' to make a booking.' is false!

In foreground the ALV grid is displayed, and when user interacts with screen the user_command and other events are triggered so the form would be executed. the SET_PF_STATUS form is only executed in foreground in the PBO of screen...

In background, a spool is génerated by REUSE_ALV_LIST_DISPLAY and bye, Bye. (look for cl_gui_alv_grid=>offline( ) in the FM execution)

So use a print event such as TOP_OF_PAGE and check if sy-batch is set. Or rewrite youw whole code for better reusability...

Read only

0 Likes
3,501

(Converted to answer)

Read only

Sandra_Rossi
Active Contributor
3,501

I vote for Raymond answer : "... or rewrite your whole code for better reusability"

Read only

matt
Active Contributor
3,501

Rewrite your code so you use CL_GUI_ALV_GRID or CL_SALV_TABLE directly.

Read only

former_member201275
Active Contributor
0 Likes
3,501

Thank you to all of you so much for your help. 😞

Read only

mmcisme1
Active Contributor
0 Likes
3,501

You could try using the parameter IS_PRINT_LVC. I believe that's what I used. However, it's been a long time. If you have the time, the best thing to do is to use one of the classes suggested above. They are actually a lot easier to work with than the function module.

Read only

former_member201275
Active Contributor
3,502

I have solved this using the advice of Raymond Giuseppi i.e. rewrite the whole Code. For some reason I cannot 'accept' his answer. All of the other answers though also helped me a lot!

Read only

3,501

raymond.giuseppi please convert your comment into an answer 🙂