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: 

Layout in ALV reports

Former Member
0 Kudos

Hi everyone, I have created an ALV report, and now I've been ask to upgrade this report putting a parameter in the selection screen where the user can select a layout, and then execute the report so when the data is display appear as the layout already chosen by the user.

Can anyone tell me how to add this functionality to my alv report.

Thanks in advanced,

Fidel

7 REPLIES 7

Former Member
0 Kudos

You need to add a parameter VARIANT on the selction screen which refers to disvariant-variant.

Add the below code to your report

AT SELECTION-SCREEN ON VALUE-REQUEST FOR variant.

DATA h_exit.

CLEAR gx_variant.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = g_variant

i_save = g_variant_save

IMPORTING

e_exit = h_exit

es_variant = gx_variant

EXCEPTIONS

not_found = 1

program_error = 2

OTHERS = 3.

IF sy-subrc IS INITIAL AND h_exit IS INITIAL.

g_variant-variant = gx_variant-variant.

p_variant = gx_variant-variant.

ELSE.

MESSAGE ID sy-msgid TYPE 'S'

NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Pass g_variant to the display function as below

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_buffer_active = g_alv_buffer

i_callback_program = g_repid

i_callback_pf_status_set = g_form_set_pf_stat

is_layout = g_layout

it_fieldcat = g_fieldcat_tab[]

it_special_groups = g_fieldgroups_tab[]

it_sort = g_sortfields_tab[]

i_default = g_n

i_save = g_a

is_variant = g_variant

it_events = g_events_tab[]

it_event_exit = g_event_exit_tab[]

is_print = g_print

i_screen_start_column = g_screen_start_column

i_screen_start_line = g_screen_start_line

i_screen_end_column = g_screen_end_column

i_screen_end_line = g_screen_end_line

TABLES

t_outtab = object_tab

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF NOT sy-subrc IS INITIAL.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

-Kiran

*Please mark useful answers

Former Member
0 Kudos

Hi fidel,

For this you have to do the following things.

1. declare one parameter in selection screen for selecting the layouts.

parameter p_var like disvariant.(I am not sure this declaration.once check this or normal char of some length)

2.below code is for f4 help on that parameter. that means what ever layouts we created that will apear for selection in f4 help.

AT SELECTION SCREEN on value request p_var.

data:l_disvariant type disvariant.

l_disvariant-report = sy-repid

l_disvariant-variant = p_var

call LVC_VARIANT_SAVE_LOAD

EXPORTING

i_save_load = 'F'

IMPORTING

cs_variant = l_variant

3. IN FM 'REUSE_ALV_GRID_DISPLAY'for parameter i_save has to be set.

if it is helpful plz reward points.

Thanks,

suma.

Former Member
0 Kudos

hi Fidel

small change

write this

call LVC_VARIANT_SAVE_LOAD

EXPORTING

i_save_load = 'F'

CHANGING

cs_variant = l_variant

INSTEAD OF THE FOLLOWING

call LVC_VARIANT_SAVE_LOAD

EXPORTING

i_save_load = 'F'

IMPORTING

cs_variant = l_variant

Former Member
0 Kudos

Hi Fidel,

Go thru these below simple steps and implement in ur prg...

1) parameter: p_varant type disvariant-variant.

2)at selection-screen on value-request for p_varant.

  • Get Variant for ALV layout

perform alv_variant.

3)&----


*& Form ALV_VARIANT

&----


  • To provide Search Help to get the ALV Layout

----


form alv_variant.

call function 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = g_variant

IMPORTING

es_variant = g_variant

EXCEPTIONS

not_found = 1

program_error = 2

others = 3.

if sy-subrc = 0.

p_varant = g_variant-variant.

endif.

endform. " ALV_VARIANT

4)

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

is_layout = x_layout

it_fieldcat = tb_fieldcat

i_save = 'X'

it_events = tb_events

IS_VARIANT = g_variant

TABLES

t_outtab = tb_final

EXCEPTIONS

program_error = 1

others = 2.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

regards,

Kiran B

former_member188685
Active Contributor
0 Kudos

Hi,

Check the functionality used in the Standard program <b>BALVST02_GRID</b>

1. have a pramter in the selection screen for variant.

PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT.

2.

  G_SAVE = 'A'.
    CLEAR G_VARIANT.
  G_VARIANT-REPORT = G_REPID.
* Get default variant
  GX_VARIANT = G_VARIANT.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
       EXPORTING
            I_SAVE     = G_SAVE
       CHANGING
            CS_VARIANT = GX_VARIANT
       EXCEPTIONS
            NOT_FOUND  = 2.
  IF SY-SUBRC = 0.
    P_VARI = GX_VARIANT-VARIANT.
  ENDIF.
* Process on value request
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
       EXPORTING
            IS_VARIANT          = G_VARIANT
            I_SAVE              = G_SAVE
*           it_default_fieldcat =
       IMPORTING
            E_EXIT              = G_EXIT
            ES_VARIANT          = GX_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 G_EXIT = SPACE.
      P_VARI = GX_VARIANT-VARIANT.
    ENDIF.
  ENDIF.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_BACKGROUND_ID         = 'ALV_BACKGROUND'
            I_CALLBACK_PROGRAM      = G_REPID
            I_STRUCTURE_NAME        = 'SFLIGHT'
            IS_LAYOUT               = GS_LAYOUT
            IT_FIELDCAT             = GT_FIELDCAT[]
*           IT_EXCLUDING            =
            IT_SPECIAL_GROUPS       = GT_SP_GROUP[]
            IT_SORT                 = GT_SORT[]
*           IT_FILTER               =
*           IS_SEL_HIDE             =
*           i_default               = g_default
<b>            I_SAVE                  = G_SAVE
            IS_VARIANT              = G_VARIANT</b>

Regards

vijay

Former Member
0 Kudos

hi,

declare a parameter by type disvariant

paramenter : p_var type disvariant-variant.

at selection-screen for p_var on value request.

call FM REUSE_ALV_VARIANT_F4

IS_VARIANT-REPORT = SY-REPID.

FOR this FM pass IS_VARIANT.

and get import is_variant-variant and assign it to p_variant.

In 'REUSE_ALV_LIST_DISPLAY'

assign the same is_variant to variant export parameter of above FM.

regards,

Manohar.

Former Member
0 Kudos

HI Fidel,

Here is example program for List and Grid

whichever u choose that report format will be displayed

check this once.

&----


*& Report ZLAXMI_ALVEXER2 *

*& *

&----


*& NAME : VENKATA LAXMI *

*& DATE : 24-02-2006 *

*& PROGRAM TO PRINT THE REPORT IN ALV LIST FORMAT AND GRID FORMAT *

*& WITH TRAFFIC LIGHTS *

&----


REPORT ZLAXMI_ALVEXER2 MESSAGE-ID ZZ .

&----


*& TABLES DECLARATION *

&----


TABLES: VBAK.

&----


*& TYPE POOLS DECLARATION *

&----


TYPE-POOLS: SLIS.

&----


*& INTERNAL TABLE DECLARATION *

&----


DATA: BEGIN OF ITAB OCCURS 0,

ICON TYPE ICON-ID,

VBELN LIKE VBAK-VBELN,

AUDAT LIKE VBAK-AUDAT,

VBTYP LIKE VBAK-VBTYP,

AUART LIKE VBAK-AUART,

AUGRU LIKE VBAK-AUGRU,

NETWR LIKE VBAK-NETWR,

WAERK LIKE VBAK-WAERK,

END OF ITAB.

*INTERNAL TABLE FOR FIELD CATALOG

DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,

IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  • IT_FIELDCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV

  • WITH HEADER LINE,

*INTERNAL TABLE FOR EVENTS

DATA: IT_EVENT TYPE SLIS_T_EVENT,

WA_EVENT TYPE SLIS_ALV_EVENT,

*INTERNAL TABLE FOR SORTING

IT_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV,

*INTERNAL TABLE FOR LAYOUT

WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

&----


*& VARIABLE DECLARATION *

&----


DATA : V_REPID TYPE SY-REPID,

V_PAGNO(4) TYPE N,

V_DATE(8) TYPE C.

&----


*& CONSTANTS *

&----


CONSTANTS: C_X TYPE C VALUE 'X'.

&----


*& SELECTION SCREEN *

&----


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

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN,

S_VBTYP FOR VBAK-VBTYP DEFAULT 'C'.

SELECTION-SCREEN: END OF BLOCK B1.

SELECTION-SCREEN: BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

*SELECTION-SCREEN : BEGIN OF LINE.

*SELECTION-SCREEN COMMENT 1(20) TEXT-003.

PARAMETERS: P_LIST RADIOBUTTON GROUP RAD1 DEFAULT 'X'.

*SELECTION-SCREEN : END OF LINE.

*SELECTION-SCREEN : BEGIN OF LINE.

*SELECTION-SCREEN COMMENT 1(20) TEXT-004.

PARAMETERS: P_GRID RADIOBUTTON GROUP RAD1.

*SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN: END OF BLOCK B2.

AT SELECTION-SCREEN.

PERFORM VALIDATE_SCREEN.

&----


*& START OF SELECTION *

&----


START-OF-SELECTION.

CLEAR: ITAB, ITAB[].

  • V_REPID = SY-REPID.

PERFORM GET_DATA.

PERFORM DISPLAY_DATA.

&----


*& END OF SELECTION *

&----


END-OF-SELECTION.

*--DO ALV Process

V_REPID = SY-REPID.

*--Sort the Output Fields

PERFORM SORT_FIELDS.

*--Build Field catalog for the Output fields

  • PERFORM BUILD_FIELDCAT.

*--Set the Layout for ALV

PERFORM SET_LAYOUT.

&----


*& Form GET_DATA

&----


  • text

----


  • TO GET THE DATA FROM TABLES INTO ITAB

----


FORM GET_DATA .

SELECT VBELN

AUDAT

VBTYP

AUART

AUGRU

NETWR

WAERK

INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM VBAK

WHERE VBELN IN S_VBELN AND

AUDAT > '04.04.2005'

AND NETWR > 0.

LOOP AT ITAB.

IF ITAB-NETWR < 10000.

ITAB-ICON = '@08@'.

ELSEIF ITAB-NETWR > 10000 AND ITAB-NETWR < 100000.

ITAB-ICON = '@09@'.

ELSEIF ITAB-NETWR > 100000.

ITAB-ICON = '@0A@'.

ENDIF.

MODIFY ITAB INDEX SY-TABIX.

ENDLOOP.

ENDFORM. " GET_DATA

&----


*& Form sort_fields

&----


FORM SORT_FIELDS .

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'VBTYP'.

WA_SORT-SPOS = '1'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'NETWR'.

WA_SORT-SPOS = '2'.

WA_SORT-UP = 'X'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO IT_SORT.

ENDFORM. " sort_fields

&----


*& Form build_fieldcat

&----


*FORM BUILD_FIELDCAT .

*

  • IT_FIELDCAT-COL_POS = '1'.

  • IT_FIELDCAT-FIELDNAME = 'ICON'.

  • IT_FIELDCAT-KEY = 'X'.

  • IT_FIELDCAT-OUTPUTLEN = '10'.

  • IT_FIELDCAT-SELTEXT_L = 'LIGHT'.

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

*

  • IT_FIELDCAT-COL_POS = '2'.

  • IT_FIELDCAT-FIELDNAME = 'VBELN'.

  • IT_FIELDCAT-KEY = 'X'.

  • IT_FIELDCAT-OUTPUTLEN = '10'.

  • IT_FIELDCAT-SELTEXT_L = 'SALES DOC NUMBER'(009).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

  • IT_FIELDCAT-COL_POS = '3'.

  • IT_FIELDCAT-FIELDNAME = 'AUDAT'.

  • IT_FIELDCAT-KEY = 'X'.

  • IT_FIELDCAT-OUTPUTLEN = '4'.

  • IT_FIELDCAT-SELTEXT_L = 'DOCUMENT DATE'(010).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

  • IT_FIELDCAT-COL_POS = '4'.

  • IT_FIELDCAT-FIELDNAME = 'VBTYP'.

  • IT_FIELDCAT-KEY = 'X'.

  • IT_FIELDCAT-OUTPUTLEN = '4'.

  • IT_FIELDCAT-SELTEXT_L = 'CATEGORY'(011).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

  • IT_FIELDCAT-COL_POS = '5'.

  • IT_FIELDCAT-FIELDNAME = 'AUART'.

  • IT_FIELDCAT-OUTPUTLEN = '4'.

  • IT_FIELDCAT-SELTEXT_L = 'DOCUMENT TYPE'(012).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

  • IT_FIELDCAT-COL_POS = '6'.

  • IT_FIELDCAT-FIELDNAME = 'AUGRU'.

  • IT_FIELDCAT-OUTPUTLEN = '12'.

  • IT_FIELDCAT-SELTEXT_L = 'Order reason'(013).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

  • IT_FIELDCAT-COL_POS = '7'.

  • IT_FIELDCAT-FIELDNAME = 'NETWR'.

  • IT_FIELDCAT-OUTPUTLEN = '12'.

  • IT_FIELDCAT-SELTEXT_L = 'NET VALUE'(014).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

  • IT_FIELDCAT-COL_POS = '8'.

  • IT_FIELDCAT-FIELDNAME = 'WAERK'.

  • IT_FIELDCAT-OUTPUTLEN = '12'.

  • IT_FIELDCAT-SELTEXT_L = 'SD DOC CURR'(015).

  • APPEND IT_FIELDCAT.

  • CLEAR IT_FIELDCAT.

*

*

*ENDFORM. " build_fieldcat

*

&----


*& Form set_layout

&----


FORM SET_LAYOUT .

IF P_LIST = C_X .

WA_LAYOUT-WINDOW_TITLEBAR = 'LIST DISPLAY'(016).

WA_LAYOUT-ZEBRA = 'X'.

*-- ALV LIST DISPLAY

PERFORM LIST_DISPLAY TABLES ITAB.

*-- ALV GRID DISPLAY

ELSEIF P_GRID = C_X.

WA_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'(017).

WA_LAYOUT-ZEBRA = 'X'.

PERFORM GRID_DISPLAY TABLES ITAB.

ENDIF.

ENDFORM. " set_layout

&----


*& Form list_display

&----


FORM LIST_DISPLAY TABLES P_ITAB .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

IT_SORT = IT_SORT[]

I_SAVE = 'U'

TABLES

T_OUTTAB = ITAB

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " list_display

&----


*& Form GRID_DISPLAY

&----


FORM GRID_DISPLAY TABLES P_ITAB .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

IT_SORT = IT_SORT[]

IT_EVENTS = IT_EVENT

TABLES

T_OUTTAB = ITAB

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " GRID_DISPLAY

&----


*& Form VALIDATE_SCREEN

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_SCREEN .

DATA: LV_VBELN LIKE VBAK-VBELN.

IF NOT S_VBELN IS INITIAL.

SELECT VBELN

INTO LV_VBELN

UP TO 1 ROWS

FROM VBAK

WHERE VBELN IN S_VBELN.

ENDSELECT.

IF SY-SUBRC <> 0.

MESSAGE E000 WITH 'INVALID SALES DOC'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_SCREEN

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_DATA .

DEFINE M_FIELDCAT.

ADD 1 TO WA_FIELDCAT-COL_POS.

WA_FIELDCAT-FIELDNAME = &1.

WA_FIELDCAT-REF_TABNAME = 'VBAK'.

WA_FIELDCAT-DO_SUM = &2.

WA_FIELDCAT-CFIELDNAME = &3.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

END-OF-DEFINITION.

DATA:

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv.

m_fieldcat 'ICON' '' ''.

m_fieldcat 'VBELN' '' ''.

m_fieldcat 'AUDAT' '' ''.

m_fieldcat 'VBTYP' '' ''.

m_fieldcat 'AUART' '' ''.

m_fieldcat 'AUGRU' '' ''.

m_fieldcat 'NETWR' 'C' 'WAERK'.

m_fieldcat 'WAERK' '' ''.

ENDFORM. " display_data

Regards,

Laxmi