37
Interactive Reporting in SAP ABAP Interactive reports and it`s events Events of Interactive reports in SAP ABAP, interactive reporting in SAP ABAP Displaying the basic information on the basic list and the detailed information in the secondary list is called as interactive reports. In SAP, there are 21 lists, out of which first list is called basic list with list number 0 and remaining lists are called as secondary lists with list numbers 1,2,3,4...to...20. 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. Interactive Reports Events 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

10-Interactive Reporting in SAP ABAP

  • Upload
    kiran

  • View
    160

  • Download
    14

Embed Size (px)

DESCRIPTION

10-Interactive Reporting in SAP ABAP

Citation preview

Page 1: 10-Interactive Reporting in SAP ABAP

Interactive Reporting in SAP ABAP

Interactive reports and it`s eventsEvents of Interactive reports in SAP ABAP, interactive reporting in SAP ABAP

Displaying the basic information on the basic list and the detailed information in the secondary list is called as interactive reports.

In SAP, there are 21 lists, out of which first list is called basic list with list number 0 and remaining lists are called as secondary lists with list numbers 1,2,3,4...to...20.

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.

Interactive Reports Events

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

Top Of Page During line selection

This is used to print heading for secondary lists in interactive reports .

Syntax: TOP-OF-PAGE DURING LINE-SELECTION . "Prints secondary list header

Techniques used in interactive reporting

Hide area

It is a key word which is used to store the data into a temporary memory call as HIDE area.

Page 2: 10-Interactive Reporting in SAP ABAP

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.

Syntax: HIDE <WA>. "store total work area in hide area

OR

HIDE <WA-FIELD>. "store work area field in hide area

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

Page 3: 10-Interactive Reporting in SAP ABAP

Developing a Interactive report in SAP ABAPRequirement: Develop an interactive report to display material basic details in basic list, material plant details in secondary list for a material type input and display header and footer for primary and secondary list.

Requirement Analysis: In the above requirement we have to get material details for a material type input(Parameter input for MTART field), when ever user double clicks on any record of basic list, it will go to second screen and display list plants for that material, display page header and footer for the report.

SAP Tables to be used are: MARA(Material Master), MARC(Material Plants).

Step1: Define report heading.

Go to SE38, create a program ZSAPN_INTERACTIVE_REPORT.In order to display footer information we have to provide some space for footer, it can be defined at report definition(First line of the report), to provide space for footer we use below syntax.

REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 34(2) NO STANDARD PAGE HEADING. "leave some pages for footer and hide standard heading

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.

Step2:Data decelerations and Selection screen.

Declare the required internal tables, work areas, variables etc and add selection screen element parameter for material type input.

DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table

WA_MARA TYPE MARA, "mara work area

IT_MARC TYPE TABLE OF MARC, "marc internal table

WA_MARC TYPE MARC. "marc work area

PARAMETERS P_MTART TYPE MARA-MTART. "selection screen element input field

Step3: Add code to get material basic details.

Add logic to get material details for the material type input under START-OF-SELECTION event.

START-OF-SELECTION.

SELECT * FROM MARA

Page 4: 10-Interactive Reporting in SAP ABAP

INTO TABLE IT_MARA

WHERE MTART = P_MTART.

Display materials and use HIDE technique

Display materials and use HIDE technique( HIDE area) to store line data.

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.

Step4: Get plant details using hide area

Get material plants from MARC table based on HIDE area storage under AT LINE-SELECTION event.

AT LINE-SELECTION.

SELECT * FROM MARC

INTO TABLE IT_MARC

WHERE MATNR = WA_MARA-MATNR.

Step5: Display plant data

Display material plant data.

LOOP AT IT_MARC INTO WA_MARC.

WRITE :/ WA_MARC-MATNR, WA_MARC-WERKS.

ENDLOOP.

Step6:Display top of page for basic list and secondary list

Display page heading for basic list under TOP-OF-PAGE event and display secondary list heading under TOP-OF-PAGE DURING LINE-SELECTION event.

TOP-OF-PAGE.

WRITE : 'Material Basic Details' COLOR 5.

TOP-OF-PAGE DURING LINE-SELECTION.

WRITE: 'List of Plants for material:', WA_MARA-MATNR COLOR 6.

Step7: Display footer for basic list

Display footer information for basic material list.

Page 5: 10-Interactive Reporting in SAP ABAP

WRITE: 'Report Generated at:', SY-DATUM COLOR 1.

Final report after modularization is below

REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 33(3) NO STANDARD PAGE HEADING. "leave some pages for footer and hide standard heading

DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table

WA_MARA TYPE MARA, "mara work area

IT_MARC TYPE TABLE OF MARC, "marc internal table

WA_MARC TYPE MARC. "marc work area

PARAMETERS P_MTART TYPE MARA-MTART. "selection screen element input field

INITIALIZATION. "initialization event

AT SELECTION-SCREEN. "at selection screen event to validate inputs

PERFORM VALIDATE_INPUT. "Subroutine to validate input

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.

TOP-OF-PAGE DURING LINE-SELECTION.

PERFORM DISPLAY_LIST_HEADER.

FORM VALIDATE_INPUT .

IF P_MTART IS INITIAL.

MESSAGE 'Please enter input' TYPE 'E'.

Page 6: 10-Interactive Reporting in SAP ABAP

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 .

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

Page 7: 10-Interactive Reporting in SAP ABAP

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.

Page 8: 10-Interactive Reporting in SAP ABAP

Interactive report using HIDE techniqueRequirement:Develop a material master report which displays the basic details on the basic list and description details in the secondary list for a material type input (selection screen parameter).

Requirement Analysis: In the above requirement we have to get material details for a material type input(Parameter input for MTART field), when ever user double clicks on any record of basic list, it will go to second screen and display descriptions for that material, display page header and footer for the report.

SAP Tables to be used are: MARA(Material Master), MAKT(Material descriptions).

Step1: Define report heading.

Go to SE38, create a program ZSAPN_INTERACTIVE_REPORT1.In order to display footer information we have to provide some space for footer, it can be defined at report definition(First line of the report), to provide space for footer we use below syntax.

REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 34(2) NO STANDARD PAGE HEADING. "leave some pages for footer and hide standard heading

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.

Step2:Data decelerations and Selection screen.

Declare the required internal tables, work areas, variables etc and add selection screen element parameter for material type input.

DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table

WA_MARA TYPE MARA, "mara work area

IT_MAKT TYPE TABLE OF MAKT, "MAKT internal table

WA_MAKT TYPE MAKT. "MAKT work area

PARAMETERS P_MTART TYPE MARA-MTART. "selection screen element input field

Step3: Add code to get material basic details.

Add logic to get material details for the material type input under START-OF-SELECTION event.

START-OF-SELECTION.

SELECT * FROM MARA

INTO TABLE IT_MARA

Page 9: 10-Interactive Reporting in SAP ABAP

WHERE MTART = P_MTART.

Display materials and use HIDE technique

Display materials and use HIDE technique( HIDE area) to store line data.

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.

Step4: Get material descriptions using hide area

Get material descriptions from MAKT table based on HIDE area storage under AT LINE-SELECTION event.

AT LINE-SELECTION.

SELECT * FROM MAKT

INTO TABLE IT_MAKT

WHERE MATNR = WA_MARA-MATNR.

Step5: Display material descriptions data

Display material descriptions data in secondary list.

LOOP AT IT_MAKT INTO WA_MAKT.

WRITE :/ WA_MAKT-MATNR, WA_MAKT-MAKTX.

ENDLOOP.

Step6:Display top of page for basic list and secondary list

Display page heading for basic list under TOP-OF-PAGE event and display secondary list heading under TOP-OF-PAGE DURING LINE-SELECTION event.

TOP-OF-PAGE.

WRITE : 'Material Basic Details' COLOR 5.

TOP-OF-PAGE DURING LINE-SELECTION.

WRITE: 'Descriptions of material:', WA_MARA-MATNR COLOR 6.

Step7: Display footer for basic list

Display footer information for basic material list.

WRITE: 'Report Generated at:', SY-DATUM COLOR 1.

Page 10: 10-Interactive Reporting in SAP ABAP

Final report after modularization is below

REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 33(3) NO STANDARD PAGE HEADING. "leave some pages for footer and hide standard heading

DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table

WA_MARA TYPE MARA, "mara work area

IT_MAKT TYPE TABLE OF MAKT, "MAKT internal table

WA_MAKT TYPE MAKT. "MAKT work area

PARAMETERS P_MTART TYPE MARA-MTART. "selection screen element input field

INITIALIZATION. "initialization event

AT SELECTION-SCREEN. "at selection screen event to validate inputs

PERFORM VALIDATE_INPUT. "Subroutine to validate input

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.

TOP-OF-PAGE DURING LINE-SELECTION.

PERFORM DISPLAY_LIST_HEADER.

FORM VALIDATE_INPUT .

IF P_MTART IS INITIAL.

MESSAGE 'Please enter input' TYPE 'E'.

ENDIF.

ENDFORM. " VALIDATE_INPUT

Page 11: 10-Interactive Reporting in SAP ABAP

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

Page 12: 10-Interactive Reporting in SAP ABAP

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.

Page 13: 10-Interactive Reporting in SAP ABAP

Interactive report using GET CURSOR techniqueRequirement:Develop a material master report which displays list of materials for a range of materials (select-options input).

1. If the use double clicks on material number, it should display the details of that material in secondary list.

2. If the use clicks on material type, it should display all the materials of that material type.

Requirement Analysis: To fulfill this requirement, we need to get material details from MARA for selection options input and need to get click position of basic list(wether use clicked on material no or material type) and need to display data based on user click.

GET CURSOR is a key word, which is used to get cursor position with field name and value, by using this key work we can get value and field name at cursor .

SAP Tables to be used: for the above requirement, we are going to use MARA table.

For this requirement, everyting is same as previous program except some changes at line selection evet, at line selection we use key word GET CURSOR.

DATA : FNAM(30), FVAL(50).

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.

Page 14: 10-Interactive Reporting in SAP ABAP

Final code will be

REPORT ZSAPN_INTERACTIVE_GETCURSOR LINE-COUNT 30(3) NO STANDARD PAGE HEADING.

DATA : IT_MARA TYPE TABLE OF MARA,

WA_MARA TYPE MARA,

IT_MAKT TYPE TABLE OF MAKT,

WA_MAKT TYPE MAKT.

DATA : FNAM(30), FVAL(50).

SELECT-OPTIONS : S_MATNR FOR WA_MARA-MATNR.

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.

TOP-OF-PAGE DURING LINE-SELECTION.

PERFORM LINE_TOPOFPAGE.

FORM VALIDATE_INPUT .

IF S_MATNR IS INITIAL.

MESSAGE 'Enter material input' TYPE 'E'.

ENDIF.

ENDFORM. " VALIDATE_INPUT

FORM GET_DATA .

SELECT * FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.

ENDFORM. " GET_DATA

Page 15: 10-Interactive Reporting in SAP ABAP

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

Page 16: 10-Interactive Reporting in SAP ABAP

Interactive Reporting FAQ in SAP ABAPWhat is interactive reporting?

It helps you to create easy-to-read lists. You can display an overview list first that contains general information and provide the user with the possibility of choosing detailed information that you display on further lists.

What are the uses of interactive reporting?

The user can actively control data retrieval and display during the session. Instead of an extensive and detailed list, you create a basic list with condensed information from which the user can switch to detailed displays by positioning the cursor and entering commands. The detailed information appears in secondary lists.

What are the event key words in interactive reporting?

Event Description

AT LINE-SELECTIONMoment 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 Moment at which the user presses a function key

TOP-OF-PAGE DURING LINE-SELECTION

Moment during list processing of a secondary list at which a new page starts

What is a secondary list?

It allows you to enhance the information presented in the basic list. The user can, for example, select a line of the basic list for which he wants to see more detailed information. You display these details on a secondary list. Secondary lists may either overlay the basic list completely or you can display them in an extra window on the screen. The secondary lists can themselves be interactive again.

How to select valid lines for secondary list?

To prevent the user from selecting invalid lines, ABAP/4 offers several possibilities. At the end of the processing block END-OF-SELECTION, delete the contents of one or more fields you previously stored for valid lines using the HIDE statement. At the event AT LINE-SELECTION, check whether the work area is initial or whether the HIDE statement stored field contents there. 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.

Page 17: 10-Interactive Reporting in SAP ABAP

How to create user interfaces for lists?

The R/3 system automatically, generates a graphical user interface (GUI) for your lists that offers the basic functions for list processing, such as saving or printing the list. If you want to include additional functionality, such as pushbuttons, you must define your own interface status. To create a new status, the Development Workbench offers the Menu Painter. With the Menu Painter, you can create menus and application toolbars. And you can assign Function Keys to certain functions. At the beginning of the statement block of AT END-OF-SELECTION, active the status of the basic list using the statement: SET PF-STATUS 'STATUS'.

What is interactive reporting?

A classical non-interactive report consists of one program that creates a single list. Instead of one extensive and detailed list, with interactive reporting you create basic list from which the user can call detailed information by positioning the cursor and entering commands. Interactive reporting thus reduces information retrieval to the data actually required.

Can we call reports and transactions from interactive reporting lists?

Yes. It also allows you to call transactions or other reports from lists. These programs then use values displayed in the list as input values. The user can, for example, call a transaction from within a list of change the database table whose data is displayed in the list.

What are system fields for secondary lists?

SY-LSIND Index of the list created during the current event (basic list = 0)

SY-LIST1 Index of the list level from which the event was triggered

SY-LILLI Absolute number of the line from which the event was triggered

SY-LISEL Contents of the line from which the event was triggered

SY-CUROW

Position of the line in the window from which the event was triggered (counting starts with 1)

SY-CUCOL

Position of the column in the window from which the event was triggered (counting starts with 2)

SY-CPAGE

Page number of the first displayed page of the list from which the event was triggered

SY-STARO

Number of the first line of the first page displayed of the list from which the event was triggered (counting starts with 1). Possibly, a page header occupies this line

SY-STACO

Number of the first column displayed in the list from which the event was triggered (counting starts with 1)

SY-UCOMM

Function code that triggered the event

Page 18: 10-Interactive Reporting in SAP ABAP

SY-PFKEY

Status of the displayed list

How to maintain lists?

To return from a high list level to the next-lower level (SY-LSIND), the user chooses Back on a secondary list. The system then releases the currently displayed list and activates the list created one step earlier. The system deletes the contents of the released list. To explicitly specify the list level, into which you want to place output, set the SY-lsind field. The system accepts only index values, which correspond to existing list levels. It then deletes all existing list levels whose index is greater or equal to the index specify. For example, if you set SY-LSIND to 0, the system deletes all secondary lists and overwrites the basic list with the current secondary list.

What are the page headers for secondary lists?

On secondary lists, the system does not display a standard page header and it does not trigger the event TOP-OF-PAGE. To create page headers for secondary list, you must enhance TOP-OF-PAGE: Syntax TOP-OF-PAGE DURING LINE-SELECTION. The system triggers this event for each secondary list. If you want to create different page headers for different list levels, you must program the processing block of this event accordingly, for example by using system fields such as SY-LSIND or SY-PFKEY in control statements (IF, CASE).

How to use messages in lists?

ABAP/4 allows you to react to incorrect or doubtful user input by displaying messages that influence the program flow depending on how serious the error was. Handling messages is mainly a topic of dialog programming. You store and maintain messages in table T100. Messages are sorted by language, by a two-character ID, and by a three-digit number. You can assign different message types to each message you output. The influence of a message on the program flow depends on the message type. In our program, use the MESSAGE statement to output messages statically or dynamically and to determine the message type.Syntax: REPORT MESSAGE-ID <msgid>.

What are the user interfaces of interactive lists?

If you want the user to communicate with the system during list display, the list must be interactive. You can define specific interactive possibilities in the status of the list's user interface (GUI). To define the statuses of interfaces in the R/3 system, use the Menu Painter tool. In the Menu Painter, assign function codes to certain interactive functions. After an user action occurs on the completed interface, the ABAP/4 processor checks the function code and, if valid, triggers the corresponding event.

What are the drill-down features provided by ABAP/4 in interactive lists?

ABAP/4 provides some interactive events on lists such as AT LINE-SELECTION (double click) or AT USER-COMMAND (pressing a button). You can use these events to move through layers of information about individual items in a list.

Page 19: 10-Interactive Reporting in SAP ABAP

What is meant by stacked list?

A stacked list is nothing but secondary list and is displayed on a full-size screen unless you have specified its coordinates using the window command.

Is the basic list deleted when the new list is created?

No. It is not deleted and you can return back to it using one of the standard navigation functions like clicking on the back button or the cancel button.

What is meant by hotspots?

A Hotspot is a list area where the mouse pointer appears as an upright hand symbol. When a user points to that area (and the hand cursor is active), a single click does the same thing as a double-click. Hotspots are supported from R/3 release 3.0c.

What is the length of function code at user-command?

Each menu function, push button, or function key has an associated function code of length FOUR (for example, FREE), which is available in the system field SYUCOMM after the user action.

Can we create a gui status in a program from the object browser?

Yes. You can create a GUI STATUS in a program using SET PF-STATUS.

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.

What is meant by hide area?

The hide command temporarily stores the contents of the field at the current line in a system-controlled memory called the HIDE AREA. At an interactive event, the contents of the field are restored from the HIDE AREA.

When the get cursor command used in interactive lists?

If the hidden information is not sufficient to uniquely identify the selected line, the command GET CURSOR is used. The GET CURSOR command returns the name of the field at the cursor position in a field specified after the addition field, and the value of the selected field in a field specified after value.

Page 20: 10-Interactive Reporting in SAP ABAP

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.

How the at-user command serves mainly in lists?

The AT USER-COMMAND event serves mainly to handle own function codes. In this case, you should create an individual interface with the Menu Painter and define such function codes.

How to pass data from list to report?

ABAP/4 provides three ways of passing data:---Passing data automatically using system fields---Using statements in the program to fetch data---Passing list attributes

How can you manipulate the presentation and attributes of interactive lists?

---Scrolling through Interactive Lists.---Setting the Cursor from within the Program.---Modifying List Lines.

How to call other programs?

Report TransactionCall and return: SUBMIT <progname> AND RETURN, CALL TRANSACTIONCall without return: SUBMIT, LEAVE TO TRANSACTIONYou can use these statements in any ABAP/4 program.

What will exactly the hide statement do?

For displaying the details on secondary lists requires that you have previously stored the contents of the selected line from within the program. To do this, ABAP/4 provides the HIDE

Page 21: 10-Interactive Reporting in SAP ABAP

statement. This statement stores the current field contents for the current list line. When calling a secondary list from a list line for which the HIDE fields are stored, the system fills the stored values back into the variables in the program. In the program code, insert the HIDE statement directly after the WRITE statement for the current line. Interactive lists provide the user with the so-called 'INTERACTIVE REPORTING' facility. For background processing the only possible method of picking the relevant data is through 'NON INTERACTIVE REPORT' . After starting a background job, there is no way of influencing the program. But whereas for dialog sessions there are no such restrictions.

How many lists can a program can produce?

Each program can produce up to 21 lists: one basic list and 20 secondary lists. If the user creates a list on the next level (that is, SY-LSIND increases), the system stores the previous list and displays the new one. Only one list is active, and that is always the most recently created list.

Page 22: 10-Interactive Reporting in SAP ABAP

Using Conversion routine in ABAP programsWhat is a conversion routine in SAP ABAP ?, Using conversion exit in SAP ABAP, conversion exit in SAP ABAP

What is a conversion exit ?

Conversion exit is a function module, which is used to convert a value from external format to SAP internal format and from internal format to external format.

If a screen field refers to a domain with a conversion routine, or is directly assigned a conversion routine in its attributes, the system automatically executes the function module ..._INPUT for every input in the relevant screen field and the function module ..._OUTPUT when values are displayed in this screen field and uses the converted content in each case.

Conversion routines are identified by a five-place name and are stored as a group of two function modules. The function modules have a fixed naming convention. The following function modules are assigned to conversion routine xxxxx:

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.

How to find conversion exit ?

Go to a table, field for which you wants to find conversion exit.

Double click on data element and double click on domain.

You can see conversion exit at domain level ex: MATN1 for MARA-MATNR field.

Double click on conversion exit, you will find two function modules.

CONVERSION_EXIT_MATN1_INPUT CONVERSION_EXIT_MATN1_OUTPUT

CONVERSION_EXIT_MATN1_INPUT is used to convert external value to internal value.

CONVERSION_EXIT_MATN1_OUTPUT is used to convert internal value to external value.

Scenario and example of using conversion exit in ABAP programs

Requirement: Develop an interactive report to display material basic details in basic list, material plant details in secondary list for a material type input and display header and footer for primary and secondary list.

Page 23: 10-Interactive Reporting in SAP ABAP

In the below example, when we are getting data from MARC table at line selection we are converting material external format to internal format.

REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 33(3) NO STANDARD PAGE HEADING. "leave some pages for footer and hide standard heading

DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table

WA_MARA TYPE MARA, "mara work area

IT_MARC TYPE TABLE OF MARC, "marc internal table

WA_MARC TYPE MARC. "marc work area

PARAMETERS P_MTART TYPE MARA-MTART. "selection screen element input field

INITIALIZATION. "initialization event

AT SELECTION-SCREEN. "at selection screen event to validate inputs

PERFORM VALIDATE_INPUT. "Subroutine to validate input

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.

TOP-OF-PAGE DURING LINE-SELECTION.

PERFORM DISPLAY_LIST_HEADER.

FORM VALIDATE_INPUT .

IF P_MTART IS INITIAL.

MESSAGE 'Please enter input' TYPE 'E'.

ENDIF.

Page 24: 10-Interactive Reporting in SAP ABAP

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 .

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

EXPORTING

input = WA_MARA-MATNR

IMPORTING

output = WA_MARA-MATNR .

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.

Page 25: 10-Interactive Reporting in SAP ABAP

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

Page 26: 10-Interactive Reporting in SAP ABAP

TREE list report using SAP ABAPHow to develop A TREE LIST interactive report Using SAP ABAP with Function modules RS_TREE_CONSTRUCT and RS_TREE_LIST_DISPLAY

As we already know SAP supports multiple types of drill down reports like ABAP Interactive reports, ALV Interactive etc, in this lesson we are going to develop a drill down report with TREE structure.

Requirement: Display list of materials for a give input(Material number ranges) with descriptions in different languages in the form of a tree.To create a TREE LIST, we use RS_TREE_CONSTRUCT and RS_TREE_LIST_DISPLAY Function Modules

RS_TREE_CONSTRUCT is used to construct a TREE node.

RS_TREE_LIST_DISPLAY is used to display/print constructed TREE.

Final output of the TREE like looks like below.

Steps to follow to create TREE LIST

1. Data Declarations for required tables2. Get Data From Required Tables

3. Construct TREE node

4. Display TREE

Page 27: 10-Interactive Reporting in SAP ABAP

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.

Get Data from required tables MARA and MAKT

Get data from tables MARA and MAKT under START-OF-SELECTION event using FOR ALL ENTRIES.

**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.

Construct TREE node suing RS_TREE_CONSTRUCT

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.

Page 28: 10-Interactive Reporting in SAP ABAP

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.

**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.

Create Root level

"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 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.

Page 29: 10-Interactive Reporting in SAP ABAP

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.

Call Function module RS_TREE_CONSTRUCT

Page 30: 10-Interactive Reporting in SAP ABAP

**Construct Tree

CALL FUNCTION 'RS_TREE_CONSTRUCT'

* EXPORTING

* INSERT_ID = '000000'

* RELATIONSHIP = ' '

* LOG =

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.

Testing the above report

Go to SE11 -> MAKT 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)

Execute, expand TREE and observe

Final and Full program source code

*&---------------------------------------------------------------------*

*& Report ZSAPN_TREE_MATERIAL

*&

Page 31: 10-Interactive Reporting in SAP ABAP

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

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.

Page 32: 10-Interactive Reporting in SAP ABAP

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.

Page 33: 10-Interactive Reporting in SAP ABAP

"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 = '000000'

* RELATIONSHIP = ' '

* LOG =

TABLES

NODETAB = IT_NODE

EXCEPTIONS

TREE_FAILURE = 1

ID_NOT_FOUND = 2

WRONG_RELATIONSHIP = 3

OTHERS = 4.

Page 34: 10-Interactive Reporting in SAP ABAP

IF SY-SUBRC <> 0.

WRITE 'Error in Tree Construction'.

ENDIF.

***Display TREE

CALL FUNCTION 'RS_TREE_LIST_DISPLAY'

EXPORTING

CALLBACK_PROGRAM = SY-REPID.

Note: By using RS_TREE_LIST_DISPLAY and RS_TREE_CONSTRUCT function modules, we can display maximum of 10 columns in each level.