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 selction before ALV report gets executed.

Former Member
0 Kudos

Hi,

I have an ALV grid display report. I need to choose the layout of the grid display before i execute the report. That is on the selection screen. How can i possibly do that ??

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Srikanth,

There is an option in FM reuse_alv_grid_display where in you can pass the lay out name. I guess you are using the same FM, if not you will be having this option in othe fm even. Lemme know which function module are you using?

Regards,

Kiran I

9 REPLIES 9

Former Member
0 Kudos

Hello Srikanth,

There is an option in FM reuse_alv_grid_display where in you can pass the lay out name. I guess you are using the same FM, if not you will be having this option in othe fm even. Lemme know which function module are you using?

Regards,

Kiran I

0 Kudos

Hi kiran,

i am using the function module REUSE_ALV_GRID_DISPLAY. let me know how i can use this and have choose layout option on the selection screen.

0 Kudos

Hi,

Check the sample code in my last reply. It has all the details.

Let me know if you have any problems.

Regards,

Pankaj

0 Kudos

Well pankaj, I have checked the code you have put over here. This code, at my place , when f4 is pressed is going into an infinite loop at a FM conversion_exit_alpha_output. Don't know why ???

0 Kudos

Hi,

its not a function call .

check this.


CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname                         = sy-cprog
      dynumb                         = '1000'
*    TRANSLATE_TO_UPPER             = ' '
*    REQUEST                        = ' '
*    PERFORM_CONVERSION_EXITS       = ' '
*    PERFORM_INPUT_CONVERSION       = ' '
*    DETERMINE_LOOP_INDEX           = ' '
    TABLES
      dynpfields                     = tl_dynpfields
*  EXCEPTIONS
*    INVALID_ABAPWORKAREA           = 1
*    INVALID_DYNPROFIELD            = 2
*    INVALID_DYNPRONAME             = 3
*    INVALID_DYNPRONUMMER           = 4
*    INVALID_REQUEST                = 5
*    NO_FIELDDESCRIPTION            = 6
*    INVALID_PARAMETER              = 7
*    UNDEFIND_ERROR                 = 8
*    DOUBLE_CONVERSION              = 9
*    STEPL_NOT_FOUND                = 10
*    OTHERS                         = 11

Code Formatted by: Alvaro Tejada Galindo on Jan 29, 2008 10:49 AM

Former Member
0 Kudos

Hi,

Define one field on selection screen


*PARAMETERS: alv_def LIKE disvariant-variant.*

To populate F4 help


AT SELECTION-SCREEN ON VALUE-REQUEST FOR alv_def.
  PERFORM layout.

FORM layout .

  g_save = 'A'.

  CLEAR g_variant.

  g_variant-report = sy-repid.

  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.
    alv_def = gx_variant-variant.
  ENDIF.


*   Get values from the selection screen to determine layout set
  wal_dynpfields-fieldname = 'ALV_DEF'.
  APPEND wal_dynpfields TO tl_dynpfields.

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname                         = sy-cprog
      dynumb                         = '1000'
*    TRANSLATE_TO_UPPER             = ' '
*    REQUEST                        = ' '
*    PERFORM_CONVERSION_EXITS       = ' '
*    PERFORM_INPUT_CONVERSION       = ' '
*    DETERMINE_LOOP_INDEX           = ' '
    TABLES
      dynpfields                     = tl_dynpfields
*  EXCEPTIONS
*    INVALID_ABAPWORKAREA           = 1
*    INVALID_DYNPROFIELD            = 2
*    INVALID_DYNPRONAME             = 3
*    INVALID_DYNPRONUMMER           = 4
*    INVALID_REQUEST                = 5
*    NO_FIELDDESCRIPTION            = 6
*    INVALID_PARAMETER              = 7
*    UNDEFIND_ERROR                 = 8
*    DOUBLE_CONVERSION              = 9
*    STEPL_NOT_FOUND                = 10
*    OTHERS                         = 11
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE tl_dynpfields INTO wal_dynpfields INDEX 1.
  IF sy-subrc EQ 0.
    g_variant-variant = wal_dynpfields-fieldvalue.
  ENDIF.

  g_variant-report   = sy-repid.
  g_variant-username = sy-uname.


**-- Display all existing variants
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = g_variant
      i_save     = g_save
    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.
      alv_def = gx_variant-variant.
      g_variant = gx_variant.

    ELSE.
      MESSAGE 'No layouts found' TYPE 'I'.

    ENDIF.
  ENDIF.


ENDFORM.                    " layout

Pass Exporting parameter is_variant = gx_variant in CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

Regards,

Pankaj

Code Formatted by: Alvaro Tejada Galindo on Jan 29, 2008 10:47 AM

Former Member
0 Kudos

hi,

check this code also:


data : repname  like sy-repid.
data : g_save.
data : g_exit.
data : g_variant like disvariant.
data : gx_variant like disvariant.

parameters: p_vari like disvariant-variant. " ALV Variant

initialization.
  repname = sy-repid.
  perform initialize_variant.

at selection-screen.
  repname = sy-repid.
  perform pai_of_selection_screen.

at selection-screen on value-request for p_vari.
  perform f4_for_variant.

*&---------------------------------------------------------------------*
*&      Form  initialize_variant
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form initialize_variant.
  g_save = 'A'.
  clear g_variant.
  g_variant-report = repname.
  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.
endform.                    " initialize_variant
*&---------------------------------------------------------------------*
*&      Form  f4_for_variant
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form f4_for_variant.
  call function 'REUSE_ALV_VARIANT_F4'
       exporting
            is_variant = g_variant
            i_save     = g_save
       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.

endform.                    " f4_for_variant
*&---------------------------------------------------------------------*
*&      Form  pai_of_selection_screen
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form pai_of_selection_screen.
  if not p_vari is initial.
    move g_variant to gx_variant.
    move p_vari to gx_variant-variant.
    call function 'REUSE_ALV_VARIANT_EXISTENCE'
         exporting
              i_save     = g_save
         changing
              cs_variant = gx_variant.
    g_variant = gx_variant.
  else.
    perform variant_init.
  endif.

endform.                    " pai_of_selection_screen
*&---------------------------------------------------------------------*
*&      Form  variant_init
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form variant_init.
  clear g_variant.
  g_variant-report = repname.
endform.                    " variant_init

regards,

n.jain

Code Formatted by: Alvaro Tejada Galindo on Jan 29, 2008 10:48 AM

Former Member
0 Kudos

hi shrikant,

check the code i made, it might help you


*CONSTANTS*
CONSTANTS: C_SAVE VALUE 'A'  *for user specific/default*

*WORKAREA DECLARATION*
* Structure to display variants
*DATA : WA_VARIANT LIKE DISVARIANT,*
          * WA_VARIANT1 LIKE DISVARIANT.*
*----------------------------------------------------------------------*
*                 VARIABLE   DECLARATION                               *
*----------------------------------------------------------------------*

DATA : V_PROGNAME TYPE SYREPID.

************************************************************************
*                SELECTION SCREEN                                      *
************************************************************************

* SCREEN FOR ENTERING INFORMATION

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

SELECT-OPTIONS: R_MATNR FOR MARD-MATNR.
SELECT-OPTIONS: R_WERKS FOR MARD-WERKS.
SELECT-OPTIONS: R_LGORT FOR MARD-LGORT.

SELECTION-SCREEN END OF BLOCK FIELDS.

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

*RADIO BUTTON

PARAMETERS: P_R01  RADIOBUTTON GROUP RAD1 DEFAULT 'X',  "GRID FORMAT
            P_R02  RADIOBUTTON GROUP RAD1 .             "LIST FORMAT

SELECTION-SCREEN END OF BLOCK OPTIONS.

*VARIANT
SELECTION-SCREEN BEGIN OF BLOCK VARI WITH FRAME TITLE TEXT-051.

*PARAMETERS: P_VAR TYPE SLIS_VARI.*

SELECTION-SCREEN END OF BLOCK VARI.

*----------------------------------------------------------------------*
*                 INITIALIZATION EVENT                                 *
*----------------------------------------------------------------------*
INITIALIZATION.

*&--assigns main program name to v_progname which becomes the calling
* program
  V_PROGNAME = SY-REPID.

* Display default variant using FM *REUSE_ALV_VARIANT_DEFAULT_GET*
  PERFORM ZF_GET_DEFAULT_VARIANT.
-->this is form for setting the default variant and saving it,
*&---------------------------------------------------------------------*
*&      Form  ZF_GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ZF_GET_DEFAULT_VARIANT .

  *WA_VARIANT1-REPORT = SY-REPID.*
* Search default variant for the report
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      I_SAVE        = C_SAVE          "all user/default
    CHANGING
      CS_VARIANT    = WA_VARIANT1
    EXCEPTIONS
      WRONG_INPUT   = 1
      NOT_FOUND     = 2
      PROGRAM_ERROR = 3
      OTHERS        = 4.
  IF SY-SUBRC = 0.       "if succesful set as default.
    P_VAR = WA_VARIANT1-VARIANT.
  ENDIF.



ENDFORM.                    " ZF_GET_DEFAULT_VARIANT

*----------------------------------------------------------------------*
*             AT SELECTION SCREEN ON VLAUE REQUEST                     *
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VAR.*
* CALL FOR FM to provide SEARCH HELP for VARIANTS
*PERFORM ZF_VARIANT_F4.*  "USING FM REUSE_ALV_VARIANT_F4

*&---------------------------------------------------------------------*
*&      Form  ZF_VARIANT_F4
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ZF_VARIANT_F4 .
  *WA_VARIANT-REPORT = SY-REPID.*
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      IS_VARIANT    = WA_VARIANT
      I_SAVE        = C_SAVE          "all user/default
    IMPORTING
      ES_VARIANT    = WA_VARIANT1
    EXCEPTIONS
      NOT_FOUND     = 1
      PROGRAM_ERROR = 2
      OTHERS        = 3.
  IF SY-SUBRC = 0.     "if sccesfully found, load the variant

    P_VAR = WA_VARIANT1-VARIANT.

  ELSE.

    P_VAR = TEXT-052.    "\DEFAULT

  ENDIF.
ENDFORM.                    " ZF_VARIANT_F4

*----------------------------------------------------------------------*
*                          AT SELECTION SCREEN                         *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.

*check the material no.
  PERFORM ZF_VALIDATE_FIELD.

*check the variant provided
PERFORM ZF_VARIANT_CHECK.

*&---------------------------------------------------------------------*
*&      Form  ZF_VARIANT_CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ZF_VARIANT_CHECK .
* if variant field is filled with some value
  IF NOT P_VAR IS INITIAL.

   WA_VARIANT-REPORT = SY-REPID.
    WA_VARIANT-VARIANT = P_VAR.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
      EXPORTING
        I_SAVE        = C_SAVE        "all user/default
      CHANGING
        CS_VARIANT    = WA_VARIANT
      EXCEPTIONS
        WRONG_INPUT   = 1
        NOT_FOUND     = 2
        PROGRAM_ERROR = 3
        OTHERS        = 4.
    IF SY-SUBRC = 0.
      CLEAR WA_VARIANT1.
      MOVE P_VAR TO WA_VARIANT1-VARIANT.
      MOVE SY-REPID TO WA_VARIANT1-REPORT.
    ELSE.
      MESSAGE E007.

    ENDIF.

  ELSE.
    CLEAR WA_VARIANT.
  ENDIF.


ENDFORM.                    " ZF_VARIANT_CHECK

*NOW AFTER THIS PASS I_SAVE AND IS_VARIANT VALUE IN ALV GRID/LIST FM*

like this

*&---------------------------------------------------------------------
*
*&      Form  zf_display_alv_grid
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM ZF_DISPLAY_ALV_GRID .
*&--calling FM to display GRID LAYOUT
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = V_PROGNAME
      IS_LAYOUT          = WA_LAYOUT
      IT_FIELDCAT        = I_FIELDCAT
      IT_EVENTS          = I_EVENTCAT
      IT_SORT            = I_SORTINFO
      I_DEFAULT          = TEXT-029
      *I_SAVE             = C_SAVE*          "all user/default
     * IS_VARIANT         = WA_VARIANT1*
    TABLES
      T_OUTTAB           = I_FINAL      "output table
    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.                    " zf_display_alv_grid
*&---------------------------------------------------------------------
*
*&      Form  zf_display_alv_list
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------
*
FORM ZF_DISPLAY_ALV_LIST .
*&--calling FM to display LIST LAYOUT
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = V_PROGNAME
      IS_LAYOUT          = WA_LAYOUT
      IT_FIELDCAT        = I_FIELDCAT
      I_DEFAULT          = TEXT-029
      IT_EVENTS          = I_EVENTCAT
      IT_SORT            = I_SORTINFO
*      I_SAVE             = C_SAVE        "all user/default*
 *     IS_VARIANT         = WA_VARIANT1*
    TABLES
      T_OUTTAB           = I_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.

ENDFORM.                    " zf_display_alv_list

do reply , if any questions, happy coding

<REMOVED BY MODERATOR>

Rohan malik

Edited by: Alvaro Tejada Galindo on Jan 29, 2008 10:50 AM

Former Member
0 Kudos

Hi Srikanth,

Declare a structure/work area

DATA: gs_variant       LIKE disvariant.

Use FM HR_F4_FOR_ALV_VARIANT to get the ALV variants created for the ALV Report.

In event AT Selection Screen on Value Request Fld_variant.
Use FM HR_F4_FOR_ALV_VARIANT passing the report name.

This FM will give you a pop up with Variants. The selected Variant will come as an export parameter VARIANT of the function module.

Pass this Variant to gs_variant-VARIANT.

gs_repid = sy-repid.

gs_variant-report = gs_repid.

gs_variant-username = sy-uname.

Pass this Structure/Work area to FM call for ALV.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_background_id    = 'SIWB_WALLPAPER'
      i_callback_program = gs_repid
      is_layout          = gs_layout
      it_fieldcat        = gt_fieldcat_alv
      i_save             = 'A'
      is_variant         = gs_variant
      it_events          = gt_events
    TABLES
      t_outtab           = gt_itab.

Hope it helps.

Lokesh

Edited by: Lokesh Aggarwal on Jan 29, 2008 3:36 PM