You are on page 1of 43

Classical Reports

 Classical Reports are reports which contains both selection-screen and output screen.
 SAP ABAP is an event driven programing language, ABAP programs executed based on
events not line-by-line.

Events in Classical Reports

Below are the list and sequence of events available under classical reports, each event has it`s own
importance.

Load-of-program (Not in Use)


This event is used to load program into memory for execution and this is the first event in execution
sequence.

Initialization
This event is used to initialize variables, screen default values and other default actions.

At Selection-Screen
This event is used to validate multiple input fields

Syntax: AT SELECTION-SCREEN . "used to validate multiple input fields

At Selection-Screen on field
This event is used to validate a single selection-screen input parameter.

Syntax: AT SELECTION-SCREEN ON . "Validate a input parameter

At Selection-Screen on value request


This event is used to provide value help ( field help ) for a input field.

Syntax: AT SELECTION-SCREEN ON VALUE REQUEST FOR . "Input search help for a input
parameters

At Selection-Screen on help request


By using this event we can provide F1 help for a input field.

Syntax: AT SELECTION-SCREEN ON HELP REQUEST FOR . "Input (F1) help for a input
parameters

At Selection-Screen output
By using this event we can manipulate dynamic selection-screen changes.
Start-of-Selection
This is default event which is used to write actual business logic.

Syntax: START-OF-SELECTION. "Default event

End-of-Selection
We can use this event just to state that start-of-selection is ended, this event is used with logical
databases, logical databases are in HR ABAP only. In normal ABAP we don`t have much
importance.

Syntax: END-OF-SELECTION. "Start of selection is ended

Top-of-Page
This event prints constant heading for all pages.

Syntax: TOP-OF-PAGE. "Page heading

End-of-Page
This event prints constant footer for all pages.
Before using this event, we need to reserve some lines for displaying footer .

Syntax: END-OF-PAGE. "Page footer


Example: REPORT ZPROGRAM LINE-COUNT 27(3). " Here we reserve 3 lines for footer

Set default values on selection-screen using INITIALIZATION event in SAP


ABAP programming
+ -

Most of the times in real-time business requirements we need to set default values on selection-
screen elements like input fields, check boxes, select-options, radio buttons etc. We use initialization
event to set default values on selection screen.

REPORT ZSAPN_INITIALIZATION.
TABLES : MARA. "tables decleration for select-options
PARAMETERS : P_INPUT TYPE CHAR20. "Input fied with 20 character length.

SELECT-OPTIONS: S_SO FOR MARA-MATNR. "select-options

PARAMETERS P_CHK AS CHECKBOX. "check box


PARAMETERS P_RAD1 RADIOBUTTON GROUP RB1.
PARAMETERS P_RAD2 RADIOBUTTON GROUP RB1.

By using the above code we can display the below screen.

But we need to set default values to the input field, select-options(High, low), check box(default
select), select radio button default.

Set Default values for parameters using INITIALIZATION


The below example explains you how to set default values using INITIALIZATION event to set
default values on selection screen.

INITIALIZATION. "this event will trigger first


P_INPUT = 'SAPNuts'.

Set default vales for Select-Options using initialization event


Technically select-options are nothing but internal tables with four fields, the four fields are
SIGN(Stores I - Inclusive of Defined Values/Range and E - Exclusive of Defined Values/Range,
OPTION(Stores EQ - Equal, NE- Not Equal, LT - Lower Than, LE - Lower Equal, GT - Greater Than,
GE - Greater Equal, BT - Between, CP - Covers Pattern and NP - Does Not Cover
Pattern,LOW(Stores low value), HIGH(Stores high value), the below code is used to set default
values for select-options.

INITIALIZATION.
S_SO-LOW = '1'.
S_SO-OPTION = 'BT'.
S_SO-SIGN = 'I'.
S_SO-HIGH = '100'.
APPEND S_SO. " append select-options to screen

Set Default values for check box and radio buttons group
Check box and radio buttons store either X or space, X means selected, space means not selected,
use the below code to default check box and radio buttons.

INITIALIZATION.
P_CHK = 'X'.
P_RAD2 = 'X'.

The final code will be

REPORT ZSAPN_INITIALIZATION.
TABLES : MARA. "tables decleration for select-options
PARAMETERS : P_INPUT TYPE CHAR20. "Input fied with 20 character length.

SELECT-OPTIONS: S_SO FOR MARA-MATNR. "select-options

PARAMETERS P_CHK AS CHECKBOX. "check box

PARAMETERS P_RAD1 RADIOBUTTON GROUP RB1.


PARAMETERS P_RAD2 RADIOBUTTON GROUP RB1.

INITIALIZATION.

P_INPUT = 'SAP'.
S_SO-LOW = '1'.
S_SO-OPTION = 'BT'.
S_SO-SIGN = 'I'.
S_SO-HIGH = '100'.
APPEND S_SO.
P_CHK = 'X'.
Difference between at selection screen on field and at selection screen events in
SAP ABAP programming.
+ -

At selection screen on field and at selection screen are selection-screen events which are used for
input validations in SAP report programming.

At Selection Scteen on Field At Selection Screen

This event is used to validate single input field. This event is used to validate multiple input fields.
At Selection Scteen on Field At Selection Screen

By using this event, if any error the error field will be By using this event, the error field is heiglited and
heighleted and the remaining fields will be disabled. all the remaining fields will be enabled.

Example to explain At Selection-Screen on field and At Selection-Screen difference .


In below example we are going to validate two input fields and we will see the difference in screen
behavior .

At Selection Screen At Selection Screen on Field

REPORT REPORT ZSPN_SELECTION_SCREEN_EVENT.


ZSPN_SELECTION_SCREEN_EVENT.
PARAMETERS P_FIELD1 TYPE CHAR10 .
PARAMETERS P_FIELD1 TYPE
CHAR10 . PARAMETERS P_FIELD2 TYPE CHAR10.

PARAMETERS P_FIELD2 TYPE


CHAR10. AT SELECTION-SCREEN ON P_FIELD1.
IF P_FIELD1 IS INITIAL.
AT SELECTION-SCREEN. MESSAGE 'Please enter field1' TYPE 'E'.
IF P_FIELD1 IS INITIAL. ENDIF.
MESSAGE 'Please enter AT SELECTION-SCREEN ON P_FIELD2 .
field1' TYPE 'E'.
IF P_FIELD2 IS INITIAL.
ENDIF.
MESSAGE 'Please enter field2' TYPE 'E'.
IF P_FIELD2 IS INITIAL.
ENDIF.
MESSAGE 'Please enter
field2' TYPE 'E'.
ENDIF.
At Selection Screen At Selection Screen on Field

After error message both input


fields are enabled for input.

After error message all input fields are disabled, only


error field will be enables and heightened .

Using Selection Screen output for dynamic modifications on selection screen in


SAP ABAP

At Selection Screen output is a selection-screen event, which is used to manipulate dynamic


changes on selection-screen.
Loop At Screen. Screen is structure with Name, Group1, Group2, Group3, Group4, invisible, active,
intensified etc fields, this holds the screen information at run time, Loop at Screen...Endloop. is
used to loop through screen elements, and based on the values in above structure (SCREEN) we
can manipulate changes.
MODIF ID : MODIF ID is a three character id (without quotes), we can process a screen elements
group using this MODIF ID, this will be stored in SCREEN-GROUP1.
All Screen modifications should be done under AT SELECTION-SCREEN OUTPUT event only.
MODIFY SCREEN is keyword which is used to apply screen modification.

The below is the sample code for dynamic screen modification .

When ever we check enable input field check box, one input field will be enabled.
REPORT ZSELECTION_SCREEN_OUTPUT.
PARAMETERS P_ENABLE AS CHECKBOX USER-COMMAND UC1.
PARAMETERS: INPUT(5) TYPE C MODIF ID IN1 . "Based on modif id we will perform dynamic
operations
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF P_ENABLE = 'X' . " If check box is selected
IF SCREEN-GROUP1 = 'IN1' .
SCREEN-ACTIVE = 1.
MODIFY SCREEN.
ENDIF.
ELSE.
IF SCREEN-GROUP1 = 'IN1' .
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.

Requirement:
Develop a Classical Report to display list of materials for a material input range(select-Options) and
for a material type (screen input) with validations, search help and value help, the report can be able
to download into excel sheet.
Input elements : Select-options for matnr ( material no for MARA table), parameter mtart( Material
type from MARA), a check box and a parameter limit for limiting no of results.
Whenever we click on download data, select file to download field will be enabled otherwise this
should be disabled.
Input Screen.

REPORT  ZCLASSICAL_REPORT NO STANDARD PAGE HEADING LINE-COUNT 20(3).
TABLES : MARA.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        ERSDA TYPE MARA-ERSDA,
        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. "material out put internal table
DATA : WA_MARA TYPE TY_MARA. " work area

DATA : LV_MTART TYPE MARA-MTART.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. "designs a bloc
k just for design double click on TEXT-001 to add text

SELECT-OPTIONS : S_MATNR FOR MARA-MATNR. " Material range input
PARAMETERS : P_MTART TYPE MARA-MTART. "material type input

SELECTION-SCREEN END OF BLOCK B1.

PARAMETERS  P_DLOAD AS CHECKBOX USER-COMMAND UC1.
PARAMETERS  P_FILE TYPE RLGRAP-FILENAME MODIF ID DLD .
PARAMETERS P_LIMIT TYPE I  . "Limit no of rows to display to avoid burden on 
database
*
INITIALIZATION. "triggers First
  P_MTART = 'FERT'. "MATERIAL TYPE DEFAULT VALUE
  P_LIMIT = '50'. "Limit rows to 50
*
AT SELECTION-SCREEN OUTPUT . "for dynamic modifications
  IF P_DLOAD IS INITIAL .
    LOOP AT SCREEN.
      CHECK SCREEN-GROUP1 = 'DLD'.
      SCREEN-INPUT = '0'.
      MODIFY SCREEN.
    ENDLOOP.
 ELSE.
  MESSAGE 'please select the file name to download' TYPE 'I'.
  ENDIF.

AT SELECTION-SCREEN ON P_MTART . " Validate single input field at selection-
screen
PERFORM MTART_VALIDATE.
*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE .
  PERFORM FILE_VALUE_HELP .
*
AT SELECTION-SCREEN ON HELP-REQUEST FOR P_MTART . " provide help request F1 h
elp .
  PERFORM MTART_HELP.
*
*
AT SELECTION-SCREEN.
  PERFORM VALIDATE_INPUTS.
*
START-OF-SELECTION.
  PERFORM GET_MATERIALS .
*
END-OF-SELECTION.

  PERFORM DISPLAY_OUTPUT.
  IF P_DLOAD = 'X'.
    PERFORM DOWNLOAD_DATA.
  ENDIF.
*
*
TOP-OF-PAGE.
  WRITE : 'Material Details ' COLOR 7.

END-OF-PAGE.
  WRITE : 'The above materials are active materials available in database' COL
OR 3.
*
FORM VALIDATE_INPUTS .
  IF S_MATNR IS INITIAL OR P_MTART IS INITIAL.

    MESSAGE 'Please enter required inputs' TYPE 'E'.
*
  ELSE.
*
***Validate material type is valid or not
    SELECT MTART FROM MARA INTO LV_MTART
       UP TO 1 ROWS WHERE MTART = P_MTART .
    ENDSELECT.
    IF LV_MTART IS INITIAL.
      MESSAGE 'Material type is not available in MARA' TYPE 'E'.
    ENDIF.
  ENDIF.
ENDFORM.                    " VALIDATE_INPUTS
*
FORM GET_MATERIALS .
  SELECT MATNR ERSDA MTART MBRSH MATKL MEINS FROM MARA
     INTO TABLE IT_MARA
    UP TO P_LIMIT ROWS
    WHERE MATNR IN S_MATNR AND MTART = P_MTART .

ENDFORM.                    " GET_MATERIALS

FORM DISPLAY_OUTPUT .
  IF IT_MARA IS NOT INITIAL.
    LOOP AT IT_MARA INTO WA_MARA.

      WRITE :/ WA_MARA-MATNR, WA_MARA-ERSDA, WA_MARA-MTART, WA_MARA-MBRSH, WA_
MARA-MATKL, WA_MARA-MEINS .

    ENDLOOP.
  ELSE.
    WRITE : 'No Data Found for your Query'.
  ENDIF.
ENDFORM.                    " DISPLAY_OUTPUT
*
FORM MTART_HELP .
  MESSAGE 'This is a Material Type from MARA Table' TYPE 'I'.
ENDFORM.                    " MTART_HELP
*
FORM MTART_VALIDATE.
  IF P_MTART IS INITIAL.
  MESSAGE 'Enter a Material type as input example: FERT' TYPE 'I'.
  ENDIF.
ENDFORM.                    " MTART_VSLUE_HELP
FORM DOWNLOAD_DATA .
  DATA : LV_FILE TYPE STRING .
  LV_FILE = P_FILE .
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
*   BIN_FILESIZE                    =
      FILENAME                        = LV_FILE
     FILETYPE                        = 'ASC'
*   APPEND                          = ' '
     WRITE_FIELD_SEPARATOR           = 'X'
*   HEADER                          = '00'
*   TRUNC_TRAILING_BLANKS           = ' '
*   WRITE_LF                        = 'X'
*   COL_SELECT                      = ' '
*   COL_SELECT_MASK                 = ' '
*   DAT_MODE                        = ' '
*   CONFIRM_OVERWRITE               = ' '
*   NO_AUTH_CHECK                   = ' '
*   CODEPAGE                        = ' '
*   IGNORE_CERR                     = ABAP_TRUE
*   REPLACEMENT                     = '#'
*   WRITE_BOM                       = ' '
*   TRUNC_TRAILING_BLANKS_EOL       = 'X'
*   WK1_N_FORMAT                    = ' '
*   WK1_N_SIZE                      = ' '
*   WK1_T_FORMAT                    = ' '
*   WK1_T_SIZE                      = ' '
*   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*   SHOW_TRANSFER_STATUS            = ABAP_TRUE
* IMPORTING
*   FILELENGTH                      =
    TABLES
      DATA_TAB                        = IT_MARA
*   FIELDNAMES                      =
* EXCEPTIONS
*   FILE_WRITE_ERROR                = 1
*   NO_BATCH                        = 2
*   GUI_REFUSE_FILETRANSFER         = 3
*   INVALID_TYPE                    = 4
*   NO_AUTHORITY                    = 5
*   UNKNOWN_ERROR                   = 6
*   HEADER_NOT_ALLOWED              = 7
*   SEPARATOR_NOT_ALLOWED           = 8
*   FILESIZE_NOT_ALLOWED            = 9
*   HEADER_TOO_LONG                 = 10
*   DP_ERROR_CREATE                 = 11
*   DP_ERROR_SEND                   = 12
*   DP_ERROR_WRITE                  = 13
*   UNKNOWN_DP_ERROR                = 14
*   ACCESS_DENIED                   = 15
*   DP_OUT_OF_MEMORY                = 16
*   DISK_FULL                       = 17
*   DP_TIMEOUT                      = 18
*   FILE_NOT_FOUND                  = 19
*   DATAPROVIDER_EXCEPTION          = 20
*   CONTROL_FLUSH_ERROR             = 21
*   OTHERS                          = 22
            .
  IF SY-SUBRC = 0.
    WRITE :/ 'Data downloaded to'.
    WRITE : P_FILE.
  ENDIF.

ENDFORM.                    " DOWNLOAD_DATA
*
FORM FILE_VALUE_HELP .

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      FIELD_NAME = 'P_FILE'
    IMPORTING
      FILE_NAME  = P_FILE.
ENDFORM.                    " FILE_VALUE_HELP

SELECT WITH JOINS statement is used to read data simultaneously from multiple database tables .
As per performance standards, SELECT WITH JOINS for more than 3 tables is not advisable, as it
puts heavy load on database

Syntax :

SELECT T1~FIELD1
  T1~FIELD2
  T2~FIELD1
T2~FIELD2
  INTO TABLE ITAB
 FROM T1 INNER JOIN T2 ON T1~FIELD1 = T2~FIELD 
 WHERE T1~FIELD1 = P_FIELD1 .
** Here T1 and T2 are database tables, FIELD1 and FIELD2 are fields in respective
tables

Example of using SELECT JOINS in SAP ABAP

**DATA DECLERATIONS
TYPES: BEGIN OF T_MARA,
MATNR TYPE MARA-MATNR, "FIELD1 FROM MARA TABLE
MTART TYPE MARA-MTART, "FIELD2 FROM MARA TABLE
MAKTX TYPE MAKT-MAKTX, "FIELD1 FROM MAKT TABLE
SPRAS TYPE MAKT-SPRAS, "FIELD2 FROM MAKT TABLE
END OF T_MARA.

DATA: IT_MARA TYPE TABLE OF T_MARA .


DATA : WA_MARA TYPE T_MARA.
SELECT MARA~MATNR
MARA~MTART
MAKT~MAKTX
MAKT~SPRAS
INTO TABLE IT_MARA
FROM MARA INNER JOIN MAKT ON MARA~MATNR = MAKT~MATNR
UP TO 50 ROWS. “ WHERE MARA~MATNR IN S_MATNR.

LOOP AT IT_MARA INTO WA_MARA.


WRITE : / WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MAKTX, WA_MARA-SPRAS .
ENDLOOP.

SELECT FOR ALL ENTRIES is the best alternative for SELECT WITH JOINS, this statement is very
helpful for reading data from more than 2 tables.
The load on database will be very less.
Syntax :
SELECT <FIELDS> FROM <DBTABLE1> INTO TABLE <ITAB1>
WHERE <CONDITION>.
SELECT <FIELDS> FROM <DBTABLE2> INTO <ITAB2> FOR ALL ENTRIES IN <ITAB1>
WHERE <FIELD1> = <ITAB1>-FIELD1.
**HERE WE ARE READING DATA 2 DATABASE TABLES, SEE WHERE CONDITIONS OF SECOND SELECT
STATEMENT

Ensure before using SELECT FOR ALL ENTRIES

 Parent internal table must not be empty ( If it is empty, where condition fails and it will get all
records from database).
 Remove all duplicate entries in parent internal table.

Here is the example of using SELECT FOR ALL ENTRIES in real-time applications

**DATA DECLARATIONS
DATA : IT_MARA TYPE TABLE OF MARA.
DATA : IT_MAKT TYPE TABLE OF MAKT .
**GET DATA FROM MARA TABLE
SELECT * FROM MARA INTO TABLE IT_MARA
 WHERE MATNR = '0001'.
**SORT MARA TABLE, TO DELETE ADJACENT DUPLICATES THE TABLE MUST BE SORTED IN ASCENDIN
G ORDER
SORT IT_MARA ASCENDING .
**DELETE ADJACENT DUPLICATES FROM IT_MARA COMPARING ALL FIELDS
DELETE ADJACENT DUPLICATES FROM IT_MARA COMPARING ALL FIELDS.

**TO USE SELECT FOR ALL ENTRIES, THE PARENT INTERNAL TABLE MUST NOT BE EMPTY SO CHECK 
IT
IF IT_MARA IS NOT INITIAL. "CHECK PARENT INTERNAL TABLE 
**SECOND SELECT STATEMENT TO GET DATA FROM MAKT (MATERIAL DESCRIPTIONS), HERE WE ARE 
GETTING DATA
**FROM MAKT FOR ALL THE RECORDS IN IT_MARA, SEE WHERE CONDITION SHOULD BE PARENT INTE
RNAL TABLE 
SELECT * FROM MAKT INTO TABLE IT_MAKT
 FOR ALL ENTRIES IN IT_MARA
 WHERE MATNR = IT_MARA-MATNR.
ENDIF.
LOOP AT it_makt INTO wa_makt.
WRITE:/ wa_makt-matnr,wa_makt-spras,wa_makt-maktx,wa_makt-maktg.
ENDLOOP.
SYSTEM VARIABLES

SYST is a predefined Database structure for ABAP System fields

Systems fields can be called even as System Variables

SAP provided 171 system variables

SY-SUBRC is a system variable for Error Handling

IF SY-SUBRC = 0. Then NO ERROR

IF SY_SUBRC <> 0. Then there is an Error

SY-ULINE is a system variable which can draws Underline

SY-VLINE is a system variable which can draw Vertical line

SY-DATUM is a system variable for DATE

SY-UZEIT is a system variable for TIME

SY_PAGNO is a system variable for PAGE NUMBER

Interactive Reports
 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 System 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 . "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.

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 . "store total work area in hide area


OR
HIDE . "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 ,


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

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

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

Final report after modularization is below

REPORT  ZINTERACTIVE_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.
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_HEADE
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.

Hide and Get cursor

Both the statements are used in interactive reports only but the difference is in hide statement based
on which field you want to go to next list that field name you have to mention in the hide statement.
Where as in get cursor you can give the field name dynamically.

Interactive report using GET CURSOR technique

Requirement: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.
Final code will be

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

DATA : IT_MARA TYPE TABLE OF MARA,
       WA_MARA TYPE MARA.

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
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.
  CLEAR WA_MARA.
  CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
    EXPORTING
      INPUT         = FVAL
   IMPORTING
     OUTPUT        = 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_MAR
A-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

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.

How 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 tables


2. Get Data From Required Tables
3. Construct TREE node
4. Display TREE

Go to SE38, create a report with name ZTREE_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.

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

**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 ZTREE_MATERIAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTREE_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 R
OWS 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                = '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
  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.
Menu painter is used to create custom GUI with custom buttons, custom toolbar and custom menu for a
specific ABAP program.
The t-code for menu painter is SE41, we can create menu using SET PF-STATUS keyword from ABAP
program .

Syntax: SET PF-STATUS '.

Create a custom GUI for a SAP ABAP program


Create an ABAP program ZSAP_MENU in SE38.
Add the below code and double click on menu name to create menu.

SET PF-STATUS 'ZSAP_MENU'. " Double click on ZSAPN_MENU to create

Click on Yes and provide short description, enter.

Using Menu Painter


Requirement: Develop a report to display material details for a material type, create a custom GUI to
provide user to download the data into an excel sheet, provide back button only. Go to se38, create a
program to display material details for a material type.

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

PARAMETERS : P_MTART TYPE MARA-MTART.

START-OF-SELECTION.

SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA


INTO TABLE IT_MARA
WHERE MTART = P_MTART.

LOOP AT IT_MARA INTO WA_MARA.


WRITE : WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MBRSH, WA_MARA-MATKL, WA_MARA-
MEINS.
ENDLOOP.

Add below code after START-OF-SELECTION to create custom GUI,save and double click on the menu
name to create custom GUI.

SET PF-STATUS 'ZSAPN_MENU'. "Double click on ZSAPN_MENU to create menu

Click Yes

Provide short text and enter.

You can create menus, toolbar buttons, function keys by using menu painter.
In this lesson we learn to create menu item ( download).

Expand Menu Bar, provide name as Download, double click on Download, provide code as DLOD and text
as Download, save and activate.

Go back to the program and add below code to download (when ever user click on download).

AT USER-COMMAND
This is a event which is used to implement user actions, it will trigger whenever a function button is pressed or
a function code is pressed.

SY-UCOMM
SY-UCOMM is a system variable which stores the function code of the current action.

GUI_DOWNLOAD
GUI_DOWNLOAD is the function module which is used to download data from an internal table to local
computer.

In order to implement the download functionality, we have to use AT USER-COMMAND event and SY-
UCOMM system variable, here function code is DLOD, which we have provided in menu painter.
AT USER-COMMAND .
IF SY-UCOMM = 'DLOD'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
FILENAME = 'C:\MARA.XLS'
FILETYPE = 'ASC'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* VIRUS_SCAN_PROFILE = '/SCET/GUI_DOWNLOAD'
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = IT_MARA
* FIELDNAMES =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22 .
IF SY-SUBRC = 0.
MESSAGE 'Data downloaded successfully' TYPE 'S'.
ENDIF.
ENDIF.

The final program code will be

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

PARAMETERS : P_MTART TYPE MARA-MTART.

START-OF-SELECTION.

  SET PF-STATUS 'ZSAP_MENU'. "double click on ZSAPN_MENU to create menu

  SELECT MATNR MTART MBRSH MATKL MEINS FROM MARA
    INTO TABLE IT_MARA UP TO 50 ROWS
    WHERE MTART = P_MTART .

  LOOP AT IT_MARA INTO WA_MARA.
    WRITE :/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MBRSH, WA_MARA-MATKL, WA_MA
RA-MEINS.
  ENDLOOP.

AT USER-COMMAND .
  IF SY-UCOMM = 'DLOD'.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*       BIN_FILESIZE                    =
        FILENAME = 'C:\Users\ARSUSER\Desktop\MARA.txt'
        FILETYPE = 'ASC'
*       APPEND   = ' '
*       WRITE_FIELD_SEPARATOR           = ' '
*       HEADER   = '00'
*       TRUNC_TRAILING_BLANKS           = ' '
*       WRITE_LF = 'X'
*       COL_SELECT                      = ' '
*       COL_SELECT_MASK                 = ' '
*       DAT_MODE = ' '
*       CONFIRM_OVERWRITE               = ' '
*       NO_AUTH_CHECK                   = ' '
*       CODEPAGE = ' '
*       IGNORE_CERR                     = ABAP_TRUE
*       REPLACEMENT                     = '#'
*       WRITE_BOM                       = ' '
*       TRUNC_TRAILING_BLANKS_EOL       = 'X'
*       WK1_N_FORMAT                    = ' '
*       WK1_N_SIZE                      = ' '
*       WK1_T_FORMAT                    = ' '
*       WK1_T_SIZE                      = ' '
*       WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*       SHOW_TRANSFER_STATUS            = ABAP_TRUE
*       VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'
*     IMPORTING
*       FILELENGTH                      =
      TABLES
        DATA_TAB = IT_MARA
*       FIELDNAMES                      =
*     EXCEPTIONS
*       FILE_WRITE_ERROR                = 1
*       NO_BATCH = 2
*       GUI_REFUSE_FILETRANSFER         = 3
*       INVALID_TYPE                    = 4
*       NO_AUTHORITY                    = 5
*       UNKNOWN_ERROR                   = 6
*       HEADER_NOT_ALLOWED              = 7
*       SEPARATOR_NOT_ALLOWED           = 8
*       FILESIZE_NOT_ALLOWED            = 9
*       HEADER_TOO_LONG                 = 10
*       DP_ERROR_CREATE                 = 11
*       DP_ERROR_SEND                   = 12
*       DP_ERROR_WRITE                  = 13
*       UNKNOWN_DP_ERROR                = 14
*       ACCESS_DENIED                   = 15
*       DP_OUT_OF_MEMORY                = 16
*       DISK_FULL                       = 17
*       DP_TIMEOUT                      = 18
*       FILE_NOT_FOUND                  = 19
*       DATAPROVIDER_EXCEPTION          = 20
*       CONTROL_FLUSH_ERROR             = 21
*       OTHERS   = 22
      .
    IF SY-SUBRC = 0.
      MESSAGE 'Data downloaded successfully' TYPE 'S'.
    ENDIF.
  ENDIF.

Provide a material type, execute the report, click on 'Download' link from menu, the data will be downloaded
into C:\MARA.XLS, check it (when ever you are testing please close the excel file or else it will get a run time
error ).
The below are the list of FAQ on Interactive reporting, the original post is in SCN.

What 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
Moment at which the user selects a line by double clicking on it or by
AT LINE-SELECTION
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- Moment during list processing of a secondary list at which a new page
SELECTION 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.

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-
Position of the line in the window from which the event was triggered (counting starts with 1)
CUROW
SY-
Position of the column in the window from which the event was triggered (counting starts with 2)
CUCOL
SY-
Page number of the first displayed page of the list from which the event was triggered
CPAGE
SY- Number of the first line of the first page displayed of the list from which the event was triggered
STARO (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 (counting
STACO starts with 1)
SY-
Function code that triggered the event
UCOMM
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 .

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.

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.

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 Transaction
Call and return: SUBMIT AND RETURN, CALL TRANSACTION
Call without return: SUBMIT, LEAVE TO TRANSACTION
You 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 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.

You might also like