cancel
Showing results for 
Search instead for 
Did you mean: 

regarding WD ABAP

Former Member
0 Kudos

Hi All,

I want to ADD and DELETE a row from the table in WD ABAP.I have created a button for add but it is not working while run time.So please sort it out and if anyone of you is sending a code then please validate it so that I can easily understand it.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Anand,

This code will help you.

***************To ADD RECORD**********************************

********declaration for retriving data from user*******************

data : emp_id type zhg_emp1-emp_id,

emp_name type zhg_emp1-emp_name,

contact_no type zhg_emp1-contact_no,

ext_no type zhg_emp1-ext_no,

desk_no type zhg_emp1-desk_no.

******cerate internal table and work area************************

data : it_emp type table of ZHG_EMP1S.

data : wa_emp like line of it_emp.

*******************here EMP_REC is the node********************

data : emp type ref to IF_WD_CONTEXT_NODE.

emp = WD_CONTEXT->GET_CHILD_NODE( 'EMP_REC' ).

***************Retriving data from GUI***************************

emp->get_attribute( exporting name = 'EMP_ID' importing value = emp_id ).

emp->get_attribute( exporting name = 'EMP_NAME' importing value = emp_name ).

emp->get_attribute( exporting name = 'CONTACT_NO' importing value = contact_no ).

emp->get_attribute( exporting name = 'EXT_NO' importing value = ext_no ).

emp->get_attribute( exporting name = 'DESK_NO' importing value = desk_no ).

*********************keep into work area***********************

wa_emp-emp_id = emp_id.

wa_emp-emp_name = emp_name.

wa_emp-contact_no = contact_no.

wa_emp-ext_no = ext_no.

wa_emp-desk_no = desk_no.

*************code for adding record into table *******************

insert ZHG_EMP1 from wa_emp.

*******************************************************************************

**********************TO DELETE RECORD**************************************

delete from ZHG_EMP1 where emp_id = wa_emp-emp_id.

Table name : ZHG_EMP1

Table's key field : emp_id

Input from user/ GUI: wa_emp-emp_id

Former Member
0 Kudos

Hi,

To add rows, use the below code and change node structure accordingly

DATA: L_NODE TYPE REF TO IF_WD_CONTEXT_NODE.

DATA: L_ELEMENT TYPE REF TO IF_WD_CONTEXT_ELEMENT.

DATA: L_STRUC TYPE IF_WD_CONTEXT_NODE-NODE1.

L_NODE = WD_CONTEXT->GET_CHILD_NODE( 'NODE1' ).

L_ELEMENT =

L_NODE->BIND_ELEMENT( NEW_ITEM = L_STRUC SET_INITIAL_ELEMENTS = ABAP_FALSE ).

To delete, get the lead selection first and delete that element.

L_ELEMENT = L_NODE->GET_LEAD_SELECTION( ).

L_NODE->REMOVE_ELEMENT( L_ELEMENT ).

regards

Jose

Former Member
0 Kudos

Hi Anand,

Write following line of code to action of 'Add Row' Button. Please note that 'node_name' is the name of the node u would have actually bind your table with.

*************************************************

DATA:

node_tab TYPE REF TO if_wd_context_node,

elem_tab TYPE REF TO if_wd_context_element.

node_tab = wd_context->get_child_node( <node_name> ).

elem_tab = node_tab->create_element( ).

node_Tab->bind_element( new_item = elem_tab SET_INITIAL_ELEMENTS = abap_false ).

*************************************************

Write following line of code to action of 'Delete Row' Button.

****************************************************

DATA:

node_tab TYPE REF TO if_wd_context_node,

elem_tab TYPE REF TO if_wd_context_element.

node_tab = wd_context->get_child_node( <node_name> ).

elem_tab = node_tab->get_lead_selection( ).

node_Tab->remove_element( elem_tab ).

****************************************************

Hope that helps. Let me know if still any issues.

Regards,

Amit

abhimanyu_lagishetti7
Active Contributor
0 Kudos

to Add

data: lr_node type ref to if_wd_context_node.

data: lr_element type ref to if_wd_context_element.

data: ls_stru type < node type >

lr_node = wd_context->get_child_node( '<node_name>' ).

lr_element =

lr_node->bind_element( new_item = ls_stru SET_INITIAL_ELEMENTS = abap_false ).

to delete

lr_element = lr_node->get_lead_selection( ).

lr_node->remove_element( lr_element ).

Abhi