cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete the record in the table without using lead selection?

Former Member
0 Kudos

hi,

I have added the separate column "delete" to the table uielement and so for each record or row of the table the appropriate "delete" link to action will be there................the code below works when the particular row is selected through lead selection only.......

help me how to delete without using lead selection.....

DATA:

NODE_MODULE TYPE REF TO IF_WD_CONTEXT_NODE,

ELEM_MODULE TYPE REF TO IF_WD_CONTEXT_ELEMENT,

STRU_MODULE TYPE IF_V_MODULE=>ELEMENT_MODULE .

data itab TYPE TABLE OF zac_modules.

  • navigate from <CONTEXT> to <MODULE> via lead selection

NODE_MODULE = WD_CONTEXT->GET_CHILD_NODE( NAME = `MODULE` ).

  • get element via lead selection

ELEM_MODULE = NODE_MODULE->GET_ELEMENT( ).

  • get all declared attributes

ELEM_MODULE->GET_STATIC_ATTRIBUTES(

IMPORTING

STATIC_ATTRIBUTES = STRU_MODULE ).

NODE_MODULE->GET_STATIC_ATTRIBUTES_TABLE(

IMPORTING

TABLE = itab )

.

DELETE itab WHERE zmodule_id = STRU_MODULE-zmodule_id.

CALL METHOD NODE_MODULE->BIND_TABLE

EXPORTING

NEW_ITEMS = itab

  • SET_INITIAL_ELEMENTS = ABAP_TRUE

  • INDEX =

.

ENDMETHOD.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Alagappen,

i think onbutton action send you the standard parameters id and context_element. If you do not have them already, you can delete the action and create a action with event-parameters checkbox selected or you can insert these parameters on your own.

if_wd_context_node has parameter remove_element and it accepts a context_element as importing parameter.

Former Member
0 Kudos

hi baskaran,

But i have delete button for each and every record for the table.....................and i have to delete the record without using lead selection........

Edited by: Alagappan.S on Jan 31, 2011 4:49 PM

gill367
Active Contributor
0 Kudos

Hi

In the eventhandler of the delete button .

write the code to get the element from which the button has been clicked by using the following code and then delete it.

DATA lo_el TYPE REF TO if_wd_context_element.
      lo_el = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).

then delete

DATA lo_nd TYPE REF TO if_wd_context_node.

    lo_nd = wd_context->get_child_node( name = '<node name>' ).

     lo_nd->remove_element( lo_el ).

Regards,

Sarb

Former Member
0 Kudos

>

> hi baskaran,

>

> But i have delete button for each and every record for the table.....................and i have to delete the record without using lead selection........

>

> Edited by: Alagappan.S on Jan 31, 2011 4:49 PM

Right, on every button click you get the corresponding context_element along with the wdevent object.

If your event handler has this parameter (importing) then data transport happens automatically. You do not need any lead selection.

Former Member
0 Kudos

@sarbjeet

plz edit me in the above code which i have written bcoz i dont know where the prob. occurs exactly......

Former Member
0 Kudos

Hi ,

The onclick event provides you with a standard paramater "CONTEXT_ELEMENT" which has the element from which the event is triggered.

so you can declare this in the handler(if it is not there) and use it as follows.

CONTEXT_ELEMENT TYPE REF TO IF_WD_CONTEXT_ELEMENT an importing paramater.

DATA:
NODE_MODULE TYPE REF TO IF_WD_CONTEXT_NODE,
ELEM_MODULE TYPE REF TO IF_WD_CONTEXT_ELEMENT,
STRU_MODULE TYPE IF_V_MODULE=>ELEMENT_MODULE .
data itab TYPE TABLE OF zac_modules.

CONTEXT_ELEMENT->GET_STATIC_ATTRIBUTES(
IMPORTING
STATIC_ATTRIBUTES = STRU_MODULE ). "Using the context_element paramater to get the static attributes.

NODE_MODULE->GET_STATIC_ATTRIBUTES_TABLE(
IMPORTING
TABLE = itab )   "getting all the data.
.


DELETE itab WHERE zmodule_id = STRU_MODULE-zmodule_id. "deleting the particular row from the table and binding it.
CALL METHOD NODE_MODULE->BIND_TABLE
EXPORTING
NEW_ITEMS = itab
* SET_INITIAL_ELEMENTS = ABAP_TRUE
* INDEX =
.

thanks,

Aditya.

gill367
Active Contributor
0 Kudos

>

> @sarbjeet

>

> plz edit me in the above code which i have written bcoz i dont know where the prob. occurs exactly......

You just need to write this code as it is with node name in the place mentioned below in the code.

DATA lo_el TYPE REF TO if_wd_context_element.
      lo_el = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).

DATA lo_nd TYPE REF TO if_wd_context_node.
 
    lo_nd = wd_context->get_child_node( name = '<node name>' ).       " here <node name> give your node's name which is          
                                    "bound to data source of the table.
 
     lo_nd->remove_element( lo_el ).

Thanks

sarbjeet singh

Former Member
0 Kudos

@sarbjeet,

but it is working with lead selection only.............if there are 10 records inside the table,i also have 10 delete buttons inside the table for each and every row................I have inserted the delete button into the table by right clicking on the table uielement and i have selected tablecolumn option to insert the seperate column and iside that i have inserted the button............

gill367
Active Contributor
0 Kudos

Yeah thats what i am saying .

all the delete buttons will be having the action.

go to that eventhandler and just paste the code there.

it will delete that particular row.

i have tested this.

thanks

sarbjeet singh

Former Member
0 Kudos

sarbjeet,

shall plz paste that code fully which u have tested...............and also the record should get deleted from database............

Thanks in advance.........

gill367
Active Contributor
0 Kudos

Here is what i am writing in my delete eventhandler top delete the record from backend as well as from table.

my table is zdealer and i am deleting after checking the id of the selected row.

DATA lo_el TYPE REF TO if_wd_context_element.
      lo_el = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).



    DATA lo_nd_zdealer TYPE REF TO if_wd_context_node.

    lo_nd_zdealer = wd_context->get_child_node( name = 'DEALER' ).


     lo_nd_zdealer->remove_element( lo_el ).

data lv_id type ZDEALER-ID.

   lo_el->get_attribute(
     EXPORTING
       name =  `ID`
     IMPORTING
       value = lv_id ).



 delete from zdealer where id = lv_id.

Regards,

Sarbjeet singh

amber_garg
Active Participant
0 Kudos

@sarbjeet: I too tried the same thing just now and Wrote the code exactly u told . I am also getting the same error as ALAGAPPAN (he is working with me )

The error(runtime) which I am getting is "ACCESS VIA NULL OBJJECT " when we call the function GET_ATTRIBUTE at the end through ELEMENT. UPon debugging i found out that the line when we write

ELEM_TABLE_EMP = WDEVENT->GET_CONTEXT_ELEMENT( 'CONTEXT ELEMENT' ).

is not storing anything in ELEM_TABLE_EMP. ITs value after this statement remains . Thats why later when we try to call GET_ATTRIBUTE from this object , since its containing NULL VALUE , we get the runtime error.

So dont know why nothing is stored in ELEM_TABLE_EMP.

THANKS

Former Member
0 Kudos

Hi,

Did you misspell here

ELEM_TABLE_EMP = WDEVENT->GET_CONTEXT_ELEMENT( 'CONTEXT ELEMENT' ).

ELEM_TABLE_EMP = WDEVENT->GET_CONTEXT_ELEMENT( 'CONTEXT_ELEMENT' ). " see the underscore

amber_garg
Active Participant
0 Kudos

@BAsakaran: Bingo , it the because of the mispelling you pointed out.

Thanks everyone

gill367
Active Contributor
0 Kudos

Oh you were missing that underscore.

IF now you are able to delete the rows and ur purpose is done.

You can close the thread.

thanks

sarbjeet singh

Answers (0)