ABAP Object Event
Hi All,
Could anybody send me a document for ABAP Object events.
And simple programs for Events.
My id - [email protected]
Thanks,
Ponraj.s.
Hi,
Go thru this basic simple program with documentation which demonstrates how to handle events, for nodes in a tree using abap objects
REPORT YLIST_TREE MESSAGE-ID ZER_INFO.
CLASS LCL_EVT_HDLR DEFINITION DEFERRED. " definition is given later
CLASS CL_GUI_CFW DEFINITION LOAD. " global class to be loaded
DATA:G_EVENT(50), " to hold the event
G_NODE_KEY TYPE TV_NODEKEY, "holds the node key
G_ITEM_NAME TYPE TV_ITMNAME,
G_KEY TYPE TV_ITMNAME.
DATA:G_EVT_HDLR TYPE REF TO LCL_EVT_HDLR,
G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
G_TREE TYPE REF TO CL_GUI_LIST_TREE,
G_OK_CODE TYPE SY-UCOMM.
TYPES:ITEM_TABLE_TYPE LIKE STANDARD TABLE OF MTREEITM
WITH DEFAULT KEY.
CLASS lcl_evt_hdlr DEFINITION
CLASS LCL_EVT_HDLR DEFINITION.
PUBLIC SECTION.
METHODS:
*---- methods for action handling for nodes
NODE_DBL_CLK
FOR EVENT NODE_DOUBLE_CLICK
OF CL_GUI_LIST_TREE
IMPORTING NODE_KEY,
HANDLE_NODE_KEY_PRESS
FOR EVENT NODE_KEYPRESS
OF CL_GUI_LIST_TREE
IMPORTING NODE_KEY KEY,
*---- methods for action handling for Items
ITEM_DBL_CLK
FOR EVENT ITEM_DOUBLE_CLICK
OF CL_GUI_LIST_TREE
IMPORTING NODE_KEY ITEM_NAME,
HANDLE_ITEM_KEY_PRESS
FOR EVENT ITEM_KEYPRESS
OF CL_GUI_LIST_TREE
IMPORTING NODE_KEY ITEM_NAME KEY,
*---- Common methods for action handling
HANDLE_RIGHT_CLICK
FOR EVENT RIGHT_CLICK
OF CL_GUI_LIST_TREE,
HANDLE_EXPAND_NO_CHILDREN
FOR EVENT EXPAND_NO_CHILDREN
OF CL_GUI_LIST_TREE
IMPORTING NODE_KEY.
ENDCLASS. "lcl_evt_hdlr DEFINITION
CLASS lcl_evt_hdlr IMPLEMENTATION
CLASS LCL_EVT_HDLR IMPLEMENTATION.
METHOD NODE_DBL_CLK.
this method handles the node double click event of the tree control
and shows the key of the double clicked node in a dynpro field
G_EVENT = 'NODE_DOUBLE_CLICK'.
G_NODE_KEY = NODE_KEY.
G_ITEM_NAME = ' '.
ENDMETHOD. "node_dbl_clk
METHOD ITEM_DBL_CLK.
G_EVENT = 'ITEM_DOUBLE_CLICK'.
G_NODE_KEY = NODE_KEY.
G_ITEM_NAME = ITEM_NAME.
ENDMETHOD. "ITEM_DBL_CLK
METHOD HANDLE_NODE_KEY_PRESS.
G_EVENT = 'NODE_KEYPRESS'.
G_NODE_KEY = NODE_KEY.
G_ITEM_NAME = ' '.
G_KEY = KEY.
ENDMETHOD. "HANDLE_NODE_KEY_PRESS
METHOD HANDLE_ITEM_KEY_PRESS.
G_EVENT = 'ITEM_KEYPRESS'.
G_NODE_KEY = NODE_KEY.
G_ITEM_NAME = ITEM_NAME.
G_KEY = KEY.
ENDMETHOD. "HANDLE_ITEM_KEY_PRESS
METHOD HANDLE_RIGHT_CLICK.
G_EVENT = 'RIGHT_CLICK'.
ENDMETHOD. "handle_right_click
METHOD HANDLE_EXPAND_NO_CHILDREN.
G_EVENT = 'EXPAND_NO_CHILDREN'.
G_NODE_KEY = NODE_KEY.
ENDMETHOD. "handle_EXPAND_NO_CHILDREN
ENDCLASS. "lcl_evt_hdlr IMPLEMENTATION
*------ start-of-selection.
START-OF-SELECTION.
*data: G_EVT_HDLR TYPE REF TO LCL_EVT_HDLR.
CREATE OBJECT G_EVT_HDLR. "create an object for the class lcl_evt_hdlr
SET SCREEN 100.
MODULE pbo_100 OUTPUT
MODULE PBO_100 OUTPUT.
SET PF-STATUS 'BUT'.
IF G_TREE IS INITIAL.
the tree control has not yet been created
create a tree control and insert nodes into it.
PERFORM CREATE_AND_INIT_TREE.
ENDIF.
ENDMODULE. "pbo_100 OUTPUT
MODULE pai_100 INPUT
MODULE PAI_100 INPUT.
DATA:RETURN_CODE TYPE I.
CL_GUI_CFW=>DISPATCH must be called if events are registered
that trigger PAI
this method calls the event handler method of an event
CALL METHOD CL_GUI_CFW=>DISPATCH
IMPORTING
RETURN_CODE = RETURN_CODE.
IF RETURN_CODE <> CL_GUI_CFW=>RC_NOEVENT.
" a control event occured => exit PAI
CLEAR G_OK_CODE.
EXIT.
ENDIF.
*at user-command.
g_ok_code = sy-ucomm.
CASE G_OK_CODE.
WHEN 'BACK'. " Finish program
IF NOT G_CUSTOM_CONTAINER IS INITIAL.
" destroy tree container (detroys contained tree control, too)
CALL METHOD G_CUSTOM_CONTAINER->FREE
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
CLEAR G_CUSTOM_CONTAINER.
CLEAR G_TREE.
ENDIF.
LEAVE PROGRAM.
ENDCASE.
CAUTION: clear ok code!
CLEAR G_OK_CODE.
ENDMODULE. "pai_100 INPUT
*& Form create_and_init_tree
text
--> p1 text
<-- p2 text
FORM CREATE_AND_INIT_TREE .
DATA:NODE_TABLE TYPE TREEV_NTAB,
ITEM_TABLE TYPE ITEM_TABLE_TYPE,
EVENTS TYPE CNTL_SIMPLE_EVENTS,
EVENT TYPE CNTL_SIMPLE_EVENT.
create a container for the tree control.
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING
the container is linked to the custom control with the
name 'TREE_CONTAINER' on the dynpro
CONTAINER_NAME = 'TREE_CONTAINER'
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
create a list tree control
CREATE OBJECT G_TREE
EXPORTING
PARENT = G_CUSTOM_CONTAINER
NODE_SELECTION_MODE = CL_GUI_LIST_TREE=>NODE_SEL_MODE_SINGLE
ITEM_SELECTION = 'X'
WITH_HEADERS = ' '
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CREATE_ERROR = 2
FAILED = 3
ILLEGAL_NODE_SELECTION_MODE = 4
LIFETIME_ERROR = 5.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
*------- KEY = enter
CALL METHOD G_TREE->ADD_KEY_STROKE
EXPORTING
KEY = CL_TREE_CONTROL_BASE=>KEY_ENTER
EXCEPTIONS
FAILED = 1
ILLEGAL_KEY = 2
CNTL_SYSTEM_ERROR = 3.
IF SY-SUBRC <> 0.
MESSAGE W006 WITH 'ADD_KEY_STROKE'.
ENDIF.
define the events which will be passed to the backend
node double click
EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_NODE_DOUBLE_CLICK.
EVENT-APPL_EVENT = 'X'.
APPEND EVENT TO EVENTS.
EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_ITEM_DOUBLE_CLICK.
EVENT-APPL_EVENT = 'X'.
APPEND EVENT TO EVENTS.
EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_NODE_KEYPRESS.
EVENT-APPL_EVENT = 'X'.
APPEND EVENT TO EVENTS.
EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_ITEM_KEYPRESS.
EVENT-APPL_EVENT = 'X'.
APPEND EVENT TO EVENTS.
EVENT-EVENTID = LCL_EVT_HDLR=>EVENT_RIGHT_CLICK.
EVENT-APPL_EVENT = 'X'.
APPEND EVENT TO EVENTS.
EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_EXPAND_NO_CHILDREN.
EVENT-APPL_EVENT = 'X'.
APPEND EVENT TO EVENTS.
*------ register the events
CALL METHOD G_TREE->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = EVENTS
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
ILLEGAL_EVENT_COMBINATION = 3.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
assign event handlers in the application class to each desired events
SET HANDLER G_EVT_HDLR->NODE_DBL_CLK FOR G_TREE.
SET HANDLER G_EVT_HDLR->ITEM_DBL_CLK FOR G_TREE.
SET HANDLER G_EVT_HDLR->HANDLE_NODE_KEY_PRESS FOR G_TREE.
SET HANDLER G_EVT_HDLR->HANDLE_ITEM_KEY_PRESS FOR G_TREE.
SET HANDLER G_EVT_HDLR->HANDLE_RIGHT_CLICK FOR G_TREE.
SET HANDLER G_EVT_HDLR->HANDLE_EXPAND_NO_CHILDREN FOR G_TREE.
add some nodes to the tree control
PERFORM BUILD_NODE_AND_ITEM_TABLE USING NODE_TABLE ITEM_TABLE.
CALL METHOD G_TREE->ADD_NODES_AND_ITEMS
EXPORTING
NODE_TABLE = NODE_TABLE
ITEM_TABLE = ITEM_TABLE
ITEM_TABLE_STRUCTURE_NAME = 'mtreeitm'
EXCEPTIONS
FAILED = 1
CNTL_SYSTEM_ERROR = 3
ERROR_IN_TABLES = 4
DP_ERROR = 5
TABLE_STRUCTURE_NAME_NOT_FOUND = 6.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
ENDFORM. " create_and_init_tree
*& Form build_node_and_item_table
text
-->P_NODE_TABLE text
-->P_ITEM_TABLE text
FORM BUILD_NODE_AND_ITEM_TABLE USING
NODE_TABLE TYPE TREEV_NTAB
ITEM_TABLE TYPE ITEM_TABLE_TYPE.
DATA:NODE TYPE TREEV_NODE,
ITEM TYPE MTREEITM.
build the node table
node with key 'root'.
CLEAR NODE.
NODE-NODE_KEY = 'Root'. " key of the node
CLEAR NODE-RELATKEY. " root node has no parent node
CLEAR NODE-RELATSHIP.
NODE-HIDDEN = ' '. " the node is visible
NODE-DISABLED = ' '. " selectable
NODE-ISFOLDER = 'X'. " a folder
CLEAR NODE-N_IMAGE. " folder-/ leaf symbol in state "closed"
"use default.
CLEAR NODE-EXP_IMAGE. " folder-/ leaf symbol in state "open"
"use default.
CLEAR NODE-EXPANDER. " the width of the item is adjusted to its "
" content (text)
APPEND NODE TO NODE_TABLE.
node with key 'child1'.
CLEAR NODE.
NODE-NODE_KEY = 'Child1'. "key of the node
NODE-RELATKEY = 'Root'.
NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.
NODE-ISFOLDER = 'X'.
APPEND NODE TO NODE_TABLE.
node with key 'Subchild1' for child1.
CLEAR NODE.
NODE-NODE_KEY = 'SubChild1'.
NODE-RELATKEY = 'Child1'.
NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.
NODE-ISFOLDER = 'X'.
APPEND NODE TO NODE_TABLE.
node with key 'subchild2' for child1.
CLEAR NODE.
NODE-NODE_KEY = 'SubChild2'.
NODE-RELATKEY = 'Child1'.
NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.
APPEND NODE TO NODE_TABLE.
node with key 'subchild3' for child1.
CLEAR NODE.
NODE-NODE_KEY = 'SubChild3'.
NODE-RELATKEY = 'Child1'.
NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.
APPEND NODE TO NODE_TABLE.
node with key 'child2'.
CLEAR NODE.
NODE-NODE_KEY = 'Child2'. "key of the node
NODE-RELATKEY = 'Root'.
NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.
NODE-ISFOLDER = 'X'.
NODE-EXPANDER = 'X'. " The node is marked with a '+', although
" it has no children. When the user clicks on the
" + to open the node, the event expand_nc is
" fired. The programmerr can
" add the children of the
" node within the event handler of the expand_nc
" event (see callback handle_expand_nc).
APPEND NODE TO NODE_TABLE.
items of the nodes
item with key 'root'.
CLEAR ITEM.
ITEM-NODE_KEY = 'Root'.
ITEM-ITEM_NAME = '1'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. " text item
ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. "the width of the item
"is adjusted to its content
ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. "use proportional font
" for the item
ITEM-TEXT = 'object'.
APPEND ITEM TO ITEM_TABLE.
item with key 'child1'.
CLEAR ITEM.
ITEM-NODE_KEY = 'Child1'.
ITEM-ITEM_NAME = '11'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.
ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.
ITEM-TEXT = 'dynpros'.
APPEND ITEM TO ITEM_TABLE.
item with key 'child2'.
CLEAR ITEM.
ITEM-NODE_KEY = 'Child2'.
ITEM-ITEM_NAME = '12'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.
ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.
ITEM-TEXT = 'programme'.
APPEND ITEM TO ITEM_TABLE.
items of node with key 'Subchild1'.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild1'.
ITEM-ITEM_NAME = '111'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-LENGTH = 11.
ITEM-TEXT = 'include'.
APPEND ITEM TO ITEM_TABLE.
items of node with key 'SubChild2'.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild2'.
ITEM-ITEM_NAME = '112'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-LENGTH = 4. " the width of the item is 4 chars
ITEM-IGNOREIMAG = 'X'. " see documentation of structure treev_item
ITEM-USEBGCOLOR = 'X'.
ITEM-T_IMAGE = '@01@'.
APPEND ITEM TO ITEM_TABLE.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild2'.
ITEM-ITEM_NAME = '113'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-LENGTH = 4. " the width of the item is 4 chars
ITEM-USEBGCOLOR = 'X'.
ITEM-TEXT = '0100'.
APPEND ITEM TO ITEM_TABLE.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild2'.
ITEM-ITEM_NAME = '114'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-LENGTH = 11.
ITEM-USEBGCOLOR = 'X'.
ITEM-TEXT = ' mueller'.
APPEND ITEM TO ITEM_TABLE.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild2'.
ITEM-ITEM_NAME = '115'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.
ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.
ITEM-TEXT = ' comment to dynpro 100'.
APPEND ITEM TO ITEM_TABLE.
items of node with key 'SubChild3'.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild3'.
ITEM-ITEM_NAME = '121'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-LENGTH = 20.
ITEM-IGNOREIMAG = 'X'.
ITEM-USEBGCOLOR = 'X'.
ITEM-T_IMAGE = '@02@'.
ITEM-TEXT = ' 0200 harryhirsch'.
APPEND ITEM TO ITEM_TABLE.
CLEAR ITEM.
ITEM-NODE_KEY = 'SubChild3'.
ITEM-ITEM_NAME = '122'.
ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.
ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.
ITEM-TEXT = ' comment to dynpro 200'.
APPEND ITEM TO ITEM_TABLE.
ENDFORM. " build_node_and_item_table
also i have sent a material to ur id
I hope you will get a clear idea on events
Regards,
Sowjanya
Similar Messages
-
Example programs on abap object events?
Hi Experts,
I need some example programs on abap object events.
regards,
vijayHi,
go thru the below program. hope it could help you.
REPORT sapmz_hf_alv_grid .
Type pool for icons - used in the toolbar
TYPE-POOLS: icon.
TABLES: zsflight.
To allow the declaration of o_event_receiver before the
lcl_event_receiver class is defined, decale it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
G L O B A L I N T E R N A L T A B L E S
*DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
To include a traffic light and/or color a line the structure of the
table must include fields for the traffic light and/or the color
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for traffic light
TYPES: traffic_light TYPE c.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
G L O B A L D A T A
DATA: ok_code LIKE sy-ucomm,
Work area for internal table
g_wa_sflight TYPE st_sflight,
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Declare reference variables to the ALV grid and the container
DATA:
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container,
o_event_receiver TYPE REF TO lcl_event_receiver.
DATA:
Work area for screen 200
g_screen200 LIKE zsflight.
Data for storing information about selected rows in the grid
DATA:
Internal table
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
C L A S S E S
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object e_interactive,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
Event handler method for event toolbar.
CONSTANTS:
Constants for button type
c_button_normal TYPE i VALUE 0,
c_menu_and_default_button TYPE i VALUE 1,
c_menu TYPE i VALUE 2,
c_separator TYPE i VALUE 3,
c_radio_button TYPE i VALUE 4,
c_checkbox TYPE i VALUE 5,
c_menu_entry TYPE i VALUE 6.
DATA:
ls_toolbar TYPE stb_button.
Append seperator to the normal toolbar
CLEAR ls_toolbar.
MOVE c_separator TO ls_toolbar-butn_type..
APPEND ls_toolbar TO e_object->mt_toolbar.
Append a new button that to the toolbar. Use E_OBJECT of
event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
This class has one attribute MT_TOOLBAR which is of table type
TTB_BUTTON. The structure is STB_BUTTON
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
Handle own functions defined in the toolbar
CASE e_ucomm.
WHEN 'CHANGE'.
PERFORM change_flight.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
S T A R T - O F - S E L E C T I O N.
START-OF-SELECTION.
SET SCREEN '100'.
*& Module USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module STATUS_0100 OUTPUT
MODULE status_0100 OUTPUT.
DATA:
For parameter IS_VARIANT that is sued to set up options for storing
the grid layout as a variant in method set_table_for_first_display
l_layout TYPE disvariant,
Utillity field
l_lines TYPE i.
After returning from screen 200 the line that was selected before
going to screen 200, should be selected again. The table gi_index_rows
was the output table from the GET_SELECTED_ROWS method in form
CHANGE_FLIGHT
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
EXPORTING
it_index_rows = gi_index_rows.
CALL METHOD cl_gui_cfw=>flush.
REFRESH gi_index_rows.
ENDIF.
Read data and create objects
IF go_custom_container IS INITIAL.
Read data from datbase table
PERFORM get_data.
Create objects for container and ALV grid
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
Create object for event_receiver class
and set handlers
CREATE OBJECT o_event_receiver.
SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
Layout (Variant) for ALV grid
l_layout-report = sy-repid. "Layout fo report
Setup the grid layout using a variable of structure lvc_s_layo
Set grid title
gs_layout-grid_title = 'Flights'.
Selection mode - Single row without buttons
(This is the default mode
gs_layout-sel_mode = 'B'.
Name of the exception field (Traffic light field) and the color
field + set the exception and color field of the table
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
gs_layout-info_fname = 'LINE_COLOR'.
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
Value of traffic light field
g_wa_sflight-traffic_light = '1'.
Value of color field:
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
ELSE.
g_wa_sflight-traffic_light = '3'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_variant = l_layout
i_save = 'A'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
*-- End of grid setup -
Raise event toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid. This is not necessary in this
example as there is only one control on the screen
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0200 INPUT
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT200'.
LEAVE TO SCREEN 100.
WHEN'SAVE'.
PERFORM save_changes.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
*& Form get_data
FORM get_data.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
ENDFORM. " load_data_into_grid
*& Form change_flight
Reads the contents of the selected row in the grid, ans transfers
the data to screen 200, where it can be changed and saved.
FORM change_flight.
DATA:l_lines TYPE i.
REFRESH gi_index_rows.
CLEAR g_selected_row.
Read index of selected rows
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
Check if any row are selected at all. If not
table gi_index_rows will be empty
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a line'.
EXIT.
ENDIF.
Read indexes of selected rows. In this example only one
row can be selected as we are using gs_layout-sel_mode = 'B',
so it is only ncessary to read the first entry in
table gi_index_rows
LOOP AT gi_index_rows INTO g_selected_row.
IF sy-tabix = 1.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Transfer data from the selected row to screenm 200 and show
screen 200
CLEAR g_screen200.
MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
LEAVE TO SCREEN '200'.
ENDFORM. " change_flight
*& Form save_changes
Changes made in screen 200 are written to the datbase table
zsflight, and to the grid table gi_sflight, and the grid is
updated with method refresh_table_display to display the changes
FORM save_changes.
DATA: l_traffic_light TYPE c.
Update traffic light field
Update database table
MODIFY zsflight FROM g_screen200.
Update grid table , traffic light field and color field.
Note that it is necessary to use structure g_wa_sflight
for the update, as the screen structure does not have a
traffic light field
MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
clear g_wa_sflight-line_color.
ELSE.
g_wa_sflight-traffic_light = '3'.
clear g_wa_sflight-line_color.
ENDIF.
MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
Refresh grid
CALL METHOD go_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN '100'.
ENDFORM. " save_changes
regards
-Rakesh -
Internal table modification in ABAP object event
Hi Gurus
I have an internal table displayed using ALV - OOPS concept. THe internal table has 15 rows in my test program but it can go up depending on user inpout.
I am able to display it . on the screen . One of the fields is editable . It is required that it take input from user and on pressing enter , the value entered in that cell should be subtracted from a total amout displayed in the cell next to it.
I have used the following code . There are no errors , but nothing happens when I edit it. The screen remains as it is.
Any help will be very useful
DATA : ITAB type ITABT occurs 0.
DATA : itab_w like line of itab.
CLASS LCL_EVENTS_D0100 IMPLEMENTATION.
METHOD handle_data_changed.
DATA: ls_good TYPE lvc_s_modi.
DATA : L_PLANETYPE TYPE ITABT-SEL_QUANT.
LOOP AT er_data_changed->mt_good_cells INTO ls_good.
CASE ls_good-fieldname.
check if column PLANETYPE of this row was changed
WHEN 'SEL_QUANT'.
CALL METHOD pr_data_changed->get_cell_value
EXPORTING
i_row_id = ls_good-row_id
i_fieldname = ls_good-fieldname
IMPORTING
e_value = l_planetype.
ENDCASE.
LOOP AT ITAB INTO ITAB_W .
read table itab into itab_w WITH KEY FINDEX = LS_GOOD-ROW_ID .
itab_w-f_balquant = itab_w-f_balquant - l_planetype.
modify itab FROM itab_w .
endloop.
ENDLOOP.
ENDMETHOD.
ENDCLASS.Hi,
Hi,
AND also use
* Module Pai INPUT *
* PAI module *
module pai input.
save_ok = ok_code.
clear ok_code.
call method grid1->check_changed_data
importing
e_valid = v_valid.
" After this system will automatically update your changed data into
" internal table t_zthlog
case save_ok.
when 'EXIT'.
perform f_exit_program.
when 'CANC'.
perform f_exit_program.
when 'BACK'.
perform f_exit_program.
when 'SAVE'.
perform f_save_data.
endcase.
endmodule. " Pai INPUT
aRs -
Can anyone tell me how to Copy a node on an ALV Tree using context menu ?
Hello Vidya
The sample report ZUS_SDN_ALVTREE_CTXMENU demonstrates how to copy nodes on an ALV tree.
Before showing the entire coding I would like to point out a few crucial parts of the coding:
(1) Defintion of OUTTAB list
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
The OUTTAB list contains two additional fields holding the tree key (LVC_NKEY) and the node type.
(2) The main logic of the report is implemented in event handler method handle_node_ctxmenu_sel.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
" Note: similar logic like in routine CREATE_HIERARCHY
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
*& Report ZUS_SDN_ALVTREE_CTXMENU
*& Based on: BCALV_TREE_03
REPORT zus_sdn_alvtree_ctxmenu.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_repid TYPE syst-repid,
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_alvtree TYPE REF TO cl_gui_alv_tree.
DATA:
gt_outtab TYPE ty_t_outtab, " Sales Document
gt_fcat TYPE lvc_t_fcat.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
* §2. Define an event handler method to build up a context menu
* (postfix of event name: _CONTEXT_MENU_REQUEST).
* This event is fired each time the user klick with the right
* mouse button on a node.
CLASS-METHODS:
handle_node_ctxmenu_req
FOR EVENT node_context_menu_request OF cl_gui_alv_tree
IMPORTING
node_key
menu,
* §3. Define an event handler method to respond to a function code
* triggered by your menu (postfix: _CONTEXT_MENU_SELECTED).
* This event is fired when the user selects an entry of the
* build up context menu.
handle_node_ctxmenu_sel
FOR EVENT node_context_menu_selected OF cl_gui_alv_tree
IMPORTING
node_key
fcode
sender.
* 'sender' is an implicit event parameter that is provided by
* ABAP Objects runtime system. It contains a reference to the
* object that fired the event. You may directly use it to
* call methods of this instance.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
* §4. Implement your event handler methods.
METHOD handle_node_ctxmenu_req.
* Event parameter 'menu' holds a reference to the standard context
* menu of ALV Tree (functions 'Expand'/'Collapse' on nodes).
* You may either append your own functions (separated by a line)
* or clear the menu if you do not want to allow standard functions.
* In this case the standard menu is cleared.
CALL METHOD menu->clear.
* The next line defines one line of the context menu.
CALL METHOD menu->add_function
EXPORTING
fcode = 'DEL_SUBTREE'
text = 'Delete Subtree'(901). "Delete Subtree
CALL METHOD menu->add_function
EXPORTING
fcode = 'COPY_SUBTREE'
text = 'Copy Subtree'(902). "Copy Subtree
ENDMETHOD. "handle_node_ctxmenu_req
METHOD handle_node_ctxmenu_sel.
* At this point of execution, the user selected a menu entry of the
* menu build up in event handler method handle_node_cm_req.
* Query your own function codes and react accordingly.
DATA:
l_rc TYPE c,
ld_ntype TYPE lvc_value,
ld_parent_key TYPE lvc_nkey,
ld_node_key TYPE lvc_nkey,
lt_subtree TYPE lvc_t_nkey,
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
CASE fcode.
WHEN 'DEL_SUBTREE'.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
textline1 = 'Do you really want to delete'(902)
textline2 = 'this node and all its subnodes?'(903)
titel = 'Confirmation'(904)
cancel_display = ' '
IMPORTING
answer = l_rc.
IF l_rc EQ 'J'.
CALL METHOD sender->delete_subtree
EXPORTING
i_node_key = node_key.
* Do not forget to refresh the display when you change the contents
* of your list.
CALL METHOD sender->frontend_update.
ENDIF.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
IF ( ld_ntype = 'VKORG' ).
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' ).
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' OR
ld_ntype = 'SPART' ).
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH_TREE'
* IMPORTING
* RC =
ENDCASE.
ENDMETHOD. "handle_node_ctxmenu_sel
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
PERFORM init_controls.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL SCREEN '0100'.
* NOTE: no screen elements, ok_code -> gd_okcode
** PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
** PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE. " facilitate manual entries
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
when 'REFRESH_TREE'.
CALL METHOD go_alvtree->update_calculations
* EXPORTING
* NO_FRONTEND_UPDATE =
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
DATA:
ls_hierarchy_header TYPE treev_hhdr.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size screen
EXCEPTIONS
cntl_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.
* create tree control
CREATE OBJECT go_alvtree
EXPORTING
parent = go_docking
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = ' '
no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
PERFORM build_hierarchy_header CHANGING ls_hierarchy_header.
* Hide columns and sum up values initially using the fieldcatalog
PERFORM build_fieldcatalog.
* IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
* (even after this method call). You can change data of your table
* by calling methods of CL_GUI_ALV_TREE.
* Furthermore, the output table 'gt_outtab' must be global and can
* only be used for one ALV Tree Control.
CALL METHOD go_alvtree->set_table_for_first_display
EXPORTING
is_hierarchy_header = ls_hierarchy_header
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_outtab. "table must be empty !
PERFORM init_tree.
ENDFORM. " INIT_CONTROLS
*& Form INIT_TREE
* text
* --> p1 text
* <-- p2 text
FORM init_tree .
PERFORM create_hierarchy.
PERFORM register_events.
* Update calculations which were initially defined by field DO_SUM
* of the fieldcatalog. (see build_fieldcatalog).
CALL METHOD go_alvtree->update_calculations.
* Send data to frontend.
CALL METHOD go_alvtree->frontend_update.
ENDFORM. " INIT_TREE
*& Form build_hierarchy_header
* text
* <--P_LS_HIERARCHY_HEADER text
FORM build_hierarchy_header
CHANGING
cs_hierarchy_header TYPE treev_hhdr.
cs_hierarchy_header-heading =
'SalesOrg/DistChannel/Division'(300).
cs_hierarchy_header-tooltip = 'Customer: Master Sales Data'(400).
cs_hierarchy_header-width = 45.
cs_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form build_fieldcatalog
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
REFRESH: gt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT gt_fcat INTO ls_fcat.
CASE ls_fcat-fieldname.
WHEN 'VBELN' OR
'AUDAT' OR
'AUART' OR
'WAERK' OR
'VKORG' OR
'VTWEG' OR
'SPART' OR
'BSTNK' OR
'KUNNR'.
WHEN 'NETWR'.
ls_fcat-do_sum = 'X'.
ls_fcat-h_ftype = 'SUM'. " or: 'MAX' / 'AVG'
WHEN OTHERS.
ls_fcat-tech = 'X'.
ENDCASE.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.
ENDFORM. " build_fieldcatalog
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
FORM create_hierarchy .
* define local data
DATA:
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
" Select data
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE lt_outtab
UP TO 1550 ROWS.
" sort table according to conceived hierarchy
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
* Define one top node. In this way it is possible to calculate
* values for the whole hierarchy.
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = 'Sales Documents'
IMPORTING
e_new_node_key = ld_top_key.
CLEAR: ls_outtab.
ls_outtab-nkey = ld_top_key.
ls_outtab-ntype = 'ROOT'.
MODIFY gt_outtab FROM ls_outtab INDEX 1
TRANSPORTING nkey ntype.
LOOP AT lt_outtab INTO ls_outtab.
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form ADD_SALES_ORG
* text
* -->P_LS_OUTTAB text
* -->P_LD_TOP_KEY text
* <--P_LD_VKORG_KEY text
FORM add_sales_org
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vkorg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " ADD_SALES_ORG
*& Form add_DISTRIB_CHAN
* text
* -->P_LS_OUTTAB text
* -->P_LD_VKORG_KEY text
* <--P_LD_VTWEG_KEY text
FORM add_distrib_chan
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vtweg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_DISTRIB_CHAN
*& Form add_division
* text
* -->P_LS_OUTTAB text
* -->P_LD_VTWEG_KEY text
* <--P_LD_SPART_KEY text
FORM add_division
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-spart.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_division
*& Form add_complete_line
* text
* -->P_LS_OUTTAB text
* -->P_LD_SPART_KEY text
* <--P_LD_LAST_KEY text
FORM add_complete_line
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
WRITE us_outtab-kunnr TO ld_nodetext+0 NO-ZERO.
WRITE us_outtab-audat TO ld_nodetext+20 DD/MM/YYYY.
CONDENSE ld_nodetext.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = us_outtab " !!!
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
FORM register_events .
DATA:
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
* The following four tree events registers ALV Tree in the constructor
* method itself.
* - cl_gui_column_tree=>eventid_expand_no_children
* (needed to load data to frontend when a user expands a node)
* - cl_gui_column_tree=>eventid_header_context_men_req
* (needed for header context menu)
* - cl_gui_column_tree=>eventid_header_click
* (allows selection of columns (only when item selection activated))
* - cl_gui_column_tree=>eventid_item_keypress
* (needed for F1-Help (only when item selection activated))
* Nevertheless you have to provide their IDs again if you register
* additional events with SET_REGISTERED_EVENTS (see below).
* To do so, call first method GET_REGISTERED_EVENTS (this way,
* all already registered events remain registered, even your own):
CALL METHOD go_alvtree->get_registered_events
IMPORTING
events = lt_events.
* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.
* Register additional events for your own purposes:
* §5. Register first context menu event on frontend (with postfix
* (_REQUEST). The second is registered automatically.
ls_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND ls_event TO lt_events.
* register events on frontend
CALL METHOD go_alvtree->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
* §6. Register both context menu events on backend (ABAP Objects
* event handling).
SET HANDLER:
lcl_eventhandler=>handle_node_ctxmenu_req FOR go_alvtree,
lcl_eventhandler=>handle_node_ctxmenu_sel FOR go_alvtree.
ENDFORM. " register_events
Regards,
Uwe -
Issue regarding [Work Flow] Business Object Event Raise in ABAP Program
Hi All,
I have one issue regarding [Work Flow] Business Object Event Raise in ABAP Program.
Actual TDS is as below:
If E message type written, raise Business object BUS2005 (Production order) Event PickShortage for production order passing warehouse, transfer request
(BUS2065 Object key) in event container. Also include table of text version of error
messages for this set of Transfer
Request.
Can anybody tell me how can i write it technically in ABAP Code.
Can anybody solve this issue!
Thanks in advance.
Thanks,
Deep.Hi,
Can anybody solve above posted issue!
Thanks,
Deep. -
Event handling in global class (abap object)
Hello friends
I have 1 problem regarding events in abap object... how to handel an event in global class in se24 .
Regards
Reema jain.
Message was edited by:
Reema JainHello Reema
The following sample report shows how to handle event in principle (see the § marks)..
The following sample report show customer data ("Header"; KNB1) in the first ALV list and sales areas ("Detail"; KNVV) for the selected customer (event double-click) in the second ALV list.
*& Report ZUS_SDN_TWO_ALV_GRIDS
REPORT zus_sdn_two_alv_grids.
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_cell_top TYPE REF TO cl_gui_container,
go_cell_bottom TYPE REF TO cl_gui_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_knvv TYPE STANDARD TABLE OF knvv.
"§1. Define and implement event handler method
" (Here: implemented as static methods of a local class)
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
* IS_ROW_ID =
* IS_COLUMN_ID =
is_row_no = es_row_no.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = '1000'.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 2
columns = 1
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_top.
CALL METHOD go_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = go_cell_bottom.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_top
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"§2. Set event handler (after creating the ALV instance)
SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1. " Or:
" SET HANDLER: lcl_eventhandler=>handle_double_click FOR all instances.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_cell_bottom
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Display data
gs_layout-grid_title = 'Customers'.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNB1'
is_layout = gs_layout
CHANGING
it_outtab = gt_knb1
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
gs_layout-grid_title = 'Customers Details (Sales Areas)'.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'KNVV'
is_layout = gs_layout
CHANGING
it_outtab = gt_knvv " empty !!!
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid2->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
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.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
* User has pushed button "Display Details"
WHEN 'DETAIL'.
PERFORM entry_show_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form ENTRY_SHOW_DETAILS
* text
* --> p1 text
* <-- p2 text
FORM entry_show_details .
* define local data
DATA:
ld_row TYPE i,
ls_knb1 TYPE knb1.
CALL METHOD go_grid1->get_current_cell
IMPORTING
e_row = ld_row.
READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
CHECK ( syst-subrc = 0 ).
SELECT * FROM knvv INTO TABLE gt_knvv
WHERE kunnr = ls_knb1-kunnr.
ENDFORM. " ENTRY_SHOW_DETAILS
Regards
Uwe -
Why and how to use events in abap objects
Dear all,
Please explain me why and how to use events in abap objects with real time example
regards
pankaj giriHi Pankaj,
I will try to explain why to use events... How to use is a different topic.. which others have already answered...
This is same from your prev. post...
Events :
Technically speaking :
" Events are notifications an object receives from, or transmits to, other objects or applications. Events allow objects to perform actions whenever a specific occurrence takes place. Microsoft Windows is an event-driven operating system, events can come from other objects, applications, or user input such as mouse clicks or key presses. "
Lets say you have an ALV - An editable one ...
Lats say - Once you press some button you want some kind of validation to be done.
How to do this ?
Raise an Event - Which is handled by a method and write the validation code.
Now you might argue, that I can do it in this way : Capture the function code - and call the validate method.
Yes, in this case it can be done.. But lets say .. you change a field in the ALV and you want the validation to be done as soon as he is done with typing.
Where is the function code here ? No function code... But there is an event here - The data changed event.
So you can raise a data changed event that can be handled and will do the validation.
It is not user friendly that you ask the user to press a button (to get the function code) for validation each time he enters a data.
The events can be raised by a system, or by a program also. So in this case the data changed event is raised by a system that you can handle.
Also, Lets say on a particular action you want some code to trigger. (You can take the same example of validation code). In this case the code to trigger is in a separate class. The object of which is not available here at this moment. (This case happens very frequently).
Advantage with events : Event handlers can be in a separate class also.
e.g : In the middle of some business logic .. you encounter a error. You want to send this information to the UI (to user - in form of a pop up) and then continue with some processing.
In many cases - A direct method call to trigger the pop up is not done. Because (in ideal cases) the engine must not interact with UI directly - Because the UI could be some other application - like a windows UI but the error comes from some SAP program.
So - A event is raised from the engine that is handled in the UI and a pop up is triggered.
Here -- I would have different classes (lets say for different Operating Systems). And all these classes must register to the event ERROR raised in application.
And these different classes for different Operation systems will have different code to raise a pop-up.
Now you can imagine : If you coded a pop-up for Windows (in your application logic) .. it will not work for Mac or Linux. But of you raise a event.. that is handled separately by a different UI classes for Win, Linux or Mac they will catch this event and process accordingly.
May be I complicated this explanation .... but I couldn't think of a simpler and concrete example.
Cheers.
Varun. -
How to Handle Business Object event in ABAP class
Hello Everybody,
I wanted to know if it was possible to reference BOR objects in ABAP class and handle BOR events in ABAP Objects.
Thanks in advance.Hi,
Catch the et_VALIDATE event, when InnerEvent = False and ItemChanged = True.
If pVal.EventType = BoEventTypes.et_VALIDATE Then
If pVal.InnerEvent = False And pVal.ItemChanged Then
'TODO Your code here...
End If
End If
Regards,
Vítor Vieira -
What is the equivalent for 'On Change of' Event in ABAP OBJECTS?
What is the equivalent for 'On Change of' Event in ABAP OBJECTS? and how to use it in LOOP control?
hi,
There is no such Equivalent in OO ABAP.
You have to Raise your own Event within tha class checking the value of the field whose value is changing.
Regards
Sumit Agarwal -
Regarding [Work Flow] Business Object Event Raise in ABAP Program
Hi All,
I have one issue regarding [Work Flow] Business Object Event Raise in ABAP Program.
Actual TDS is as below:
If E message type written, raise Business object BUS2005 (Production order) Event PickShortage for production order passing warehouse, transfer request
(BUS2065 Object key) in event container. Also include table of text version of error
messages for this set of Transfer
Request.
Can anybody tell me how can i write it technically in ABAP Code.
Can anybody solve this issue!
Thanks in advance.
Thanks,
Deep.Hi,
Can anybody solve above posted issue!
Thanks,
Deep. -
Dear All,
Would you mind tell me the concept of the event in the ABAP objects.
Regards,
LukehI
Triggering and Handling Events
In ABAP Objects, triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.
This section contains explains how to work with events in ABAP Objects. For precise details of the relevant ABAP statements, refer to the corresponding keyword documentation in the ABAP Editor.
Triggering Events
To trigger an event, a class must
· Declare the event in its declaration part
· Trigger the event in one of its methods
Declaring Events
You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:
EVENTS ) TYPE type ..
To declare static events, use the following statement:
CLASS-EVENTS ... ...
It links a list of handler methods with corresponding trigger methods. There are four different types of event.
It can be
· An instance event declared in a class
· An instance event declared in an interface
· A static event declared in a class
· A static event declared in an interface
The syntax and effect of the SET HANDLER depends on which of the four cases listed above applies.
For an instance event, you must use the FOR addition to specify the instance for which you want to register the handler. You can either specify a single instance as the trigger, using a reference variable ...
The registration applies automatically to the whole class, or to all of the classes that implement the interface containing the static event. In the case of interfaces, the registration also applies to classes that are not loaded until after the handler has been registered.
Timing of Event Handling
After the RAISE EVENT statement, all registered handler methods are executed before the next statement is processed (synchronous event handling). If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.
Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm -
hi,
can any1 pls explain me the single click event LINK_CLICK in abap object.
does this single click event mean that if i click anywhere on my alv report it will trigger the event.
pls explain me about this LINK_CLICK event in details plsanswered the similar question last week. You can see here Event
Link_click or ALV_Object Model HYPERLINK.
This example demonstrates how to use a Hiperlink field in ALV. These example was based on 'SALV_DEMO_TABLE_COLUMNS' that contains Hiperlink, icon, Hotspot...
The Code is:
REPORT zsalv_mar NO STANDARD PAGE HEADING.
CLASS lcl_handle_events DEFINITION
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
CLASS lcl_handle_events IMPLEMENTATION
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_link_click.
DATA: l_row_string TYPE string,
l_col_string TYPE string,
l_row TYPE char128.
WRITE row TO l_row LEFT-JUSTIFIED.
CONCATENATE text-i02 l_row INTO l_row_string SEPARATED BY space.
CONCATENATE text-i03 column INTO l_col_string SEPARATED BY space.
MESSAGE i000(0k) WITH 'Single Click' l_row_string l_col_string.
ENDMETHOD. "on_single_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
DATA: gr_events TYPE REF TO lcl_handle_events.
TYPES: BEGIN OF g_type_s_outtab.
INCLUDE TYPE alv_tab.
TYPES: t_hyperlink TYPE salv_t_int4_column,
END OF g_type_s_outtab.
DATA: gt_outtab TYPE STANDARD TABLE OF g_type_s_outtab.
DATA: gr_table TYPE REF TO cl_salv_table.
TYPES: BEGIN OF g_type_s_hyperlink,
handle TYPE salv_de_hyperlink_handle,
hyperlink TYPE service_rl,
carrid TYPE s_carrid,
END OF g_type_s_hyperlink.
DATA: gt_hyperlink TYPE STANDARD TABLE OF g_type_s_hyperlink.
SELECTION-SCREEN BEGIN OF BLOCK gen WITH FRAME.
PARAMETERS: p_amount TYPE i DEFAULT 30.
SELECTION-SCREEN END OF BLOCK gen.
START-OF-SELECTION.
PERFORM select_data.
PERFORM display.
*& Form select_data
text
--> p1 text
<-- p2 text
FORM select_data .
DATA: line_outtab TYPE g_type_s_outtab,
ls_hype TYPE g_type_s_hyperlink,
lt_hyperlink TYPE salv_t_int4_column,
ls_hyperlink TYPE salv_s_int4_column,
v_tabix TYPE sytabix.
SELECT *
FROM alv_tab
INTO CORRESPONDING FIELDS OF TABLE gt_outtab
UP TO p_amount ROWS.
LOOP AT gt_outtab INTO line_outtab.
v_tabix = sy-tabix.
ls_hype-handle = sy-tabix.
ls_hype-hyperlink = line_outtab-url.
ls_hype-carrid = line_outtab-carrid.
INSERT ls_hype INTO TABLE gt_hyperlink.
ls_hyperlink-columnname = 'URL'.
ls_hyperlink-value = sy-tabix.
APPEND ls_hyperlink TO lt_hyperlink.
line_outtab-t_hyperlink = lt_hyperlink.
MODIFY gt_outtab FROM line_outtab INDEX v_tabix.
CLEAR line_outtab.
CLEAR lt_hyperlink.
CLEAR ls_hyperlink.
ENDLOOP.
ENDFORM. " select_data
*& Form display
text
--> p1 text
<-- p2 text
FORM display .
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = gt_outtab ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
DATA: lr_functions TYPE REF TO cl_salv_functions_list.
lr_functions = gr_table->get_functions( ).
lr_functions->set_default( abap_true ).
*... set the columns technical
DATA: lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column_table.
lr_columns = gr_table->get_columns( ).
lr_columns->set_optimize( abap_true ).
*... §4.7 set hyperlink column
DATA: lr_hyperlinks TYPE REF TO cl_salv_hyperlinks,
ls_hyperlink TYPE g_type_s_hyperlink.
DATA: lr_functional_settings TYPE REF TO cl_salv_functional_settings.
TRY.
lr_columns->set_hyperlink_entry_column( 'T_HYPERLINK' ).
CATCH cx_salv_data_error. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column ?= lr_columns->get_column( 'URL' ).
lr_column->set_cell_type( if_salv_c_cell_type=>link ).
lr_column->set_long_text( 'URL' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
lr_functional_settings = gr_table->get_functional_settings( ).
lr_hyperlinks = lr_functional_settings->get_hyperlinks( ).
LOOP AT gt_hyperlink INTO ls_hyperlink.
TRY.
lr_hyperlinks->add_hyperlink(
handle = ls_hyperlink-handle
hyperlink = ls_hyperlink-hyperlink ).
CATCH cx_salv_existing. "#EC NO_HANDLER
ENDTRY.
ENDLOOP.
DATA: lr_events TYPE REF TO cl_salv_events_table.
lr_events = gr_table->get_event( ).
CREATE OBJECT gr_events.
SET HANDLER gr_events->on_link_click FOR lr_events.
gr_table->display( ).
ENDFORM. " display -
How to use LDB PNP with ABAP objects in a program
Hello,
I am wondering if anybody has used the HR logical database(LDB) PNP with user defined ABAP objects in a program? I am using the FM- <b>LDB_PROCESS</b> but its not working. Also assigning PNP in the attributes section of the program -- so that I can use predefined fields from the LDB and then invoking the FM doesn't work -- throwing 'Logical database already active' error.
I suppose even with the ABAP objects and the new FM -- I should still be able to utilize the pre-defined fields of the PNP database -- and also the built in authorizations. I cannot use GET PERNR and REJECT as they give errors. I understand that the use of HR-macros (RP-PROVIDE-FROM-LAST and et al.) are not allowed as they use the table work area -- which is not allowed in ABAP-OOPS.
I would really appreciate if anyone could show me some insight regarding this. Thank you.
Kshitij R. DevreHi Kshitij
It would be really good if we could use both together. But as I know, it is not possible. "GET pernr." is an event-like loop statement and so cannot be used in OO context. And I guess, the same restriction holds for the "LDB_PROCESS" since it uses LDB-specific processing.
What I suggest you is to use standard and BAPI functions.
Sorry for giving bad news...
*--Serdar -
Can anybody help me sending some ABAP Objects
Hi gurus,
can anybody give me some ABAP objects ( i.e. Scenaro or FS or TS ).
I am new in SAP. It will immensely be helpful to me to understand the real business scenarios.
Any type of response is appriciated.
Thanks,
Ajoy Chatterjee.
Email ID : [email protected]Hi Chatterjee,
Go through this,
OO ABAP
http://www.sapgenie.com/abap/OO/
For understanding COntrol Frameworks in OO ABAP, check this.
http://www.sapgenie.com/abap/controls/index.htm
ABAP_OBJECTS_ENJOY_0 Template for Solutions of ABAP Object Enjoy Course
ABAP_OBJECTS_ENJOY_1 Model Solution 1: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_2 Model Solution 2: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_3 Model Solution 3: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_4 Model Solution 4: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_5 Model Solution 5: ABAP Objects Enjoy Course
DEMO_ABAP_OBJECTS Complete Demonstration for ABAP Objects
DEMO_ABAP_OBJECTS_CONTROLS GUI Controls on Screen
DEMO_ABAP_OBJECTS_EVENTS Demonstration of Events in ABAP Objects
DEMO_ABAP_OBJECTS_GENERAL ABAP Objects Demonstration
DEMO_ABAP_OBJECTS_INTERFACES Demonstration of Interfaces in ABAP Objects
DEMO_ABAP_OBJECTS_METHODS Demonstration of Methods in ABAP Objects
DEMO_ABAP_OBJECTS_SPLIT_SCREEN Splitter Control on Screen
You can get nice docs regarding OO ABAP from these links also...
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
Check this link
http://help.sap.com/saphelp_nw2004s/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
You can also check the transaction ABAPDOCU for sample abap OO programs..
Go through the following Documents Links & Materials for ABAP Objects
check the below links lot of info and examples r there
http://www.sapgenie.com/abap/OO/index.htm
http://www.geocities.com/victorav15/sapr3/abap_ood.html
http://www.brabandt.de/html/abap_oo.html
Check this cool weblog:
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
/people/sap.user72/blog/2005/05/10/a-small-tip-for-the-beginners-in-oo-abap
/people/ravikumar.allampallam/blog/2005/02/11/abap-oo-in-action
/people/thomas.jung3/blog/2005/09/08/oo-abap-dynpro-programming
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
these links
http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
For funtion module to class
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm
for classes
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm
for methods
http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
for inheritance
http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm
for interfaces
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
For Materials:
1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291
2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
8) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
1) http://www.erpgenie.com/sap/abap/OO/index.htm
2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
Reward points if helpful.
Thanks
Naveen khan -
List header for alv grid using abap objects
Hai all,
I have displayed alv grid in container control using abap objects i.e. using method set_table_for_first_display.
now i need to display list header for this alv grid.
please help me how to create with a sample coding.
Thanks and regards,
Prabu S.Create a splitter using CL_GUI_EASY_SPLITTER_CONTAINER with a top and bottom half. Put the alv grid in the bottom half. Use cl_dd_document (documented in help.sap.com ) to build the header in the top half. Use events on CL_GUI_ALV_GRID to handle the top-of-list printing.
Or, if available, use CL_SALV_TABLE, and read the documentation on that. When I needed a header for my report, that's what I did. There's plenty of good documentation about if you'll search for it.
matt
Maybe you are looking for
-
Can you embed a video in a full screen slide show?
Is that possible? I've seen similar effects in a few muse templates on Themeforest. Any direction on this would be great!
-
CS2 12.0 crash when i load up a file
I have AI CS2 12.0 installed and I have some files that i created about 9 months ago. I don't remember what version of CS it was then but it was CS2. Now when i load up the files they load fine but every time i go to 'file' and click 'save' the progr
-
Edit Form in Document Library missing data
When I try to create a new Edit Form for a Document Library in SP Designer 2013 the new form is missing the Name field. The people picker field doesn't do lookups anymore either. Like the Java is broke. When I tried to do the same thing on a Drop
-
MBP Core Duo 17" 2.16Ghz - Why is 2GB the limit? 4GB?
All the past and future Mac Notebooks allowed memory upgrades when the chips either became available or affordable. The Apple store advisor (when I purchased last year) said that like older Mac Notebooks they assumed that the MBP memory would be upgr
-
I'm having a strange problem with itunes Match (as do many apparently)
In several instances, I have individual songs within an album that has been matched that are showing as ineligible. How to fix? I have two Apple IDs authorized on my computer (my wife's and mine) but that shouldn't explain individual songs that have