cancel
Showing results for 
Search instead for 
Did you mean: 

Declaring Variable in Web dynpro ABAP

Former Member
0 Kudos

Hi all

I want to know how to declare variables globally and how to use internal tables from one method to another method without declaring each and every time in methods?

Please suggest me to do this

Appreciated your solution

Regards

Indiranjithn

Accepted Solutions (0)

Answers (3)

Answers (3)

sahai
Contributor
0 Kudos

hi,

1) if you want to have any variable to be defined globally ..then kindly define it as an attribute in the component controler ... by declaring it you can always fetch it in the context of the view you require that variable.

2) the internal tables in WDA are based on the cardinality of the node you have declared....it is like table name will be your node name and the attributes will be the columns....remember the cardinality must be 0:n if you want to declare it as an internal table

3)simialrly for methods to be reused you can define them in the component controller...and the in any view you can reuse it writing

wd_component_controller->method()." method() is my method declared in the component controller.....

hope this will help you....

regards,

sahai.s

Former Member
0 Kudos

Hi

I understood that if we want to declare variables or internal tables globally. We should declare this as node in componentcontroller

But i have a query that, say itab type from one componentcontroller say node_vbak is an internal table i am using this itab in onselect() method with some logic and i got some filtered data in itab. If i use the same internal table to another method call onclick(), Should the internal table has the same data or needs to be filter again what i did in onselect() method?

Is there any way to get the same filtered data in itab? where should i declare how to declare that give me with example?

Looking forward to your solution

Regards

Indiranjithn

Former Member
0 Kudos

Hi,

No need to create node to declare it always. if you need binding declare. otherwise in compcontroller attributes table

declare your internal table and you can use it in any view methods.

cheers,

Kris.

sahai
Contributor
0 Kudos
DATA node_vbak TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA itab TYPE WD_THIS->ELEMENTS_CTX_VN_TABLE_PO.
  DATA wa_itab WD_THIS->ELEMENT_CTX_VN_TABLE_PO.
*   navigate from <CONTEXT> to <CTX_VN_TABLE_PO> via lead selection
  node_vbak = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->itab ).


select the values and put it in the itab........

node_vbak->BIND_TABLE( itab ).

this bind statement will put the data in the node which is present in the internal table itab.... now this node will have the data contained and since it is declared in component controller we will be able to get the data in all the views used in the program

Regards,

sahai.s

Former Member
0 Kudos

Hi

This code in onselct method. For example

DATA lt_node_am_detl1 TYPE wd_this->Elements_node_am_detl1.

logic to move the data to internal table.

lo_nd_node_am_detl1->bind_table( lt_node_am_detl1 ).

Now the filterd data in internal table and

I declared this internal table in componentcontroller attributes tab like

lt_node_am_detl1 and Elements_node_am_detl1 (Associate column ) and i tick the pulic check box.

i am using another method onclick() .

As you said the internal table declaration is not required if declared already in componentcontroller attributes tab .

data wa_itab like line of lt_node_am_detl1 .

Loop at lt_node_am_detl1 to wa_itab.

endloop.

while debugging i am not getting data in internal table .. Should I declared correctly in componentcontroller attributes tab .

Tlhanks

Indiranjithn

Former Member
0 Kudos

Problem solved

Former Member
0 Kudos

Hi,

If you declare all your attributes in COMPCOnftoller it is global to that component. you can use in any views.

Context also, if you declare in compcont you can use in any no of view by using context mapping.

If you want to methods, use assistance class as suggested above.

OR you can create that method in compcontroller and you can use that method in any other methods or any views method

using attribute WD_COMP_CONTROLLER.

Cheers,

Kris.

Former Member
0 Kudos

You have a few options. You can declare variable in your assistance class, if appropriate. You an also do the same by declaring them as attributes at the component controller level (not to be confused with context attributes, there is an actual attribute tab). Within the scope of a view, you can declare them as attributes at the view level.

You can also save values, like the table especially, in a context node. You have options there as well when it comes to scope. You can declare it as a component controller context node and map it to the views that need access. Or, you can declare a context node at the view level and save the values there.

The answer lies in how global you want the data to be.