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
Similar Messages
-
Passing a program defined internal table to an abap object
Hi. I have an internal table that was previously defined and created by SAP that I need to process in a user exit. The table is defined exactly as shown below.
Is it possible to pass a table that was defined in this manner (not in the ABAP dictionary) as an argument to a method of an ABAP object?
If so, what would the data type of the itab parameter have to be when defining the object's method parameter list? Is it necessary to somehow "cast it" to the KNA1 table type once I receive the table into the method? If so, what is the data type of the object's receiving variable/attribute?
data: begin of lkna1 occurs 0001.
include structure kna1 .
data:
end of lkna1 .
Just as one additional piece of information, I am using version 4.5B and I am trying to do this through se24.
Thanks so much!Hi again,
<b>This kind of simple approach,
we can pass ANY KIND OF TABLE
WITHOUT HAVING TO DEFINE
LINE TYPE IN SE11.</b>
1. doing this simply u will achieve what u want.
( i just tried the same)
2. in se24,
give like this
ITAB Importing Type <b>STANDARD TABLE</b>
3. in the calling program,
call like this,
report abc.
data: begin of lkna1 occurs 0001.
include structure kna1.
data: end of lkna1.
data: testobj type ref to zsdtest.
select * from kna1
into table lkna1.
lkna1-kunnr = '000234'.
create object testobj.
<b>call method testobj->testreceive
exporting itab = lkna1[].</b>
4.
then in the class, source code,
just use like this
(so that u can accesss the fields of the itab,
using myitab)
<b>method TESTRECEIVE .
data : myitab type table of kna1.
myitab[] = itab[].
break-point.
endmethod.</b>
5. thats all !
regards,
amit m. -
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 declaration -OO ABAP
Hi,
I am looking to declare an internal table using OO objects. My declaration are as follows..
TYPES : Begin of itab,
f1 type c,
f2 type c,
End of itab.
DATA : itab1 type standard table of itab.
DATA: wa_tab type itab.
I have an internal table to say itab_pa2001 which i am reading all the records of pernr into ITAB_PA2001.To get the text i want to select * from t5*** into ..... Finally wht am looking is to move some of the fields into the final table ITAB. Could you please let me know how to set this up as i am getting wrong values when i am looping as below.
how to declare a structure in ITAB using ABAP OO....??
LOOP at ITAB_PA2001 into wa_itab.
ENDLOOP.
Thanks,
VindHi,
Please refer to following links :
[How to declare an internal table in OO-ABAP programming? |Re: How to declare an internal table in OO-ABAP programming?;
[sample object oriented ABAP program |http://wiki.sdn.sap.com/wiki/display/Snippets/sampleobjectorientedABAPprogram]
Hope this helps.
Regards,
Chandravadan -
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 -
To know the functionality of table control in ABAP Objects
Hi,
Is there any technique to achieve the functionality of table conrol in ABAP Objects?
Thanks.Hello Raja
If you are using an editable ALV grid then you have the functionality of a table control and much much more.
ABAP-OO based ALV grids are much more powerful (and easier) than simple table controls.
Regards
Uwe -
How to upload XML file into the internal table in Webdynpro ABAP ?
Hi Friends,
I am not able to upload the XML file into ABAP,can you please help me in solving this issue with the help of source code.
Regards
DineshHi Dinesh,
Try go through this program which I had developed earlier. It takes as input an XML file and then breaks it down into name-value pairs of an intrnal table. You need to pass an XML file as input to this program. (I had hard coded the path for my XML file in it. You need to replace it with 1 of your own or you can just delete it and use the browse button to selet the file on your PC)
Regards,
Uday
REPORT ZUDAY_XML no standard page heading.
" Internal table to store the XML file in binary mode
data: begin of it_xml occurs 1,
c(255) type x,
end of it_xml,
" Name-value pairs table rturned by FM SMUM_XML_PARSE
it_SMUM_XMLTB type SMUM_XMLTB occurs 0 with header line,
" Table returned by FM SMUM_XML_PARSE for error handling
it_bapiret2 type bapiret2 occurs 0 with header line.
" XSTRING variable to be used by FM SCMS_BINARY_TO_XSTRING to hold the XML file in XSTRING format
data: I_xstring type xstring,
" String variable to hold XML file path to pass to GUI_UPLOAD
I_file_path type string,
" Variable to store the size of the uploaded binary XML file
I_LENGTH TYPE I VALUE 0.
parameters: P_path type IBIPPARMS-PATH default 'C:\Documents and Settings\c5104398\Desktop\flights.xml'.
" Get the XML file path from the user
at selection-screen on value-request for P_path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = P_PATH. -
Use Internal table in WebDynpro ABAP.
Hi,
I am using a internal table, for calling a FM, which require Internal table as its parameter. Since Internal table with header line is not supported in ABAP OO. How to attain this.
Thanq For Ur time.
Cheers,
SamHi Sam,
If we want to use an internal table for the FM as input then we can declare a table and use it.
But when we want use it as a workarea we need to define a work area (another attribute) of a internal table saparatly and use it.
Best regards,
Suresh -
XML to internal table conversion within ABAP mapping class
I am doing a ABAP mapping for file to Idoc. My requirement is to convert XML file into ABAP internal table (within ABAP mapping class). Is there any standard FM, method, transformation etc, which can be used here.
Thanks, DehraDehra,
Have you seen this weblogs which talks about this:
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
/people/r.eijpe/blog/2006/02/19/xml-dom-processing-in-abap-part-iiia150-xml-dom-within-sap-xi-abap-mapping
/people/r.eijpe/blog/2006/02/20/xml-dom-processing-in-abap-part-iiib150-xml-dom-within-sap-xi-abap-mapping
Hope this helps you....
---Satish -
How to avaoid tables declaration in abap object 's
Hi Folks,
I realised that in abap objects we should not declare tables statement, instead we have to declare wa type dbtable. But my qsn is i am using select single * from dbtable in at selection-screen for validation, in that situation in that situation how to avoid table declaration, i tried with select single * dbtable into wa , but still its asking table declaration.
Pls help me out, thanks.
Regards
Vishal<b>method GET_VENDOR_4_USER .
Get the Vendor for the User
data: x_lfa1 type lfa1.
clear vendor.
select
lifnr
into VENDOR
from zsiacvendor
up to 1 rows
where bname = sy-uname.
endselect.
get the name of the vendor
select single *
into x_lfa1
from lfa1
where lifnr = vendor.
endmethod.</b>
The above code works fine for me. -
hello gurus,
I got output of a report as bellow.
sl no date name state contry
1 10.10.2009 mtm
1 10.10.2009 A1
1 10.10.2009 abc
1 10.10.2009 b1
1 10.10.2009 c1
but my required output is.
sl no date name state contry
1 10.10.2009 A1 mtm ABC
1 10.10.2009 B1
1 10.10.2009 C1
can any body tell me how to change the format.
my internal table data contains as displayed output only.
so i need to do operations at internal table level to get the required output.
thanks,
padmaja.
Edited by: padmaja vaddi on Mar 9, 2009 5:09 AMHi Padmaja,
Please see the code below:
itab1[ ] = itab[ ].
sort itab1 comparing date name.
delete adjacent duplicates from itab1.-->itab1 will contain 3 records and itab will contain 5 records
loop at itab1 into wa_itab1.
clear: wa_itab2, wa_itab.
loop at itab into wa_itab where date = wa_itab1-date
name = ' '.
if wa_itab-state is not initial.
wa_itab2-state = wa_itab-state.
endif.
if wa_itab-country is not initial.
wa_itab2-country = wa_itab-country.
endif.
endloop.
wa_itab2-name = wa_itab1-name.
wa_itab2-date = wa_itab1-date.
wa_itab2-sl_no = wa_itab1-sl_no.
append wa_itab2 to itab2.
endloop.
And in the internal table itab2 , u will have the required output.
Keerthi. -
Unicode error:a line of internal table and a data object are not mutually c
Hi Friends,
This is the issue in upgradation from 4.6c to ECC6.0
I have an internal table itab which has include structure say 'xyz' . In xyz there is a field of type int4 as third field. I have a field as l_line which is a string.
data : begin of itab occurs 0.
include structure zxyz.
data: end of itab.
data: l_line type string.
In the program I am getting the unicode error as:
" A line of "itab" and "l_line" are not mutually convertible in unicode program." at he following line.
loop at itab into l_line.
endloop.
Thanks,
Ali.Hi Narendran,
I did the same earlier, but the field l_line is again used in the another line as follows
IF l_line CS w_group.----
(1)
where w_group LIKE zstr-cctr_group.
here zstr-cctr_group is same as one of the fields of structure xyz.
in line 1 it is giving warning as
l_line is incompatible and it must be C,N,D,T or string.
Thanks,
Ali -
How to populate internal table( varaible of ABAP table type) in Excel VBA?
Hi,
I am trying to update a database table from excel using a VBA Macro.
I am able to connect to SAP and able to read data from SAP using a RFC. Similarly after updating certain values, i want to update a table in SAP.
Below are the steps I am doing apart from basic settings.
Getting the reference of the SAP TABLE type from RFC fucntion module
' Call RFC
Set MyFunc = R3.Add("UPDATE_TVARVC_VIA_RFC")
' Get reference and Values TVARVC
Set oParam4 = MyFunc.Tables("TVARVC")
2. Loop over the active cells and populate oParam4
" add values as below
oParam4.Rows.Add
oParam4.Value(1, "NAME") = ..................
oParam4.Value(1, "TYPE") = ..................
oParam4.Value(1, "NUMB") = ..................
Do it for all columns in the table line.
My query is how to identify active cells and make the above code dynamic in step 2.
Thanks in Advance,
Best,
AneelHi Aneel,
You can try the following:
e.g.
for j = 1 to ActiveCell.SpecialCells(11).Column
oParam4.Rows.Add
if j=1 then oParam4.Value(j, "NAME") = ActiveSheet.Cells(1,j).Value
if j=2 then oParam4.Value(j, "TYPE") = ActiveSheet.Cells(1,j).Value
if j=3 then oParam4.Value(j, "NUMB") = ActiveSheet.Cells(1,j).Value
next j
Regards,
ScriptMan -
Passing an internal table WITH HEADER LINE to abap object
Hi. In another thread, it was explained how to pass an internal table to an abap object method. Is it possible to pass an internal table that has a header line, and RETAIN the header line once the table has been passed?
My problem is, that I can pass the table, update it, but the read buffer is not populated when returning from the object's method. This is the result of being able to pass a STANDARD TABLE type, but not a STANDARD TABLE WITH HEADER LINE.
This means that I have to read the table into a work area instead of doing a READ TABLE LKNA1 within the method, which is what I need to do.
Thanks.Please check this sample program, notice that it is modifing the internal table and passing it back modified as well as passing the "work area" or "header line" back thru the exporting parameter.
report zrich_0001.
* CLASS lcl_app DEFINITION
class lcl_app definition.
public section.
types: t_t001 type table of t001.
class-data: it001 type table of t001.
class-data: xt001 like line of it001.
class-methods: change_table
exporting ex_wt001 type t001
changing im_t001 type t_t001.
endclass.
data: w_t001 type t001.
data: a_t001 type table of t001 with header line.
start-of-selection.
select * into table a_t001 from t001.
call method lcl_app=>change_table
importing
ex_wt001 = w_t001
changing
im_t001 = a_t001[] .
check sy-subrc = 0.
* CLASS lcl_app IMPLEMENTATION
class lcl_app implementation.
method change_table.
loop at im_t001 into xt001.
concatenate xt001-butxt 'Changed'
into xt001-butxt separated by space.
modify im_t001 from xt001.
endloop.
ex_wt001 = xt001.
endmethod.
endclass.
Regards,
Rich Heilman -
Declaring the internal table in ABAP objects
Hi every1,
Please any one let me know how to declare an internal table in class (ABAP objects). Bcos i am new to this classes.
help me out.
Regards,
MadhaviHi,
Check this example..
TYPES: BEGIN OF TYPE_DATA,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
END OF TYPE_DATA.
DATA: T_DATA TYPE STANDARD TABLE OF TYPE_DATA.
DATA: WA_DATA TYPE TYPE_DATA.
Adding rows to the internal table.
WA_DATA-MATNR = 'AA'.
APPEND WA_DATA TO T_DATA.
Processing the interna table
LOOP AT T_DATA INTO WA_DATA.
ENDLOOP.
Thanks,
Naren
Maybe you are looking for
-
How to Add a Linefeed to the Very End of a TextFrame's Contents
(IND 5.0, Actionscript) Hi all, I need to be able to add a linefeed ("\n") to the very end of a TextFrame's contents, which may include any combination of tagged and untagged texts, and tagged and untagged image frames. There seems to be an endless v
-
My computer crashed and the hard drive is no longer. I have purchased a new laptop but now have no access to my old itunes library. My laptop has created a new itunes account with NOTHING in it?? My Itouch has everything loaded but it wont sync wit
-
Suggest file name in JFileChooser?
I'm a newbie (student) to both Swing and Java in general. In using JFileChooser, It occurred to me that it would be nice to offer a suggested file name when saving files. For those of you who have used MS Word, when one saves a new file, Word offers
-
Recording Audio From A Sound Board
I was originally planning on buying a Samson Zoom H2, H4N, or ProTrack Stereo Recorder to begin recording audio at concerts I attend using the house sound board, but began wondering if the iPod Touch had the same capability, perhaps by adding an app
-
My iphone will not turn on.... it froze earlier today and now it will not turn on all i get is a black screen with the apple symbol every once in awhile... also it will not connect to my computer so i can reset it to factory settings