You are on page 1of 39

VINAYAKA

ALV (Advanced List Viewer / ABAP List Viewer): -

1) Using classes
2) Using function module

ALV Reporting using classes: -

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.

A custom control is a physical control which is available as part of dialog screen.

ALV grid cannot recognize custom control on its own it required an interface. These interfaces are
provided in the form of a standard class.

This class can be either.


1) CL_GUI_CUSTOM_CONTAINER
2) CL_GUI_CONTAINER
CL_GUI_CUSTOM_CONTAINER /
CL_GUI_CONTAINER

ALV GRID

CUSTOM CONTROL

MODULE POOL SCREEN

1|Pa g e Santosh P
CUSTOM CONTROL CONTAINER ALV GRID

PHYSICAL CONTAL CL_GUI_CUSTOM_CONTAINER / CL_GUI_CONTAINER


CL_GUI_CONTAINER

Example1: -

Sale Document Header Data Sale Document Item Data

VBELN ERDAT ERZET ERNAM VBELN POSNR MATNR NETWR

4970 4972 10 M1

4971 4972 20 M2

4972 4972 30 M3

Material Data MM02 Transaction(Change Material)


MATNR MTART MATKL

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.

A field catalog can generate in two waves by using.

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: -

It is the event of the class CL_GUI_ALV_GRID which triggered by SAP, whenever a


hotspot column is clicked.

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: -

It is the instance event of the class CL_GUI_ALV_GRID which is triggered whenever a


ALV column cell value is double click.

REPORT Z9AM_ALV1.
tables : vbak.

types : begin of ty_vbak,


vbeln type vbak-vbeln,
erdat type vbak-erdat,
erzet type vbak-erzet,
ernam type vbak-ernam,
end of ty_vbak.

data : lt_vbak type standard table of ty_vbak,


ls_vbak type ty_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.

data : lt_vbap type standard table of ty_vbap,


ls_vbap type ty_vbap.

types : begin of ty_mara,


matnr type mara-matnr,
mtart type mara-mtart,
matkl type mara-matkl,
end of ty_mara.

data : lt_mara type standard table of ty_mara,


ls_mara type ty_mara.

data : vbak_grid type ref to


cl_gui_alv_grid,
vbak_cont type ref to
cl_gui_custom_container,
vbap_grid type ref to
cl_gui_alv_grid,
vbap_cont type ref to
cl_gui_custom_container,
mara_cont type ref to
cl_gui_custom_container,
mara_grid type ref to cl_gui_alv_grid.

data : lt_fcat type lvc_t_fcat,


ls_fcat type lvc_s_fcat,
* ls_fcat like line of lt_fcat,
ls_layo type lvc_s_layo.

select-options : so_vbeln for vbak-vbeln.

class lcl_eventreceiver definition.


public section.
methods handle_hotspot_click
for event hotspot_click
of cl_gui_alv_grid
importing e_row_id.
methods handle_double_click
for event double_click
of cl_gui_alv_grid
importing e_row.
methods handle_button_click
for event button_click
of cl_gui_alv_grid

4|Pa g e Santosh P
importing ES_ROW_NO.
endclass.

class lcl_eventreceiver implementation.


method handle_hotspot_click.
read table lt_vbak into ls_vbak
index e_row_id-index.
if sy-subrc eq 0.
perform get_vbap.
if lt_vbap[] is not initial.
perform fldcat_vbap.
perform layout_vbap.
call screen 200.
endif.
endif.
endmethod.

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.

data ob type ref to lcl_eventreceiver.

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'.

CREATE OBJECT vbak_cont


EXPORTING
container_name = 'VBAK_CUST'.

CREATE OBJECT vbak_grid


EXPORTING
i_parent = vbak_cont.

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.

endform. " fldcat_vbak

module USER_COMMAND_0100 input.


case sy-ucomm.
when 'BACK'.
if vbap_cont is not initial.
call method vbap_grid->free.
call method vbap_cont->free.
endif.
call method vbak_grid->free.
call method vbak_cont->free.
leave program.
endcase.
endmodule. " USER_COMMAND_0100 INPUT

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.

endform. " fldcat_vbap

form layout_vbap .
clear ls_layo.
ls_layo-grid_title = 'SALES Document Item data'.
ls_layo-zebra = 'X'.
endform. " layout_vbap

module linkvbap output.


if vbap_cont is initial.
set pf-status 'PQR'.
CREATE OBJECT vbap_cont
EXPORTING
container_name = 'VBAP_CUST'.

CREATE OBJECT vbap_grid


EXPORTING
i_parent = vbap_cont.

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.

endmodule. " linkvbap OUTPUT

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[].

endform. " display_vbap

module USER_COMMAND_0200 input.


case sy-ucomm.
when 'BACK'.
leave to screen 100.
endcase.
endmodule. " USER_COMMAND_0200 INPUT

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[].

if lt_fcat[] is not initial.


loop at lt_fcat into ls_fcat.
if ls_fcat-fieldname = 'MATNR'.
ls_fcat-style = cl_gui_alv_grid=>mc_style_button.

9|Pa g e Santosh P
modify lt_fcat from ls_fcat
transporting style.
endif.
endloop.
endif.

endform. " fldcat_mara

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.

endform. " display_mara

module linkmara output.


if mara_cont is initial.
set pf-status 'PWE'.
CREATE OBJECT mara_cont
EXPORTING
container_name = 'MARA_CUST'.

CREATE OBJECT mara_grid


EXPORTING
i_parent = mara_cont.

set handler ob->handle_button_click for mara_grid.

perform display_mara.
else.
CALL METHOD mara_grid->refresh_table_display.

endif.
endmodule. " linkmara OUTPUT

module USER_COMMAND_0300 input.


case sy-ucomm.
when 'BACK'.
leave to screen 200.
endcase.
endmodule. " USER_COMMAND_0300 INPUT

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

VBELN ERDAT ERZET ERNAM NETWR

4970
4971
4972

VBELN POSNR MATNR

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.

By using the method GET_METHOD of the class CL_GUI_SPLITTER_CONTAINER this


method takes the row and column as input and return the container object of type
CL_GUI_CONTAINER.

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: -

BUTTON_CLICK is the instance of event of the class CL_GUI_ALV_GRID which is


triggered whenever the user click on the ALV cell value display on top of a button.

TOP-OF-PAGE: -

TOP-OF-PAGE is the instance of event of the class CL_GUI_ALV_GRID which is


triggered whenever an ALV grid is displayed. This event can be used for generating the heading for
an ALV GRID.

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.

DATA CUST_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.


DATA O_SPLIT TYPE REF TO CL_GUI_SPLITTER_CONTAINER.
DATA : O_CONT1 TYPE REF TO CL_GUI_CONTAINER,
O_CONT2 TYPE REF TO CL_GUI_CONTAINER,
O_CONT3 TYPE REF TO CL_GUI_CONTAINER.

DATA VBAK_GRID TYPE REF TO CL_GUI_ALV_GRID.


DATA VBAP_GRID TYPE REF TO CL_GUI_ALV_GRID.

TYPES : BEGIN OF TY_VBAK,


VBELN TYPE VBAK-VBELN,
ERDAT TYPE VBAK-ERDAT,
ERZET TYPE VBAK-ERZET,
END OF TY_VBAK.

DATA : LT_VBAK TYPE STANDARD TABLE OF TY_VBAK,


LS_VBAK TYPE TY_VBAK.

TYPES : BEGIN OF TY_VBAP,


VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
END OF TY_VBAP.

DATA : LT_VBAP TYPE STANDARD TABLE OF TY_VBAP,


LS_VBAP TYPE TY_VBAP.

DATA : LT_FCAT TYPE LVC_T_FCAT,


LS_FCAT TYPE LVC_S_FCAT.

12 | P a g e Santosh P
DATA LS_LAYO TYPE LVC_S_LAYO.

DATA IDX TYPE I.


DATA LV_VBELN TYPE VBELN.

CLASS LCL_EVENTRECEIVER DEFINITION.


PUBLIC SECTION.
METHODS HANDLE_BUTTON_CLICK
FOR EVENT BUTTON_CLICK
OF CL_GUI_ALV_GRID
IMPORTING ES_ROW_NO.
METHODS HANDLE_TOP_OF_PAGE
FOR EVENT TOP_OF_PAGE
OF CL_GUI_ALV_GRID
IMPORTING E_DYNDOC_ID.
ENDCLASS.

CLASS LCL_EVENTRECEIVER IMPLEMENTATION.


METHOD HANDLE_BUTTON_CLICK.
IDX = ES_ROW_NO-ROW_ID.
IF IDX IS NOT INITIAL.
READ TABLE LT_VBAK INTO LS_VBAK INDEX IDX.
IF SY-SUBRC EQ 0.
LV_VBELN = LS_VBAK-VBELN.
IF LV_VBELN IS NOT INITIAL.
PERFORM GETVBAP.
IF LT_VBAP[] IS NOT INITIAL.
PERFORM FLDCATVBAP.
PERFORM LAYOUTVBAP.
PERFORM DISPLAYVBAP.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.

METHOD HANDLE_TOP_OF_PAGE.

CALL METHOD E_DYNDOC_ID->ADD_TEXT


EXPORTING
TEXT = TEXT-001.

CALL METHOD E_DYNDOC_ID->ADD_GAP


EXPORTING
WIDTH = 5.

CALL METHOD E_DYNDOC_ID->ADD_TEXT


EXPORTING
TEXT = TEXT-002.

13 | P a g e Santosh P
CALL METHOD E_DYNDOC_ID->NEW_LINE
EXPORTING
REPEAT = 1.

CALL METHOD E_DYNDOC_ID->ADD_TEXT


EXPORTING
TEXT = TEXT-003.

CALL METHOD E_DYNDOC_ID->DISPLAY_DOCUMENT


EXPORTING
PARENT = O_CONT1.
ENDMETHOD.
ENDCLASS.

DATA OB TYPE REF TO LCL_EVENTRECEIVER.


INITIALIZATION.
SO_VBELN-LOW = '4970'.
SO_VBELN-HIGH = '4975'.
APPEND SO_VBELN.

START-OF-SELECTION.
CALL SCREEN 100.

MODULE STATUS_0100 OUTPUT.


SET PF-STATUS 'ABC'.
IF CUST_CONT IS INITIAL.
CREATE OBJECT CUST_CONT
EXPORTING
CONTAINER_NAME = 'CNTRL1'.

CREATE OBJECT O_SPLIT


EXPORTING
PARENT = CUST_CONT
ROWS =3
COLUMNS = 1.

CALL METHOD O_SPLIT->SET_ROW_HEIGHT


EXPORTING
ID =1
HEIGHT = 3.

CALL METHOD O_SPLIT->SET_ROW_HEIGHT


EXPORTING
ID =2
HEIGHT = 14.

CALL METHOD O_SPLIT->SET_ROW_HEIGHT


EXPORTING
ID =3
HEIGHT = 12.

14 | P a g e Santosh P
CALL METHOD O_SPLIT->GET_CONTAINER
EXPORTING
ROW =1
COLUMN = 1
RECEIVING
CONTAINER = O_CONT1.

CALL METHOD O_SPLIT->GET_CONTAINER


EXPORTING
ROW =2
COLUMN = 1
RECEIVING
CONTAINER = O_CONT2.

CALL METHOD O_SPLIT->GET_CONTAINER


EXPORTING
ROW =3
COLUMN = 1
RECEIVING
CONTAINER = O_CONT3.

PERFORM GETVBAK.
IF LT_VBAK[] IS NOT INITIAL.
PERFORM FLDCATVBAK.
PERFORM LAYOUTVBAK.
PERFORM DISPLAYVBAK.
ENDIF.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT.


CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

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.

CREATE OBJECT OB.


SET HANDLER OB->HANDLE_BUTTON_CLICK FOR VBAK_GRID.
SET HANDLER OB->HANDLE_TOP_OF_PAGE FOR VBAK_GRID.
DATA K TYPE REF TO CL_DD_DOCUMENT.
CREATE OBJECT K.

CALL METHOD VBAK_GRID->LIST_PROCESSING_EVENTS


EXPORTING
I_EVENT_NAME = 'TOP_OF_PAGE'
I_DYNDOC_ID = K.

CALL METHOD VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY


EXPORTING
IS_LAYOUT = LS_LAYO
CHANGING
IT_OUTTAB = LT_VBAK[]
IT_FIELDCATALOG = LT_FCAT[].
ENDFORM. " displayvbak

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.

CALL METHOD VBAP_GRID->SET_TABLE_FOR_FIRST_DISPLAY


EXPORTING
IS_LAYOUT = LS_LAYO
CHANGING
IT_OUTTAB = LT_VBAP[]
IT_FIELDCATALOG = LT_FCAT[].
ELSE.
CALL METHOD VBAP_GRID->REFRESH_TABLE_DISPLAY.
ENDIF.
ENDFORM. displayvbap

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)

UPLOADING PICTURE TO DISPLAY IN DIALOG SCREENS: -

SMWO is the T-code for uploading the pictures.

PROCEDURE FOR DISPLAYING IMAGES IN DIALOG SCREENS: -

1) Call the function module DP_PUBLISH_WWW_URL.

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.

PROCEDURE FOR DESIGNING TREE STRUCTURE: -

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.

2) NODE_TABLE it holds the internal table representing the ABDEMONODESTRUCTURE.

Every node in a tree is associated with a node key it used for indentifying the node which
selected on a tree.

Icon is a type group it is provided by sap itself.

CNTL is a type group it is provided by SAP itself.

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.

The event NODE_DOUBLE_CLICK is not triggered by default if must be registered


explicitly by using the method SET_REGISTERED_EVENT.

This method contains of parameter event of type CNTL_SIMPLE_EVENT it is an


internal declared in the type group CNTL this internal table contains two fields.
1) EVENT_ID AND
2) APPL_EVENT

LVC_FIELDCATALOG_MERGE is a function module it generate the field catalog on the


structure as input generates the field catalog this function module take the dictionary structure
fields and return the field catalog which the type LVC_T_FCAT.

MODIFYING ALV CELL VALUES IN RUN-TIME: -

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.

By default DATA_CHANGED is not triggered it must be registered explicitly by calling


the method REGISTER_EDIT_EVENT of a class CL_GUI_ALV_GRID.

As part of event DATA_CHANGED we need to import the parameters


ER_DATA_CHANGED it is a parameter which is the object of the class
CL_GUI_CHANGE_DATA_PROTOCOL.

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.

EXCLUDING ALV TOOLBAR BUTTONS: -

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.

We need to loop this internal table to enabled are disabled buttons.

ADDING CUSTOM PUSH BUTTONS ON ALV TOOLBAR: -

MENU_BUTTON: -

MENU_BUTTON is the instance events of the class CL_GUI_ALV_GRID which is


triggered whenever a menu button in the ALV toolbar is clicked we can handle the event is
associates with the list of menu items of the menu buttons.

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

IDENTIFYING SELECTED ROWS: -

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.

DATA : CUST_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER,


O_SPLIT1 TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
O_CONT1 TYPE REF TO CL_GUI_CONTAINER,
O_CONT2 TYPE REF TO CL_GUI_CONTAINER,
O_SPLIT2 TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
O_CONT3 TYPE REF TO CL_GUI_CONTAINER,
O_CONT4 TYPE REF TO CL_GUI_CONTAINER,
O_PIC TYPE REF TO CL_GUI_PICTURE,
O_TREE TYPE REF TO CL_GUI_SIMPLE_TREE,
O_GRID TYPE REF TO CL_GUI_ALV_GRID.

20 | P a g e Santosh P
TYPES : BEGIN OF TY_NODES.
INCLUDE STRUCTURE ABDEMONODE.
TYPES END OF TY_NODES.

DATA : LT_NODES TYPE STANDARD TABLE OF TY_NODES,


LS_NODES TYPE TY_NODES.

DATA : LT_EVENTS TYPE TABLE OF CNTL_SIMPLE_EVENT,


LS_EVENTS TYPE CNTL_SIMPLE_EVENT.

TYPES : BEGIN OF TY_DEPT.


INCLUDE STRUCTURE Z730CDEPT.
TYPES END OF TY_DEPT.

DATA : LT_DEPT TYPE STANDARD TABLE OF TY_DEPT,


LS_DEPT TYPE TY_DEPT.

DATA : LT_FCAT TYPE LVC_T_FCAT.

FIELD-SYMBOLS <FS> LIKE LINE OF LT_FCAT.

DATA : LT_FUNCTIONS TYPE UI_FUNCTIONS,


LV_FUNCTION TYPE UI_FUNC.

DATA LS_TOOLBAR TYPE STB_BUTTON.

DATA : LT_ROWS TYPE LVC_T_ROW,


LS_ROWS TYPE LVC_S_ROW.

CLASS LCL_EVENTRECEIVER DEFINITION.


PUBLIC SECTION.
METHODS HANDLE_NODE_DOUBLE_CLICK
FOR EVENT NODE_DOUBLE_CLICK
OF CL_GUI_SIMPLE_TREE
IMPORTING NODE_KEY.
METHODS HANDLE_DATA_CHANGED
FOR EVENT DATA_CHANGED
OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED.
METHODS HANDLE_TOOLBAR
FOR EVENT TOOLBAR
OF CL_GUI_ALV_GRID
IMPORTING E_OBJECT.
METHODS HANDLE_MENU_BUTTON
FOR EVENT MENU_BUTTON
OF CL_GUI_ALV_GRID
IMPORTING E_OBJECT E_UCOMM.
METHODS HANDLE_BEFORE_USER_COMMAND
FOR EVENT BEFORE_USER_COMMAND
OF CL_GUI_ALV_GRID.

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.

CLASS LCL_EVENTRECEIVER IMPLEMENTATION.


METHOD HANDLE_NODE_DOUBLE_CLICK.
CASE NODE_KEY.
WHEN 'CSO'.
CALL TRANSACTION 'VA01'.
WHEN 'CHSO'.
CALL TRANSACTION 'VA02'.
WHEN 'CPO'.
CALL TRANSACTION 'ME21N'.
WHEN 'CHPO'.
CALL TRANSACTION 'ME22N'.
ENDCASE.
ENDMETHOD.

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

READ TABLE E_OBJECT->MT_TOOLBAR


INTO LS_TOOLBAR
WITH KEY FUNCTION = '&LOCAL&INSERT_ROW'.
IF SY-SUBRC EQ 0.
LS_TOOLBAR-DISABLED = 'X'.
MODIFY TABLE E_OBJECT->MT_TOOLBAR
FROM LS_TOOLBAR
TRANSPORTING DISABLED.
ENDIF.

* Adding pushbuttons on ALV toolbar


CLEAR LS_TOOLBAR.
LS_TOOLBAR-FUNCTION = 'P1'.
LS_TOOLBAR-ICON = '@15@'.
LS_TOOLBAR-QUICKINFO = 'This is Button1'.
LS_TOOLBAR-BUTN_TYPE = 0.
LS_TOOLBAR-DISABLED = ' ' .
LS_TOOLBAR-TEXT = 'Button1'.
LS_TOOLBAR-CHECKED = ' '.
APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

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'.

CALL METHOD E_OBJECT->ADD_FUNCTION


EXPORTING
FCODE = 'MI2'
TEXT = 'Menu item2'.
ENDCASE.
ENDMETHOD.

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[].

IF LT_ROWS[] IS NOT INITIAL.


SORT LT_ROWS BY INDEX DESCENDING.
LOOP AT LT_ROWS INTO LS_ROWS.
DELETE LT_DEPT INDEX LS_ROWS-INDEX.
ENDLOOP.
CALL METHOD O_GRID->REFRESH_TABLE_DISPLAY.
ELSE.
MESSAGE 'Please select atleast one row' TYPE 'I'.
ENDIF.
ENDCASE.
ENDMETHOD.

METHOD HANDLE_AFTER_USER_COMMAND.
* message 'After user command' type 'I'.
ENDMETHOD.
ENDCLASS.

DATA OB TYPE REF TO LCL_EVENTRECEIVER.


START-OF-SELECTION.
CALL SCREEN 100.

MODULE STATUS_0100 OUTPUT.


SET PF-STATUS 'ABC'.
IF CUST_CONT IS INITIAL.
CREATE OBJECT CUST_CONT
EXPORTING
CONTAINER_NAME = 'CNTRL1'.

24 | P a g e Santosh P
CREATE OBJECT O_SPLIT1
EXPORTING
PARENT = CUST_CONT
ROWS =1
COLUMNS = 2.

CALL METHOD O_SPLIT1->SET_COLUMN_WIDTH


EXPORTING
ID = 1
WIDTH = 3.

CALL METHOD O_SPLIT1->SET_COLUMN_WIDTH


EXPORTING
ID = 2
WIDTH = 8.

CALL METHOD O_SPLIT1->GET_CONTAINER


EXPORTING
ROW =1
COLUMN = 1
RECEIVING
CONTAINER = O_CONT1.

CALL METHOD O_SPLIT1->GET_CONTAINER


EXPORTING
ROW =1
COLUMN = 2
RECEIVING
CONTAINER = O_CONT2.

CREATE OBJECT O_SPLIT2


EXPORTING
PARENT = O_CONT2
ROWS =2
COLUMNS = 1.

CALL METHOD O_SPLIT2->SET_ROW_HEIGHT


EXPORTING
ID = 1
HEIGHT = 5.

CALL METHOD O_SPLIT2->SET_ROW_HEIGHT


EXPORTING
ID = 2
HEIGHT = 8.

CALL METHOD O_SPLIT2->GET_CONTAINER


EXPORTING
ROW =1
COLUMN = 1

25 | P a g e Santosh P
RECEIVING
CONTAINER = O_CONT3.

CALL METHOD O_SPLIT2->GET_CONTAINER


EXPORTING
ROW =2
COLUMN = 1
RECEIVING
CONTAINER = O_CONT4.

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.

CALL FUNCTION 'DP_PUBLISH_WWW_URL'


EXPORTING
OBJID = 'Z915OBJ'
LIFETIME = CNDP_LIFETIME_TRANSACTION
IMPORTING
URL = PIC_URL.

CREATE OBJECT O_PIC


EXPORTING
PARENT = O_CONT3.

26 | P a g e Santosh P
CALL METHOD O_PIC->LOAD_PICTURE_FROM_URL
EXPORTING
URL = PIC_URL.

ENDFORM. " picture

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.

CREATE OBJECT O_TREE


EXPORTING
PARENT = O_CONT1
NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE.

CREATE OBJECT OB.


SET HANDLER OB->HANDLE_NODE_DOUBLE_CLICK FOR O_TREE.

* Explicit registration of node_double_click


CLEAR LS_EVENTS.
LS_EVENTS-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
APPEND LS_EVENTS TO LT_EVENTS.

CALL METHOD O_TREE->SET_REGISTERED_EVENTS


EXPORTING
EVENTS = LT_EVENTS[].

CALL METHOD O_TREE->ADD_NODES


EXPORTING
TABLE_STRUCTURE_NAME = 'ABDEMONODE'
NODE_TABLE = LT_NODES[].

ENDFORM. " tree

FORM DEPTGRID .
CREATE OBJECT O_GRID
EXPORTING
I_PARENT = O_CONT4.

CREATE OBJECT OB.


SET HANDLER OB->HANDLE_DATA_CHANGED FOR O_GRID.
SET HANDLER OB->HANDLE_TOOLBAR FOR O_GRID.
SET HANDLER OB->HANDLE_MENU_BUTTON FOR O_GRID.
SET HANDLER OB->HANDLE_BEFORE_USER_COMMAND FOR O_GRID.
SET HANDLER OB->HANDLE_USER_COMMAND FOR O_GRID.
SET HANDLER OB->HANDLE_AFTER_USER_COMMAND FOR O_GRID.

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.

SELECT * FROM Z730CDEPT


INTO TABLE LT_DEPT.
IF SY-SUBRC EQ 0.
PERFORM FLDCAT.
PERFORM EXCLUDEBUTTONS.
PERFORM DISPLAY.
ENDIF.

ENDFORM. " deptgrid

FORM FLDCAT .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'Z730CDEPT'
CHANGING
CT_FIELDCAT = LT_FCAT[].

LOOP AT LT_FCAT ASSIGNING <FS>.


IF <FS>-FIELDNAME = 'LOC'.
<FS>-EDIT = 'X'.
<FS>-COL_POS = 3.
ELSEIF <FS>-FIELDNAME = 'DNAME'.
<FS>-COL_POS = 4.
ENDIF.
ENDLOOP.
ENDFORM. " fldcat

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

1) Define background job (SM36)


2) Define step (program name, variant name)
3) Define start condition (immediate specific period)
4) Save the job (release the job)
5) Check the job overview (SM37)

SM36-> JOBNAME (ANY NAME)


JOBCLASS A
|
CLICK ON STEP (F6)
|
Z915AM_ALV4
|
VAR1
|
SAVE
|
BACK
|
START CONDITON
|
IMMEDIATE
|
SAVE
|
BACK-> SAVE

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.

Declare an additional column of type character in the finial internal table.

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.

COLORING ALV ROWS: -


PROCEDURE: -

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.

DISPLAYING ALV CELLS AS DROP DOWN: -

Taken an additional column which is supposed to display as dropdown.

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.

By handling on F1 event of the class CL_GUI_ALV_GRID.

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.

DATA : O_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER,


O_GRID TYPE REF TO CL_GUI_ALV_GRID.

SELECT-OPTIONS SO_VBELN FOR VBAK-VBELN.

TYPES : BEGIN OF TY_VBAK,


LIGHTS(1) TYPE C, "traffic lights
COLOR(4) TYPE C,
COURSE(10) TYPE C,
SEL TYPE C,
VBELN TYPE VBAK-VBELN,
ERDAT TYPE VBAK-ERDAT,
ERNAM TYPE VBAK-ERNAM,
END OF TY_VBAK.

DATA : LT_VBAK TYPE STANDARD TABLE OF TY_VBAK,


LS_VBAK TYPE TY_VBAK.

DATA : LT_FCAT TYPE LVC_T_FCAT,


LS_FCAT TYPE LVC_S_FCAT.

DATA : LS_LAYO TYPE LVC_S_LAYO.

DATA MODE TYPE I.

DATA O_DOCK TYPE REF TO CL_GUI_DOCKING_CONTAINER.

DATA : LT_DROP TYPE LVC_T_DROP,


LS_DROP TYPE LVC_S_DROP.

32 | P a g e Santosh P
DATA : LT_F4 TYPE LVC_T_F4,
LS_F4 TYPE LVC_S_F4.

CLASS LCL_EVENTRECEIVER DEFINITION.


PUBLIC SECTION.
METHODS HANDLE_ONF1
FOR EVENT ONF1
OF CL_GUI_ALV_GRID
IMPORTING E_FIELDNAME
ER_EVENT_DATA.
METHODS HANDLE_ONF4
FOR EVENT ONF4
OF CL_GUI_ALV_GRID
IMPORTING E_FIELDNAME.
ENDCLASS.

CLASS LCL_EVENTRECEIVER IMPLEMENTATION.


METHOD HANDLE_ONF1.
CASE E_FIELDNAME.
WHEN 'VBELN'.
ER_EVENT_DATA->M_EVENT_HANDLED = 'X'.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Custom F1 help'
TXT1 = 'VBAK Table'
TXT2 = 'Sales Document-VBELN'.
ENDCASE.
ENDMETHOD.

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.

DATA OB TYPE REF TO LCL_EVENTRECEIVER.

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.

CREATE OBJECT O_CONT


EXPORTING
CONTAINER_NAME = 'CTRL'.

CREATE OBJECT O_GRID


EXPORTING
I_PARENT = O_CONT.
ENDIF.
ELSE.
CREATE OBJECT O_GRID
EXPORTING
I_PARENT = O_DOCK.
ENDIF.

PERFORM GETDATA.
IF LT_VBAK[] IS NOT INITIAL.
PERFORM FLDCAT.
PERFORM LAYOUT.
PERFORM TRAFFICLIGHTS_COLOR.
PERFORM DROPDOWN.
PERFORM REGISTER.
PERFORM DISPLAY.
ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

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.

ENDFORM. " fldcat


*&---------------------------------------------------------------------*
*& Form layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LAYOUT .
CLEAR LS_LAYO.
LS_LAYO-GRID_TITLE = 'SALES DOCUMENT HEADER DATA'.
LS_LAYO-EXCP_FNAME = 'LIGHTS'.
* ls_layo-info_fname = 'COLOR'.
ENDFORM. " layout

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

MODULE USER_COMMAND_0100 INPUT.


CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT

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[].

ENDFORM. " dropdown

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.

CALL METHOD O_GRID->REGISTER_F4_FOR_FIELDS


EXPORTING
IT_F4 = LT_F4[].

ENDFORM. " register

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.

1) By using the function module REUSE_ALV_FIELDCATALOG_MERGE this function


module takes dictionary structure as input and return the field catalog of type
SLIS_I_FIELDCAT_ALV.
2) Manually by using the internal table SLIS_T_FIELDCAT_ALV.

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.

PROCEDURE FOR DISPLAYING IMAGES IN ALV GRID DEVELOPED USING F M S:-

1) Upload the picture using OAER with object id.


2) Pass the object ID in the function module call 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

ALV BLOCKED LIST: -

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

1) Initialize the ALV block by using the function module


REUSE_ALV_BLOCK_LIST_INTI

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.

3) Display the function module using function module


RESUE_ALV_BLOCK_LIST_DISPLAY.

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

You might also like