Application Development 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: 

ALV: Foreground Vs Background

Former Member
0 Kudos

Can someone explain steps involved in coding ALV which can be used both in foreground and in background?

Thanks,

Bala

10 REPLIES 10

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Use function module REUSE_ALV_GRID_DISPLAY.

First, build your ALV internal table to store the data to be shown in report. Then build your field catalog. Then call REUSE_ALV_GRID_DISPLAY.

If you need a complete sample program, I can post one.

Regards,

Rich Heilman

0 Kudos

Here is a sample program for you. Running this program in background will automatically convert to print preview mode when printing occurs. You can then check the spool via SP01. Hope this helps.

Regards,

Rich Heilman

********************************************************

  • Created 05/28/2004 By: Rich Heilman, Jr.

********************************************************

REPORT ZSAMPLE .

TABLES: VBAP.

  • Global ALV Data Declarations

TYPE-POOLS SLIS.

  • Miscellanous Data Declarations

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  • Internal Tables

DATA: BEGIN OF IALV OCCURS 0,

VBELN TYPE VBAP-VBELN,

POSNR TYPE VBAP-POSNR,

MATNR TYPE VBAP-MATNR,

KWMENG TYPE VBAP-KWMENG,

END OF IALV .

  • Selection Screen

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .

SELECT-OPTIONS: S_VBELN FOR VBAP-VBELN,

S_POSNR FOR VBAP-POSNR.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM CALL_ALV.

                                                                                                                      • FORM GET_DATA.

**********************************************************

FORM GET_DATA.

CLEAR IALV. REFRESH IALV.

SELECT * INTO CORRESPONDING FIELDS OF TABLE IALV

FROM VBAP

WHERE VBELN IN S_VBELN

AND POSNR IN S_POSNR.

ENDFORM.

**********************************************************

  • CALL_ALV

**********************************************************

FORM CALL_ALV.

DATA: VARIANT TYPE DISVARIANT.

VARIANT-REPORT = SY-REPID.

VARIANT-USERNAME = SY-UNAME.

PERFORM BUILD_FIELD_CATALOG.

  • Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IT_FIELDCAT = FIELDCAT

IS_VARIANT = VARIANT

I_SAVE = 'U'

TABLES

T_OUTTAB = IALV.

ENDFORM.

**********************************************************

  • Form BUILD_Fieldcatalog - Set Up Columns/Headings

**********************************************************

FORM BUILD_FIELD_CATALOG.

DATA: LS_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

REFRESH: FIELDCAT.

CLEAR: LS_FCAT.

LS_FCAT-REPTEXT_DDIC = 'Sales Doc Number'.

LS_FCAT-FIELDNAME = 'VBELN'.

LS_FCAT-OUTPUTLEN = '10'.

LS_FCAT-COL_POS = 1.

APPEND LS_FCAT TO FIELDCAT.

CLEAR: LS_FCAT.

LS_FCAT-REPTEXT_DDIC = 'SD Item'.

LS_FCAT-FIELDNAME = 'POSNR'.

LS_FCAT-OUTPUTLEN = '6'.

LS_FCAT-COL_POS = 2.

APPEND LS_FCAT TO FIELDCAT.

CLEAR: LS_FCAT.

LS_FCAT-REPTEXT_DDIC = 'Material'.

LS_FCAT-FIELDNAME = 'MATNR'.

LS_FCAT-OUTPUTLEN = '18'.

LS_FCAT-COL_POS = 3.

LS_FCAT-NO_OUT = 'X'.

LS_FCAT-REF_FIELDNAME = 'MATNR'.

LS_FCAT-REF_TABNAME = 'MARA'.

APPEND LS_FCAT TO FIELDCAT.

CLEAR: LS_FCAT.

LS_FCAT-REPTEXT_DDIC = 'Quantity'.

LS_FCAT-FIELDNAME = 'KWMENG'.

LS_FCAT-OUTPUTLEN = '12'.

LS_FCAT-COL_POS = 5.

APPEND LS_FCAT TO FIELDCAT.

ENDFORM.

Former Member
0 Kudos

Thank you for your response, Rich. It is so fast.

I was reading the documentation in SAP Library and found the similar example shown below. It works fine. (I apologize for any improper copy&paste!!).

Thanks,

Bala

&----


*& Report ZBA_TEST_ALV_001 *

*& *

&----


*& *

*& *

&----


REPORT zba_test_alv_001 .

  • Tables

TABLES: mara.

  • Output internal table

DATA: itab TYPE TABLE OF mara.

  • ALV Grid

DATA: r_grid TYPE REF TO cl_gui_alv_grid.

DATA: r_control TYPE REF TO cl_gui_custom_container.

DATA: g_dock TYPE REF TO cl_gui_docking_container.

  • Other Data Declaration

DATA: okcode(4) TYPE C.

  • Selection screen

SELECTION-SCREEN BEGIN OF BLOCK ONE with frame.

SELECT-OPTIONS: so_matnr FOR mara-matnr.

SELECTION-SCREEN END OF BLOCK ONE.

START-OF-SELECTION.

SELECT * FROM mara INTO TABLE itab WHERE matnr IN so_matnr.

CALL SCREEN 100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'LISTOUT1'.

SET TITLEBAR 'LIST1'.

IF r_control IS INITIAL.

  • Check whether the program is run in batch or foreground

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

  • Run in foreground

CREATE OBJECT r_control EXPORTING container_name = 'CONTAINER_1'.

CREATE OBJECT r_grid EXPORTING i_parent = r_control.

ELSE.

  • Run in background

CREATE OBJECT r_grid EXPORTING i_parent = g_dock.

ENDIF.

  • Structure ZBA_MARA1 is defined in DDIC as linetype

CALL METHOD r_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'ZBA_MARA1'

CHANGING

it_outtab = itab.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

CASE okcode.

WHEN 'BACK'.

SET SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

0 Kudos

I wouldn't use that code if I were you. If submitted in background it will bomb every time. Remember that "CALL SCREEN" is a dialog statement. Background process does not know where to throw the screen. That is why I sent you the code for using the function module. Its easier and cleaner. I am 100% sure that your previous code will not work. I have written ABAPS using both ways. I only use the "OBJECT" way when the user has to select rows in the ALV grid. Otherwise I use the FM.

Regards,

Rich Heilman

0 Kudos

Bala,

I tried your example, but found that on executing it in background, i just do get the List output and not the alv output as i do get when i run it in foreground.

Thanks in advance....

Balaji

Former Member
0 Kudos

Contrary to popular opinion, "Call Screen . . ." syntax for ALV can be used for background processing. We've done it. We do not allow the use of the REUSE functions because SAP does not officially support these functions.

0 Kudos

Wow! How did you do it!!?? Did you use SUPRESS DIALOG by any chance?

REUSE FM processing takes place in the server and CREATE OBJECT processes at the frontend (GUI) level. So technically REUSE FM's shouldnt be used at all as it takes up server processing time...but can the 'CALL SCREEN' statement be used in the background? I thought it bombs out?

Very curious

Cheers,

Sougata.

Former Member
0 Kudos

Hi Kenneth,

its happy to note that it can be run in background.

can you explain how you did it.

it would be of great help.

thnx in advance...

regards

Balaji

0 Kudos

Trust you figured this out by now but... just in case:

  • Create Container object - but not in background

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

CREATE OBJECT alv_cus_con EXPORTING container_name = alv_con.

ENDIF.

Former Member
0 Kudos

My example above with 'Call Screen ..' works fine in background. FYI.

Thanks,

Bala