‎2015 Nov 18 9:51 AM
Hello,
I am new to ABAP and i want ask a question.
I want to create a ALV report program that able to display all fields and data from two different tables. (ex:mara and makt)
What is the best way to write this type of program especially if it includes too many fields that needed to be fetched from the tables?
Thanks in advance,
Alvin.
‎2015 Nov 18 3:11 PM
Hi,
best way is to create a new structure (local or ddic) for your alv-output.
define a table that has this structure and fill the table with data.
then create an alv using this table
advantage:
the column-text is taken from the field-types inside the struture and no custom field-catalog is needed.
you can decide if you want to just add some fields tot he structure, or if you want to make use of layouts to change the amount of fields listed in the alv by default. (search scn how to use layouts if you need them )
regards
Stefan Seeburger
‎2015 Nov 18 10:06 AM
‎2015 Nov 18 10:10 AM
Hi Abaper,
best way is use join for not more than 2 table.
and if you have more than 2 table's output needed then you take (1-2)join-(1-2)-3for all entries or
(1-2)for all entries-(1-2)-3for all entries.
‎2015 Nov 18 10:23 AM
Hi Alvinraj,
first fetch the data from mara into internal table gt_mara, fetch makt fields into table gt_makt you can use for all entries or joins and then loop the data and move the fields to final table.
TABLES : MARA.
TYPES : BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
LAEDA TYPE MARA-LAEDA,
AENAM TYPE MARA-AENAM,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
BSTME TYPE MARA-BSTME,
AESZN TYPE MARA-AESZN,
END OF TY_MARA.
TYPES : BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR,
MAKTX TYPE MAKT-MAKTX,
MAKTG TYPE MAKT-MAKTG,
END OF TY_MAKT.
TYPES : BEGIN OF TY_FINAL,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
LAEDA TYPE MARA-LAEDA,
AENAM TYPE MARA-AENAM,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
BSTME TYPE MARA-BSTME,
AESZN TYPE MARA-AESZN,
MAKTX TYPE MAKT-MAKTX,
MAKTG TYPE MAKT-MAKTG,
END OF TY_FINAL.
DATA : GT_MARA TYPE TABLE OF TY_MARA,
GT_MAKT TYPE TABLE OF TY_MAKT,
GT_FINAL TYPE TABLE OF TY_FINAL,
GS_FINAL TYPE TY_FINAL,
GS_MAKT TYPE TY_MAKT,
GS_MARA TYPE TY_MARA.
SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.
START-OF-SELECTION.
SELECT MATNR
ERSDA
ERNAM
LAEDA
AENAM
MTART
MBRSH
MATKL
MEINS
BSTME
AESZN FROM MARA INTO TABLE GT_MARA
WHERE MATNR IN S_MATNR.
IF GT_MARA IS NOT INITIAL.
SELECT MATNR
MAKTX
MAKTG FROM MAKT INTO TABLE GT_MAKT
FOR ALL ENTRIES IN GT_MARA
WHERE MATNR = GT_MARA-MATNR.
ENDIF.
END-OF-SELECTION.
LOOP AT GT_MARA INTO GS_MARA WHERE MATNR IN S_MATNR.
GS_FINAL-MATNR = GS_MARA-MATNR.
GS_FINAL-ERSDA = GS_MARA-ERSDA.
*similarly move the remaining fields*
READ TABLE GT_MAKT INTO GS_MAKT WITH KEY MATNR = GS_MARA-MATNR.
IF SY-SUBRC = 0.
GS_FINAL-MAKTX = GS_MAKT-MAKTX.
GS_FINAL-MAKTG = GS_MAKT-MAKTG.
ENDIF.
APPEND GS_FINAL TO GT_FINAL.
CLEAR : GS_FINAL, GS_MARA, GS_MAKT.
ENDLOOP.
PERFORM FIELD_CATALOG.
IF GT_FINAL[] IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE '
IT_FIELDCAT = IT_FCAT
I_SAVE = 'A'
TABLES
T_OUTTAB = GT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
ELSE.
MESSAGE TEXT-002 TYPE 'E'.
ENDIF.
‎2015 Nov 18 3:11 PM
Hi,
best way is to create a new structure (local or ddic) for your alv-output.
define a table that has this structure and fill the table with data.
then create an alv using this table
advantage:
the column-text is taken from the field-types inside the struture and no custom field-catalog is needed.
you can decide if you want to just add some fields tot he structure, or if you want to make use of layouts to change the amount of fields listed in the alv by default. (search scn how to use layouts if you need them )
regards
Stefan Seeburger