You are on page 1of 63

AB1004 - ALV using Functions v1.

India SAP CoE, Slide 1

AB1004 - ALV using Functions v1.0


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 2

Introduction
ALV Grid Control
Purpose Use Challenges

India SAP CoE, Slide 3

Introduction
Purpose
The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).

India SAP CoE, Slide 4

Introduction
Use provides typical list functions as sorting, filtering, summing, while also gives the opportunity to develop user functions where needed. It presents numerous interfaces like Excel Inplace and Crystal Reports. Using ALV, we can have three types of reports: 1. Simple Report 2. Block Report 3. Hierarchical Sequential Report

India SAP CoE, Slide 5

Introduction
Challenges To use ALV Grid Functions in a simple manner, sufficient just having experience on Modular programming.

India SAP CoE, Slide 6

AB1004 - ALV using Functions v1.0


1 2

PrepareMe Syntax description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 7

Function Modules used for ALV

India SAP CoE, Slide 8

Function Modules used for ALV


Purpose of Function Modules: There are some function modules which will enable to produce the above reports without much effort. All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.

India SAP CoE, Slide 9

Function Modules used for ALV Contd


Simple Report The important function modules are: REUSE_ALV_LIST_DISPLAY REUSE_ALV_FIELDCATALOG_MERGE REUSE_ALV_EVENTS_GET REUSE_ALV_COMMENTARY_WRITE REUSE_ALV_GRID_DISPLAY

India SAP CoE, Slide 10

Function Modules used for ALV Contd


Function modules description as below:

REUSE_ALV_LIST_DISPLAY Prints the data in List Format


REUSE_ALV_FIELDCATALOG_MERGE: Used to populate field-catalog essential for ALV display. If output data is from single dictionary table and all the columns are selected, then creation of field catalog is not necessary.
Pass the Table name as a parameter I_STRUCTURE_NAME in the FM REUSE_ALV_LIST_DISPLAY.
India SAP CoE, Slide 11

Function Modules used for ALV Contd


Function modules description as below: REUSE_ALV_EVENTS_GET Returns table of possible events for a list type REUSE_ALV_COMMENTARY_WRITE Used in the Top-of-page event to print the headings and other comments for the list REUSE_ALV_GRID_DISPLAY Display the results in a grid format rather than as a list
India SAP CoE, Slide 12

Function Modules used for ALV Contd


Usage of FM: REUSE_ALV_GRID_DISPLAY & REUSE_ALV_LIST_DISPLAY Important Exporting parameters: I_CALLBACK_PROGRAM: Report ID I_CALLBACK_PF_STATUS_SET: Routine name to Set custom PF-status / change the functionality of the existing PF- status I_CALLBACK_USER_COMMAND: Routine name to handle Function codes
India SAP CoE, Slide 13

Function Modules used for ALV Contd


I_STRUCTURE_NAME: Name of the dictionary table IS_LAYOUT: Structure to set the layout of the report IT_FIELDCAT: Internal table with the list of all fields and their attributes which are to be printed Can auto-populate using REUSE_ALV_FIELDCATALOG_MERGE

India SAP CoE, Slide 14

Function Modules used for ALV Contd


IT_EVENTS: Internal table with a list of all possible events of ALV and their corresponding routine names (TABLES) T_OUTTAB: Internal table with the data to be output

India SAP CoE, Slide 15

Function Modules used for ALV Contd


Usage of REUSE_ALV_FIELDCATALOG_MERGE Exporting Parameters: I_PROGRAM_NAME: Report id I_INTERNAL_TABNAME: Internal output table I_INCLNAME: Include or the report name where all the dynamic forms are handled. Changing Parameters: IT_FIELDCAT: Internal table with the type SLIS_T_FIELDCAT_ALV which is declared in the type pool ,,SLIS.
India SAP CoE, Slide 16

Function Modules used for ALV Contd


Usage of REUSE_ALV_EVENTS_GET Importing Parameters: ET_EVENTS: Event table is returned with all possible CALLBACK events for the specified list type (column NAME). To enable process of particular events by the Callback, their corresponding FORM field must be filled. Read the event name entry from the event table and assign the corresponding routine name.

India SAP CoE, Slide 17

Function Modules used for ALV Contd


Usage of REUSE_ALV_EVENTS_GET Exporting Parameters: I_LIST_TYPE
0 = Simple list 1 = Hierarchical-sequential list 2 = Simple block list 3 = Hierarchical-sequential block list

India SAP CoE, Slide 18

Function Modules used for ALV Contd


Usage of REUSE_ALV_COMMENTARY_WRITE IT_LIST_COMMENTARY: Internal table with the headings of the type slis_t_listheader This internal table has three fields: Typ: H - header, S - selection, A action Key: only when type is S Info: the text to be printed

India SAP CoE, Slide 19

Example Simple List

India SAP CoE, Slide 20

Hierarchical Reports
Function module to display ALV List in Hierarchical format: REUSE_ALV_HIERSEQ_LIST_DISPLAY Exporting Parameters: I_CALLBACK_PROGRAM I_CALLBACK_PF_STATUS_SET I_CALLBACK_USER_COMMAND IS_LAYOUT

India SAP CoE, Slide 21

Hierarchical Reports
Exporting Parameterscontinued

IT_FIELDCAT IT_EVENTS I_TABNAME_HEADER : Internal table name with output data of the highest hierarchy level I_TABNAME_ITEM : Internal table name with output data of the lowest hierarchy level IS_KEYINFO : Structure contains the header and item table field names which link the two tables (shared key)

India SAP CoE, Slide 22

Hierarchical Reports
Tables T_OUTTAB_HEADER: Header table with data to be output T_OUTTAB_ITEM: Name of the internal table in the program containing the output data of the lowest hierarchy level.

India SAP CoE, Slide 23

Output

India SAP CoE, Slide 24

Block ALV Report


Purpose of Block List ALV used to display multiple lists continuously. Important functions used in this report are: REUSE_ALV_BLOCK_LIST_INIT REUSE_ALV_BLOCK_LIST_APPEND REUSE_ALV_BLOCK_HS_LIST_APPEND REUSE_ALV_BLOCK_LIST_DISPLAY

India SAP CoE, Slide 25

Block ALV Report


REUSE_ALV_BLOCK_LIST_INIT Initialize Block List used to set the default GUI status etc. Exporting Parameters: I_CALLBACK_PROGRAM I_CALLBACK_PF_STATUS_SET I_CALLBACK_USER_COMMAND

India SAP CoE, Slide 26

Block ALV Report


REUSE_ALV_BLOCK_LIST_APPEND Exporting Parameters: IS_LAYOUT: Layout settings for block IT_FIELDCAT: Field catalog I_TABNAME: Internal table name of the output data IT_EVENTS: Internal table name with all possible events Tables: T_OUTTAB: Internal table with output data. This function module adds the data to the block.
India SAP CoE, Slide 27

Block ALV Report


REUSE_ALV_LIST_HS_APPEND

used to append the Hierarchical Sequential blocks.

India SAP CoE, Slide 28

Block ALV Report


REUSE_ALV_BLOCK_LIST_DISPLAY

Parameters: All the parameters are optional. This function module display the list with data appended by the above function.

India SAP CoE, Slide 29

Example

Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used


India SAP CoE, Slide 30

Steps
Step 1 Declare global variables to be used for ALV Grid / List. Step 2 Declare your internal table which is supposed to hold the list data. Step 3 Populate the data to be displayed in the internal table . Step 4 Prepare the field catalog using functional Module REUSE_ALV_FIELDCATALOG_MERGE Step 5 Populate the Event Table , layout Table etc . Step 6 Call the appropriate Function Module REUSE_ALV_LIST_DIAPLAY / REUSE_ALV_GRID_DIAPLAY

India SAP CoE, Slide 31

AB1004 - ALV using Functions v1.0


1 2

PrepareMe Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 32

Demo
Step 1 Global data definition

India SAP CoE, Slide 33

Demo
Step 2 Global data definition

India SAP CoE, Slide 34

Demo
Step 4 - Building Field Catalog

Prepare the Field Catalog Structure of field catalog


Refer to the attached document

India SAP CoE, Slide 35

Demo
Step 4 Building Field Catalog Manually

India SAP CoE, Slide 36

Demo
Step 4 Building a field catalog
Pass the internal table/ structure name to get the field catalog

Modifying the field catalog according to requirements

India SAP CoE, Slide 37

Demo
Step 4 Layout Adjustments

Attributes of Layout
Refer to the attached document

India SAP CoE, Slide 38

Demo
Step 4 Layout Adjustments

Populating the layout structure as required and pass it to the export parameter IS_LAYOUT

India SAP CoE, Slide 39

Demo
Step 5 Populating events table

Populating Event table with TOP OF PAGE routine Populating Event table with END OF PAGE routine Populating Event table with user command routine

India SAP CoE, Slide 40

Demo
Step 5 Populating event table Contd..
The report will contain three forms for the above events: FORM TOP_OF_PAGE: This form will contain the top of page event for the report i.e. header etc Using the function module

REUSE_ALV_COMMENTARY_WRITE the internal table containing the headings for top of page event can be passed to the list output. Also, any logo specific to the report can be passed to the function module. FORM END_OF_PAGE: This form will contain the end of page event for the report i.e. footer etc
FORM USER_COMMAND: This form will contain the desired user command i.e. pick/line selection

India SAP CoE, Slide 41

Demo
Step 5 Populating event table TOP_OF_PAGE

Populating Line type and Text to be displayed

Passing Logo which would be displayed on the top

India SAP CoE, Slide 42

Example

Logo and header text is getting displayed

India SAP CoE, Slide 43

Demo
Step 5 Populating event table Contd.. User command

Implementing the functionality for user command event

India SAP CoE, Slide 44

Demo
Step 5 Populating event table Contd.. User command Note that the routine ( form ) which would execute after the user command can also be passed to the export parameter I_CALLBACK_USER_COMMANND Note that the routine ( form ) which would execute after the user command can also be passed to the export parameter I_CALLBACK_USER_COMMANND

India SAP CoE, Slide 45

Demo
Adding new buttons Add new buttons in the application toolbar Pass a name of the routine to the export parameter I_CALLBACK_PF_STATUS_SET . In the Form routine we need to set the new PF-STATUS .This PF-STATUS would be the copy of the PF_STATUS STANDARD of program SAPLSALV . We can add pushbuttons to the newly created PF-STATUS with the proper function codes We can write the functionality for the pushbutton event in the USER_COMMAND routine by making use of the function code .

India SAP CoE, Slide 46

Demo
Adding new buttons
This form routine name (SET_STATUS) will be passed to parameter I_CALLBACK_PF_STATU S_SET Add the function codes of the newly added buttons to the exclusion list maintained by table type SLIS_EXTAB

India SAP CoE, Slide 47

Demo
Adding new buttons

Added buttons

India SAP CoE, Slide 48

Demo
Step 5 Populating event table Contd.

Taking care of Double click event Taking care of pushbutton event

India SAP CoE, Slide 49

Demo
Step 6 Call the Function for ALV display

India SAP CoE, Slide 50

AB1004 - ALV using Functions v1.0


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 51

Exercises
List out all events used in ALV reports

Develop a reports using all events


Analyses technical specification attached and develop report according to specification.

India SAP CoE, Slide 52

ExercisesContd
Complete the ALV Report development using Function Modules Use the Technical specification below

India SAP CoE, Slide 53

AB1004 - ALV using Functions v1.0


1 2

Introduction Syntax Description


3

Demonstration
Exercises HelpMe

5
India SAP CoE, Slide 54

HelpMe

Tips and Tricks Additional Info

India SAP CoE, Slide 55

Additional Info
Advantages of ALV Reports Collapse multiple reports into one, drastically cutting down your report development time Save many hours using built-in ALV sorting, subtotaling and filtering capabilities Add conditional structures into your ALV report: No programming required Dynamically reorder column layouts and add/subtract fields

India SAP CoE, Slide 56

Event Handling Aspects of the ALV Grid


The ALV Grid Control uses the grid control to display the output table. So we can say that the ALV Grid Control is a wrapper that uses the wrapper of a Basis control. As the 'outer layer', this wrapper spares the developer from having to register the events on the front-end in order to simplify event handling.

The ALV Grid Control differs from Basis controls in the following respects

India SAP CoE, Slide 57

Contd
All events are registered as system events when the control is instantiated. If you want to register all events as application events, you must use parameter I_APPL_EVENTS Events DELAYED_CALLBACK or DELAYED_CHANGED_SEL_CALLBACK are registered using method

India SAP CoE, Slide 58

Graphical presentation of ALV


The following graphic illustrates the steps required to display a list with the ALV Grid Control

India SAP CoE, Slide 59

Tips & Tricks


Displaying and Deleting Subtotals This concept also applies to the calculation of subtotals for averages, minimums, and maximums. The procedure is the same as for subtotals procedure. You select a column by single-clicking the column header. Select one or more columns. Choose Subtotals tab.

India SAP CoE, Slide 60

Tips & Tricks


Displaying and Deleting Subtotals:

Select sub total tab To view the sub total


India SAP CoE, Slide 61

Tips & Tricks


Link for more information regarding ALV http://help.sap.com/saphelp_46c/helpdata/en/c5/3b d1369f2d280ee10000009b38f889/frameset.htm

India SAP CoE, Slide 62

Example ALV Reports

Example of Block list Example of Hierarchical list

India SAP CoE, Slide 63

You might also like