Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

SAP alv Layout programming

Some requirements need to allow user to choose a specific layout in the report selection screen. This means that
we need to add some additional codes to achieve that. There several FM for this purpose.
REUSE_ALV_VARIANT_DEFAULT_GET get the default layout of this report
REUSE_ALV_VARIANT_EXISTENCE check whether the input layout name exists
REUSE_ALV_VARIANT_F4 pop up a screen to allow user to choose existing layout
Below are several steps to use these FM.
Step 1. Define layout data.
DATA: GS_VARIANT LIKE DISVARIANT. define the data representation of a layout
V_EXIT.
Step 2. Define selection screen.

SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.

PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT. "define a parameter using


type DISVARIANT-VARIANT

SELECTION-SCREEN END OF BLOCK B3.


Step 3. Define event AT SELECTION-SCREEN ON VALUE-REQUEST FOR .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.


GS_VARIANT-REPORT = SY-REPID. "set the report name to the current
report.

CALL FUNCTION REUSE_ALV_VARIANT_F4 "call layout selection screen


EXPORTING
IS_VARIANT = GS_VARIANT
I_SAVE = 'A'
IMPORTING
E_EXIT = V_EXIT
ES_VARIANT = GS_VARIANT
EXCEPTIONS
NOT_FOUND = 2.

IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF V_EXIT = SPACE.
P_VARI = GS_VARIANT-VARIANT.
ENDIF.
ENDIF.
Step 4. Define event Initialization to get the default layout.

GS_VARIANT-REPORT = SY-REPID.

CALL FUNCTION REUSE_ALV_VARIANT_DEFAULT_GET


EXPORTING
I_SAVE = A
CHANGING
CS_VARIANT = GS_VARIANT
EXCEPTIONS
WRONG_INPUT = 1
NOT_FOUND = 2
PROGRAM_ERROR = 3
OTHERS = 4.

IF SY-SUBRC EQ 0.

P_VARI = GS_VARIANT-VARIANT.

ENDIF.
Step 5. Pass the selected layout to the REUSE_ALV_GRID_DISPLAY.
We need to pass the selected layout to parameter named IS_VARIANT. At the same time we need to pass a
value to paramenter named I_SAVE. I_SAVE has a type of c and several value can be passed into it.

= display variants cannot be saved


Defined display variants (e.g. delivered display variants) can be selected for presentation independently of this
flag. Changes can not be saved.
X = standard save
Display variants can be saved as standard display variants. User-specific saving is not possible.
U = only user-specific saving
The user can only save display variants user-specifically
A = standard and user-specific saving
The user can save a display variant user-specifically and as standard display variant. The user chooses in the
display variant save popup.

You might also like