32
ALV Reports using FM

ALV Reports Using FM

Embed Size (px)

Citation preview

Page 1: ALV Reports Using FM

ALV Reports using FM

Page 2: 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. 

Page 3: ALV Reports Using FM

SLIS – Type Library for ALV

Page 4: ALV Reports Using FM

Implementing a report with ALV FM

Start

End

Type-pools: SLIS

Logic to fill output table

Fill ALV field catalog table

Fill ALV sort table

Fill ALV event table

Call ALV FM

Page 5: ALV Reports Using FM

Modularized ALV FM Code*Start of Selection. START-OF-SELECTION.*Extract Data from required tables.  PERFORM data_retrieval. (Logic to fill output table)*Build Field Catalog.  PERFORM build_fieldcatalog. (Fill ALV fieldcatalog table)*Build Layout.  PERFORM build_layout. (Fill ALV layout table)*Build Events.  PERFORM build_events. (Fill ALV events table)*Build Sort.  PERFORM build_sort. (Fill ALV sort table)*Display ALV Report.  PERFORM display_alv_report. (Call ALV FM to display output)

*End of Selection.

END-OF-SELECTION.

Page 6: ALV Reports Using FM

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.

Page 7: ALV Reports Using FM

ALV Fieldcatalog – Using FM

Page 8: ALV Reports 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.

Page 9: ALV Reports Using FM

ALV Fieldcatalog – Without using FM

Page 10: ALV Reports 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’.

Page 11: ALV Reports Using FM

ALV Layout Sample Code

FORM build_layout.

   gs_layout-no_input           = 'X'.   gs_layout-colwidth_optimize  = 'X'. gs_layout-no_totalline = ‘X’.   gs_layout-subtotals_text    = 'Sub Total'.   gs_layout-zebra  = 'X'.

ENDFORM.

Page 12: ALV Reports Using FM

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.

Page 13: ALV Reports Using FM

ALV Sorting Sample Code DATA: wa_sort TYPE slis_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'.

  APPEND wa_sort TO gt_sort .  CLEAR wa_sort.

Page 14: ALV Reports Using FM

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 : field catalog — populate the field

names, column description, column width etc.

IT_SORT : sorts the ALV list — populate the field on which sort is required.

IT_EVENTS : populate the events to be triggered along with the subroutine names.

Tables T_OUTTAB : pass the output table, this is

mandatory.

Page 15: ALV Reports Using FM

ALV Grid List Display

Page 16: ALV Reports Using FM

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.

ExportingIT_EVENTS: Events table — Populate the event table and the form/subroutine name into the tableCall 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 eventform: Name of the routine

Declare the form/endform for the subroutine passed and write the required logic.

Page 17: ALV Reports Using FM

ALV Events Handling

Page 18: ALV Reports Using FM

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'

Page 19: ALV Reports Using FM

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.

Page 20: ALV Reports Using FM

ALV Events handling – Top of Page

Page 21: ALV Reports Using FM

ALV Events handling – HTML Top of PageUse:Populate the text to be displayed on top of the page using SE24 Class - ‘Document’.Data Declaration:DATA: text TYPE sdydo_text_element. Syntax:FORM html_top_of_page USING document TYPE REF TO  cl_dd_document. ENDFORM.Parameter: I_CALLBACK_HTML_TOP_OF_PAGE

Sample Code:

text = sy-datum. CALL METHOD document->add_text

     EXPORTING       text          = text       sap_emphasis  = ’Strong’.

   CALL METHOD document->add_gap     EXPORTING       width  = 15.

Page 22: ALV Reports Using FM

ALV Events handling – HTML Top of Page

Page 23: ALV Reports Using FM

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.

Page 24: ALV Reports Using FM

ALV Events handling – User Command

Page 25: ALV Reports Using FM

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 status STANDARD of program

SAPLKKBL to the user defined PF status of the current program. Now the buttons can be added to the custom PF status.

Page 26: ALV Reports Using FM

ALV Event handling – PF Status (Sample Code)

FORM pf_status_set USING rt_extab TYPE slis_t_extab.

set pf-status 'ZSTANDARD'.

ENDFORM.

Page 27: ALV Reports Using FM

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

Page 28: ALV Reports Using FM

Adding Push button column to ALV output

Page 29: ALV Reports Using FM

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.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'    EXPORTING      i_interface_check  = ' '      is_print           = ls_print.

Sample Program: Z31_SAMP

Page 30: ALV Reports Using FM

ALV Block List Display output

Page 31: ALV Reports Using FM

Hierarchical list display

Hierarchical list display uses the function module REUSE_ALV_HIERSEQ_LIST_DISPLAY. Syntax:

Call function ’Reuse_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)

Page 32: ALV Reports Using FM

Hierarchical list display output