Anda di halaman 1dari 32

ALV Reports using FM

Type-Pool Declaration

All the definitions of internal tables, structures and


constants are declared in a type-pool called SLIS.

Before calling the ALV function module, type pools


declaration is mandatory.
Syntax Type-pools:SLIS.
Note:
slis_t_fieldcat_alv contains "_t_.
It means that it is an internal table and slis_fieldcat_alv
is header line of that.

SLIS Type Library for ALV

Implementing a report with ALV FM


Start
Type-pools: SLIS
Logic to fill output table
Fill ALV field catalog table
Fill ALV sort table
Fill ALV event table
Call ALV FM
End

Modularized ALV FM Code


*Start of Selection.
START-OF-SELECTION.
*ExtractDatafromrequired tables.
PERFORMdata_retrieval. (Logic to fill output table)
*BuildFieldCatalog.
PERFORMbuild_fieldcatalog. (Fill ALV fieldcatalog table)
*BuildLayout.
PERFORMbuild_layout. (Fill ALV layout table)
*BuildEvents.
PERFORMbuild_events. (Fill ALV events table)
*BuildSort.
PERFORMbuild_sort. (Fill ALV sort table)
*DisplayALVReport.
PERFORMdisplay_alv_report. (Call ALV FM to display output)
*End of Selection.
END-OF-SELECTION.

ALV Fieldcatalog population


Use:
Populate the field names, column description, column width etc.
Data Declaration:
For field catalog population, declare an internal table of type
SLIS_T_ADD_FIELDCAT and a structure of type SLIS_ADD_FIELDCAT.
There are two methods to populate Field Catalog in ALV FM:
1.) Using FM REUSE_ALV_FIELDCATALOG_MERGE.
Exporting: IT_FIELDCAT - field catalog Internal Table.
Declare a data dictionary structure containing fields to be
displayed in the output.
Call the FM and pass the structure name to the FM. The FM
automatically populates the fieldcatalog internal table.

ALV Fieldcatalog Using FM

ALV Fieldcatalog Without using FM


2.) In this method, we can directly add fields by appending the filled attributes of
structure to internal table for each field individually.
Fields of the field catalog structure:
COL_POS Determines column position of a field. Ex: COL_POS = 1
EMPHASIZE Used to emphasize the importance of the field/column using different
background colors. Pass X to activate.
KEY Used to identify key fields. Usually used along with EMPHASIZE. Pass X to
activate.
OUTPUTLEN Determines the output length of the column. Ex: OUTPUTLEN = 15.
SELTEXT_L Column title. (Long text) . Pass X to activate.
SELTEXT_M Column title. (Medium text) . Pass X to activate.
SELTEXT_S Column title. (Small text) . Pass X to activate.
DO_SUM To display total for the field. Pass X to activate.
NO_OUT To set a column/field not to be displayed. Pass X to activate.
CHECKBOX To set a column as check box. Pass X to activate.
HOTSPOT Display the field content as hotspot. Pass X to activate.

ALV Fieldcatalog Without using FM

ALV Layout
Use:
Populate Layout Features for ALV output.
Data Declaration:
For field catalog population, declare a structure of type SLIS_LAYOUT_ALV.

Exporting:
IS_LAYOUT: ALV layout structure.

Fields of the layout structure:


COLWIDTH_OPTIMIZE optimizes the column width. Pass X to activate.
ZEBRA ALV layout will be displayed in a zebra color format. Pass X to
activate.
NO_SUBTOTALS subtotals will not be displayed. Pass X to activate.
NO_TOTALLINE the grand total line will not be displayed. Pass X to
activate.
SUBTOTALS_TEXT displays the subtotal text next to the subtotal.
Ex: subtotals_text = Sub Total.

ALV Layout Sample Code


FORMbuild_layout.

gs_layout-no_input
='X'.
gs_layout-colwidth_optimize
='X'.
gs_layout-no_totalline
= X.
gs_layout-subtotals_text
='SubTotal'.
gs_layout-zebra
='X'.
ENDFORM.

ALV Sorting
Use:

Identify the fields on which sorting needs to be performed. Subtotaling is


also performed here.

Data Declaration:

For sort table population, declare a internal table of type


SLIS_T_SORTINFO_ALV.

Exporting
IT_SORT: internal table for Sorting.
Fields of the sort structure:
- FIELDNAME : field name on which sort is required.
- SPOS : sort priority, pass incremental numbers example:
1, 2, 3 etc.
- UP : pass X to sort in ascending order.
- DOWN : pass X to sort in descending order.
- SUBTOT : pass X to get the subtotal for every break of the sort.

ALV Sorting Sample Code


DATA:wa_sortTYPEslis_sortinfo_alv,
gt_sort TYPE slis_t_sortinfo_alv.
wa_sort-spos='00'.
wa_sort-fieldname='VBELN'.
wa_sort-tabname='IT_VBAKVBAP'.
wa_sort-up='X'.
wa_sort-subtot='X'.
APPENDwa_sortTOgt_sort.
CLEARwa_sort.

ALV Grid List Display

REUSE_ALV_GRID_DISPLAY FM to display ALV Grid Output.

The following are the important parameters:

Exporting

I_CALLBACK_PROGRAM

: report id

IS_LAYOUT

: report layout.

IT_FIELDCAT
names,

: field catalog populate the field


column description, column width etc.

IT_SORT
on which

: sorts the ALV list populate the field


sort is required.

IT_EVENTS
along with

: populate the events to be triggered


the subroutine names.

Tables

T_OUTTAB
mandatory.

: pass the output table, this is

ALV Grid List Display

ALV Events handling


Use: Populate the event and subroutine name for each form into
events table.
Data Declaration: For events population declare an internal
table of type SLIS_T_EVENT.
Exporting
IT_EVENTS: Events table Populate the event table and the
form/subroutine name into the table
Call the FM, REUSE_ALV_EVENTS_GET to get all the events
into the table declared.
Loop the events table and populate the subroutine name
The columns are
name: Name of the event
form: Name of the routine
Declare the form/endform for the subroutine passed and write
the
required logic.

ALV Events Handling

Some of the Events available in ALV FM


CALL FUNCTION REUSE_ALV_GRID_DISPLAY
EXPORTING
I_CALLBACK_TOP_OF_PAGE
='TOP-OF-PAGE
I_CALLBACK_HTML_TOP_OF_PAGE ='HTML_TOP_OF_PAGE
I_CALLBACK_USER_COMMAND
='USER_COMMAND
I_CALLBACK_PF_STATUS_SET
='PF_STATUS_SET'

ALV Events handling Top of Page


Use:
Populate the text to be displayed on top of the page.
Data Declaration:
Declare a structure of type SLIS_LISTHEADER and an
internal table of type SLIS_T_LISTHEADER.
Parameter: I_CALLBACK_TOP_OF_PAGE
Fields of the list header structure.
- INFO : field to be displayed.
- TYP : type of display of text. Example values are
H,S and A
- KEY : text to be displayed in front of the field.
Call the FM REUSE_ALV_COMMENTARY_WRITE in the
subroutine and pass the internal table to it.

ALV Events handling Top of Page

ALV Events handling HTML Top of Page


Use:
Populate the text to be displayed on top of the page using SE24 Class Document.
Data Declaration:
DATA:textTYPEsdydo_text_element.
Syntax:
FORMhtml_top_of_pageUSINGdocumentTYPEREFTO
cl_dd_document.
ENDFORM.
Parameter: I_CALLBACK_HTML_TOP_OF_PAGE

Sample Code:
text=sy-datum.
CALLMETHODdocument->add_text
EXPORTING

text =text

sap_emphasis =Strong.

CALLMETHODdocument->add_gap
EXPORTING

width =15.

ALV Events handling HTML Top of Page

ALV Events handling User Command

Use To define user interaction on specific fields and their


individual
behavior.
Parameter:
I_CALLBACK_USER_COMMAND
Syntax:
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
The parameter R_UCOMM contains the function code.
The structure RS_SELFIELD has the details about the current
cursor position.

ALV Events handling User Command

ALV Events handling PF Status


Use:
To add application toolbar buttons and their functions.
Syntax:
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
ENDFORM.
Parameter:
I_CALLBACK_PF_STATUS_SET

Custom buttons on Application Toolbar:


Copy the PF statusSTANDARDofprogram
SAPLKKBLtotheuserdefinedPF statusofthecurrentprogram.
Now the buttons can be added to the custom PF status.

ALV Event handling PF Status (Sample Code)

FORMpf_status_setUSINGrt_extabTYPEslis_t_ext
ab.
setpf-status'ZSTANDARD'.
ENDFORM.

Adding Push button column to ALV output

Define a field of type CHAR1 in the data internal


table and subsequently the field catalog table.
Fill the layout properties of ALV as follows:
Is_layout-box_fieldname = <field_name>
Ex: Define field FLAG of type CHAR1 as first field of
data internal table.
ls_layout-box_fieldname = FLAG.
Pass the parameter Is_layout to the function module
REUSE_ALV_GRID_DISPLAY

Adding Push button column to ALV output

ALV Block List Display

Block List Display uses the Function Module


REUSE_ALV_BLOCK_LIST_DISPLAY.
Sample Code:
DATA ls_print TYPE slis_print_alv.
CALLFUNCTION'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
i_interface_check =''
is_print =ls_print.
Sample Program:

Z31_SAMP

ALV Block List Display output

Hierarchical list display

Hierarchical list display uses the function module


REUSE_ALV_HIERSEQ_LIST_DISPLAY.
Syntax:
CallfunctionReuse_ALV_Hierseq_List_Display
Exporting
I_Tabname_Header=(pass header table name)
I_Tabname_Item =(pass item table name)
Tables
T_Outtab_Header=(pass the header internal table)
T_Outtab_Item=(pass the item internal table)

Hierarchical list display output

Anda mungkin juga menyukai