Sie sind auf Seite 1von 4

SAP ABAP MATERIALS: ABAP REPORTS

1 of 4

http://sap-abap-materials.blogspot.in/p/abap-reports.html

SAP ABAP MATERIALS


Home

SAP ABAP Topics Complete Information

ABAP INTERNAL TABLES

MESSAGES

ABAP 51 DAY COURSE

MODULARIZATION

ABAP BASICS

DIALOG PROGRAMMING

ABAP DATA DICTIONARY

ABAP REPORTS

OPEN SQL

BDC PROGRAMMING

What is SAP ALV?


ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our ABAP reports. ALV is created by a set of standard function
modules provided by SAP.
ALV provides a lot of inbuilt functions to our reports and some of the functions are listed below.
Sorting of records
Filtering of records
Totals and Sub-totals
Download the report output to Excel/HTML
Changing the order of the columns in the report
Hide the unwanted columns from the report
Because of the above functions, ALV substantially decreases the report development time. ALV takes care of rendering the list and we can concentrate only on
the data retrieval part.
Some of the function modules used to create ALV reports are listed below.
Function Module
Description
REUSE_ALV_LIST_DISPLAY

Display an ALV list

REUSE_ALV_GRID_DISPLAY

Display an ALV grid

REUSE_ALV_COMMENTARY_WRITE

Output List header information

REUSE_ALV_VARIANT_F4

Display variant selection dialog box

REUSE_ALV_VARIANT_EXISTENCE

Checks whether a variant exists

REUSE_ALV_FIELDCATALOG_MERGE Create field catalog from dictionary structure or internal


table
Simple ALV report.
DATA: it_spfli TYPE TABLE OF spfli.
SELECT * FROM spfli INTO TABLE it_spfli.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_structure_name = 'SPFLI'
TABLES
t_outtab
= it_spfli.
Simple ALV Output List

2/22/2016 11:45 AM

SAP ABAP MATERIALS: ABAP REPORTS

2 of 4

http://sap-abap-materials.blogspot.in/p/abap-reports.html

Create a Simple SAP ALV Report


ALV report is created using the standard function modules provided by SAP.
An ALV report can be created using the following steps.
Include SLIS type pool SLIS type pool contains all the data types required by ALV function modules.
Data retrieval Code the logic to fetch the data from database table into an Internal Table.
Build Field Catalog Add the columns into an internal that you want to display in the ALV output list.
Pass the data table and field catalog table to ALV function module
TYPE-POOLS: slis.

" SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook
TYPE TABLE OF sbook.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Fetch data from the database
SELECT * FROM sbook INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname = 'CARRID'.
wa_fieldcat-seltext_m = 'Airline'.
APPEND wa_fieldcat TO it_fieldcat.

" Fieldname in the data table


" Column description in the output

wa_fieldcat-fieldname = 'CONNID'.
wa_fieldcat-seltext_m = 'Con. No.'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'FLDATE'.
wa_fieldcat-seltext_m = 'Date'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'BOOKID'.
wa_fieldcat-seltext_m = 'Book. ID'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'PASSNAME'.
wa_fieldcat-seltext_m = 'Passenger Name'.
APPEND wa_fieldcat TO it_fieldcat.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
= 2.
Output

Field Catalog in SAP ALV


The field catalog is a table which contains information on the fields to be displayed on the ALV output.
First we need to build a field catalog before displaying any output in the ALV. We have the following three ways to build a field catalog.
Automatically through a Data Dictionary structure. (Example in What is SAP ALV?)
Manually in ABAP program. (Example in Create a simple ALV)
Semi-automatically by combining the above two procedures.

2/22/2016 11:45 AM

SAP ABAP MATERIALS: ABAP REPORTS

3 of 4

http://sap-abap-materials.blogspot.in/p/abap-reports.html

The third option is used in the following cases.


We want to display all the fields from the DDIC structure but want to modify certain attributes like descriptions etc.
We want to display most of the fields i.e. we want to hide certain fields.
Add new fields.
To generate a field catalog semi-automatically:
Declare an internal table of type SLIS_T_FIELDCAT_ALV.
Call function module REUSE_ALV_FIELDCATALOG_MERGE and pass the DDIC structure of the output table and the internal table for the field
catalog. The function module generates the field catalog and fills the internal table accordingly.
Read the rows you want to change, and adapt the fields accordingly. If your output table contains more fields than are stored in the Data Dictionary,
you must append one row for each new field to the field catalog.
Example Program
TYPE-POOLS: slis.

" SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: BEGIN OF wa_sbook,
status(4).
INCLUDE STRUCTURE sbook.
DATA: END OF wa_sbook.
DATA: it_sbook
TYPE TABLE OF sbook.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Fetch data from the database
SELECT * UP TO 10 ROWS FROM sbook INTO TABLE it_sbook.
*Build field catalog
wa_fieldcat-fieldname = 'STATUS'.
wa_fieldcat-seltext_m = 'Status'.
APPEND wa_fieldcat TO it_fieldcat.

" Fieldname in the data table


" Column description in the output

*Merge Field Catalog


CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name
= 'SBOOK'
CHANGING
ct_fieldcat
= it_fieldcat
EXCEPTIONS
inconsistent_interface
= 1
program_error
= 2
OTHERS
= 3.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat
= it_fieldcat
TABLES
t_outtab
= it_sbook
EXCEPTIONS
program_error = 1
OTHERS
= 2.
Output

Status column is added to the field catalog along all the fields of structure SBOOK.
Recommend this on Google

Download

Free Downloads

3 System

Adapt

Dictionary english to spanish


Bench

Build

Download

English dictionary online


Free Downloads

Postings

Online Dictionaries

Dictionary english to spanish

No comments:
Post a Comment

2/22/2016 11:45 AM

SAP ABAP MATERIALS: ABAP REPORTS

4 of 4

http://sap-abap-materials.blogspot.in/p/abap-reports.html

Comment as:

Publish

Subscribe to: Posts (Atom)

Total Pageviews

13399
Powered by Blogger.

2/22/2016 11:45 AM

Das könnte Ihnen auch gefallen