Anda di halaman 1dari 13

ABAP Programming

Laboratory 3 Reporting

Reporting
Objectives:
1.

Creating a program

2.

Using a table

3.

Using an interval parameter in SELECTION-OPTIONS

4.

Using types and local variables

5.

Using SELECT statement

6.

Creating routines and subroutines

7.

Displaying using ALV

ABAP Programming Laboratory 3. Reporting

Study case
1.

Create a program named ZTEST_DT_008 without Top Include.

2.

The table that will be used must be declared (ZTEST_FEAA_001).

3.

In SELECT-OPTIONS an interval parameter p_uname of ztest_feaa_001-username type will be


declared.

4.

In Start-of-selection a MAIN routine will be called. Two routines will be called in this procedure:
READ and ALV_DISPLAY.
In READ subroutine the data from ZTEST_FEAA_001 will be read, the data beying filtered by
the interval value of p_uname;
In ALV_DISPLAY we will use REUSE_ALV_GRID_DISPLAY.
for creating the fieldcatalog table we will use another routine ALV_FIELDCAT.

ABAP Programming Laboratory 3. Reporting

Creating a program
In SE80, right-click on Program, then choose Create.

Give it a name and unselect Top Include, then click on Continue.

ABAP Programming Laboratory 3. Reporting

Creating a program
Select as a type Executable program, as a Status Test program, then click Continue.

ABAP Programming Laboratory 3. Reporting

Writing the code


REPORT ZTEST_DT_008.
TABLES ztest_feaa_001.
TYPES gty_t_ztest_feaa_001 TYPE TABLE OF ztest_feaa_001.
SELECTION-SCREEN BEGIN OF BLOCK 1.
SELECT-OPTIONS: s_uname FOR ztest_feaa_001-username.
SELECTION-SCREEN END OF BLOCK 1.

INITIALIZATION.

START-OF-SELECTION.
PERFORM main.
END-OF-SELECTION.

ABAP Programming Laboratory 3. Reporting

Writing the code

FORM main.
DATA: lt_feaa_001 TYPE gty_t_ztest_feaa_001.
PERFORM read CHANGING lt_feaa_001.
PERFORM alv_display USING lt_feaa_001.
ENDFORM.

" MAIN

FORM read CHANGING ch_t_feaa_001 TYPE gty_t_ztest_feaa_001.


SELECT * FROM ztest_feaa_001
INTO TABLE ch_t_feaa_001
WHERE username IN s_uname.
ENDFORM.

" READ

ABAP Programming Laboratory 3. Reporting

Writing the code


FORM alv_display USING im_t_feaa_001 TYPE gty_t_ztest_feaa_001.
TYPE-POOLS: slis.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
ls_layout TYPE slis_layout_alv.
PERFORM alv_fieldcat CHANGING lt_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout
= ls_layout
it_fieldcat
= lt_fieldcat
TABLES
t_outtab
= im_t_feaa_001
EXCEPTIONS
program_error
=1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'Atentie, eroare ALV!'.
* &1&2&3&4&5&6&7&8
ENDIF.
ENDFORM.

Select Pattern in order to call a function.

"alv_display
ABAP Programming Laboratory 3. Reporting

Writing the code


FORM alv_fieldcat CHANGING ch_t_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-fieldname = 'MANDT'.
ls_fieldcat-key = 'X'.
ls_fieldcat-reptext_ddic
= text-001.
APPEND ls_fieldcat TO ch_t_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-fieldname = 'USERNAME'.
ls_fieldcat-reptext_ddic
= text-002.
APPEND ls_fieldcat TO ch_t_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-fieldname = 'FIRSTNAME'.
ls_fieldcat-reptext_ddic
= text-003.
APPEND ls_fieldcat TO ch_t_fieldcat.
CLEAR: ls_fieldcat.

ABAP Programming Laboratory 3. Reporting

Writing the code


ls_fieldcat-fieldname = 'LASTNAME'.
ls_fieldcat-reptext_ddic
= text-004.
APPEND ls_fieldcat TO ch_t_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-fieldname = 'DATEOFBIRTH'.
ls_fieldcat-reptext_ddic
= text-005.
APPEND ls_fieldcat TO ch_t_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-fieldname = 'ADDRESS'.
ls_fieldcat-reptext_ddic
= text-006.
APPEND ls_fieldcat TO ch_t_fieldcat.
CLEAR: ls_fieldcat.
ENDFORM.
" ALV_FIELDCAT
All the Text Symbols text-001 ... text-006 should be created by forward navigation, inserting the text we
want to be displayed, from MANDT to ADDRESS.

ABAP Programming Laboratory 3. Reporting

10

Running the program


Select two username values from the table.

Select Execute.

ABAP Programming Laboratory 3. Reporting

11

Running the program


Check the data from the table (SE16n). Type the name of the table, then select Execute.

ABAP Programming Laboratory 3. Reporting

12

Summary
In this laboratory work we created a program, we used a table and an interval parameter in a
SELECTION-OPTIONS, we used types and local variables, SELECT statement, we created
routines and subroutines and we displayed the filtered data using ALV.

ABAP Programming Laboratory 3. Reporting

13

Anda mungkin juga menyukai