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

display 2 internal tables as 2 ALV-lists..

Hi

I have 2 internal tables itab1 and itab2. I have to display the contents of these internal tables as 2 different ALV lists in the same screen..Please help me with steps and if we have to use module pool kindly hep me with the code that has to be included in the PBO and PAI blocks.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 09:28 AM

    HI

    see this program you can understand very easily

    REPORT  ZNNR_ALVOOPS_SCREEN.
    
    tables: mara,spfli.
    
    types: begin of ty_tab,
            matnr type mara-matnr,
            ernam type mara-ernam,
            ersda type mara-ersda,
           end of ty_tab.
    
    DATA ITAB1 TYPE TABLE OF SPFLI.
    DATA WA1 LIKE LINE OF ITAB1.
    
    DATA IO1 TYPE SPFLI-CARRID VALUE 'AA'.
    
    
    
    data itab type table of ty_tab.
    
    data wa like line of itab.
    
    DATA OK_CODE TYPE SY-UCOMM.
    
    DATA: GRID TYPE REF TO CL_GUI_ALV_GRID,
          CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    
    DATA: GRID1 TYPE REF TO CL_GUI_ALV_GRID,
          CONTA TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    
    
    CREATE OBJECT CONT EXPORTING CONTAINER_NAME = 'CONT1' .
    CREATE OBJECT GRID EXPORTING I_PARENT = CONT .
    
    CREATE OBJECT CONTA EXPORTING CONTAINER_NAME = 'CONT2' .
    CREATE OBJECT GRID1 EXPORTING I_PARENT = CONTA .
    
    
    
    selection-screen begin of block b1 with frame title text-100.
    
    select-options: s_matnr for mara-matnr.
    
    selection-screen end of block b1.
    
    select matnr ernam ersda from mara into corresponding fields of table itab up to 15 rows
    where matnr in s_matnr .
    
    call selection-screen 100.
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE USER_COMMAND_0100 INPUT.
    
    if ok_code = 'PB1'.
    
    leave to screen 0.
    
    else.
    
    leave to screen 100.
    
    endif.
    
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE STATUS_0100 OUTPUT.
    *  SET PF-STATUS 'xxxxxxxx'.
    *  SET TITLEBAR 'xxx'.
    
     SELECT * FROM SPFLI INTO
      CORRESPONDING FIELDS OF TABLE ITAB1 WHERE CARRID = IO1.
    
    
    CALL METHOD grid->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
    *    I_BUFFER_ACTIVE               =
    *    I_BYPASSING_BUFFER            =
    *    I_CONSISTENCY_CHECK           =
        I_STRUCTURE_NAME              = 'MARA'
    *    IS_VARIANT                    =
    *    I_SAVE                        =
    *    I_DEFAULT                     = 'X'
    *    IS_LAYOUT                     =
    *    IS_PRINT                      =
    *    IT_SPECIAL_GROUPS             =
    *    IT_TOOLBAR_EXCLUDING          =
    *    IT_HYPERLINK                  =
    *    IT_ALV_GRAPHICS               =
    *    IT_EXCEPT_QINFO               =
    *    IR_SALV_ADAPTER               =
      CHANGING
        IT_OUTTAB                     = itab.
    *    IT_FIELDCATALOG               =
    *    IT_SORT                       =
    *    IT_FILTER                     =
    *  EXCEPTIONS
    *    INVALID_PARAMETER_COMBINATION = 1
    *    PROGRAM_ERROR                 = 2
    *    TOO_MANY_LINES                = 3
    *    others                        = 4
            .
    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 METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          I_STRUCTURE_NAME = 'SPFLI'
        CHANGING
          IT_OUTTAB        = ITAB1.
    
    
    ENDMODULE.                 " STATUS_0100  OUTPUT

    <b>Rewar dif usefull</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 09:29 AM

    Hi Renu,

    Please call the function CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    2 times,one for each internal table and build 2 fieldcatalog for both ALv's.

    Reward if useful.

    Thakx.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 09:36 AM

    Hi Naresh,

    I copied the code that you had posted and executed it ....I am just getting a blank screen...What to do??

    Thanks.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 09:39 AM

    hi,

    u can use block ALV like,

    TYPE-POOLS : slis.

    TABLES : mara,

    makt.

    SELECT-OPTIONS : mat FOR mara-matnr.

    DATA : BEGIN OF itab OCCURS 0,

    matnr LIKE mara-matnr,

    maktx LIKE makt-maktx,

    matkl LIKE mara-matkl,

    mtart LIKE mara-mtart,

    END OF itab.

    DATA : BEGIN OF itab1 OCCURS 0,

    mtart LIKE mara-mtart,

    count TYPE i,

    END OF itab1.

    DATA : BEGIN OF itab1_col OCCURS 0,

    mtart LIKE mara-mtart,

    count TYPE i,

    END OF itab1_col.

    DATA : t_fcat1 TYPE slis_t_fieldcat_alv,

    t_fcat2 TYPE slis_t_fieldcat_alv,

    wa_fcat TYPE slis_fieldcat_alv,

    t_eve TYPE slis_t_event,

    wa_eve TYPE slis_alv_event,

    t_layout TYPE slis_layout_alv.

    DATA : v_repid LIKE sy-repid,

    t_mat LIKE mara-matnr.

    DEFINE create_fcat.

    clear wa_fcat.

    wa_fcat-fieldname = &1.

    wa_fcat-seltext_l = &2.

    wa_fcat-outputlen = &3.

    append wa_fcat to t_fcat1.

    END-OF-DEFINITION.

    START-OF-SELECTION.

    PERFORM get_data.

    PERFORM dis_data.

    &----


    *& Form get_data

    &----


    • text

    ----


    FORM get_data.

    SELECT amatnr bmaktx amtart amatkl INTO CORRESPONDING FIELDS OF TABLE itab

    FROM mara AS a INNER JOIN makt AS b ON

    amatnr = bmatnr

    WHERE a~matnr IN mat.

    LOOP AT itab.

    itab1-mtart = itab-mtart.

    itab1-count = 1.

    APPEND itab1.

    ENDLOOP.

    SORT itab1 BY mtart.

    LOOP AT itab1.

    MOVE-CORRESPONDING itab1 TO itab1_col.

    COLLECT itab1_col.

    ENDLOOP.

    ENDFORM. "get_data

    &----


    *& Form dis_data

    &----


    • text

    ----


    FORM dis_data.

    v_repid = sy-repid.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

    EXPORTING

    i_callback_program = v_repid.

    REFRESH t_fcat1.

    CLEAR t_fcat1.

    REFRESH t_eve.

    wa_eve-name = 'TOP_OF_PAGE'.

    wa_eve-form = 'TOP_OF_PAGE1'.

    APPEND wa_eve TO t_eve.

    create_fcat:

    'MATNR' 'Material' '10',

    'MAKTX' 'Material Description' '40',

    'MTART' 'Type' '10',

    'MATKL' 'Group' '10'.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

    is_layout = t_layout

    it_fieldcat = t_fcat1

    i_tabname = 'ITAB'

    it_events = t_eve

    TABLES

    t_outtab = itab.

    REFRESH t_fcat1.

    CLEAR t_fcat1.

    REFRESH t_eve.

    wa_eve-name = 'TOP_OF_PAGE'.

    wa_eve-form = 'TOP_OF_PAGE2'.

    APPEND wa_eve TO t_eve.

    create_fcat:

    'MTART' 'Type' '10',

    'COUNT' 'Total' '5'.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

    is_layout = t_layout

    it_fieldcat = t_fcat1

    i_tabname = 'ITAB1_COL'

    it_events = t_eve

    TABLES

    t_outtab = itab1_col.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.

    ENDFORM. "dis_data

    &----


    *& Form top_of_page1

    &----


    • text

    ----


    FORM top_of_page1.

    FORMAT COLOR COL_POSITIVE.

    WRITE:/ 'First Block'.

    FORMAT COLOR OFF.

    ENDFORM. "top_of_page

    &----


    *& Form top_of_page2

    &----


    • text

    ----


    FORM top_of_page2.

    FORMAT COLOR COL_NEGATIVE.

    WRITE /5 'Second Block'.

    FORMAT COLOR OFF.

    ENDFORM. "top_of_page

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 03, 2007 at 09:43 AM

    Hi

    Use block alv for that

    Refer thios code

    &----


    *& Form sub_alv_display *

    &----


    • This form displays the output using REUSE_ALV_GRID_DISPLAY *

    • function module *

    ----


    FORM sub_alv_display .

    *--Local Variables

    DATA : lv_index LIKE sy-tabix.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

    EXPORTING

    i_callback_program = v_repid.

    wa_layout1-colwidth_optimize = 'X'.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

    is_layout = wa_layout1

    it_fieldcat = it_fieldcat[]

    i_tabname = 'it_final'

    it_events = it_events

    TABLES

    t_outtab = it_final

    EXCEPTIONS

    program_error = 1

    maximum_of_appends_reached = 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 it_fieldcat INTO wa_fieldcat.

    lv_index = sy-tabix.

    IF wa_fieldcat-fieldname = 'ERDAT'.

    wa_fieldcat-fieldname = 'TITLE'.

    wa_fieldcat-seltext_m = text-026.

    wa_fieldcat-outputlen = 10.

    ENDIF.

    MODIFY it_fieldcat FROM wa_fieldcat INDEX lv_index TRANSPORTING

    fieldname seltext_m outputlen.

    CLEAR : wa_fieldcat.

    ENDLOOP.

    wa_layout2-no_colhead = 'X'.

    wa_layout2-colwidth_optimize = 'X'.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

    is_layout = wa_layout2

    it_fieldcat = it_fieldcat[]

    i_tabname = 'it_total'

    it_events = it_event1

    TABLES

    t_outtab = it_total

    EXCEPTIONS

    program_error = 1

    maximum_of_appends_reached = 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.

    wa_layout3-no_colhead = 'X'.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

    EXPORTING

    is_layout = wa_layout3

    it_fieldcat = it_fieldcat2[]

    i_tabname = 'it_ship'

    it_events = it_event2

    TABLES

    t_outtab = it_ship

    EXCEPTIONS

    program_error = 1

    maximum_of_appends_reached = 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.

    IF NOT it_final IS INITIAL OR

    NOT it_total IS INITIAL OR

    NOT it_ship IS INITIAL.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

    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.

    ENDIF.

    ENDFORM. "sub_alv_display

    also refer this program ALV Block List BALVBT01

    Regards,

    Prashant

    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.