Displaying ALV Grid in Background Job
Many a times there is a requirement to display ALV Grid (not ALV List) in the background Job. I have checked the SDN Forum for the same and it has been mentioned that ALV Grid cannot be displayed in Background, but the list output of ALV is possible. So user wont have the actual Grid interface but the List interface.
There is a workaround to display ALV Grid in Background Job. The only restriction is you cant schedule the job through SM36. You need to execute the transaction of the report program, fill in the selection screen data and hit Execute.
The job would be executed in background. User will be able to see the Job Log and Job Status after executing the program. User doesnt have to go to SM37 to view the job status/log. Once the Job Status is changed to COMPLETED, user can click on DISPLAY SPOOL to view the ALV Grid.
Limitations:
- Cant schedulea background job
- The session should be active until the background job is completed. If the session is closed, then user wont be able to check the output in ALV Grid. User would be able to check the output through spool or SM37
Advantages:
- If the spool width is greater than 255 characters, then the entire width could be seen in the output because the output is directed to an ALV Grid and not to spool
- Interface of ALV Grid is available instead of ALV List even though its a background job.
- Program wont give the TIME OUT error
Steps Required:
- 1. Once you execute the program, the following screen would be displayed
- 2. Click Display Job Status to check the Status of the Background Job
- 3. Click on Display the Job Log to check the Log
- 4. Click on Display Job Status to check the Job Status
- 5. Click on DISPLAY SPOOL to check the spool content once the Job Status is changed to COMPLETED. Output is displayed in ALV Grid
Programs:
1. Two different programs needs to be created
ZPROGRAM_ONE: This is the 1st program, where the selection screen and all the data validations would be done. Error handling for invalid data should be done in this program.
Once the data validation is done, this program would call the 2nd program ZPROGEAM_TWO. Build the logic to display ALV Grid in this program. The logic will only display ALV in foreground and it wont be reflected in the spool.
ZPROGRAM_TWO: This program would fetch all the data and do all the processing. If you want the spool output along with ALV Grid output, then build the logic in this program to display ALV Grid.





Greetings,
Blag.
Cheers
Thanks for the input. I have removed the blank spaces.
I hope the code looks much better now.
Best regards,
Prashant
A good idea to store the data that is fetched in indx.
Now if you are storing the data in INDX, then all you have to do is write a program to list out contents in INDX for a particular area and then when a particular record is selected, pick up the data and call the display routine to show the alv grid.
If you do the above, then both your 'limitations' vanish. 🙂
regards,
Kevin
Thanks for your valuable suggestion.
The suggestion which you have given is the same thing which i have implemented. But it doesnt overcome the limitations.
Through SM37, if you check the spool content, it will always be displayed in ALV List format and not in Grid format.
Hence the limitation to execute the program and keep the session active rather than killing the session.
Best regards,
Prashant
Tell me what is the use of this article if you couldn't schedule it in background.
Regs,
Venkat Ramanan N
Many a times, a program when executed in foreground gives a dump because of Max. time limit of execution set in SAP.
If the max. execution time is set to say 5 min., and if your program to display output in ALV takes 6 or 7 min. . You can't execute such program in foreground bcz it will time out.
No point in scheduling the job in background bcz User wants to see an interactive ALV output and not ALV list.
In such case, the only alternative is to use the program mentioned in the Blog.
Hence the purpose of this article.
Hope it clears your doubts.
Best regards,
Prashant
Is it possible for you to provide some details with respect to OO ALV display?
Any way thanks for sharing the information.
Thanks.
Yes, its possible to display ALV Grid using OO ALV. Following code can be used instead of FM.
* In the PBO, add following code
SET PF-STATUS 'ZSTAT'.
* If program is executed in background
CALL METHOD cl_gui_alv_grid=>offline
RECEIVING
e_offline = off.
IF off IS INITIAL.
IF container1 IS INITIAL.
CREATE OBJECT container1
EXPORTING
container_name = 'CC_ALV1' .
ENDIF.
ENDIF.
CREATE OBJECT g_grid1
EXPORTING
i_parent = container1.
CALL METHOD g_grid1->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
i_save = 'A'
i_default = ' '
* is_layout =
* is_print =
* IT_SPECIAL_GROUPS =
* it_toolbar_excluding =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
CHANGING
it_outtab = i_output
it_fieldcatalog = i_fieldcatalog
* IT_SORT =
* IT_FILTER =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Best regards,
Prashant
However, the background program can also be called using the SUBMIT command, which may make select-option and parameter passing more easy:
SUBMIT PROGRAM_TWO
WITH s_sel1 BETWEEN s_sel1-low AND s_sel1-high
WITH s_sel2 BETWEEN s_sel2-low AND s_sel2-high
WITH p_parm1 = p_parm1
TO SAP-SPOOL
SPOOL PARAMETERS print_parameters
WITHOUT SPOOL DYNPRO
VIA JOB jobname NUMBER jbcount
AND RETURN.
This just as a suggestion.
Regards,
Trond
plz check with FM 'REUSE_ALV_GRID_DISPLAY_LVC'. It can display in background.
In this program, ALV Grid is displayed in foreground session, and the only portion which is done in background is the data processing part.
The author himself mentions that, "The session should be active until the background job is completed". Whereas the title reads, "Displaying ALV Grid in Background Job".
I feel the title is misleading.
Regards,
-Abhijit.