Home > ABAP, ALV > SAP ALV Tutorial – Layout

SAP ALV Tutorial – Layout

September 19th, 2009 Leave a comment Go to comments

The layout stands for a set of settings about sort, total and which fields need to be displayed. It is a common case that different user needs to have different layout of the alv. SAP has provide functionality to user to create, change, save or even transport the layout to the subsequent systems.

SAP alv Layout Common functionality

1. Choose Layout.

To choose an existing layout for the display of the list, choose Choose layout or Settings ® Display layout ® Choose. You can change the layout of alv using the following alv funcitons:
a. Sort order
b. Set Filter or delete Filter
c. Change layout
d. Find…

In the dialog box, choose a layout either by clicking the layout name or by positioning the cursor on the relevant layout and choosing Copy.

2. Save Layout.

Choose Save layout or Settings->Layout->Save. In the dialog box, enter a name and a description for your layout.
You cannot gives the layout a name with number, since this type of name is reserved for the standard layouts in the standard system. In general, layouts are available for all users as client-specific standard layouts, but you can select User-specific option which means that this layout only avaliable for current user.

Naming conversion of layout. User-specific layouts must begin with a letter (A-Z). Non-user-specific layouts(client-specific standard layouts) must begin of with “/”.

3. Layout management.

To call layout management, choose Settings->Layout->Management. We can delete a layout or set a layout as default.

We can also import or transport layout using layout management. The layout will not be added to a transport when you create it, but you can add it to a transport manually using layout management.

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.

  1. No comments yet.
  1. No trackbacks yet.