Skip to Content

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 won’t 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 can’t 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 doesn’t 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:

  1. Can’t schedulea background job
  2. The session should be active until the background job is completed. If the session is closed, then user won’t be able to check the output in ALV Grid. User would be able to check the output through spool or SM37

Advantages:

  1. 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
  2. Interface of ALV Grid is available instead of ALV List even though it’s a background job.
  3. Program won’t give the TIME OUT error

Steps Required:

  • 1. Once you execute the program, the following screen would be displayed

image

  • 2. Click “Display Job Status” to check the Status of the Background Job

image

  • 3. Click on “Display the Job Log” to check the Log

image

  • 4. Click on “Display Job Status” to check the Job Status

image

  • 5. Click on “DISPLAY SPOOL” to check the spool content once the Job Status is changed to “COMPLETED”. Output is displayed in ALV Grid

image

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 won’t 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.

To report this post you need to login first.

14 Comments

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

  1. Kevin Hill
    hi,

    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

    (0) 
    1. Prashant Patil Post author
      Hi 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

      (0) 
    1. Prashant Patil Post author
      Hi Venkat,

      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

      (0) 
  2. Amit Khare
    Even a backlog of not running in background is there but still this is something new for me as all this time I am under this impression only that at any point we cant use GRID display for background process.
    Is it possible for you to provide some details with respect to OO ALV display?

    Any way thanks for sharing the information.

    (0) 
    1. Prashant Patil Post author
      Hi Amit,

      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

      (0) 
  3. Anonymous
    This was great. I used the principle in a report of my own after reading your blog.

    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

    (0) 
  4. Abhijit Deshmukh
    I feel the title of this blog is misleading.

    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.

    (0) 

Leave a Reply