Professional Documents
Culture Documents
Ooalv Notes With Programs (1) Santosh
Ooalv Notes With Programs (1) Santosh
Ooalv Notes With Programs (1) Santosh
1) Using classes
2) Using function module
ALV reports are used for displaying data in the form of the table as part of the we use the
following classes.
1) CL_GUI_ALV_GRID
2) CL_GUI_CUSTOM_CONTAINER
3) CL_GUI_CONTAINER
4) CL_GUI_SIMPLE_TREE
5) CL_GUI_PICTURE
6) CL_GUI_DOCKING_CONTAINER
7) CL_DD_DOCUMENT
8) CL_GUI_SPLITTER_CONTAINER
As part of the ALV reporting we need to develop the ALV grid which is display on top of a custom
control.
ALV grid cannot recognize custom control on its own it required an interface. These interfaces are
provided in the form of a standard class.
ALV GRID
CUSTOM CONTROL
1|Pa g e Santosh P
CUSTOM CONTROL CONTAINER ALV GRID
Example1: -
4970 4972 10 M1
4971 4972 20 M2
4972 4972 30 M3
Material Number M2
To display an internal table data in the grid we need to use the instance method
'SET_TABLE_FOR_FIRST_DISPLAY of the class CL_GUI_ALV_GRID. This method
contains only one mandatory parameter IT_OUTTAB which expects internal table of output.
2|Pa g e Santosh P
While displaying the internal table data in the ALV grid we need to generate the field catalog for
the field, if the field catalog is not specified if result in ABORT error field catalog is not found.
1) Function modules
2) Manually
Field catalog is an object which stores the information of the fields like field name, field position,
field label, etc. once the field catalog is generated we need to pass the field catalog object as on
input to the parameter IT_FIELDCATALOG of the method
SET_TABLE_FOR_TABLE_DISPLAY.
LVC_T_FCAT is a table type used for generating the field catalog this table type is associated
with the structure LVC_S_FCAT.
Note: - To display an ALV column and hotspot we need to set the field hotspot as part of field
catalog generation.
HOTSPOT_CLICK: -
REFRESH_TABLE_DISPLAY: -
Is an instance method of the class CL_GUI_ALV_GRID used for refresh the ALV grid with
the latest internal table data.
DOUDLE_CLICK: -
REPORT Z9AM_ALV1.
tables : vbak.
3|Pa g e Santosh P
types : begin of ty_vbap,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
end of ty_vbap.
4|Pa g e Santosh P
importing ES_ROW_NO.
endclass.
method handle_double_click.
read table lt_vbap into ls_vbap
index e_row-index.
if sy-subrc eq 0.
perform get_mara.
if ls_mara is not initial.
perform fldcat_mara.
perform layout_mara.
call screen 300.
endif.
endif.
endmethod.
method handle_button_click.
read table lt_mara into ls_mara
index es_row_no-row_id.
if sy-subrc eq 0.
set parameter id 'MAT' FIELD ls_mara-matnr.
call transaction 'MM02'.
endif.
endmethod.
endclass.
initialization.
so_vbeln-low = '4970'.
so_vbeln-high = '4975'.
append so_vbeln.
start-of-selection.
call screen 100.
5|Pa g e Santosh P
module link output.
if vbak_cont is initial.
set pf-status 'ABC'.
perform get_vbak.
if lt_vbak[] is not initial.
perform fldcat_vbak.
perform layout_vbak.
perform register_handlers.
perform display_vbak.
endif.
endif.
endmodule.
form get_vbak .
select vbeln erdat erzet ernam
from vbak
into table lt_vbak
where vbeln in so_vbeln.
endform. " get_vbak
form display_vbak .
CALL METHOD vbak_grid->set_table_for_first_display
EXPORTING
IS_LAYOUT = ls_layo
CHANGING
it_outtab = lt_vbak[]
IT_FIELDCATALOG = lt_fcat[].
endform. " display_vbak
form fldcat_vbak .
clear ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Sales Document'.
ls_fcat-outputlen = 12.
ls_fcat-tooltip = 'Sales Doc'.
ls_fcat-hotspot = 'X'.
append ls_fcat to lt_fcat.
6|Pa g e Santosh P
clear ls_fcat.
ls_fcat-fieldname = 'ERDAT'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Creation date'.
ls_fcat-outputlen = 12.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ERZET'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Creation Time'.
ls_fcat-outputlen = 12.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'ERNAM'.
ls_fcat-col_pos = 4.
ls_fcat-coltext = 'Created by'.
ls_fcat-outputlen = 12.
append ls_fcat to lt_fcat.
form layout_vbak .
clear ls_layo.
ls_layo-grid_title = 'Sales Document Header data'.
ls_layo-zebra = 'X'.
endform. " layout_vbak
form register_handlers .
create object ob.
set handler ob->handle_hotspot_click
for vbak_grid.
endform. " register_handlers
7|Pa g e Santosh P
form get_vbap .
select vbeln posnr matnr
from vbap
into table lt_vbap
where vbeln = ls_vbak-vbeln.
endform. " get_vbap
form fldcat_vbap .
refresh lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Sales Document'.
ls_fcat-outputlen = 11.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'POSNR'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Item Number'.
ls_fcat-outputlen = 6.
append ls_fcat to lt_fcat.
clear ls_fcat.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Material'.
ls_fcat-outputlen = 12.
append ls_fcat to lt_fcat.
form layout_vbap .
clear ls_layo.
ls_layo-grid_title = 'SALES Document Item data'.
ls_layo-zebra = 'X'.
endform. " layout_vbap
8|Pa g e Santosh P
set handler ob->handle_double_click
for vbap_grid.
perform display_vbap.
else.
CALL METHOD vbap_grid->refresh_table_display.
endif.
form display_vbap .
CALL METHOD vbap_grid->set_table_for_first_display
EXPORTING
IS_LAYOUT = ls_layo
CHANGING
it_outtab = lt_vbap[]
IT_FIELDCATALOG = lt_fcat[].
form get_mara .
select single matnr mtart matkl
from mara
into ls_mara
where matnr = ls_vbap-matnr.
if sy-subrc eq 0.
refresh lt_mara.
append ls_mara to lt_mara.
endif.
endform. " get_mara
form fldcat_mara .
refresh lt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZMARA2'
CHANGING
ct_fieldcat = lt_fcat[].
9|Pa g e Santosh P
modify lt_fcat from ls_fcat
transporting style.
endif.
endloop.
endif.
form layout_mara .
clear ls_layo.
ls_layo-grid_title = 'MATERIAL DATA'.
endform. " layout_mara
form display_mara .
CALL METHOD mara_grid->set_table_for_first_display
EXPORTING
IS_LAYOUT = ls_layo
CHANGING
it_outtab = lt_mara
IT_FIELDCATALOG = lt_fcat.
perform display_mara.
else.
CALL METHOD mara_grid->refresh_table_display.
endif.
endmodule. " linkmara OUTPUT
10 | P a g e Santosh P
CL_GUI_SPLITTER_CONTAINER: -
CUSTOM SPLITTER
CUSTOM CONTROL CONTAINER CONTAINER
CONTAINER1
CONTAINER2
CONTAINER3
CONTAINER4
PHYSICAL CL_GUI_CUSTOM_ CL_GUI_SPLITTER_
CONTROL CONTAINER CONTAINER CL_GUI_CONTAINER
Example 2: -
TOP OF PAGE HEADING
4970
4971
4972
4972 10 M1
4972 20 M2
4972 30 M3
After splitting the container into different of panes each pane should be assigned with height and
column width for setting the row height we need to use the instance method SET_ROW_HEIGHT
and column width SET_COLUMN_WIDTH of the class CL_GUI_SPLITTER_CONTAINER
after this we need to associated each pane of a container with container object.
To display an ALV column as a button we need to set the field STYLE as part of field catalog
generation. The value of these type fields are represented by the constant attribute of class
CL_GUI_ALV_GRID these constant attribute can we access by using the class name and the
starts with the naming conversion MC_STYLE.
11 | P a g e Santosh P
BUTTON_CLICK: -
TOP-OF-PAGE: -
TOP-OF-PAGE event is not triggered by default it must be register explicitly by calling the
instance method LIST_PROCESSING_EVENT.
REPORT Z915AM_ALV2.
TABLES VBAK.
SELECT-OPTIONS SO_VBELN FOR VBAK-VBELN.
12 | P a g e Santosh P
DATA LS_LAYO TYPE LVC_S_LAYO.
METHOD HANDLE_TOP_OF_PAGE.
13 | P a g e Santosh P
CALL METHOD E_DYNDOC_ID->NEW_LINE
EXPORTING
REPEAT = 1.
START-OF-SELECTION.
CALL SCREEN 100.
14 | P a g e Santosh P
CALL METHOD O_SPLIT->GET_CONTAINER
EXPORTING
ROW =1
COLUMN = 1
RECEIVING
CONTAINER = O_CONT1.
PERFORM GETVBAK.
IF LT_VBAK[] IS NOT INITIAL.
PERFORM FLDCATVBAK.
PERFORM LAYOUTVBAK.
PERFORM DISPLAYVBAK.
ENDIF.
ENDIF.
FORM GETVBAK .
SELECT VBELN ERDAT ERZET
FROM VBAK
INTO TABLE LT_VBAK
WHERE VBELN IN SO_VBELN.
ENDFORM. " getvbak
15 | P a g e Santosh P
FORM FLDCATVBAK .
REFRESH LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'VBELN'.
LS_FCAT-COL_POS = 1.
LS_FCAT-COLTEXT = 'Sales Doc'.
LS_FCAT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'ERDAT'.
LS_FCAT-COL_POS = 2.
LS_FCAT-COLTEXT = 'creation date'.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'ERZET'.
LS_FCAT-COL_POS = 3.
LS_FCAT-COLTEXT = 'Creation time'.
APPEND LS_FCAT TO LT_FCAT.
ENDFORM. " fldcatvbak
FORM LAYOUTVBAK .
CLEAR LS_LAYO.
LS_LAYO-GRID_TITLE = 'SALES DOCUMENT HEADER DATA'.
ENDFORM. " layoutvbak
FORM DISPLAYVBAK .
CREATE OBJECT VBAK_GRID
EXPORTING
I_PARENT = O_CONT2.
16 | P a g e Santosh P
FORM GETVBAP .
SELECT VBELN POSNR MATNR
FROM VBAP
INTO TABLE LT_VBAP
WHERE VBELN = LV_VBELN.
ENDFORM. " getvbap
FORM FLDCATVBAP .
REFRESH LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'VBELN'.
LS_FCAT-COL_POS = 1.
LS_FCAT-COLTEXT = 'Sales doc'.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'POSNR'.
LS_FCAT-COL_POS = 2.
LS_FCAT-COLTEXT = 'Item No'.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'MATNR'.
LS_FCAT-COL_POS = 3.
LS_FCAT-COLTEXT = 'Material'.
APPEND LS_FCAT TO LT_FCAT.
ENDFORM. " fldcatvbap
FORM LAYOUTVBAP .
CLEAR LS_LAYO.
LS_LAYO-GRID_TITLE = 'SALES DOCUMENT ITEM DATA'.
ENDFORM. " layoutvbap
FORM DISPLAYVBAP .
IF VBAP_GRID IS INITIAL.
CREATE OBJECT VBAP_GRID
EXPORTING
I_PARENT = O_CONT3.
17 | P a g e Santosh P
TREE AND PICTURE CONTROLS: -
Transaction
Sales Order
o Create Sales Order COMPANY LOGO
o Change Sales Order
Purchase Order
o Create Purchase Order
o Change Purchase Order ALV GRID
(FIELD CATALOG WITH FUNCTION MODULE)
This function module take object ID and return URL of the picture this URL is of type
CNDP_URL which is type declaration declared in the type group CNDP.
2) Call the instance method load picture for URL of the class CL_GUI_PICTURE of this method
takes the URL as input and displays the picture in the container.
1) To add the nodes to a tree structure it use the instance method ADD_NODES of the class
CL_GUI_SIMPLE_TREE this method takes the following parameters.
TABLE_STRUCTURE_NAME
1) It holds the structure name representing the node structure of a simple tree this structure is
ABDEMONODE.
Every node in a tree is associated with a node key it used for indentifying the node which
selected on a tree.
18 | P a g e Santosh P
NODE_DOUBLE_CLICK is the instance event of a class CL_GUI_SIMPLE_TREE it
is triggered whenever a node item is double click.
To make the ALV column as editable in runtime we need to set the field EDIT as part of
field catalog generation.
Whenever the user modifies ALV cell values in runtime and to reflect to change in data
base table we need to handle the event HANDLE_DATA_CHANGED of the class
CL_GUI_ALU_GRID this event is triggered enter key in the modified cell.
As part of the above class we need to use instance attribute MT_MOD_CELLS (OR)
MT_GOODS_CELLS which are of type LVC_T_MODI. It is table type associated
with the structure LVC_S_MODI.
These attributes contains a information related to be modified cell the information include
row id, field name, and value.
To exclude the standard ALV toolbar buttons we need set the parameter
IT_TOOLBAR_EXCLUDING as part of method call SET_TABLE_FOR_FIRST_DISPLAY
this parameter of an internal table of type UI_FUNCTION this internal will hold the function code
of the puss button that needs to be excluded.
19 | P a g e Santosh P
ENABLING / DISABLING STANDARD ALV TOOLBAR BUTTONS: -
For this we need to handle toolbar event of the class CL_GUI_ALV_GRID this event is
triggered whenever an ALV GRID is displayed.
As part of the event toolbar we need to import the parameter E_OBJECT, Which is the
object of a class CL_GUI_EVENT_TOOLBAR_SET this class contains an instance
attribute MT_TOOLBAR these attribute of an internal table of type TTB_BUTTON it is
associated with the structure STB_BUTTON this attribute internal table holds the
information of the ALV toolbar buttons.
MENU_BUTTON: -
Note: - Whenever we click on menu items of menu button normal push buttons (or) ALV toolbar
SAP triggers the following event one after the other.
BEFORE_USER_COMMAND
USER_COMMAND
AFTER_USER_COMMAND
To identifying the selected rows in the ALV grid we need to use the instance method
GET_SELECTED_ROWS of the class CL_GUI_ALV_GRID, this method return the indexes of
the selected rows on the grid.
REPORT Z915AM_ALV3.
TYPE-POOLS : CNDP,CNTL.
20 | P a g e Santosh P
TYPES : BEGIN OF TY_NODES.
INCLUDE STRUCTURE ABDEMONODE.
TYPES END OF TY_NODES.
21 | P a g e Santosh P
METHODS HANDLE_USER_COMMAND
FOR EVENT USER_COMMAND
OF CL_GUI_ALV_GRID
IMPORTING E_UCOMM.
METHODS HANDLE_AFTER_USER_COMMAND
FOR EVENT AFTER_USER_COMMAND
OF CL_GUI_ALV_GRID.
ENDCLASS.
METHOD HANDLE_DATA_CHANGED.
DATA LS_MODI TYPE LVC_S_MODI.
READ TABLE ER_DATA_CHANGED->MT_MOD_CELLS
INTO LS_MODI INDEX 1.
IF SY-SUBRC EQ 0.
READ TABLE LT_DEPT INTO LS_DEPT
INDEX LS_MODI-ROW_ID.
IF SY-SUBRC EQ 0.
LS_DEPT-LOC = LS_MODI-VALUE.
MODIFY TABLE LT_DEPT FROM LS_DEPT
TRANSPORTING LOC.
UPDATE Z730CDEPT
SET LOC = LS_MODI-VALUE
WHERE DEPTNO = LS_DEPT-DEPTNO.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD HANDLE_TOOLBAR.
* loop at e_object->mt_toolbar into ls_toolbar.
* if ls_toolbar-function = cl_gui_alv_grid=>mc_fc_loc_insert_row.
* ls_toolbar-disabled = 'X'.
* modify e_object->mt_toolbar
* from ls_toolbar
* transporting disabled.
* endif.
* endloop.
22 | P a g e Santosh P
* procedure 2 for disabling/enabling buttons
CLEAR LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'P2'.
LS_TOOLBAR-ICON = '@17@'.
LS_TOOLBAR-QUICKINFO = 'This is Button2'.
LS_TOOLBAR-BUTN_TYPE = 3.
LS_TOOLBAR-DISABLED = ' ' .
LS_TOOLBAR-TEXT = 'Button2'.
LS_TOOLBAR-CHECKED = ' '.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'P3'.
LS_TOOLBAR-ICON = '@16@'.
LS_TOOLBAR-QUICKINFO = 'This is Button3'.
LS_TOOLBAR-BUTN_TYPE = 2.
LS_TOOLBAR-DISABLED = ' ' .
LS_TOOLBAR-TEXT = 'Button3'.
LS_TOOLBAR-CHECKED = ' '.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
ENDMETHOD.
METHOD HANDLE_MENU_BUTTON.
CASE E_UCOMM.
WHEN 'P3'.
CALL METHOD E_OBJECT->ADD_FUNCTION
23 | P a g e Santosh P
EXPORTING
FCODE = 'MI1'
TEXT = 'Menu item1'.
METHOD HANDLE_BEFORE_USER_COMMAND.
* message 'Before user command' type 'I'.
ENDMETHOD.
METHOD HANDLE_USER_COMMAND.
CASE E_UCOMM.
WHEN 'P1'.
REFRESH LT_ROWS.
CALL METHOD O_GRID->GET_SELECTED_ROWS
IMPORTING
ET_INDEX_ROWS = LT_ROWS[].
METHOD HANDLE_AFTER_USER_COMMAND.
* message 'After user command' type 'I'.
ENDMETHOD.
ENDCLASS.
24 | P a g e Santosh P
CREATE OBJECT O_SPLIT1
EXPORTING
PARENT = CUST_CONT
ROWS =1
COLUMNS = 2.
25 | P a g e Santosh P
RECEIVING
CONTAINER = O_CONT3.
PERFORM PICTURE.
PERFORM TREE.
PERFORM DEPTGRID.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
* MODULE USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form picture
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM PICTURE .
DATA PIC_URL TYPE CNDP_URL.
26 | P a g e Santosh P
CALL METHOD O_PIC->LOAD_PICTURE_FROM_URL
EXPORTING
URL = PIC_URL.
FORM TREE .
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'ROOT'.
LS_NODES-ISFOLDER = 'X'.
LS_NODES-EXPANDER = 'X'.
LS_NODES-TEXT = 'Transactions'.
APPEND LS_NODES TO LT_NODES.
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'SO'.
LS_NODES-RELATKEY = 'ROOT'.
LS_NODES-ISFOLDER = 'X'.
LS_NODES-EXPANDER = 'X'.
LS_NODES-TEXT = 'Sales order'.
APPEND LS_NODES TO LT_NODES.
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'CSO'.
LS_NODES-RELATKEY = 'SO'.
LS_NODES-N_IMAGE = '@15@'.
LS_NODES-TEXT = 'Create Sales order'.
APPEND LS_NODES TO LT_NODES.
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'CHSO'.
LS_NODES-RELATKEY = 'SO'.
LS_NODES-N_IMAGE = '@15@'.
LS_NODES-TEXT = 'Change Sales order'.
APPEND LS_NODES TO LT_NODES.
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'PO'.
LS_NODES-RELATKEY = 'ROOT'.
LS_NODES-ISFOLDER = 'X'.
LS_NODES-EXPANDER = 'X'.
LS_NODES-TEXT = 'Purchase order'.
APPEND LS_NODES TO LT_NODES.
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'CPO'.
LS_NODES-RELATKEY = 'PO'.
LS_NODES-N_IMAGE = '@15@'.
LS_NODES-TEXT = 'Create PO'.
APPEND LS_NODES TO LT_NODES.
27 | P a g e Santosh P
CLEAR LS_NODES.
LS_NODES-NODE_KEY = 'CHPO'.
LS_NODES-RELATKEY = 'PO'.
LS_NODES-N_IMAGE = '@15@'.
LS_NODES-TEXT = 'Change PO'.
APPEND LS_NODES TO LT_NODES.
FORM DEPTGRID .
CREATE OBJECT O_GRID
EXPORTING
I_PARENT = O_CONT4.
28 | P a g e Santosh P
CALL METHOD O_GRID->REGISTER_EDIT_EVENT
EXPORTING
* I_EVENT_ID = cl_gui_alv_grid=>MC_EVT_ENTER.
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
FORM FLDCAT .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'Z730CDEPT'
CHANGING
CT_FIELDCAT = LT_FCAT[].
FORM DISPLAY .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IT_TOOLBAR_EXCLUDING = LT_FUNCTIONS[]
CHANGING
IT_OUTTAB = LT_DEPT[]
IT_FIELDCATALOG = LT_FCAT[].
ENDFORM. " display
FORM EXCLUDEBUTTONS .
CLEAR LV_FUNCTION.
LV_FUNCTION = CL_GUI_ALV_GRID=>MC_FC_FIND.
APPEND LV_FUNCTION TO LT_FUNCTIONS.
CLEAR LV_FUNCTION.
LV_FUNCTION = CL_GUI_ALV_GRID=>MC_FC_PRINT.
APPEND LV_FUNCTION TO LT_FUNCTIONS.
ENDFORM. excludebuttons
29 | P a g e Santosh P
BACKGROUND SCHEDULING OF ALV GRID: -
Steps
SM37-> Z915AM_ALV4
|
EXECUTE
Whenever an ALV reports uses custom control in the screen the reports cannot scheduled in the
background process because the background processor cannot recognized custom control, so if the
custom control is not used we cannot use custom container in this case we need to use docking
container.
Docking container cannot recognize custom control docking container is represented by the class
CL_GUI_CONTAINER.
To recognize whether the ALV report is in background error in foreground executed we need to use
the static method offline of the CL_GUI_ALV_GRID, this method returns ZERO if it is
foreground execution otherwise NON-ZERO value if it background execution.
30 | P a g e Santosh P
DIPLAYING TRAFFIC LIGHTS IN ALV GRID: -
Traffic light in the ALV grid represents the significant of the row this column is always
assed in first column in ALV grid.
We need not explicitly generate the field catalog for the traffic light column.
Before displaying the ALV grid loop final internal table and the value of traffic light
column based on a condition.
As part of layout generation we need to the field EXCP_FNAME, the value of this field
should be the name of the additional column.
Taken additional column in the final internal table it should be a char size 4.
Before displaying the ALV grid to the final internal table and the appropriate column
coding form the additional column.
As part of layout generation the set the field INFO_FNAME the value of this field
should be the name of the additional column.
Generate the field catalog for the additional column ad part of field catalog generation
assign a numeric value to the field DRDN_HNDL.
To prepare and associate the list of value to the drop down column calls the instance
method SET_DROP_DOWN_TABLE of the class CL_GUI_ALV_GRID.
F1 HELP: -
To provide custom F1 help for an ALV column we can specify into two waves.
By attaching the custom help to the field at the data element level.
To attach standard F1 help for an ALV column we need to set the fields
REF_TABLE REF_FIELD as part of field catalog generation.
31 | P a g e Santosh P
ONF4 EVENT: -
We can associate the standard F4 help for an ALV column for setting the fields REF_FIELD
REF_TABLE as part of field catalog generation, to associate the custom F4 help we need to
handle the event ONF4 of the class CL_GUI_ALV_GRID.
By default ONF4 event is not triggered it must be register explicitly by calling the instance
method REGISTER_F4_FOR_FIELDS of the class CL_GUI_ALV_GRID.
*&---------------------------------------------------------------------*
*& Report Z915AM_ALV4
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z915AM_ALV4.
TABLES VBAK.
32 | P a g e Santosh P
DATA : LT_F4 TYPE LVC_T_F4,
LS_F4 TYPE LVC_S_F4.
METHOD HANDLE_ONF4.
CASE E_FIELDNAME.
WHEN 'ERDAT'.
MESSAGE 'onf4 for erdat' TYPE 'I'.
WHEN 'ERNAM'.
MESSAGE 'onf4 for ernam' TYPE 'I'.
ENDCASE.
ENDMETHOD.
ENDCLASS.
INITIALIZATION.
SO_VBELN-LOW = '4970'.
SO_VBELN-HIGH = '4975'.
APPEND SO_VBELN.
START-OF-SELECTION.
CALL SCREEN 100.
33 | P a g e Santosh P
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ABC'.
MODE = CL_GUI_ALV_GRID=>OFFLINE( ).
IF MODE EQ 0.
IF O_CONT IS INITIAL.
PERFORM GETDATA.
IF LT_VBAK[] IS NOT INITIAL.
PERFORM FLDCAT.
PERFORM LAYOUT.
PERFORM TRAFFICLIGHTS_COLOR.
PERFORM DROPDOWN.
PERFORM REGISTER.
PERFORM DISPLAY.
ENDIF.
FORM GETDATA .
SELECT VBELN ERDAT ERNAM
FROM VBAK
INTO CORRESPONDING FIELDS OF TABLE LT_VBAK
WHERE VBELN IN SO_VBELN.
ENDFORM. " getdata
FORM FLDCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'SEL'.
LS_FCAT-COL_POS = 1.
LS_FCAT-COLTEXT = 'Selection'.
LS_FCAT-EDIT = 'X'.
LS_FCAT-CHECKBOX = 'X'.
APPEND LS_FCAT TO LT_FCAT.
34 | P a g e Santosh P
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'COURSE'.
LS_FCAT-COL_POS = 2.
LS_FCAT-COLTEXT = 'Course Name'.
LS_FCAT-DRDN_HNDL = 25.
LS_FCAT-EDIT = 'X'.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'VBELN'.
LS_FCAT-COL_POS = 3.
LS_FCAT-COLTEXT = 'Sales Doc'.
LS_FCAT-REF_TABLE = 'VBAK'.
LS_FCAT-REF_FIELD = 'VBELN'.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'ERDAT'.
LS_FCAT-COL_POS = 4.
LS_FCAT-COLTEXT = 'Creation date'.
LS_FCAT-F4AVAILABL = 'X'.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'ERNAM'.
LS_FCAT-COL_POS = 5.
LS_FCAT-COLTEXT = 'Created By'.
LS_FCAT-F4AVAILABL = 'X'.
APPEND LS_FCAT TO LT_FCAT.
35 | P a g e Santosh P
FORM DISPLAY .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = LS_LAYO
CHANGING
IT_OUTTAB = LT_VBAK[]
IT_FIELDCATALOG = LT_FCAT[].
ENDFORM. " display
FORM TRAFFICLIGHTS_COLOR.
LOOP AT LT_VBAK INTO LS_VBAK.
IF LS_VBAK-ERDAT = '19970121'.
LS_VBAK-LIGHTS = '1'.
LS_VBAK-COLOR = 'C510'.
ELSEIF LS_VBAK-ERDAT = '19970107'.
LS_VBAK-LIGHTS = '2'.
LS_VBAK-COLOR = 'C103'.
ELSE.
LS_VBAK-LIGHTS = '3'.
LS_VBAK-COLOR = 'C114'.
ENDIF.
MODIFY LT_VBAK FROM LS_VBAK
TRANSPORTING LIGHTS COLOR.
ENDLOOP.
ENDFORM. " trafficlights
FORM DROPDOWN .
CLEAR LS_DROP.
LS_DROP-HANDLE = 25.
LS_DROP-VALUE = 'CORE ABAP'.
APPEND LS_DROP TO LT_DROP.
CLEAR LS_DROP.
LS_DROP-HANDLE = 25.
LS_DROP-VALUE = 'OOPS ABAP'.
APPEND LS_DROP TO LT_DROP.
CLEAR LS_DROP.
LS_DROP-HANDLE = 25.
LS_DROP-VALUE = 'CROSS APPS'.
APPEND LS_DROP TO LT_DROP.
36 | P a g e Santosh P
CALL METHOD O_GRID->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN = LT_DROP[].
FORM REGISTER .
CREATE OBJECT OB.
SET HANDLER OB->HANDLE_ONF1 FOR O_GRID.
SET HANDLER OB->HANDLE_ONF4 FOR O_GRID.
CLEAR LS_F4.
LS_F4-FIELDNAME = 'ERNAM'.
LS_F4-REGISTER = 'X'.
* append ls_f4 to lt_f4.
INSERT LS_F4 INTO TABLE LT_F4.
CLEAR LS_F4.
LS_F4-FIELDNAME = 'ERDAT'.
LS_F4-REGISTER = 'X'.
INSERT LS_F4 INTO TABLE LT_F4.
37 | P a g e Santosh P
ALV USING FUNCTION MOUDLES: -
As part of this we use the following function module to display the ALV grid.
1) REUSE_ALV_GRID_DISPLAY
2) REUSE_ALV_LIST_DISPLAY
i. SIMPLE ALV
ii. INTERACTIVE ALV
iii. BLOCKED ALV
iv. HIERARCHICAL ALV
While calling the function module REUSE_ALV_GRID_DISPLAY we need to call field catalog
otherwise it need to abort error.
Instead of passing the field catalog we can pass the dictionary structure as input if the format of
dictionary structure does not match with format of internal table it need to runtime error.
In ALV using function module we can generate the field catalog in two waves.
As part of ALV using function module to handle the events we need to use the parameter
IT_EVENTS as part of the function call REUSE_ALV_GRID_DISPLAY this parameter is a
internal table of type SLIS_T_EVENT this event is of SLIS_ALV_EVENTS and this type
contains two fields.
1) Name
2) Form
Name will hold the name of event and form will hold the subroutines.
To display the information and picture in the TOP-OF-PAGE event we need to use the function
module REUSE_ALV_COMMENTARY_WRITE.
38 | P a g e Santosh P
OAER
|
NAME-> PICTURES
TYPE-> OT
KEY-> Z915FMALV (ANY NAME)
|
EXCUTE
|
EXPAND THE STANDARD DOCUMENT
|
DOUBLE CLICK ON SCREEN
|
GET PATH AND CONTINUE
It is used for display the data in the form of blocks as part of this we use the following function
module.
1) REUSE_ALV_BLOCK_LIST_INIT
2) REUSE_ALV_BLOCK_LIST_APPEND
3) REUSE_ALV_BLOCK_LIST_DISPALY
2) Append the internal table data to the ALV block using the function module
REUSE_ALV_BLOCK_LIST_APPEND.
Repeat the second step to each internal table.
HIERARCHICAL ALV: -
It is used for displaying the data in the form of parent and child nodes as part of this we use the
following module REUSE_ALV_HIERSEQ_LIST_DISPLAY.
INTERACTIVE ALV: -
USER COMMAND: - Is user triggered whenever the user double click on ALV cell value
developed using function module.
39 | P a g e Santosh P