Skip to Content

How to pass two internal tables into ALV report function module

while creating ALV report I'm trying to fetch data from two different tables ie: mara, makt. But on output screen data is not showing. Below is code can anyone suggest me solutions on it and how to pass both internal table structure into the Function module.

REPORT ZSPM_GUI_DOWNLOAD.

TABLES: mara,
makt.

TYPE-POOLS slis.

SELECT-OPTIONS s_matnr FOR mara-matnr.

TYPES: BEGIN OF st_op,
v_matnr TYPE mara-matnr,
v_ernam TYPE mara-ernam,
v_ersda TYPE mara-ersda,
v_maktx TYPE makt-maktx,

END OF st_op.

Data: it_op TYPE TABLE OF st_op,
wa_op TYPE st_op.

TYPES: BEGIN OF st_mara,
lv_matnr TYPE mara-matnr,
lv_ernam TYPE mara-ernam,
lv_ersda TYPE mara-ersda,
END OF st_mara,

BEGIN OF st_makt,
lv_matnr TYPE makt-matnr,
lv_maktx TYPE makt-maktx,

END OF st_makt.

DATA: it_mara TYPE TABLE OF st_mara,
wa_mara TYPE st_mara,

it_maktx TYPE TABLE OF st_makt,
wa_maktx TYPE st_makt.

***********************************************************************
************* Field Catelog*******************************************
**********************************************************************
DATA: it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv.

************************************************************************
************ select statement ******************************************
************************************************************************
START-OF-SELECTION.
PERFORM get_data.
PERFORM create_fcat.

end-of-SELECTION.

perform display_alv.



*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
SELECT matnr ernam ersda
FROM mara into TABLE it_mara
WHERE matnr = s_matnr.

SELECT matnr maktx
FROM makt INTO TABLE it_maktx
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-lv_matnr.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_FCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_fcat .
WA_FCAT-COL_POS = '1' .
WA_FCAT-FIELDNAME = 'matnr'.
wa_fcat-seltext_m = 'Material NUmber'.
wa_fcat-tabname = 'it_mara'.
WA_FCAT-KEY = 'X' .
APPEND wa_fcat to it_fcat.
clear wa_fcat.

WA_FCAT-COL_POS = '2'.
wa_fcat-fieldname = 'ernam'.
wa_fcat-seltext_m = 'material created by: NAME'.
wa_fcat-tabname = 'it_mara'.
WA_FCAT-KEY = 'X' .
APPEND wa_fcat to it_fcat.

wa_fcat-fieldname = 'ersda'.
wa_fcat-seltext_m = 'created on:'.
wa_fcat-tabname = 'it_mara'.
WA_FCAT-KEY = 'X' .
APPEND wa_fcat to it_fcat.
clear wa_fcat.

wa_fcat-fieldname = 'Maktx'.
wa_fcat-seltext_m = 'Description of material:'.
wa_fcat-tabname = 'it_maktx'.
WA_FCAT-KEY = 'X' .

APPEND wa_fcat to it_fcat.
*clear wa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = it_fcat
TABLES
t_outtab = it_op
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.

Add comment
10|10000 characters needed characters exceeded

  • May be there is no data for given selection, best way to identify the issue is - by debugging the code.

  • Try this code

    TABLES: mara,
    
            makt.
    
    TYPE-POOLS slis.
    
    SELECT-OPTIONS s_matnr FOR mara-matnr.
    
    TYPES: BEGIN OF st_op,
    
             lv_matnr TYPE mara-matnr,
    
             lv_ernam TYPE mara-ernam,
    
             lv_ersda TYPE mara-ersda,
    
             lv_maktx TYPE makt-maktx,
    
    ENDOF st_op.
    
    DATA: it_op TYPE TABLE OF st_op,
    
          wa_op TYPE st_op.
    ***********************************************************************
    ************* Field Catelog*******************************************
    **********************************************************************
    
    DATA: it_fcat TYPE slis_t_fieldcat_alv,
    
          wa_fcat TYPE slis_fieldcat_alv.
    ************************************************************************
    ************ select statement ******************************************
    ************************************************************************
    
    START-OF-SELECTION.
    
    PERFORM get_data.
    
    PERFORM create_fcat.
    
    END-OF-SELECTION.
    
    PERFORM display_alv.
    *&---------------------------------------------------------------------*
    *& Form GET_DATA
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * --> p1 text
    * <-- p2 text
    *----------------------------------------------------------------------*
    
    FORM get_data .
    
    SELECT m~matnr, m~ernam, m~ersda, mt~maktx
    
      FROM mara as m
    
    inner join makt as mt on m~matnr = mt~matnr
    
      WHERE m~matnr IN @s_matnr
    
      INTO TABLE @it_op.
    
    ENDFORM.
    *&---------------------------------------------------------------------*
    *& Form CREATE_FCAT
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * --> p1 text
    * <-- p2 text
    *----------------------------------------------------------------------*
    
    FORM create_fcat .
    
      wa_fcat-col_pos ='1'.
    
      wa_fcat-fieldname ='lv_matnr'.
    
      wa_fcat-seltext_m ='Material NUmber'.
    
      wa_fcat-tabname ='it_op'.
    
      wa_fcat-key ='X'.
    
    APPEND wa_fcat TO it_fcat.
    
    CLEAR wa_fcat.
    
      wa_fcat-col_pos ='2'.
    
      wa_fcat-fieldname ='lv_ernam'.
    
      wa_fcat-seltext_m ='material created by: NAME'.
    
      wa_fcat-tabname ='it_op'.
    
      wa_fcat-key ='X'.
    
    APPEND wa_fcat TO it_fcat.
      wa_fcat-fieldname ='lv_ersda'.
    
      wa_fcat-seltext_m ='created on:'.
    
      wa_fcat-tabname ='it_op'.
    
      wa_fcat-key ='X'.
    
    APPEND wa_fcat TO it_fcat.
    
    CLEAR wa_fcat.
      wa_fcat-fieldname ='lv_maktx'.
    
      wa_fcat-seltext_m ='Description of material:'.
    
      wa_fcat-tabname ='it_op'.
    
      wa_fcat-key ='X'.
    
    APPEND wa_fcat TO it_fcat.
    *clear wa_fcat.
    
    ENDFORM.
    *&---------------------------------------------------------------------*
    *& Form DISPLAY_ALV
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * --> p1 text
    * <-- p2 text
    *----------------------------------------------------------------------*
    
    FORM display_alv .
    
    CALLFUNCTION 'REUSE_ALV_GRID_DISPLAY'
    
    EXPORTING
    
          i_callback_program = sy-repid
    
          it_fieldcat        = it_fcat
    
        TABLES
    
          t_outtab           = it_op.
    
    IF sy-subrc <>0.
    * Implement suitable error handling here
    
    ENDIF.
    
    ENDFORM.

    1 - When select-options are used at the time of filtering, use IN no =.

    2 - When making a simple query, perform the query in the same statement and insert the data into the output table of alv (it_op).

    3 - When defining the name of the columns, you must place the name of the table that references not the name at the time of the query.

    Good luck!

  • Follow
  • Get RSS Feed

3 Answers

  • Sep 21 at 05:27 AM

    Hello,

    Please follow below guidelines :

    1) Try writing a single select query with Join.

    2) You have to pass the output structure fields into the field catalog. Not the actual structure where the data is there. For example you should pass the fields from structure st_op and not from mara table structure. Basically your field catalog should have structure fields populated from one structure that is st_op and not multiple structure

    3) While filling the Field catalog you must input your field name in capitals like this V_MATNR and not v_matnr.

    4) I also I don't see anywhere you are filling it_op table. I suggest you go for join select query as below.

    Select a~matnr

    a~ernam

    a~ersda

    b~maktx

    From mara as a

    Inner join makt as b

    On a~matnr =b~matnr

    Where a~matnr in s_matnr

    Into lt_ op.

    Above code is for lower versions if you have higher ECC Versions you can use below code

    Select a~matnr,

    a~ernam,

    a~ersda,

    b~maktx

    From mara as a

    Inner join makt as b

    On a~matnr =b~matnr

    Where a~matnr in @ s_matnr

    Into @ lt_ op.

    Hope it helps!

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 22 at 06:40 AM

    Let TABNAME of the field catalog to the initial value. Don't transmit "it_op". TABNAME of the field catalog is to be filled only when you are using "ALV hierarchical sequential list" (REUSE_ALV_HIERSEQ_LIST_DISPLAY or cl_salv_hierseq_table=>factory).

    Also a good habit is to input all technical names (like field names) in upper case, because SAP frequently does not change them to upper case, and the technical names are almost always stored in memory and in database in upper case.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 23 at 05:14 AM

    Hi,

    Another way to resolve your problem is - you can create one final table internally, which will contain the fields of your both internal tables and then by loop and read operations you can append all the data in that final table and can pass that table to function module (ALV).

    Add comment
    10|10000 characters needed characters exceeded