Skip to Content
avatar image
Former Member

interactive reports in ALV GRID

Dear gurus,

can we have interactive list in ALV ?

Regards

R.Rajendran

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 15, 2008 at 04:56 AM

    Hi,

    Hope this will help You

    &----


    *& Report ZAlv

    *&

    &----


    *&

    *&

    &----


    REPORT ZAlv.

    TYPE-POOLS : SLIS.

    TABLES : KNA1,VBAK.

    DATA : BEGIN OF ITAB OCCURS 0 ,

    KUNNR LIKE KNA1-KUNNR,

    NAME1 LIKE KNA1-NAME1,

    LAND1 LIKE KNA1-LAND1,

    ORT01 LIKE KNA1-ORT01,

    END OF ITAB.

    DATA : BEGIN OF JTAB OCCURS 0,

    VBELN LIKE VBAK-VBELN ,

    ERNAM LIKE VBAK-ERNAM ,

    ERDAT LIKE VBAK-ERDAT,

    KUNNR LIKE VBAK-KUNNR,

    END OF JTAB .

    DATA : BEGIN OF JTAB1 OCCURS 0,

    VBELN LIKE VBAK-VBELN ,

    ERNAM LIKE VBAK-ERNAM ,

    ERDAT LIKE VBAK-ERDAT,

    KUNNR LIKE VBAK-KUNNR,

    END OF JTAB1.

    DATA : V_REPID LIKE SY-REPID,

    V_LAYOUT TYPE SLIS_LAYOUT_ALV,

    V_EVENTS TYPE SLIS_T_EVENT,

    V_PRINT TYPE SLIS_PRINT_ALV,

    L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

    DATA : FIELD1 TYPE SLIS_FIELDCAT_ALV.

    DATA : FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

    DATA : FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

    SELECT-OPTIONS : CNO FOR KNA1-KUNNR.

    START-OF-SELECTION.

    V_REPID = SY-REPID .

    SELECT KUNNR NAME1 LAND1 ORT01 FROM KNA1 INTO CORRESPONDING FIELDS OF

    TABLE ITAB WHERE KUNNR IN CNO .

    SELECT VBELN ERNAM ERDAT KUNNR FROM VBAK INTO CORRESPONDING FIELDS OF

    TABLE JTAB FOR ALL ENTRIES IN ITAB WHERE KUNNR = ITAB-KUNNR.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = V_REPID

    I_INTERNAL_TABNAME = 'ITAB'

    • I_STRUCTURE_NAME =

    • I_CLIENT_NEVER_DISPLAY = 'X'

    I_INCLNAME = V_REPID

    • I_BYPASSING_BUFFER = 'X'

    • I_BUFFER_ACTIVE = ' '

    CHANGING

    CT_FIELDCAT = FIELDCAT1

    • EXCEPTIONS

    • INCONSISTENT_INTERFACE = 1

    • PROGRAM_ERROR = 2

    • OTHERS = 3

    .

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    • LOOP AT FIELDCAT1 INTO l_fieldcat.

    • CASE l_fieldcat-fieldname.

    • WHEN 'KUNNR'.

    • l_fieldcaT-hotspot = 'X'.

    • MODIFY FIELDCAT1 FROM l_fieldcat.

    • ENDCASE.

    • ENDLOOP.

    *

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    • I_BYPASSING_BUFFER = 'X'

    • I_BUFFER_ACTIVE = ' '

    I_CALLBACK_PROGRAM = V_REPID

    • I_CALLBACK_PF_STATUS_SET = ' '

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

    • I_STRUCTURE_NAME =

    • IS_LAYOUT =

    IT_FIELDCAT = FIELDCAT1

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    • IT_SORT =

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    • I_SAVE = ' '

    • IS_VARIANT =

    • IT_EVENTS =

    • IT_EVENT_EXIT =

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • IR_SALV_LIST_ADAPTER =

    • IT_EXCEPT_QINFO =

    • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    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.

    &----


    *& Form user_command

    &----


    • text

    ----


    • -->R_UCOMM text

    • -->RS_SELFIELD text

    ----


    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

    RS_SELFIELD TYPE SLIS_SELFIELD.

    IF RS_SELFIELD-FIELDNAME EQ 'KUNNR'.

    CASE R_UCOMM.

    WHEN '&IC1'.

    READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.

    REFRESH JTAB1.

    • CLEAR JTAB1.

    LOOP AT JTAB WHERE KUNNR = ITAB-KUNNR.

    APPEND JTAB TO JTAB1.

    ENDLOOP.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = V_REPID

    I_INTERNAL_TABNAME = 'JTAB1'

    • I_STRUCTURE_NAME =

    • I_CLIENT_NEVER_DISPLAY = 'X'

    I_INCLNAME = V_REPID

    • I_BYPASSING_BUFFER =

    • I_BUFFER_ACTIVE =

    CHANGING

    CT_FIELDCAT = FIELDCAT2

    • EXCEPTIONS

    • INCONSISTENT_INTERFACE = 1

    • PROGRAM_ERROR = 2

    • OTHERS = 3

    .

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    • I_BYPASSING_BUFFER = 'X'

    • I_BUFFER_ACTIVE = ' '

    I_CALLBACK_PROGRAM = V_REPID

    • I_CALLBACK_PF_STATUS_SET = ' '

    • I_CALLBACK_USER_COMMAND = ' '

    • I_STRUCTURE_NAME =

    • IS_LAYOUT =

    IT_FIELDCAT = FIELDCAT2

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    • IT_SORT =

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    • I_SAVE = 'A'

    • IS_VARIANT =

    • IT_EVENTS =

    • IT_EVENT_EXIT =

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • IR_SALV_LIST_ADAPTER =

    • IT_EXCEPT_QINFO =

    • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    TABLES

    T_OUTTAB = JTAB1

    • 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.

    ENDCASE.

    ENDIF.

    ENDFORM. "user_command

    Regards,

    Sravanthi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 04:57 AM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 05:00 AM

    Hi rajendran,

    1. In alv we cannot use AT LINE Selection

    2. For alv, there is a special syntax, so that when we double-click on alv,

    our FORM / routine is called and there we display another alv.

    3. just copy paste to get a taste of interactive alv.

    4.

    
    
    REPORT abc.
    
    TYPE-POOLS : slis.
    
    
    *-------------- Data
    
    DATA : ITAB LIKE T001 OCCURS 0 WITH HEADER LINE.
    DATA : alvfc TYPE slis_t_fieldcat_alv.
    DATA : STAB LIKE T001 OCCURS 0 WITH HEADER LINE.
    
    
    *--------- Select Data
    
    SELECT * FROM t001 INTO TABLE itab.
    
    
    *------- Field Catalogue
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
        i_program_name         = sy-repid
        i_internal_tabname     = 'ITAB'
        i_inclname             = sy-repid
      CHANGING
        ct_fieldcat            = alvfc
      EXCEPTIONS
        inconsistent_interface = 1
        program_error          = 2
        OTHERS                 = 3.
    
    
    *---------------Display
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        it_fieldcat             = alvfc
        i_callback_program      = sy-repid "<-------Important
        i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important
      TABLES
        t_outtab                = itab
      EXCEPTIONS
        program_error           = 1
        OTHERS                  = 2.
    
    
    
    *-------------------------------------------------
    * CALL BACK FORM
    *-------------------------------------------------
    
    FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
    slis_selfield.
    
    
    *--------- IMPORTANT.
    
    
    
      READ TABLE ITAB INDEX WHATROW-TABINDEX.
    *
      CLEAR STAB.
      SELECT * FROM T001
      INTO TABLE STAB
      WHERE BUKRS = ITAB-BUKRS.
    
      CLEAR ALVFC.
    *------- Field Catalogue
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         = sy-repid
          i_internal_tabname     = 'STAB'
          i_inclname             = sy-repid
        CHANGING
          ct_fieldcat            = alvfc
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
    
    
    *---------------Display
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat        = alvfc
          i_callback_program = sy-repid "<-------Important
        TABLES
          t_outtab           = Stab
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
    
    
    
    
    
    ENDFORM. "ITAB_user_command
    
    

    regards,

    amit m.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 05:05 AM

    Hi Raj,

    Yes we can have interactive list in alv .

    Check this following link for two level interactive alv.

    http://www.sap-basis-abap.com/abap/display-two-level-interactive-list-in-alv.htm

    Regards,

    Chandra Sekhar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 05:07 AM

    Hi,

    Check this link.

    Alv interactive lists:

    REPORT  yh_alvtreedemo1.
    
    TYPE-POOLS : fibs,stree.
    TYPE-POOLS:slis.
    DATA : t_node TYPE snodetext.
    
    DATA : it_node LIKE TABLE OF t_node,
           wa_node LIKE t_node.
    
    DATA: t_fieldcat    TYPE slis_t_fieldcat_alv,
          fs_fieldcat   TYPE slis_fieldcat_alv.
    
    DATA:w_repid LIKE sy-repid.
    
    *Internal Table declarations
    DATA: BEGIN OF fs_scarr,
            carrid LIKE scarr-carrid,
          END OF fs_scarr.
    
    DATA:BEGIN OF fs_spfli,
            carrid LIKE spfli-carrid,
            connid LIKE spfli-connid,
         END OF fs_spfli.
    
    DATA:BEGIN OF fs_sflight,
            carrid LIKE sflight-carrid,
            connid LIKE sflight-connid,
            fldate LIKE sflight-fldate,
         END OF fs_sflight.
    
    DATA:BEGIN OF fs_sbook,
            carrid LIKE sbook-carrid,
            connid LIKE sbook-connid,
            fldate LIKE sbook-fldate,
            bookid LIKE sbook-bookid,
         END OF fs_sbook.
    
    DATA:t_scarr LIKE TABLE OF fs_scarr,
         t_spfli LIKE TABLE OF fs_spfli,
         t_sflight LIKE TABLE OF fs_sflight,
         t_sbook LIKE TABLE OF fs_sbook.
    
    START-OF-SELECTION.
    
      PERFORM get_data.
      PERFORM build_tree.
      PERFORM display_tree.
    
    *&----------------------------------------------------------------*
    *&      Form  get_data
    *&----------------------------------------------------------------*
    
    FORM get_data .
    
      SELECT carrid
             FROM scarr
             INTO TABLE t_scarr.
    
      SELECT carrid
              connid
              FROM spfli
              INTO TABLE t_spfli
              FOR ALL ENTRIES IN t_scarr
              WHERE carrid EQ t_scarr-carrid.
    
    ENDFORM.                    " get_data
    *&----------------------------------------------------------------*
    *&      Form  build_tree
    *&----------------------------------------------------------------*
    
    FORM build_tree .
      CLEAR: it_node,
             wa_node.
    
      SORT: t_scarr BY carrid,
            t_spfli BY carrid connid,
            t_sflight BY carrid connid fldate,
            t_sbook BY carrid connid fldate bookid.
    
      wa_node-type = 'T'.
      wa_node-name = 'Flight Details'.
      wa_node-tlevel = '01'.
      wa_node-nlength = '15'.
      wa_node-color = '4'.
      wa_node-text = 'Flight'.
      wa_node-tlength ='20'.
      wa_node-tcolor = 3.
      APPEND wa_node TO it_node.
      CLEAR wa_node.
    
      LOOP AT t_scarr INTO fs_scarr.
    
        wa_node-type = 'P'.
        wa_node-name = 'CARRID'.
        wa_node-tlevel = '02'.
        wa_node-nlength = '8'.
        wa_node-color = '1'.
        wa_node-text = fs_scarr-carrid.
        wa_node-tlength ='20'.
        wa_node-tcolor = 4.
        APPEND wa_node TO it_node.
        CLEAR wa_node.
    
        LOOP AT t_spfli INTO fs_spfli WHERE carrid EQ fs_scarr-carrid.
    
          wa_node-type = 'P'.
          wa_node-name = 'CONNID'.
          wa_node-tlevel = '03'.
          wa_node-nlength = '8'.
          wa_node-color = '1'.
          wa_node-text = fs_spfli-connid.
          wa_node-tlength ='20'.
          wa_node-tcolor = 4.
          APPEND wa_node TO it_node.
          CLEAR wa_node.
    
        ENDLOOP.
      ENDLOOP.
    ENDFORM.                    " build_tree
    *&----------------------------------------------------------------*
    *&      Form  display_tree
    *&----------------------------------------------------------------*
    
    FORM display_tree .
      CALL FUNCTION 'RS_TREE_CONSTRUCT'
        TABLES
          nodetab = it_node.
    
      w_repid = sy-repid.
    
      CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
        EXPORTING
          callback_program      = w_repid
          callback_user_command = 'USER_COMMAND'
          callback_gui_status   = 'SET_PF'.
    ENDFORM.                    " display_tree
    *&----------------------------------------------------------------*
    *&      Form  pick
    *&----------------------------------------------------------------*
    *      -->COMMAND    text
    *      -->NODE       text
    *-----------------------------------------------------------------*
    
    FORM user_command    TABLES pt_nodes         STRUCTURE seucomm
                       		USING pv_command       TYPE c
                   		CHANGING pv_exit        TYPE c
                           		 pv_list_refresh  TYPE c.
    
      pv_list_refresh = 'X'.
    
      IF pt_nodes-tlevel = '03'.
    
        CLEAR t_fieldcat[].
    
        SELECT carrid
               connid
               fldate
               FROM sflight
               INTO TABLE t_sflight
               WHERE connid EQ pt_nodes-text.
    
        fs_fieldcat-col_pos = 1.
        fs_fieldcat-fieldname = 'CARRID'.
        fs_fieldcat-seltext_m = 'Airlinecarrier'.
        fs_fieldcat-key = 'X'.
        fs_fieldcat-hotspot = 'X'.
        APPEND fs_fieldcat TO t_fieldcat.
        CLEAR fs_fieldcat.
    
        fs_fieldcat-col_pos = 2.
        fs_fieldcat-fieldname = 'CONNID'.
        fs_fieldcat-seltext_m = 'Connection No'.
        fs_fieldcat-key = 'X'.
        fs_fieldcat-hotspot = 'X'.
        APPEND fs_fieldcat TO t_fieldcat.
        CLEAR fs_fieldcat.
    
        fs_fieldcat-col_pos = 3.
        fs_fieldcat-fieldname = 'FLDATE'.
        fs_fieldcat-seltext_m = 'Flight Date'.
        fs_fieldcat-key = 'X'.
        fs_fieldcat-hotspot = 'X'.
        APPEND fs_fieldcat TO t_fieldcat.
        CLEAR fs_fieldcat.
    
        w_repid = sy-repid.
    
        CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
          EXPORTING
            i_callback_program = w_repid
            it_fieldcat        = t_fieldcat[]
          TABLES
            t_outtab           = t_sflight.
      ENDIF.
    ENDFORM.                    "pick
    
    *&----------------------------------------------------------------*
    *&      Form  set_pf
    *&----------------------------------------------------------------*
    *       text
    *-----------------------------------------------------------------*
    FORM set_pf.
      SET PF-STATUS 'MYPF'.
    ENDFORM.                    "set_pf
    

    Hope this would help you.

    Regards

    Narin Nandivada

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 05:13 AM

    Hi ,

    Interactive with ALV is Possible.

    All that you have to do is you need to set the parameter-id for that particular field.

    example code.

    FORM user_command USING rf_ucomm LIKE sy-ucomm

    object TYPE slis_selfield.

    DATA:cfield(20),

    cval(10).

    IF rf_ucomm = '&IC1'.

    cfield = object-fieldname.

    cval = object-value.

    SET PARAMETER ID 'AID' FIELD cval.

    SET PARAMETER ID 'CID' FIELD ccode.

    SET PARAMETER ID 'YID' FIELD fyear.

    CASE cfield.

    WHEN 'RACCT'.

    LOOP AT it_bseg INTO wa_bseg WHERE hkont = cval.

    endform.

    This paramter-id will be present in the Database table.

    Go to SE11.

    ->Give table name as BSEG.

    -->Double click on BELNR.

    -->Now click on Further Characteristics tab.

    -->In that after Search help you have PARAMETER-ID-i.e., BLN

    For which ever field you want this is procedure is Same i.e., you have to SEt PARAMETER-ID.

    Reward Points, if it is helpful to you.

    with Regards,

    Sharmista.

    Add comment
    10|10000 characters needed characters exceeded