10-Interactive Reporting in SAP ABAP
10-Interactive Reporting in SAP ABAP
Displaying the basic information on the basic list and the detailed information in the
The Syatem Variable SY-LSIND will give the list index no.
Example: Display material basic details in first screen(basic list), when ever user clicks on any
material number it displays materials plant details in second screen.
At Line-Selection
This event will trigger when ever user double click on any list line.
Syntax: AT LINE-SELECTION . "Triggers line selection
At User Command
This event will trigger when ever user clicks on any custom buttons of GUI.
Syntax: AT USER-COMMAND . "Triggers user command
At PF Status
This event will trigger when ever user clicks on any function buttons.
Syntax: AT PF <function key> . "Triggers user command
Hide area
It is a key word which is used to store the data into a temporary memory call as HIDE area.
Functionality of HIDE is
When ever the user uses the HIDE statement, the data will be stored in HIDE area along
with line numbers.
When ever user double clicks on any list line the system takes the line number and
checks the HIDE area for the corresponding data in that particular line, then the data will
be return to the HIDE variables.
GET CURSOR
This key word is used to read the field name and field value where the mouse cursor is placed or
double click action is raised. It dosen`t use hide area.
Syntax : GET CURSOR FIELD <V_FIELDNAME>,
FIELDVALUE <V_FIELDVALUE>.
In the above deceleration we have provided 34 lines for report and 2 lines for footer i:e 34(2), we
don`t need standard page heading so we used NO STANDARD PAGE HEADING.
START-OF-SELECTION.
SELECT * FROM MARA
INTO TABLE IT_MARA
WHERE MTART = P_MTART.
START-OF-SELECTION.
PERFORM GET_MATERIAL_DATA.
PERFORM DISPLAY_MATERIALS.
TOP-OF-PAGE.
PERFORM DISPLAY_HEADER.
END-OF-PAGE.
PERFORM DISPLAY_FOOTER.
AT LINE-SELECTION.
PERFORM GET_PLANT_DATA.
PERFORM DISPLAY_PLANT_DATA.
" VALIDATE_INPUT
FORM GET_MATERIAL_DATA .
SELECT * FROM MARA
INTO TABLE IT_MARA
UP TO 50 ROWS
WHERE MTART = P_MTART .
ENDFORM.
" GET_MATERIAL_DATA
FORM DISPLAY_MATERIALS .
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MBRSH.
HIDE WA_MARA. "store line details in HIDE area
ENDLOOP.
ENDFORM.
" DISPLAY_MATERIALS
FORM DISPLAY_HEADER .
WRITE : 'Material Basic Details' COLOR 5.
ENDFORM.
" DISPLAY_HEADER
FORM DISPLAY_FOOTER .
WRITE: 'Report Generated at:', SY-DATUM COLOR 1.
ENDFORM.
" DISPLAY_FOOTER
FORM GET_PLANT_DATA .
SELECT * FROM MARC
INTO TABLE IT_MARC
WHERE MATNR = WA_MARA-MATNR.
ENDFORM.
" GET_PLANT_DATA
FORM DISPLAY_PLANT_DATA .
LOOP AT IT_MARC INTO WA_MARC.
WRITE :/ WA_MARC-MATNR, WA_MARC-WERKS.
ENDLOOP.
ENDFORM.
" DISPLAY_PLANT_DATA
FORM DISPLAY_LIST_HEADER .
WRITE: 'List of Plants for material:', WA_MARA-MATNR COLOR 6.
ENDFORM.
" DISPLAY_LIST_HEADER
Unit Testing
To test the above report go to MARA table(SE11-MARA-DISPLAY-CONTENETS), get a material
type ex: FERT, HALB etc, execute the report, provide material type and execute. The list of
materials will be displayed, double click on any record, the corresponding material plants will be
displayed in secondary list.
In the above deceleration we have provided 34 lines for report and 2 lines for footer i:e 34(2), we
don`t need standard page heading so we used NO STANDARD PAGE HEADING.
START-OF-SELECTION.
SELECT * FROM MARA
INTO TABLE IT_MARA
WHERE MTART = P_MTART.
START-OF-SELECTION.
PERFORM GET_MATERIAL_DATA.
PERFORM DISPLAY_MATERIALS.
TOP-OF-PAGE.
PERFORM DISPLAY_HEADER.
END-OF-PAGE.
PERFORM DISPLAY_FOOTER.
AT LINE-SELECTION.
PERFORM GET_DESC_DATA.
PERFORM DISPLAY_DESC_DATA.
" VALIDATE_INPUT
FORM GET_MATERIAL_DATA .
SELECT * FROM MARA
INTO TABLE IT_MARA
UP TO 50 ROWS
WHERE MTART = P_MTART .
ENDFORM.
" GET_MATERIAL_DATA
FORM DISPLAY_MATERIALS .
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MBRSH.
HIDE WA_MARA. "store line details in HIDE area
ENDLOOP.
ENDFORM.
" DISPLAY_MATERIALS
FORM DISPLAY_HEADER .
WRITE : 'Material Basic Details' COLOR 5.
ENDFORM.
" DISPLAY_HEADER
FORM DISPLAY_FOOTER .
WRITE: 'Report Generated at:', SY-DATUM COLOR 1.
ENDFORM.
" DISPLAY_FOOTER
FORM GET_DESC_DATA .
SELECT * FROM MAKT
INTO TABLE IT_MAKT
WHERE MATNR = WA_MARA-MATNR.
ENDFORM.
" GET_DESC_DATA
FORM DISPLAY_DESC_DATA .
LOOP AT IT_MAKT INTO WA_MAKT.
WRITE :/ WA_MAKT-MATNR, WA_MAKT-MAKTX.
ENDLOOP.
ENDFORM.
" DISPLAY_DESC_DATA
FORM DISPLAY_LIST_HEADER .
WRITE: 'Descriptions for material:', WA_MARA-MATNR COLOR 6.
ENDFORM.
" DISPLAY_LIST_HEADER
Unit Testing
To test the above report go to MARA table(SE11-MARA-DISPLAY-CONTENETS), get a material
type ex: FERT, HALB etc, execute the report, provide material type and execute. The list of
materials will be displayed, double click on any record, the corresponding material descriptions
will be displayed in secondary list.
INITIALIZATION.
AT SELECTION-SCREEN.
PERFORM VALIDATE_INPUT.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
TOP-OF-PAGE.
PERFORM DISPLAY_TOPOFPAGE.
AT LINE-SELECTION.
PERFORM DISPLAY_SECONDARYLIST.
" VALIDATE_INPUT
FORM GET_DATA .
SELECT * FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.
ENDFORM.
" GET_DATA
FORM DISPLAY_DATA .
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MEINS.
ENDLOOP.
ENDFORM.
" DISPLAY_DATA
FORM DISPLAY_SECONDARYLIST .
GET CURSOR FIELD FNAM VALUE FVAL.
CONDENSE FNAM.
CONDENSE FVAL.
IF FNAM = 'WA_MARA-MATNR'.
SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = FVAL .
WRITE:/ WA_MARA-MATNR, WA_MARA-MBRSH, WA_MARA-MTART, WA_MARA-MATKL,
WA_MARA-MEINS, WA_MARA-ERSDA, WA_MARA-ERNAM.
ELSEIF FNAM = 'WA_MARA-MTART'.
SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS WHERE MTART = FVAL.
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
ENDLOOP.
ENDIF.
ENDFORM.
" DISPLAY_SECONDARYLIST
FORM DISPLAY_TOPOFPAGE .
WRITE:/ 'Material Details' COLOR 3.
ENDFORM.
" DISPLAY_TOPOFPAGE
FORM LINE_TOPOFPAGE .
IF FNAM = 'WA_MARA-MATNR'.
WRITE:/ 'Material details ', WA_MARA-MATNR COLOR 5.
ELSEIF FNAM = 'WA_MARA-MTART'.
WRITE:/ 'Material with material type ', WA_MARA-MTART COLOR 5.
ENDIF.
ENDFORM.
" LINE_TOPOFPAGE
Description
Moment at which the user selects a line by double clicking on it or
by positioning the cursor on it and pressing F2
AT USER-COMMAND
TOP-OF-PAGE DURING
LINE-SELECTION
After processing the secondary list, clear the work area again. This prevents the user from trying
to create further secondary lists from the secondary list displayed.
Absolute number of the line from which the event was triggered
SY-LISEL Contents of the line from which the event was triggered
SY-
Position of the line in the window from which the event was triggered (counting starts
CUROW
with 1)
SY-
Position of the column in the window from which the event was triggered (counting
CUCOL
starts with 2)
SYCPAGE
Page number of the first displayed page of the list from which the event was triggered
SY-
Number of the first line of the first page displayed of the list from which the event was
STARO
triggered (counting starts with 1). Possibly, a page header occupies this line
SY-
Number of the first column displayed in the list from which the event was triggered
STACO
SYUCOMM
SYPFKEY
In which system field does the name of current gui status is there?
The name of the current GUI STATUS is available in the system field SY-PFKEY.
Can we display a list in a pop-up screen other than full-size stacked list?
Yes, we can display a list in a pop-up screen using the command WINDOW with the additions
starting at X1 Y1 and ending at X2 Y2 to set the upper-left and the lower-right corners where x1
y1 and x2 y2 are the coordinates.
How can you display frames (horizontal and vertical lines) in lists?
You can display tabular lists with horizontal and vertical lines (FRAMES) using the ULINE
command and the system field SY-VLINE. The corners arising at the intersection of horizontal
and vertical lines are automatically drawn by the system.
What are the events used for page headers and footers?
The events TOP-OF-PAGE and END-OF-PAGE are used for pager headers and footers.
How can you access the function code from menu painter?
From within the program, you can use the SY-UCOMM system field to access the function code.
You can define individual interfaces for your report and assign them in the report to any list level.
If you do not specify self-defined interfaces in the report but use at least one of the three
interactive event keywords. AT LINE-SELECTION, AT PF, OR AT USER-COMMAND in the
program, the system automatically uses appropriate predefined standard interfaces. These
standard interfaces provide the same functions as the standard list described under the standard
list.
CONVERSION_EXIT_xxxxx_INPUT
CONVERSION_EXIT_xxxxx_OUTPUT
The INPUT module converts from display format to internal format, and the OUTPUT module
converts from internal format to display format.
CONVERSION_EXIT_MATN1_INPUT
CONVERSION_EXIT_MATN1_OUTPUT
START-OF-SELECTION.
PERFORM GET_MATERIAL_DATA.
PERFORM DISPLAY_MATERIALS.
TOP-OF-PAGE.
PERFORM DISPLAY_HEADER.
END-OF-PAGE.
PERFORM DISPLAY_FOOTER.
AT LINE-SELECTION.
PERFORM GET_PLANT_DATA.
PERFORM DISPLAY_PLANT_DATA.
PERFORM DISPLAY_LIST_HEADER.
FORM VALIDATE_INPUT .
IF P_MTART IS INITIAL.
MESSAGE 'Please enter input' TYPE 'E'.
ENDIF.
ENDFORM.
" VALIDATE_INPUT
FORM GET_MATERIAL_DATA .
SELECT * FROM MARA
INTO TABLE IT_MARA
UP TO 50 ROWS
WHERE MTART = P_MTART .
ENDFORM.
" GET_MATERIAL_DATA
FORM DISPLAY_MATERIALS .
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MBRSH.
HIDE WA_MARA. "store line details in HIDE area
ENDLOOP.
ENDFORM.
" DISPLAY_MATERIALS
FORM DISPLAY_HEADER .
WRITE : 'Material Basic Details' COLOR 5.
ENDFORM.
" DISPLAY_HEADER
FORM DISPLAY_FOOTER .
WRITE: 'Report Generated at:', SY-DATUM COLOR 1.
ENDFORM.
" DISPLAY_FOOTER
FORM GET_PLANT_DATA .
= WA_MARA-MATNR
IMPORTING
output
= WA_MARA-MATNR .
" GET_PLANT_DATA
FORM DISPLAY_PLANT_DATA .
LOOP AT IT_MARC INTO WA_MARC.
WRITE :/ WA_MARC-MATNR, WA_MARC-WERKS.
ENDLOOP.
ENDFORM.
" DISPLAY_PLANT_DATA
FORM DISPLAY_LIST_HEADER .
WRITE: 'List of Plants for material:', WA_MARA-MATNR COLOR 6.
ENDFORM.
" DISPLAY_LIST_HEADER
4. Display TREE
Go to SE38, create a report with name ZSAPN_TREE_MATERIAL and follow below steps .
Data Declarations
Internal tables and work area declarations for required tables, in our requirement we are building
tree for MARA(Material) and MAKT(Material descriptions multiple languages).
***Material Basic Data Declarations
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA.
DATA : WA_MARA TYPE TY_MARA.
***Material Descriptions Declarations
TYPES: BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT.
DATA : WA_MAKT TYPE TY_MAKT.
Function module RS_TREE_CONSTRUCT has a table parameter with name NODETAB, this
parameter holds the TLEVEL(Level of a row ex:1, 2 etc), NAME,TEXT,TEXT1,TEXT2 TEXT9(field name ex: MATNR), NLENGTH,TLENGTH,TLENGTH1 - TLENGTH9(Length of the
field ex: 18), COLOR, TCOLOR, TCOLOR1 to TCOLOR9 etc.
Note: By using RS_TREE_LIST_DISPLAY and RS_TREE_CONSTRUCT function modules, we
can display maximum of 10 columns in each level.
***Data Table decleration for FM RS_TREE_CONSTRUCT
DATA: IT_NODE TYPE STANDARD TABLE OF SNODETEXT,
WA_NODE TYPE SNODETEXT.
Loop through IT_MARA and IT_MAKT(inside IT_MARA loop) and build level 2 and level 3
LOOP AT IT_MARA INTO WA_MARA.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 2. "Node Level 2
"Material Number
WA_NODE-NAME = WA_MARA-MATNR.
WA_NODE-NLENGTH = 18.
WA_NODE-COLOR = C_COL_MATNR.
"Material Type
WA_NODE-TEXT1 = WA_MARA-MTART.
WA_NODE-TLENGTH1 = 4.
WA_NODE-TCOLOR1 = C_COL_FIELD.
"Industry Sector
WA_NODE-TEXT2 = WA_MARA-MBRSH.
WA_NODE-TLENGTH2 = 1.
WA_NODE-TCOLOR2 = C_COL_FIELD.
"Material Group
WA_NODE-TEXT3 = WA_MARA-MATKL.
WA_NODE-TLENGTH3 = 4.
WA_NODE-TCOLOR3 = C_COL_FIELD.
"Unit of Measure
WA_NODE-TEXT4 = WA_MARA-MEINS.
WA_NODE-TLENGTH4 = 3.
WA_NODE-TCOLOR4 = C_COL_FIELD.
APPEND WA_NODE TO IT_NODE.
LOOP AT IT_MAKT INTO WA_MAKT WHERE MATNR = WA_MARA-MATNR.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 3. "Node level 3
"Material Number
WA_NODE-NAME = WA_MAKT-MATNR.
WA_NODE-NLENGTH = 18.
WA_NODE-COLOR = C_COL_MAKTX.
"Language ISO Code
WA_NODE-TEXT = WA_MAKT-SPRAS.
WA_NODE-TLENGTH = 2.
WA_NODE-TCOLOR = C_COL_FIELD.
"Material Description
WA_NODE-TEXT1 = WA_MAKT-MAKTX.
WA_NODE-TLENGTH1 = 40.
WA_NODE-TCOLOR1 = C_COL_FIELD.
APPEND WA_NODE TO IT_NODE.
ENDLOOP.
ENDLOOP.
INSERT_ID
RELATIONSHIP
LOG
= '000000'
=''
=
TABLES
NODETAB
= IT_NODE
EXCEPTIONS
TREE_FAILURE
=1
ID_NOT_FOUND
=2
WRONG_RELATIONSHIP = 3
OTHERS
= 4.
IF SY-SUBRC <> 0.
WRITE 'Error in Tree Construction'.
ENDIF.
Display TREE
Finally Display TREE by calling Function module RS_TREE_LIST_DISPLAY
***Display TREE
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = SY-REPID.
Get material numbers which has more the one description(different languages)
Execute TREE program and provide the material numbers as inputs(which we got from
MAKT)
*&---------------------------------------------------------------------*
*& Report ZSAPN_TREE_MATERIAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSAPN_TREE_MATERIAL.
***Material Basic Data Declarations
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA.
DATA : WA_MARA TYPE TY_MARA.
***Material Descriptions Declarations
TYPES: BEGIN OF TY_MAKT,
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT.
DATA : WA_MAKT TYPE TY_MAKT.
***Data Table decleration for FM RS_TREE_CONSTRUCT
DATA: IT_NODE TYPE STANDARD TABLE OF SNODETEXT,
WA_NODE TYPE SNODETEXT.
**Declare Constants for TREE
CONSTANTS:
C_COL_KEY TYPE C LENGTH 1 VALUE COL_KEY,
C_COL_FIELD TYPE C LENGTH 1 VALUE COL_NORMAL,
C_COL_MATNR TYPE C LENGTH 1 VALUE COL_KEY,
C_COL_MAKTX TYPE C LENGTH 1 VALUE COL_POSITIVE.
**Selection Screen
SELECT-OPTIONS : S_MATNR FOR WA_MARA-MATNR.
START-OF-SELECTION.
**Get Data From Tables
SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA INTO TABLE IT_MARA UP TO 50
ROWS WHERE MATNR IN S_MATNR.
SELECT MATNR SPRAS MAKTX FROM MAKT INTO TABLE IT_MAKT FOR ALL ENTRIES IN
IT_MARA WHERE MATNR = IT_MARA-MATNR.
"Create root node at level 1
WA_NODE-TLEVEL = 1.
WA_NODE-NAME = 'Materials'.
WA_NODE-NLENGTH = 20.
WA_NODE-COLOR = C_COL_KEY.
WA_NODE-TEXT = 'Material Master Report'.
WA_NODE-TLENGTH = 50.
APPEND WA_NODE TO IT_NODE.
LOOP AT IT_MARA INTO WA_MARA.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 2. "Node Level 2
"Material Number
WA_NODE-NAME = WA_MARA-MATNR.
WA_NODE-NLENGTH = 18.
WA_NODE-COLOR = C_COL_MATNR.
"Material Type
WA_NODE-TEXT1 = WA_MARA-MTART.
WA_NODE-TLENGTH1 = 4.
WA_NODE-TCOLOR1 = C_COL_FIELD.
"Industry Sector
WA_NODE-TEXT2 = WA_MARA-MBRSH.
WA_NODE-TLENGTH2 = 1.
WA_NODE-TCOLOR2 = C_COL_FIELD.
"Material Group
WA_NODE-TEXT3 = WA_MARA-MATKL.
WA_NODE-TLENGTH3 = 4.
WA_NODE-TCOLOR3 = C_COL_FIELD.
"Unit of Measure
WA_NODE-TEXT4 = WA_MARA-MEINS.
WA_NODE-TLENGTH4 = 3.
WA_NODE-TCOLOR4 = C_COL_FIELD.
APPEND WA_NODE TO IT_NODE.
LOOP AT IT_MAKT INTO WA_MAKT WHERE MATNR = WA_MARA-MATNR.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 3. "Node level 3
"Material Number
WA_NODE-NAME = WA_MAKT-MATNR.
WA_NODE-NLENGTH = 18.
WA_NODE-COLOR = C_COL_MAKTX.
"Language ISO Code
WA_NODE-TEXT = WA_MAKT-SPRAS.
WA_NODE-TLENGTH = 2.
WA_NODE-TCOLOR = C_COL_FIELD.
"Material Description
WA_NODE-TEXT1 = WA_MAKT-MAKTX.
WA_NODE-TLENGTH1 = 40.
WA_NODE-TCOLOR1 = C_COL_FIELD.
APPEND WA_NODE TO IT_NODE.
ENDLOOP.
ENDLOOP.
**Construct Tree
CALL FUNCTION 'RS_TREE_CONSTRUCT'
* EXPORTING
*
INSERT_ID
RELATIONSHIP
LOG
= '000000'
=''
=
TABLES
NODETAB
= IT_NODE
EXCEPTIONS
TREE_FAILURE
=1
ID_NOT_FOUND
=2
WRONG_RELATIONSHIP = 3
OTHERS
= 4.
IF SY-SUBRC <> 0.
WRITE 'Error in Tree Construction'.
ENDIF.
***Display TREE
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = SY-REPID.