Here is the Tutorial which gives you clear picture about Interactive reports.
In this tutorial we are going to use 3 Database tables:
MARA
MARC &
MARD
And few select queries for retrieving data from the database tables.
We are going to make use of few Interactive Report events like
AT-LINE-SELECTION
Here is the piece of code snippet which helps you to explore even more.
*&---------------------------------------------------------------------*
*& Report ZINTERACTIVE_REPORT_SAP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZINTERACTIVE_REPORT_SAP LINE-SIZE 145.
INITIALIZATION.
*//TYPES DECLARATION FOR MARA TABLE
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR, "MATERIAL NUMBER
ERSDA TYPE MARA-ERSDA, "CREATED ON
ERNAM TYPE MARA-ERNAM, "CREATED BY
LAEDA TYPE MARA-LAEDA, "LAST CHANGE ON
MTART TYPE MARA-MTART, "MATERIAL TYPE
MATKL TYPE MARA-MATKL, "MATERIAL GROUP
MEINS TYPE MARA-MEINS, "MATERIAL GROUP
END OF TY_MARA.
DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA,
WA_MARA TYPE TY_MARA.
*//TYPES DECLARATION FOR MARD TABLE
TYPES: BEGIN OF TY_MARD,
MATNR TYPE MARD-MATNR, "MATERIAL NUMBER
LGORT TYPE MARD-LGORT, "STORAGE LOCATION
WERKS TYPE MARD-WERKS, "PLANT
END OF TY_MARD.
DATA: IT_MARD TYPE STANDARD TABLE OF TY_MARD,
WA_MARD TYPE TY_MARD.
*//TYPES DECLARATION FOR MAKT TABLE
TYPES: BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR, "MATERIAL NUMBER
MAKTG TYPE MAKT-MAKTG, "DESCRIPTION
END OF TY_MAKT.
DATA: IT_MAKT TYPE STANDARD TABLE OF TY_MAKT,
WA_MAKT TYPE TY_MAKT.
*//TYPES DECLARATION FOR FINAL TABLE
TYPES: BEGIN OF TY_FINAL,
MATNR TYPE MARA-MATNR, "MATERIAL NUMBER
ERSDA TYPE MARA-ERSDA, "CREATED ON
ERNAM TYPE MARA-ERNAM, "CREATED BY
LAEDA TYPE MARA-LAEDA, "LAST CHANGE ON
MTART TYPE MARA-MTART, "MATERIAL TYPE
MATKL TYPE MARA-MATKL, "MATERIAL GROUP
MEINS TYPE MARA-MEINS, "MATERIAL GROUP
LGORT TYPE MARD-LGORT, "STORAGE LOCATION
WERKS TYPE MARD-WERKS, "PLANT
END OF TY_FINAL.
DATA: IT_FINAL TYPE STANDARD TABLE OF TY_FINAL,
WA_FINAL TYPE TY_FINAL.
*//PARAMETERS FOR RETRIEVING DATA
*//BASED ON PLANT AND STORAGE LOC
PARAMETERS: P_PLANT TYPE MARD-WERKS, "PLANT
P_STOR TYPE MARD-LGORT. "STORAGE LOCATION
START-OF-SELECTION.
*//RETRIEVING DATA FROM MARD TABLE
SELECT MATNR LGORT WERKS
FROM MARD
INTO TABLE IT_MARD
WHERE LGORT EQ P_STOR
AND WERKS = P_PLANT.
*//CHECK WHETHER IT_MARD HAS DATA OR NOT
IF IT_MARD IS NOT INITIAL.
SELECT MATNR MAKTG
FROM MAKT
INTO TABLE IT_MAKT
FOR ALL ENTRIES IN IT_MARD
WHERE MATNR EQ IT_MARD-MATNR
AND SPRAS EQ 'E'.
ENDIF.
*//CHECK WHETHER IT_MAKT HAS DATA OR NOT
IF IT_MAKT IS NOT INITIAL.
SELECT MATNR ERSDA ERNAM LAEDA MTART MATKL MEINS
FROM MARA
INTO TABLE IT_MARA
FOR ALL ENTRIES IN IT_MAKT
WHERE MATNR EQ IT_MAKT-MATNR.
ENDIF.
END-OF-SELECTION.
LOOP AT IT_MAKT INTO WA_MAKT.
WRITE: /1 WA_MAKT-MATNR COLOR 1 HOTSPOT ON,
40 WA_MAKT-MAKTG COLOR 5.
HIDE WA_MAKT-MATNR.
ENDLOOP.
AT LINE-SELECTION.
REFRESH IT_FINAL.
CLEAR WA_FINAL.
ULINE.
IF SY-LSIND = 1.
WRITE: /1 SY-VLINE, 'MATERIAL NO' COLOR 2,
22 SY-VLINE, 'CREATED ON' COLOR 3,
34 SY-VLINE, 'CREATED BY',
52 SY-VLINE, 'DATE OF LIST' ,
67 SY-VLINE, 'MATERIALTYPE',
82 SY-VLINE, 'MATGROUP' ,
92 SY-VLINE, 'UNITOFMEASURE',
112 SY-VLINE, 'STORLOCATION' COLOR 4,
132 SY-VLINE, 'PLANT' COLOR 5,
145 SY-VLINE.
ULINE.
ENDIF.
LOOP AT IT_MARA INTO WA_MARA WHERE MATNR EQ WA_MAKT-MATNR.
WA_FINAL-MATNR = WA_MARA-MATNR.
WA_FINAL-ERSDA = WA_MARA-ERSDA.
WA_FINAL-ERNAM = WA_MARA-ERNAM.
WA_FINAL-LAEDA = WA_MARA-LAEDA.
WA_FINAL-MTART = WA_MARA-MTART.
WA_FINAL-MATKL = WA_MARA-MATKL.
WA_FINAL-MEINS = WA_MARA-MEINS.
READ TABLE IT_MARD INTO WA_MARD WITH KEY MATNR = WA_MAKT-MATNR.
WA_FINAL-LGORT = WA_MARD-LGORT.
WA_FINAL-WERKS = WA_MARD-WERKS.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
LOOP AT IT_FINAL INTO WA_FINAL.
WRITE: /1 SY-VLINE, WA_FINAL-MATNR COLOR 2,
22 SY-VLINE, WA_FINAL-ERSDA COLOR 3,
34 SY-VLINE, WA_FINAL-ERNAM,
52 SY-VLINE, WA_FINAL-LAEDA,
67 SY-VLINE, WA_FINAL-MTART,
82 SY-VLINE, WA_FINAL-MATKL,
92 SY-VLINE, WA_FINAL-MEINS,
112 SY-VLINE, WA_FINAL-LGORT COLOR 4,
132 SY-VLINE, WA_FINAL-WERKS COLOR 5,
145 SY-VLINE.
ENDLOOP.
ULINE.
TOP-OF-PAGE.
WRITE: /1 'MATERIAL NUMBER' COLOR 1,
40 'MATERIAL DESCRIPTION' COLOR 5.
ULINE.