You are on page 1of 45

Introduction to ALV Classic Reporting

A step-by-step programming guide to ALV reports


http://careerabap.blogspot.in/2010/11/interactive-alv-report-using-oops.html http://www.abapprogramming.net/2010/09/abap-programming-report-sample-code.html

. . . . . . . . .

INTRODUCTION

SAP has introduced a lot of new technologies with Release 4.6. All of these are designed to have a more pleasing user interface and make the work of the developer easier by automating many of the standard functionalities, which was needed to be coded explicitly earlier. Along with automation, the new technologies also bring with it a host of new and powerful features. But to use these features you have to master them. It is similar to saying that if you have a Formula 1 Ferrari, the thrill is only if you can drive it at 200 kms/hr. ALV or the SAP LIST VIEWER is one such technology. It is a tool for making reports with a better and standardized interface. All clients want the latest of technologies to be used for their implementation and our client was no exception. We initially found the going tough because there is hardly any documentation on ALV with the small exception of a few sample codes on the Internet. But with hard work and an exploring attitude we (the SAP MAM Team of Transco ODC) developed a fair amount of competency in ALV. This document is in a way, the documentation of our learnings. This document is NOT a comprehensive work on ALV. Indeed, there are many features that we discover every week. This manual gives an introduction to ALV and on how a person can write simple ALV reports. It has been written with FULL code dumps and screen shots so that there is no scope for confusion. It tries to give the initial impetus required to venture into further exploration of the technology. There is no doubt that you will find newer features and smarter way of doing things in ALV. It is our request to you to document these learnings and contribute to the EAS Knowledge Base. Remember, Rome was not built in a day. With this let us put our best foot forward

All programs in this document (ZSOMALV1-7) are available in the SAP PDC Server. In case you are using them, you are requested to make a copy of them and then work on the copy.

. . . . . . . . .
INDEX

INTRODUCTION..............................................................................................................................2 TOPICS INTRODUCED....................................................................................................................1


Report ZSOMALV1:................................................................................................................................................. 1

OUTPUT...........................................................................................................................................2 TOPICS INTRODUCED....................................................................................................................3


Report ZSOMALV2:................................................................................................................................................. 4

OUTPUT...........................................................................................................................................4 TOPICS INTRODUCED....................................................................................................................6


Report ZSOMALV3:................................................................................................................................................. 6

OUTPUT

....................................9

TOPICS INTRODUCED..................................................................................................................10
Report ZSOMALV4:............................................................................................................................................... 10

OUTPUT.........................................................................................................................................14 TOPICS INTRODUCED..................................................................................................................16


Report ZSOMALV5:............................................................................................................................................... 16

OUTPUT.........................................................................................................................................21 TOPICS INTRODUCED..................................................................................................................22


Report ZSOMALV6:............................................................................................................................................... 22

OUTPUT.........................................................................................................................................27 TOPICS INTRODUCED..................................................................................................................28 OUTPUT.........................................................................................................................................29

Chapter

A Simple ALV Program


TOPICS INTRODUCED
1) A simple ALV program. 2) REUSE_ALV_GRID_DISPLAY. 3) Minimum parameters to be passed.

Report ZSOMALV1:
REPORT zsomalv1 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * This program shows a simple ALV display of the table QMEL. Use the * 'Pattern' button to write the call to function * 'REUSE_ALV_GRID_DISPLAY'. Pass the table i_qmel to the function. *----------------------------------------------------------------------* DATA: i_qmel LIKE qmel OCCURS 0. SELECT * FROM qmel INTO TABLE i_qmel. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' * I_CALLBACK_PROGRAM = ' ' * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' i_structure_name = 'QMEL' * I_BACKGROUND_ID = ' ' * I_GRID_TITLE = * I_GRID_SETTINGS = * IS_LAYOUT = * IT_FIELDCAT = * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' * I_SAVE = ' ' * IS_VARIANT = * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT =

* IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_qmel EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

OUTPUT

Any ALV program requires a minimum of two parameters to be passed to the function REUSE_ALV_GRID_DISPLAY.
.

Field Catalogue (Details of the format of the columns to be displayed in the report) And the data to be populated in those columns.

In the above case we are passing the name of the table itself (in place of the field catalogue which is discussed later). The function automatically creates the field catalogue in this case. ALV automatically sets a standard PF-STATUS (the row of buttons above the report). With these you can do a lot of standard functions like send it by mail, sort, save as a local file etc).

A common mistake that every beginner does is not to uncomment the EXPORTING line of the function after writing it by the Pattern button. Due to it, the function does not recognize the structure name being passed to it.

Chapter

Choosing and saving Layouts


TOPICS INTRODUCED
1) How we can ensure that report allows the user to make, choose and save layouts (also called

display variants).
2) Optimize the column width to display data in the most efficient manner. 3) Other options that can be specified for layouts.

Report ZSOMALV2:

OUTPUT

Difference in this program is the usage of a Type-Pool (SLIS). This type pool contains all the standard structures and tables (for eg. slis_alv_layout), which are to be populated and passed to REUSE_ALV_GRID_DISPLAY. It is a good idea to keep a printout of this type-pool when coding ALV programs. This is also included in this document as APPENDIX A. Other difference is that we are passing a value A to the parameter i_save, Value range of parameter i_save can be, ' ' = No display variants can be saved 'X' = Only standard display variants can be saved 'U = Only user-specific display variants can be saved 'A' = Standard and user-specific display variants can be saved

Note that 2 other buttons have appeared in the PF-STATUS (Change Layout and Save layout). When you click on Change Layout, a window comes up where you can specify the sort order, which all columns to be displayed and other properties).

You can also sort the report using the sort buttons etc and click Save Layout. Then you are asked whether it is user specific or default. For all such interactive functions to work, we also need to pass the program ID (sy-repid) to ALV (I meant REUSE_ALV .). But it should never be passed alone, only after assigning it to a variable. The final thing is the passing of layout specifications (i_layout) to ALV. Please refer to the other fields in the structure slis_layout_alv (it is combination of two structures which has more structures etc). Through them you can specify a host of other properties. For example, i_layout-zebra = X This will result in the lines of the report having alternate colour. i_layout-no_vline = X Columns are separated by space. i_layout-no_scrolling = X Scrolling is disabled.

We found that a lot of such options were not working. If you do further R&D on this; please document them and contribute to the EAS KB.

Chapter

Specifying a field Catalogue


TOPICS INTRODUCED
1) Specify a heading for a report. 2) Create a field catalogue for the report.

In real life situations we will not need to simply display a table as we have been doing above. Most probably it will be an internal table with a specific set of fields from different tables and maybe plain integer or character fields. In such cases the simplest method to follow is to create an internal table (of the same structure as what is to be displayed in the report) with the data; pass it to ALV and also a field catalogue (also called fieldcat).

Report ZSOMALV3:
REPORT zsomalv3 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Specify a heading for a report. * 2. Create a field catalogue for the report. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: DATA: DATA: DATA: report_id ws_title i_layout i_fieldcat LIKE TYPE TYPE TYPE sy-repid. lvc_title VALUE 'An ALV Report'. slis_layout_alv. slis_t_fieldcat_alv.

SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'.

LOOP AT i_data. i_data-ws_row = sy-tabix.


.

i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.

CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'. ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-key line_fieldcat-seltext_m APPEND line_fieldcat TO

= 'QMNUM'. " The field name and the table = 'I_DATA'. " name are the two minimum req. = 'X'. " Specifies the column as a key (Blue) = 'Notification No.'. " Column Header i_fieldcat.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_l line_fieldcat-datatype line_fieldcat-outputlen APPEND line_fieldcat TO

= 'QMTXT'. = 'I_DATA'. = 'Description'. i_fieldcat.

= 'WS_ROW'. = 'I_DATA'. = 'Row Number'. i_fieldcat.

= 'WS_CHAR'. = 'I_DATA'. = 'Test Character Field'. = 'CHAR'. = '15'. " You can specify the width of a i_fieldcat. " column.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init

OUTPUT

Over here we are purposely using a customized internal table which is being displayed in ALV. Notice that it contains two kinds of fields. Ones with DDIC (Data Dictionary Reference) and others without. The table we are using to create a field catalogue (i_fieldcat) is of type slis_t_fieldcat_alv. It is a table of structure slis_fieldcat_alv. Refer to the SLIS type-pool to get the other options that you can specify for a column. For example, line_fieldcat-icon = X Specifies this column as a column of icons. You must then specify valid icon values for tnem to be shown in the report. line_fieldcat-lzero = X Allows leading zeroes to be shown for a number column. line_fieldcat-just = R R Justify right, L Left, C Centre. Etc. You can display a heading for the report using type lvc_title as shown. NOTE: The table i_fieldcat is passed to the parameter it_fieldcat of the function instead of i_structure_name as earlier.

Chapter

Initialize Events
TOPICS INTRODUCED
1) Initialize events. 2) Execute a specific requirement when an event is triggered. 3) Use an event 'TOP_OF_PAGE' to write a header for the report. 4) REUSE_ALV_COMMENTARY WRITE.

Report ZSOMALV4:
REPORT zsomalv4 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Initialize events. * 2. Execute a specific requirement when an event is triggered. * 3. Use an event 'TOP_OF_PAGE' to write a header for the report. * 4. REUSE_ALV_COMMENTARY WRITE. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: DATA: DATA: DATA: DATA: DATA: report_id ws_title i_layout i_fieldcat i_events i_header LIKE TYPE TYPE TYPE TYPE TYPE sy-repid. lvc_title VALUE 'An ALV Report'. slis_layout_alv. slis_t_fieldcat_alv. slis_t_event. slis_t_listheader.

SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'.

10

LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. PERFORM f3000_build_header CHANGING i_header. PERFORM f4000_events_init CHANGING i_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------*

11

FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'. ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-key line_fieldcat-seltext_m APPEND line_fieldcat TO = 'QMNUM'. " The field name and the table = 'I_DATA'. " name are the two minimum req. = 'X'. " Specifies the column as a key (Blue) = 'Notification No.'. " Column Header i_fieldcat.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_l line_fieldcat-datatype line_fieldcat-outputlen APPEND line_fieldcat TO = 'QMTXT'. = 'I_DATA'. = 'Description'. i_fieldcat. = 'WS_ROW'. = 'I_DATA'. = 'Row Number'. i_fieldcat. = 'WS_CHAR'. = 'I_DATA'. = 'Test Character Field'. = 'CHAR'. = '15'. " You can specify the width of a i_fieldcat. " column.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init

*&---------------------------------------------------------------------* *& Form f3000_build_header *&---------------------------------------------------------------------*

12

FORM f3000_build_header USING i_header TYPE slis_t_listheader. DATA: gs_line TYPE slis_listheader. CLEAR gs_line. gs_line-typ = 'H'. gs_line-info = 'This is line of type HEADER'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = gs_line-key = gs_line-info = APPEND gs_line gs_line-key = gs_line-info = APPEND gs_line 'S'. 'STATUS 1'. 'This is line of type STATUS'. TO i_header. 'STATUS 2'. 'This is also line of type STATUS'. TO i_header.

CLEAR gs_line. gs_line-typ = 'A'. gs_line-info = 'This is line of type ACTION'. APPEND gs_line TO i_header. ENDFORM. " f3000_build_header

*&---------------------------------------------------------------------* *& Form f4000_events_init *&---------------------------------------------------------------------* FORM f4000_events_init CHANGING i_events TYPE slis_t_event. DATA: line_event TYPE slis_alv_event. CLEAR line_event. line_event-name = 'TOP_OF_PAGE'. line_event-form = 'F4100_TOP_OF_PAGE'. APPEND line_event TO i_events. ENDFORM. " f3000_events_init

*---------------------------------------------------------------------* * FORM F4100_TOP_OF_PAGE * *---------------------------------------------------------------------* FORM f4100_top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = i_header. ENDFORM.

13

OUTPUT

First let us discuss about events. As you may be aware, ABAP is a event driven language. Through ALV we can cause one or more things to occur when an event is triggered. Over here in the above example, we have defined the event TOP_OF_PAGE (By defining an event, I mean associating a form to it, which is executed when that event occurs). To define an event, first declare a table of type slis_t_event and through a form (f4000_events_init) append lines to the table i_events. Each line is of type slis_alv_event and contains only two fields; the event and the associated form, which is executed upon that event. Later i_events is passed to ALV. To write a header, we use the function REUSE_ALV_COMMENTARY_WRITE. This function can be used to write headers or footers for reports. To this function we pass a table of the text that we want to be written in the report. It is of type slis_t_listheader. This is a table of rows, which can of three types, HEADER, STATUS or ACTION as defined in the type slis_list_header, which is a line item of slis_t_listheader. (P.S: Please dont ask we why we have only three types. I dont know!!) ALV supports 16 events. They are:
1. 2. 3. 4. 5.
.

ITEM_DATA_EXPAND REP REP_SEL_MODIFY CALLER_EXIT USER_COMMAND 14

6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19.

TOP_OF_PAGE DATA_CHANGED TOP_OF_COVERPAGE END_OF_COVERPAGE FOREIGN_TOP_OF_PAGE FOREIGN_END_OF_PAGE PF_STATUS_SET LIST_MODIFY TOP_OF_LIST END_OF_PAGE END_OF_LIST AFTER_LINE_OUTPUT BEFORE_LINE_OUTPUT SUBTOTAL_TEXT

15

Chapter

Customize you PF Status


TOPICS INTRODUCED
1) Learn about the Standard PF-Status that comes as default. 2) Exclude function codes from Standard PF-Status and customize it.

In all the previous reports, we have seen that ALV displays a standard PF Status by default, which contains a bare minimum function codes (also called fcodes). This is helpful because we do not have to explicitly code the PF Status. Actually, this PF Status is the STANDARD PF Status of the program SAPLSALV with 46 function codes excluded (disabled). Use transaction SE41 to view all the function codes. In most practical cases, we will need to exclude some function codes from the standard PF Status because they might be irrelevant to our report or because we may need to disable certain standard function codes. (For example, there are reports where the user must NOT be allowed to sort). In the following program we will see how we display the entire STANDARD PF Status (including the 46 fcodes which are usually disabled) and also disable 4 of the fcodes.

Report ZSOMALV5:
REPORT zsomalv5 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Learn about the Standard PF-Status that comes as default. * 2. Exclude function codes from Standard PF-Status and customize it. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: DATA: DATA: DATA: report_id ws_title i_layout i_fieldcat LIKE TYPE TYPE TYPE sy-repid. lvc_title VALUE 'An ALV Report'. slis_layout_alv. slis_t_fieldcat_alv.

16

DATA: i_events DATA: i_header DATA: i_extab

TYPE slis_t_event. TYPE slis_t_listheader. TYPE slis_t_extab.

SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'. LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. PERFORM f3000_build_header CHANGING i_header. PERFORM f4000_events_init CHANGING i_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data

17

EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'. ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-key line_fieldcat-seltext_m APPEND line_fieldcat TO = 'QMNUM'. " The field name and the table = 'I_DATA'. " name are the two minimum req. = 'X'. " Specifies the column as a key (Blue) = 'Notification No.'. " Column Header i_fieldcat.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_l line_fieldcat-datatype line_fieldcat-outputlen APPEND line_fieldcat TO = 'QMTXT'. = 'I_DATA'. = 'Description'. i_fieldcat. = 'WS_ROW'. = 'I_DATA'. = 'Row Number'. i_fieldcat. = 'WS_CHAR'. = 'I_DATA'. = 'Test Character Field'. = 'CHAR'. = '15'. " You can specify the width of a i_fieldcat. " column.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'.

18

line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init

*&---------------------------------------------------------------------* *& Form f3000_build_header *&---------------------------------------------------------------------* FORM f3000_build_header USING i_header TYPE slis_t_listheader. DATA: gs_line TYPE slis_listheader. CLEAR gs_line. gs_line-typ = 'H'. gs_line-info = 'This is line of type HEADER'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = gs_line-key = gs_line-info = APPEND gs_line gs_line-key = gs_line-info = APPEND gs_line 'S'. 'STATUS 1'. 'This is line of type STATUS'. TO i_header. 'STATUS 2'. 'This is also line of type STATUS'. TO i_header.

CLEAR gs_line. gs_line-typ = 'A'. gs_line-info = 'This is line of type ACTION'. APPEND gs_line TO i_header. ENDFORM. " f3000_build_header

*&---------------------------------------------------------------------* *& Form f4000_events_init *&---------------------------------------------------------------------* FORM f4000_events_init CHANGING i_events TYPE slis_t_event. DATA: line_event TYPE slis_alv_event. CLEAR line_event. line_event-name = 'TOP_OF_PAGE'. line_event-form = 'F4100_TOP_OF_PAGE'. APPEND line_event TO i_events. CLEAR line_event. line_event-name = 'PF_STATUS_SET'. line_event-form = 'F4200_PF_STATUS_SET'. APPEND line_event TO i_events. ENDFORM. " f3000_events_init

*---------------------------------------------------------------------* * FORM F4100_TOP_OF_PAGE * *---------------------------------------------------------------------* FORM f4100_top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = i_header.

19

ENDFORM. *---------------------------------------------------------------------* * FORM F4200_PF_STATUS_SET * *---------------------------------------------------------------------* FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab. REFRESH i_extab. PERFORM f4210_exclude_fcodes CHANGING i_extab. SET PF-STATUS 'STANDARD' OF PROGRAM 'SAPLSALV' EXCLUDING i_extab. ENDFORM. *&---------------------------------------------------------------------* *& Form f4210_exclude_fcodes *&---------------------------------------------------------------------* FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab. DATA: ws_fcode TYPE slis_extab. CLEAR ws_fcode. ws_fcode = '&EB9'. APPEND ws_fcode TO ws_fcode = '&ABC'. APPEND ws_fcode TO ws_fcode = '&NFO'. APPEND ws_fcode TO ws_fcode = '&LFO'. APPEND ws_fcode TO ENDFORM.

" Call up Report. i_extab. " ABC Analysis. i_extab. " Info Select. i_extab. " Information. i_extab. " f4210_exclude_fcodes

20

OUTPUT

For starters, declare a new internal table ( i_extab) of type slis_t_extab. This will contain all the function codes, which should be excluded from the PF Status. Initialize a new event called PF_STATUS_SET by assigning a form to it. Inside this form (F4200_PF_STATUS_SET), first refresh the table i_extab, which gets populated by the names of the 46 function codes that are populated by default by ALV. Then call a form, which populates i_extab with the names of the 4 fcodes. Finally set the PF Status.

Chapter

21

Process callback events


TOPICS INTRODUCED
1) Add customized buttons (function codes) to Standard PF Status. 2) Customize the processing of such events.

In many cases, we may need to add buttons (function codes) to our PF status and assign a code that will be executed when that function code is triggered. We can either create our own PF status or copy the STANDARD pf status of program SAPLSALV creating our own to which we can add buttons and function codes.

Report ZSOMALV6:
REPORT zsomalv6 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Add customized buttons (function codes) to Standard PF Status. * 2. Customize the processing of such events. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: DATA: DATA: DATA: DATA: DATA: DATA: report_id ws_title i_layout i_fieldcat i_events i_header i_extab LIKE TYPE TYPE TYPE TYPE TYPE TYPE sy-repid. lvc_title VALUE 'An ALV Report'. slis_layout_alv. slis_t_fieldcat_alv. slis_t_event. slis_t_listheader. slis_t_extab.

SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'. LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid.

22

PERFORM PERFORM PERFORM PERFORM

f1000_layout_init CHANGING i_layout. f2000_fieldcat_init CHANGING i_fieldcat. f3000_build_header CHANGING i_header. f4000_events_init CHANGING i_events.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'.

23

ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-key line_fieldcat-seltext_m APPEND line_fieldcat TO

= 'QMNUM'. " The field name and the table = 'I_DATA'. " name are the two minimum req. = 'X'. " Specifies the column as a key (Blue) = 'Notification No.'. " Column Header i_fieldcat.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_m APPEND line_fieldcat TO CLEAR line_fieldcat. line_fieldcat-fieldname line_fieldcat-tabname line_fieldcat-seltext_l line_fieldcat-datatype line_fieldcat-outputlen APPEND line_fieldcat TO

= 'QMTXT'. = 'I_DATA'. = 'Description'. i_fieldcat.

= 'WS_ROW'. = 'I_DATA'. = 'Row Number'. i_fieldcat.

= 'WS_CHAR'. = 'I_DATA'. = 'Test Character Field'. = 'CHAR'. = '15'. " You can specify the width of a i_fieldcat. " column.

CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init

*&---------------------------------------------------------------------* *& Form f3000_build_header *&---------------------------------------------------------------------* FORM f3000_build_header USING i_header TYPE slis_t_listheader. DATA: gs_line TYPE slis_listheader. CLEAR gs_line. gs_line-typ = 'H'. gs_line-info = 'This is line of type HEADER'.

24

APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = gs_line-key = gs_line-info = APPEND gs_line gs_line-key = gs_line-info = APPEND gs_line

'S'. 'STATUS 1'. 'This is line of type STATUS'. TO i_header. 'STATUS 2'. 'This is also line of type STATUS'. TO i_header.

CLEAR gs_line. gs_line-typ = 'A'. gs_line-info = 'This is line of type ACTION'. APPEND gs_line TO i_header. ENDFORM. " f3000_build_header

*&---------------------------------------------------------------------* *& Form f4000_events_init *&---------------------------------------------------------------------* FORM f4000_events_init CHANGING i_events TYPE slis_t_event. DATA: line_event TYPE slis_alv_event. CLEAR line_event. line_event-name = 'TOP_OF_PAGE'. line_event-form = 'F4100_TOP_OF_PAGE'. APPEND line_event TO i_events. CLEAR line_event. line_event-name = 'PF_STATUS_SET'. line_event-form = 'F4200_PF_STATUS_SET'. APPEND line_event TO i_events. CLEAR line_event. line_event-name = 'USER_COMMAND'. line_event-form = 'F4300_USER_COMMAND'. APPEND line_event TO i_events. ENDFORM. " f3000_events_init *---------------------------------------------------------------------* * FORM F4100_TOP_OF_PAGE * *---------------------------------------------------------------------* FORM f4100_top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = i_header. ENDFORM. *---------------------------------------------------------------------* * FORM F4200_PF_STATUS_SET * *---------------------------------------------------------------------* FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab. REFRESH i_extab. PERFORM f4210_exclude_fcodes CHANGING i_extab. * The PF status is an exact copy of the PF status 'STANDARD' of program * SAPLSALV but with command 'CHNG' added to it. SET PF-STATUS 'ZSOM_STANDARD' EXCLUDING i_extab.

25

ENDFORM. *&---------------------------------------------------------------------* *& Form f4210_exclude_fcodes *&---------------------------------------------------------------------* FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab. DATA: ws_fcode TYPE slis_extab. CLEAR ws_fcode. ws_fcode = '&EB9'. APPEND ws_fcode TO ws_fcode = '&ABC'. APPEND ws_fcode TO ws_fcode = '&NFO'. APPEND ws_fcode TO ws_fcode = '&LFO'. APPEND ws_fcode TO ENDFORM.

" Call up Report. i_extab. " ABC Analysis. i_extab. " Info Select. i_extab. " Information. i_extab. " f4210_exclude_fcodes

*&---------------------------------------------------------------------* *& Form f4300_user_command *&---------------------------------------------------------------------* FORM f4300_user_command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield. CASE ucomm. WHEN '&IC1'. "Double Click line Item READ TABLE i_data INDEX selfield-tabindex. IF i_data-qmnum NE space. SET PARAMETER ID 'IQM' FIELD i_data-qmnum. CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN. CLEAR ucomm. ENDIF. WHEN 'CHNG'. " Change Notification Icon READ TABLE i_data INDEX selfield-tabindex. IF i_data-qmnum NE space. SET PARAMETER ID 'IQM' FIELD i_data-qmnum. CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN. CLEAR ucomm. ENDIF. ENDCASE. CLEAR ucomm. ENDFORM. " f4300_user_command

26

OUTPUT

In this program, first we created a PF status (ZSOM_STANDARD), which was an exact copy of STANDARD of program SAPLSALV through transaction SE41 (Menu Painter). Then we added another button to it (circled in white) with a new fcode called CHNG. Creation of PF status is not covered in this document, as it is available in any standard ABAP material. After this this we set this PF status instead of STANADRD. We initialize a third event USER_COMMAND and associate a form with it. In this form we can capture the function codes and write any functionality under it. If we write functionality for an existing fcode, then this gets precedence over the default functionality that might be associated with it. In this example, we capture a standard fcode &IC1 that is nothing but double clicking a line of the report. We are capturing the notification number of that line and calling transaction IW52 with it. We are also doing the same when a user clicks on the new Change Notification button. When the user clicks the Back button in IW52, it comes back to the report.

27

Chapter

Sort Catalogue
TOPICS INTRODUCED
1) Define a sort catalogue for a report. 2) Sort a report using a sort catalogue.

Creating a sort catalogue is very similar to creating a field catalogue. In it we can specify the fieldnames, table names, order of sorting, whether it should be sorted ascending or descending. The steps to be taken are, first declare an internal table ( i_sort ) of type slis_t_sortinfo_alv. This is a table of the structure slis_sortinfo_alv. Then create the sort catalogue in a form which is to be called before the call to ALV. (i.e. REUSE_ALV_GRID_DISPLAY)
*&---------------------------------------------------------------------* *& Form f5000_sortcat_init *&---------------------------------------------------------------------* form f5000_sortcat_init changing i_sortcat TYPE slis_t_sortinfo_alv.. DATA: line_sortinfo TYPE slis_sortinfo_alv. CLEAR line_sortinfo. line_sortinfo-fieldname = 'QMART'. line_sortinfo-tabname = 'I_DATA'. line_sortinfo-spos = 1. " First sort by this field. line_sortinfo-down = 'X'. " Descending APPEND line_sortinfo TO i_sortcat. line_sortinfo-fieldname = 'WS_ROW'. line_sortinfo-tabname = 'I_DATA'. line_sortinfo-spos = 2. " Second sort by this field. line_sortinfo-up = 'X'. " Ascending APPEND line_sortinfo TO i_sortcat. endform. " f5000_sortcat_init

Then pass i_sortcat to ALV through the parameter it_sort.


* * * * * it_fieldcat IT_EXCLUDING IT_SPECIAL_GROUPS IT_SORT IT_FILTER IS_SEL_HIDE I_DEFAULT = i_fieldcat = = = i_sortcat = = = 'X'

28

In form F4200_pf_status_set, change the setting of the PF status to,


SET PF-STATUS 'ZSOM_STANDARD' OF PROGRAM 'ZSOMALV6' EXCLUDING i_extab.

Or else you will get an error. This is because this PF status was created for program ZSOMALV6.

OUTPUT

In this example we have sorted the above list first by notification type (QMART) descending and then by row number (WS_ROW) ascending. Do note the small red arrows that come up in the column header indicating the type of sort.

The usage of a sort catalogue is actually not required !! This is also the reason why I have decided to put it towards the last. Just sort the internal data table (i_data) in the required manner before passing it to ALV and it will be displayed as shown above. The only difference is that the red arrows wont be there. . In short the statement,
SORT i_data BY qmart DESCENDING ws_row ASCENDING.

Is enough to replace all the code written above !!

29

Appendix

Type-Pool SLIS
type-pool slis . ">>Y9CK015723 types: begin of slis_lvc_s_bds_extended, bytesize type int4, EXTOBJID type char255, "Y9CK016268 end of slis_lvc_s_bds_extended. types: begin of slis_lvc_s_bds2. include type lvc_s_bds. include type slis_lvc_s_bds_extended. types: end of slis_lvc_s_bds2. types: slis_lvc_t_bds2 type slis_lvc_s_bds2 occurs 1. "<<Y9CK015723 ">>Y9CK016292 *Trace Extern-Intern-Konvertierung types: begin of slis_lvc_s_expa, OP type CHAR4, EXTERN type LVC_VALUE, INTERN type LVC_VALUE, *INCLUDE type RSCONVLITE ACTIVE type RSSCR_CFLG, OLENGTH type RSSCR_OLEN, DECIMALS type RSDECIMALS, SIGN type SIGNFLAG, LOWER type RSSCR_LOWC, CONVEXIT type CONVEXIT, *INCLUDE type TABFIELD TABNAME type TABNAME, FIELDNAME type FIELDNAME, LFIELDNAME type FNAM_____4, CURRENCY type CHAR30, end of slis_lvc_s_expa. *Textstruktur(ALV-Batch) types: begin of slis_lvc_s_1022, line(1022) type c, end of slis_lvc_s_1022. *Text-Tabelle(ALV Batch) types: slis_lvc_t_1022 type slis_lvc_s_1022 occurs 1. *Ausgabefiles types: begin of slis_lvc_s_fils, FILENAME type CHAR255, SIZE type INT4,
.

30

MIMETYPE type CHAR128, PRIMARY type FLAG, BINARY type FLAG, end of slis_lvc_s_fils. *Filestruktur types: slis_lvc_t_fils type slis_lvc_s_fils occurs 1. *Mimetype-Mapping types: begin of slis_lvc_s_mima, MIMETYPE type CHAR128, BINARY type FLAG, end of slis_lvc_s_mima. *ALV: Mime-Mapping types: slis_lvc_t_mima type slis_lvc_s_mima occurs 1. *ALV-W3Text types: slis_lvc_t_text type w3html occurs 1. *X255-Tabelle types: slis_lvc_t_mime type w3mime occurs 1. *Tabelle X1022 types: slis_lvc_t_x1022 type bapiconten occurs 1. "<<Y9CK016292 types: slis_list_type(1) type n, slis_char_1(1) type c, slis_text40(40) type c. types: slis_tabname(30) type c, slis_fieldname(30) type c, slis_sel_tab_field(60) type c, slis_formname(30) type c, slis_entry(60) type c, slis_edit_mask(60) type c, slis_coldesc(4) type c. *types: begin of slis_filtered_entries, * index type i, * end of slis_filtered_entries. types: slis_t_filtered_entries type i occurs 0. *--- Structure for additional fieldcat types: begin of slis_add_fieldcat, fieldname type slis_fieldname, web_field type slis_fieldname, href_hndl type i, end of slis_add_fieldcat. types: slis_t_add_fieldcat type slis_add_fieldcat occurs 0. *--- Structure for reprep-initialization types: begin of slis_reprep_id, tool(2) type c, appl(4) type c, subc(2) type c, onam(54) type c, end of slis_reprep_id. types: begin of slis_reprep_communication, stop(1) type c, end of slis_reprep_communication.

31

*** Structure for colors types: begin of slis_color, col type i, int type i, inv type i, end of slis_color. types: begin of slis_coltypes, heacolfir type slis_color, heacolnex type slis_color, hearowfir type slis_color, hearownex type slis_color, lisbodfir type slis_color, lisbodnex type slis_color, lisbod type slis_color, higcolkey type slis_color, higcol type slis_color, higrow type slis_color, higsum type slis_color, higsumhig type slis_color, higsumlow type slis_color, higins type slis_color, higpos type slis_color, higneg type slis_color, hig type slis_color, heahie type slis_color, lisbodhie type slis_color, end of slis_coltypes. " " " " " " " " " " " " " " " " " " " heading_cols_first heading_cols_nex heading_rows_first heading_rows_next list_body_first list_body_next list_body highlight_col_key highlight_col highlight_row highlight_sum highlight_sum_high highlight_sum_low highlight_inserted highlight_positive highlight_negative highlight heading_hier list_body_hierinfo

*** Fieldcat types: begin of slis_fieldcat_main0, row_pos like sy-curow, " output in row col_pos like sy-cucol, " position of the column fieldname type slis_fieldname, tabname type slis_tabname, currency(5) type c, cfieldname type slis_fieldname, " field with currency unit ctabname type slis_tabname, " and table ifieldname type slis_fieldname, " initial column quantity(3) type c, qfieldname type slis_fieldname, " field with quantity unit qtabname type slis_tabname, " and table round type i, " round in write statement exponent(3) type c, " exponent for floats key(1) type c, " column with key-color icon(1) type c, " as icon symbol(1) type c, " as symbol checkbox(1) type c, " as checkbox just(1) type c, " (R)ight (L)eft (C)ent. lzero(1) type c, " leading zero no_sign(1) type c, " write no-sign no_zero(1) type c, " write no-zero no_convext(1) type c, edit_mask type slis_edit_mask, " emphasize(4) type c, " emphasize fix_column(1) type c, " Spalte fixieren do_sum(1) type c, " sum up no_out(1) type c, " (O)blig.(X)no out tech(1) type c, " technical field outputlen like dd03p-outputlen, offset type dd03p-outputlen, " offset seltext_l like dd03p-scrtext_l, " long key word seltext_m like dd03p-scrtext_m, " middle key word seltext_s like dd03p-scrtext_s, " short key word ddictxt(1) type c, " (S)hort (M)iddle (L)ong

32

rollname like dd03p-rollname, datatype like dd03p-datatype, inttype like dd03p-inttype, intlen like dd03p-intlen, lowercase like dd03p-lowercase, end of slis_fieldcat_main0. types: begin of slis_fieldcat_main1, ref_fieldname like dd03p-fieldname, ref_tabname like dd03p-tabname, roundfieldname type slis_fieldname, roundtabname type slis_tabname, decimalsfieldname type slis_fieldname, decimalstabname type slis_tabname, decimals_out(6) type c, " decimals in write statement text_fieldname type slis_fieldname, reptext_ddic like dd03p-reptext, " heading (ddic) ddic_outputlen like dd03p-outputlen, end of slis_fieldcat_main1. types: begin of slis_fieldcat_main. include type slis_fieldcat_main0. include type slis_fieldcat_main1. types: end of slis_fieldcat_main. types: begin of slis_fieldcat_alv_spec, key_sel(1) type c, " no_sum(1) type c, " sp_group(4) type c, " reprep(1) type c, " input(1) type c, " edit(1) type c, " hotspot(1) type c, " end of slis_fieldcat_alv_spec. types: begin of slis_fieldcat_alv. include type slis_fieldcat_main. include type slis_fieldcat_alv_spec. types: end of slis_fieldcat_alv. types: begin of slis_fieldcat_alv1. include type slis_fieldcat_main1. types: end of slis_fieldcat_alv1. types: slis_t_fieldcat_alv type slis_fieldcat_alv occurs 1. * Events for Callback types: begin of slis_event_exit. types: ucomm like sy-ucomm, before(1) type c, after(1) type c, end of slis_event_exit. types: slis_t_event_exit type slis_event_exit occurs 1. * Callback Interface structure for non display subtotals text types: begin of slis_subtot_text, criteria type slis_fieldname, keyword like dd03p-reptext, criteria_text(255) type c, max_len like dd03p-outputlen, display_text_for_subtotal(255) type c, end of slis_subtot_text. *** Layout types: begin of slis_print_alv0, field not obligatory do not sum up group specification selection for rep/rep input internal use only hotspot

33

print(1) type c, prnt_title(1) type c, end of slis_print_alv0.

" print to spool " moment to print the title

types: begin of slis_print_alv1, no_print_selinfos(1) type c, " display no selection infos no_coverpage(1) type c, " no_new_page(1) type c, " reserve_lines type i, " lines reserved for end of page no_print_listinfos(1) type c, " display no listinfos no_change_print_params(1) type c, " don't change linesize no_print_hierseq_item(1) type c, "don't expand item end of slis_print_alv1. types: begin of slis_print_alv. include type alv_s_prnt. include type slis_print_alv1. types: end of slis_print_alv. types: begin of slis_layout_main, dummy, end of slis_layout_main. types: begin of slis_layout_alv_spec0, no_colhead(1) type c, no_hotspot(1) type c, zebra(1) type c, no_vline(1) type c, cell_merge(1) type c, edit(1) type c, edit_mode(1) type c, numc_sum(1) type c, no_input(1) type c, f2code like sy-ucomm, reprep(1) type c, no_keyfix(1) type c, expand_all(1) type c, no_author(1) type c, * PF-status def_status(1) type c, item_text(20) type c, end of slis_layout_alv_spec0. " " " " " " " " " " " " " no headings headings not as hotspot striped pattern columns separated by space not suppress field replication for grid only for grid only totals for NUMC-Fields possib. only display fields " report report interface active do not fix keycolumns Expand all positions No standard authority check

" default status space or 'A' " Text for item button

types: begin of slis_layout_alv_spec1, * Display options colwidth_optimize(1) type c, no_min_linesize(1) type c, " line size = width of the list min_linesize like sy-linsz, " if initial min_linesize = 80 max_linesize like sy-linsz, " Default 250 window_titlebar like sy-title, no_uline_hs(1) type c, * Exceptions lights_fieldname type slis_fieldname," fieldname for exception lights_tabname type slis_tabname, " fieldname for exception lights_rollname like dfies-rollname," rollname f. exceptiondocu lights_condense(1) type c, " fieldname for exception * Sums no_sumchoice(1) type c, " no choice for summing up no_totalline(1) type c, " no total line no_subchoice(1) type c, " no choice for subtotals no_subtotals(1) type c, " no subtotals possible no_unit_splitting type c, " no sep. tot.lines by inh.units totals_before_items type c, " diplay totals before the items totals_only(1) type c, " show only totals totals_text(60) type c, " text for 1st col. in total line

34

* *

subtotals_text(60) type c, " text for 1st col. in subtotals Interaction box_fieldname type slis_fieldname, " fieldname for checkbox box_tabname type slis_tabname," tabname for checkbox box_rollname like dd03p-rollname," rollname for checkbox expand_fieldname type slis_fieldname, " fieldname flag 'expand' hotspot_fieldname type slis_fieldname, " fieldname flag hotspot confirmation_prompt, " confirm. prompt when leaving key_hotspot(1) type c, " keys as hotspot " K_KEYHOT flexible_key(1) type c, " key columns movable,... group_buttons(1) type c, " buttons for COL1 - COL5 get_selinfos(1) type c, " read selection screen group_change_edit(1) type c, " Settings by user for new group no_scrolling(1) type c, " no scrolling Detailed screen detail_popup(1) type c, " show detail in popup detail_initial_lines(1) type c, " show also initial lines detail_titlebar like sy-title," Titlebar for detail Display variants header_text(20) type c, " Text for header button default_item(1) type c, " Items as default colour info_fieldname type slis_fieldname, " infofield for listoutput coltab_fieldname type slis_fieldname, " colors others list_append(1) type c, " no call screen xifunckey type aqs_xikey, " eXtended interaction(SAPQuery) xidirect type flag, " eXtended INTeraction(SAPQuery) dtc_layout type dtc_s_layo, "Layout for configure the Tabstip end of slis_layout_alv_spec1.

types: begin of slis_layout_alv_spec. include type slis_layout_alv_spec0. include type slis_layout_alv_spec1. types: end of slis_layout_alv_spec. types: begin of slis_layout_alv. include type slis_layout_main. include type slis_layout_alv_spec. types: end of slis_layout_alv. types: begin of slis_layout_alv1. include type slis_layout_main. include type slis_layout_alv_spec1. types: end of slis_layout_alv1. *--- Structure for the excluding table (function codes) types: begin of slis_extab, fcode like rsmpe-func, end of slis_extab. *--- Lineinfo before output types: begin of slis_lineinfo, tabname type slis_tabname, tabindex like sy-tabix, subtot(1) type c, subtot_level(2) type n, endsum(1) type c, sumindex like sy-tabix, linsz like sy-linsz, linno like sy-linno, end of slis_lineinfo. *--- Structure for scrolling in list types: begin of slis_list_scroll, lsind like sy-lsind, cpage like sy-cpage,

35

staro like sy-staro, staco like sy-staco, cursor_line like sy-curow, cursor_offset like sy-cucol, end of slis_list_scroll. * information cursor position ALV types: begin of slis_selfield, tabname type slis_tabname, tabindex like sy-tabix, sumindex like sy-tabix, endsum(1) type c, sel_tab_field type slis_sel_tab_field, value type slis_entry, before_action(1) type c, after_action(1) type c, refresh(1) type c, ignore_multi(1) type c, " ignore selection by checkboxes (F2) col_stable(1) type c, row_stable(1) type c, * colwidth_optimize(1) type c, exit(1) type c, fieldname type slis_fieldname, grouplevel type i, collect_from type i, collect_to type i, end of slis_selfield. *--- excluding table types: slis_t_extab type slis_extab occurs 1. * special groups for column selection types: begin of slis_sp_group_alv, sp_group(4) type c, text(40) type c, end of slis_sp_group_alv. types: slis_t_sp_group_alv type slis_sp_group_alv occurs 1. * information for sort and subtotals types: begin of slis_sortinfo_alv, * spos(2) type n, spos like alvdynp-sortpos, fieldname type slis_fieldname, tabname type slis_fieldname, * up(1) type c, * down(1) type c, * group(2) type c, * subtot(1) type c, up like alvdynp-sortup, down like alvdynp-sortdown, group like alvdynp-grouplevel, subtot like alvdynp-subtotals, comp(1) type c, expa(1) type c, obligatory(1) type c, end of slis_sortinfo_alv. types: slis_t_sortinfo_alv type slis_sortinfo_alv occurs 1. * information for selections types: begin of slis_seldis1_alv, field like dfies-fieldname, table like dfies-tabname, stext(40), valuf(80), valut(80), sign0(1), optio(2), ltext(40),

36

stype(1), length type p, no_text(1), inttype like dfies-inttype, fieldname type slis_fieldname, tabname type slis_tabname, org_selname type rsscr_name, "introduced this FO 09.01.00 end of slis_seldis1_alv. types: slis_seldis_alv type slis_seldis1_alv occurs 1. * filter types: begin of slis_filter_alv0, fieldname type slis_fieldname, tabname type slis_tabname, seltext(40), valuf(80), valut(80), valuf_int(80), valut_int(80), sign0(1), sign_icon(4), optio(2), stype(1), decimals like dfies-decimals, intlen like dfies-intlen, convexit like dfies-convexit, edit_mask type slis_edit_mask, lowercase like dfies-lowercase, inttype like dfies-inttype, datatype like dfies-datatype, exception(1) type c, no_sign(1) type c, or(1) type c, order type order, cqvalue(5) type c, end of slis_filter_alv0. types: begin of slis_filter_alv1, ref_fieldname like dfies-fieldname, ref_tabname like dfies-tabname, ddic_outputlen like dfies-outputlen, end of slis_filter_alv1. types: begin of slis_filter_alv. include type slis_filter_alv0. include type slis_filter_alv1. types: end of slis_filter_alv. types: slis_t_filter_alv type slis_filter_alv occurs 1. * delete or add an entry in the select-option info types: begin of slis_selentry_hide_alv, mode(1) type c, "(D)elete (A)dd selname like rsparams-selname. include type slis_seldis1_alv. types end of slis_selentry_hide_alv. types: slis_t_selentry_hide_alv type slis_selentry_hide_alv occurs 1. * delete or add an entry in the select-option info types: begin of slis_sel_hide_alv, mode(1) type c, "(R)eplace or (C)hange t_entries type slis_t_selentry_hide_alv, end of slis_sel_hide_alv. * Header table for top of page types: begin of slis_listheader,

37

typ(1) type c, " H = Header, S = Selection, A = Action key(20) type c, info type slis_entry, end of slis_listheader. types: slis_t_listheader type slis_listheader occurs 1. *--- Structure for specific color settings types: begin of slis_specialcol_alv, fieldname type slis_fieldname, color type slis_color, nokeycol(1) type c, end of slis_specialcol_alv. types: slis_t_specialcol_alv type slis_specialcol_alv occurs 1. *--- Structure for event handling types: begin of slis_alv_event, name(30), form(30), end of slis_alv_event. types: slis_t_event type slis_alv_event occurs 0. *--- Structure for key information types: begin of slis_keyinfo_alv, header01 type slis_fieldname, item01 type slis_fieldname, header02 type slis_fieldname, item02 type slis_fieldname, header03 type slis_fieldname, item03 type slis_fieldname, header04 type slis_fieldname, item04 type slis_fieldname, header05 type slis_fieldname, item05 type slis_fieldname, end of slis_keyinfo_alv. *--- Structure for callback CALLER_EXIT and REUSE_ALV_POPUP_TO_SELECT types: begin of slis_data_caller_exit, dummy like sy-repid, without_load_variant(1), callback_header_transport type slis_formname, columnopt(1), end of slis_data_caller_exit. types: begin of slis_status, callback_program like sy-repid, callback_pf_status_set type slis_formname, callback_user_command type slis_formname, counter_of_lists_added type i, actual_list_to_display type i, flg_to_be_refreshed, it_excluding type slis_t_extab, print type slis_print_alv, flg_checkboxes_active, flg_overview_active, flg_intcheck(1) type c, end of slis_status. * Exporting structure types: begin of slis_exit_by_user, back(1) type c, exit(1) type c, cancel(1) type c, end of slis_exit_by_user. constants: * Events slis_ev_item_data_expand type slis_formname value 'ITEM_DATA_EXPAND', slis_ev_reprep_sel_modify type slis_formname value 'REPREP_SEL_MODIFY', slis_ev_caller_exit_at_start type slis_formname value 'CALLER_EXIT', slis_ev_user_command type slis_formname value 'USER_COMMAND',

38

slis_ev_top_of_page type slis_formname value 'TOP_OF_PAGE', slis_ev_data_changed type slis_formname value 'DATA_CHANGED', slis_ev_top_of_coverpage type slis_formname value 'TOP_OF_COVERPAGE', slis_ev_end_of_coverpage type slis_formname value 'END_OF_COVERPAGE', slis_ev_foreign_top_of_page type slis_formname value 'FOREIGN_TOP_OF_PAGE', slis_ev_foreign_end_of_page type slis_formname value 'FOREIGN_END_OF_PAGE', slis_ev_pf_status_set type slis_formname value 'PF_STATUS_SET', slis_ev_list_modify type slis_formname value 'LIST_MODIFY', slis_ev_top_of_list type slis_formname value 'TOP_OF_LIST', slis_ev_end_of_page type slis_formname value 'END_OF_PAGE', slis_ev_end_of_list type slis_formname value 'END_OF_LIST', slis_ev_after_line_output type slis_formname value 'AFTER_LINE_OUTPUT', slis_ev_before_line_output type slis_formname value 'BEFORE_LINE_OUTPUT', slis_ev_subtotal_text type slis_formname value 'SUBTOTAL_TEXT'.

39

Appendix

How to colour lines of a report


1. Include a 4-character field in the internal data table that is being passed to REUSE_ALV_GRID_DISPLAY. Eg: DATA: BEGIN OF i_data OCCURS 10, qmnum LIKE viqmel-qmnum, qmart LIKE viqmel-qmart, zzvalstat LIKE viqmel-zzvalstat, valstattxt LIKE zawprcode-valstattxt, kunum LIKE viqmel-kunum, bstnk LIKE viqmel-bstnk, qmtxt LIKE viqmel-qmtxt, ws_color(4)Type c, END OF i_data. 2. In the code, loop through the lines of the internal table and assign values to this field. The 4character value will be of the format - Cxyz. Char 1 is always C indicating that its a color property. Char 2 (x) color code, which can be any value from (1 7). Char 3 (y) Intensity on/off. (1 = on, 0 = off). Char 4 (z) Inverse display on/off. (1 = on, 0 = off). (From the above, it is clear that we can have only 28 different coloring options) Eg: C401. LOOP AT i_data. IF (expression 1). i_data-ws_color = C510. ELSEIF(expression 2). i_data-ws_color = C200. ELSE. i_data-ws_color = C711. ENDIF. MODIFY i_data. ENDLOOP. 3. When specifying the layout properties, specify the name of this field (ws_color) as the color field. FORM f1200_define_layout CHANGING p_i_layout TYPE slis_layout_alv. CLEAR p_i_layout. p_i_layout-zebra = 'X'. p_i_layout-colwidth_optimize = 'X'.

40

p_i_layout-info_fieldname = 'WS_COLOR'. ENDFORM. " F1200_define_layout

Example:
Shown below is screen dump with 14 coloring options. You could try out the rest 14!!

Code: LOOP AT i_data. cnt = cnt + 1. IF cnt = 1. i_data-ws_color = 'C110'. ELSEIF cnt = 2. i_data-ws_color = 'C210'. ELSEIF cnt = 3. i_data-ws_color = 'C310'. ELSEIF cnt = 4. i_data-ws_color = 'C410'. ELSEIF cnt = 5. i_data-ws_color = 'C510'. ELSEIF cnt = 6. i_data-ws_color = 'C610'. ELSEIF cnt = 7. i_data-ws_color = 'C710'.

elseIF cnt = 8. i_data-ws_color = 'C100'. ELSEIF cnt = 9. i_data-ws_color = 'C200'. ELSEIF cnt = 10 i_data-ws_color = 'C300'. ELSEIF cnt = 11. i_data-ws_color = 'C400'. ELSEIF cnt = 12. i_data-ws_color = 'C500'. ELSEIF cnt = 13. i_data-ws_color = 'C600'. ELSEIF cnt = 14. i_data-ws_color = 'C700'. ENDIF. MODIFY i_data. ENDLOOP.

41

42

You might also like