Skip to Content
author's profile photo Former Member
Former Member

Interactive lists from ALV

Hi experts,

Please tell me how to generate Interactive list from ALV.

I have already created interactive list without ALV

( using AT LINE SELECTION)

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Posted on Jul 21, 2008 at 02:42 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 21, 2008 at 02:45 PM

    The first step is to SEARCH SDN as, not surprisingly, you aren't the first person in the world to ask about this.

    There is lots of information on SDN that will help you if you search.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 21, 2008 at 08:15 PM

    Hello Ajay

    You may have a look at my ZUS_SDN sample reports in

    Regards

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 21, 2008 at 08:25 PM

    Please refer to the below code.

    A very good example with most of the company Standards.

    *&---------------------------------------------------------------------*
    *& Report  zalv                                                      *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    
    REPORT zalv .
    
    TYPE-POOLS: kkblo,
                slis.
    
    TABLES: mara, marc, mard.
    
    DATA:       disvariant   LIKE disvariant,
                eventcat     TYPE slis_t_event,
                eventcat_ln  LIKE LINE OF eventcat,
                fieldcat     TYPE slis_t_fieldcat_alv,
                fieldcat_kkb TYPE kkblo_t_fieldcat,
                fieldcat_ln  LIKE LINE OF fieldcat,
                keyinfo      TYPE slis_keyinfo_alv,
                layout       TYPE slis_layout_alv,
                layout_kkb   TYPE kkblo_layout,
                pgm          LIKE sy-repid,
                printcat     TYPE slis_print_alv,
                sortcat      TYPE slis_t_sortinfo_alv,
                sortcat_ln   LIKE LINE OF sortcat,
    
                BEGIN OF coltab OCCURS 50,
                  fieldname LIKE fieldcat_ln-fieldname,
                END OF coltab.
    
    DATA: print          TYPE slis_print_alv.
    
    DATA : v_repid TYPE sy-repid.
    
    DATA: BEGIN OF wa OCCURS 0,
            matnr TYPE mara-matnr,
            ersda TYPE mara-ersda,
            ernam TYPE mara-ernam,
            aenam TYPE mara-aenam,
            werks TYPE marc-werks,
            pstat TYPE marc-pstat,
            lfmon TYPE mard-lfmon,
          END OF wa.
    
    DATA: itab LIKE TABLE OF wa.
    
    **Selection Screen
    
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001..
    SELECT-OPTIONS: mat_no FOR mara-matnr.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK b1.
    * Parameter for list viewer display variant
    
    PARAMETERS:    variant  LIKE disvariant-variant.
    
    AT SELECTION-SCREEN ON variant.
      CHECK NOT variant IS INITIAL.
      PERFORM check_variant_existence USING variant 'U'.
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR variant.
      PERFORM f4_display_variant USING variant 'U'.
    
    *Initialization
    INITIALIZATION.
      v_repid = sy-repid.
    
    *Start of selection
      PERFORM check_tcode_authority USING 'SA38'.
    
    START-OF-SELECTION.
      SELECT a~matnr a~ersda
             a~ernam a~aenam
             c~werks c~pstat d~lfmon
      INTO TABLE itab
      UP TO 10 ROWS
      FROM mara AS a
      INNER JOIN marc AS c ON a~matnr = c~matnr
      INNER JOIN mard AS d ON c~matnr = d~matnr
      WHERE a~matnr IN mat_no.
    
    *End of Selection
    END-OF-SELECTION.
      PERFORM call_list_viewer.
    
    *&---------------------------------------------------------------------*
    *&      Form  call_list_viewer
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM call_list_viewer .
      PERFORM build_fieldcat USING:
               'MATNR' 'ITAB'
                'Material #' 'CHAR'     18 ' ' ' ' ' ' ' ' ' ',
               'ERSDA' 'ITAB'
                'Date Created' 'CHAR'   10 ' ' ' ' ' ' ' ' ' ',
               'ERNAM' 'ITAB'
                'Created By' 'CHAR'     10 ' ' ' ' ' ' ' ' ' ',
               'AENAM' 'ITAB'
                'Changed By' 'CHAR'     10 ' ' ' ' ' ' ' ' ' ',
               'WERKS' 'ITAB'
                'Plant' 'CHAR'           4 ' ' ' ' ' ' ' ' ' ',
               'PSTAT' 'ITAB'
                'Status' 'CHAR'         10 ' ' ' ' ' ' ' ' ' ',
               'LFMON' 'ITAB'
                'Current Period' 'CHAR'  8 ' ' ' ' ' ' ' ' ' '.
    
      PERFORM build_eventcat USING: 'TOP_OF_LIST',
                                    'TOP_OF_PAGE'.
      PERFORM list_display TABLES itab.
    
    ENDFORM.                    "call_list_viewer
    
    *----------------------------------------------------------------------*
    * build field catalog entry                                            *
    *----------------------------------------------------------------------*
    FORM build_fieldcat USING a_fieldname
                              a_tabname
                              a_heading
                              a_datatype
                              a_outputlen
                              a_key
                              a_no_out
                              a_no_sum
                              a_do_sum
                              a_no_zero.
    
    
      CLEAR fieldcat_ln.
      fieldcat_ln-fieldname = a_fieldname.
      fieldcat_ln-tabname  = a_tabname.
      fieldcat_ln-outputlen = a_outputlen.
      fieldcat_ln-datatype = a_datatype.
      fieldcat_ln-reptext_ddic = a_heading.
      fieldcat_ln-key = a_key.
      fieldcat_ln-no_out = a_no_out.
      fieldcat_ln-no_sum = a_no_sum.
      fieldcat_ln-do_sum = a_do_sum.
      fieldcat_ln-no_zero = a_no_zero.
      APPEND fieldcat_ln TO fieldcat.
    
    ENDFORM.                    "BUILD_FIELDCAT
    *----------------------------------------------------------------------*
    *       FORM BUILD_EVENTCAT
    *----------------------------------------------------------------------*
    FORM build_eventcat USING a_event.
    
      eventcat_ln-name = eventcat_ln-form = a_event.
      APPEND eventcat_ln TO eventcat.
    
    ENDFORM.                    "BUILD_EVENTCAT
    *----------------------------------------------------------------------*
    * call the ABAP list viewer                                            *
    *----------------------------------------------------------------------*
    FORM list_display TABLES a_output.
    
      pgm = disvariant-report = sy-repid.
      disvariant-variant = variant.
    * call list viewer
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = pgm
    *      i_callback_pf_status_set = 'SET_PF_STATUS'
          it_fieldcat              = fieldcat
          is_variant               = disvariant
          is_layout                = layout
          is_print                 = print
          i_save                   = 'A'
          it_events                = eventcat
          it_sort                  = sortcat
    *      i_callback_user_command  = 'USER_COMMAND'
        TABLES
          t_outtab                 = a_output
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
    
    ENDFORM.                    "LIST_DISPLAY
    
    
    *&---------------------------------------------------------------------*
    *&      Form  top_of_page
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM top_of_page.
      PERFORM standard_headings.
    
      PERFORM print_selection_screen TABLES:
                   mat_no USING  'Material No  : ' 18 'N' 1.
    ENDFORM.                    "top_of_page
    
    
    
    
    *----------------------------------------------------------------------*
    *       FORM CHECK_VARIANT_EXISTENCE
    *----------------------------------------------------------------------*
    *       Verify that a variant on the selection screen exists
    *----------------------------------------------------------------------*
    FORM check_variant_existence USING varname LIKE disvariant-variant
                                       save   TYPE c.
    
      DATA: xdisvar LIKE disvariant.
    
      xdisvar-report  = sy-repid.
      xdisvar-variant = varname.
    
      CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
        EXPORTING
          i_save        = save
        CHANGING
          cs_variant    = xdisvar
        EXCEPTIONS
          wrong_input   = 1
          not_found     = 2
          program_error = 3
          OTHERS        = 4.
    
      IF sy-subrc <> 0.
        MESSAGE e256(56) WITH varname.
    *   Anzeigevariante &1 nicht gefunden
      ENDIF.
    
      disvariant-report  = sy-repid.
      disvariant-variant = varname.
    
    ENDFORM.                    "check_variant_existence
    *----------------------------------------------------------------------*
    *       Form  F4_DISPLAY_VARIANT
    *----------------------------------------------------------------------*
    *       F4 help to find a display variant
    *       varname = name of the dynpro field for which f4 is requested
    *       save    = type of list variant saving
    *                 ' ' = no saving allowed
    *                 'A' = standard & user specific variants can be saved
    *                 'U' = only user specific variants can be saved
    *                 'X' = only standard variants can be saved
    *----------------------------------------------------------------------*
    FORM f4_display_variant USING varname LIKE disvariant-variant
                                  save    TYPE c.
    
      disvariant-report = sy-repid.
    
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant    = disvariant
          i_save        = save
        IMPORTING
          es_variant    = disvariant
        EXCEPTIONS
          not_found     = 1
          program_error = 2
          OTHERS        = 3.
    
      IF sy-subrc = 0.
        varname = disvariant-variant.
      ELSE.
        MESSAGE s245(56).
    *   Keine Anzeigevariante(n) vorhanden
      ENDIF.
    ENDFORM.                               " F4_DISPLAY_VARIANT
    
    
    
    *---------------------------------------------------------------------*
    *       FORM STANDARD_HEADINGS                                        *
    *---------------------------------------------------------------------*
    *       Print standard page headings for report                       *
    *---------------------------------------------------------------------*
    FORM standard_headings.
      DATA: start_column TYPE i,
            title_len TYPE i,
            header_for_80_col(45),
            date_time_for_80_col(45),
            text_h0(11) VALUE 'Report No. ',
            text_h1(5) VALUE 'Date ',
            text_h2(6) VALUE 'Page -',
            text_h3(7) VALUE 'System ',
            text_h4(5) VALUE 'Time ',
            text_h5(11) VALUE 'Run By     '.
      FORMAT INTENSIFIED ON.
    
      CONDENSE syst-title.
    
      IF syst-linsz > 80.
        WRITE: /  text_h0,                 "Report No.
               12 syst-repid(8),
               23 text_h1,                 "Date
                  sy-datlo.
        title_len = STRLEN( syst-title ) / 2.
        start_column = ( syst-linsz / 2 ) - title_len.
        IF start_column < 40.
          start_column = 40.
        ENDIF.
        WRITE: AT start_column syst-title.
      ELSE.
        WRITE: /  text_h0,                 "Report No.
               12 syst-repid(8).
        start_column = 22.
        WRITE syst-title TO header_for_80_col CENTERED.
        WRITE: header_for_80_col.
      ENDIF.
    
      start_column = syst-linsz - 12.
      WRITE: AT start_column text_h2, syst-pagno LEFT-JUSTIFIED.
    
      IF syst-linsz > 80.
        WRITE: / text_h3,                  "System
              12 syst-sysid(4),
                 syst-mandt,
              23 text_h4,                  "Time
                 syst-timlo.
        WRITE: / text_h5,                  "Run By
              12 syst-uname.
      ELSE.
        WRITE: / text_h3,                  "System
              12 syst-sysid(4),
                 syst-mandt,
              23 text_h1,                  "Date
                 syst-datlo.
        WRITE: / text_h5,                  "Run By
              12 syst-uname,
              23 text_h4,                  "Time
                 syst-timlo.
    
      ENDIF.
    
      SKIP.
    ENDFORM.                    "STANDARD_HEADINGS
    
    *---------------------------------------------------------------------*
    *       FORM PRINT_SELECTION_SCREEN                                        *
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    *  -->  SIGN                                                          *
    *  -->  OPTION                                                        *
    *  -->  LOW                                                           *
    *  -->  HIGH                                                          *
    *  -->  D_IND                                                         *
    *  -->  S_STRING                                                      *
    *---------------------------------------------------------------------*
    FORM print_selection_screen TABLES r_selection TYPE table
                           USING  p_name
                                  p_length TYPE i
                                  p_ind
                                  p_start_col.
    
      DATA: year(4)       TYPE c,
            month(2)      TYPE c,
            day(2)        TYPE c,
            low_date(10)  TYPE c,
            high_date(10) TYPE c,
            offset(80)    TYPE c.
    
      DATA: BEGIN OF l_selline,
              sign(1) TYPE c,
              option(2) TYPE c,
              data(200) TYPE c,
            END OF l_selline.
    
      DATA: l_string(80) TYPE c,
            l_temp(80) TYPE c,
            len TYPE i,
            len1 TYPE i.
    
      DESCRIBE FIELD p_name LENGTH len IN CHARACTER MODE.
      len = len + p_start_col + 2.
    
      LOOP AT r_selection.
        IF syst-tabix = 1.
          WRITE AT /p_start_col p_name.
        ELSE.
          len1 = ( STRLEN( l_string ) ).
          len = len1 + len + 2.
        ENDIF.
    
        MOVE r_selection TO l_selline.
        SHIFT l_selline-data LEFT DELETING LEADING '0'.
    
        CLEAR l_string.
        CASE l_selline-option.
          WHEN 'EQ'.
            CONCATENATE l_string '=' INTO l_string.
          WHEN 'NE'.
            CONCATENATE l_string 'not =' INTO l_string.
          WHEN 'LT'.
            CONCATENATE l_string '<' INTO l_string.
          WHEN 'GT'.
            CONCATENATE l_string '>' INTO l_string.
          WHEN 'LE'.
            CONCATENATE l_string '<=' INTO l_string.
          WHEN 'GE'.
            CONCATENATE l_string '>=' INTO l_string.
          WHEN 'BT'.
            CONCATENATE l_string 'between' INTO l_string.
          WHEN 'NB'.
            CONCATENATE l_string 'not between' INTO l_string.
          WHEN 'CP'.
            CONCATENATE l_string 'contains pattern' INTO l_string.
          WHEN 'NP'.
            CONCATENATE l_string 'no pattern' INTO l_string.
        ENDCASE.
        IF l_selline-sign EQ 'E'.
          CONCATENATE 'NOT' l_string INTO l_string SEPARATED BY ' '.
        ENDIF.
        IF p_ind EQ 'Y'.
          MOVE l_selline-data(4) TO year.
          MOVE l_selline-data+4(2) TO month.
          MOVE l_selline-data+6(2) TO day.
    
          CONCATENATE month '/' day '/' year INTO low_date.
    
          CONCATENATE l_string low_date INTO l_string SEPARATED BY ' '.
          IF l_selline-option EQ 'BT' OR l_selline-option EQ 'NB'.
            MOVE l_selline-data+p_length(4) TO year.
            offset = p_length + 4.
            MOVE l_selline-data+offset(2) TO month.
            ADD 2 TO offset.
            MOVE l_selline-data+offset(2) TO day.
    
            CONCATENATE month '/' day '/' year INTO high_date.
    
            CONCATENATE l_string 'and' high_date INTO l_string SEPARATED
                                                  BY ' '.
          ENDIF.
        ELSE.
          MOVE l_selline-data(p_length) TO l_temp.
          CONCATENATE l_string l_temp INTO l_string SEPARATED BY ' '.
          IF l_selline-option EQ 'BT' OR l_selline-option EQ 'NB'.
            MOVE l_selline-data+p_length(p_length) TO l_temp.
            CONCATENATE l_string 'and' l_temp INTO l_string SEPARATED
                                                                BY ' '.
          ENDIF.
        ENDIF.
        WRITE AT len l_string.
      ENDLOOP.
      IF syst-subrc <> 0.
        WRITE: AT /p_start_col p_name, ' *** ALL ***'.
      ENDIF.
    ENDFORM.                    "PRINT_SELECTION_SCREEN
    
    *---------------------------------------------------------------------*
    *       FORM CHECK_TCODE_AUTHORITY                                    *
    *---------------------------------------------------------------------*
    *       Check User Security Against A SAP Transaction                 *
    *---------------------------------------------------------------------*
    *  -->  a_tcode  Transaction Code For Security                        *
    *---------------------------------------------------------------------*
    FORM check_tcode_authority USING a_tcode.
    *
    * if tcode is not passed, then return ok.
    *
    
      IF NOT a_tcode IS INITIAL.
        CALL FUNCTION 'AUTHORITY_CHECK_TCODE'"Only People that
             EXPORTING                     " have access to
               tcode  = a_tcode            " Transaction t-tcode
             EXCEPTIONS                    " are ALLOWED to execute
                  ok     = 1               " this Program
                  not_ok = 2.
        IF syst-subrc NE 1.
          MESSAGE a999(zz) WITH 'YOU Do Not Have Authority to Execute'.
        ENDIF.
      ELSE.
        MOVE 1 TO syst-subrc.
      ENDIF.
    ENDFORM.                    "CHECK_TCODE_AUTHORITY
    

    Shreekant

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2008 at 03:40 AM

    Hi Ajay,

    To create interactive list go through the events used in the ALV reports. This will help you in creating the interactive lists in ALV.

    Sharin

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 23, 2008 at 11:02 AM

    Helo Ajay,

    I've got a very simple and small code for an interactive ALV report whcih u can simply copy & paste on ur editor screen & activate & run it....Hope this helps!

    Below is the code for it:

    REPORT ZALV_INTERACTIVE.

    TYPE-POOLS:SLIS.

    TYPES: BEGIN OF TY_MARA.

    INCLUDE STRUCTURE MARA.

    TYPES: END OF TY_MARA.

    TYPES: BEGIN OF TY_MAKT.

    INCLUDE STRUCTURE MAKT.

    TYPES: END OF TY_MAKT.

    DATA: I_MARA TYPE TABLE OF TY_MARA,

    W_MARA TYPE TY_MARA,

    I_MAKT TYPE TABLE OF TY_MAKT,

    W_MAKT TYPE TY_MAKT.

    DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

    W_FIELDCAT TYPE SLIS_FIELDCAT_ALV,

    I_EVENT TYPE SLIS_T_EVENT,

    I_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

    SELECT * FROM MARA INTO TABLE I_MARA.

    SELECT * FROM MAKT INTO TABLE I_MAKT.

    PERFORM POPULATE.

    PERFORM GRID.

    FORM POPULATE .

    W_FIELDCAT-FIELDNAME = 'MATNR'.

    W_FIELDCAT-TABNAME = 'I_MAKT'.

    W_FIELDCAT-REF_FIELDNAME ='MATNR'.

    W_FIELDCAT-REF_TABNAME ='MAKT'.

    W_FIELDCAT-SELTEXT_M = 'MATNR'.

    APPEND W_FIELDCAT TO I_FIELDCAT.

    CLEAR W_FIELDCAT.

    W_FIELDCAT-FIELDNAME = 'ERSDA'.

    W_FIELDCAT-TABNAME = 'I_MAKT'.

    W_FIELDCAT-REF_FIELDNAME ='ERSDA'.

    W_FIELDCAT-REF_TABNAME ='MAKT'.

    W_FIELDCAT-SELTEXT_M = 'ERSDA'.

    APPEND W_FIELDCAT TO I_FIELDCAT.

    CLEAR W_FIELDCAT.

    ENDFORM. " populate

    FORM GRID .

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = SY-REPID

    I_CALLBACK_USER_COMMAND = 'LISTDISP'

    IT_FIELDCAT = I_FIELDCAT

    TABLES

    T_OUTTAB = I_MAKT

    .

    ENDFORM. " Grid

    FORM LISTDISP USING V_UCOMM LIKE SY-UCOMM HIDEV TYPE SLIS_SELFIELD.

    SELECT * FROM MAKT INTO TABLE I_MAKT WHERE MATNR = HIDEV-VALUE.

    PERFORM LIST.

    ENDFORM. "LISTDISP

    FORM LIST .

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = SY-REPID

    I_STRUCTURE_NAME = 'MAKT'

    TABLES

    T_OUTTAB = I_MAKT.

    ENDFORM. " List

    Regards

    Ankur

    Edited by: Ankur Godre on Jul 23, 2008 1:02 PM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.