Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Pass value to a field dynamically..

former_member307726
Participant
0 Likes
2,970

Hi Experts,

Can any one solve this issue?.

I want to pass value to different fields dynamically..

Egu2026

I have work are having fields

lwa_table-var1,

lwa_table-var2,

lwa_table-var3,

lwa_table-var4,

-


- -

---

u2026.. up to lwa_table-var100.

My logic is I have to pass l_tot value .. based on the last letter like below.

if l_tot value is 1 we have pass to lwa_table-var1

if l_tot value is 2 we have pass to lwa_table-var2

if l_tot value is 3 we have pass to lwa_table-var3

---

-


-


if l_tot value is 100 we have pass to lwa_table-var100.

<removed_by_moderator>

Thanks in advance.

Regards,

Kumar.

Edited by: Julius Bussche on Aug 12, 2009 8:41 AM

Hi Experts,

Can any one solve this issue?.

I want to pass value to different fields dynamically..

Egu2026

I have work are having fields

lwa_table-var1,

lwa_table-var2,

lwa_table-var3,

lwa_table-var4,

-


- -

---

u2026.. up to lwa_table-var100.

My logic is I have to pass l_tot value .. based on the last letter like below.

if l_tot value is 1 we have pass to lwa_table-var1

if l_tot value is 2 we have pass to lwa_table-var2

if l_tot value is 3 we have pass to lwa_table-var3

---

-


-


if l_tot value is 100 we have pass to lwa_table-var100.

<removed_by_moderator>

Thanks in advance.

Regards,

Kumar.

Edited by: Julius Bussche on Aug 12, 2009 8:41 AM

9 REPLIES 9
Read only

former_member194669
Active Contributor
0 Likes
1,848

Try this way

data : v_field(30) type c.

loop at l_tot.

concatenate 'LWA_TABLE-VAR' l_tot-value into v_field.

condense v_field no-gaps.

write l_tot-value' to ( v_field ).

endloop.

, a®

Read only

Former Member
0 Likes
1,848

Hi Friend,

U can do Following.....

data: text(12) type c.

data : num type n.

data: int type i.

data: begin of wa_test,

var1,

var2,

var3,

var4,

end of wa_test.

FIELD-SYMBOLS <fs_wa> TYPE ANY.

do 4 times.

int = int + 1.

num = int.

CONCATENATE 'wa_test-' 'var' num into text.

ASSIGN (text) to <fs_wa>.

<fs_wa> = num.

UNASSIGN <fs_wa>.

enddo.

write : wa_test-var1 , wa_test-var2 , wa_test-var3 ,wa_test-var4 .

ouput will be : 1 2 3 4.

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

Lets take Your Scenario----


>>>>>>>>>>>>>>>>>

Data: begin of lwa_table,

Var1,

Var2,

Var3,

u2026..

u2026u2026

Var100,

End of lwa_table.

Data: l_tot type i.

u2022 For example l_tot = 36.

u2022 Then u want to pass the same to lwa_table36.

For this do followingu2026..

Now Define-->>>

data: text(13) type c.

data : num type n.

FIELD-SYMBOLS <fs_wa> TYPE ANY.

*Now till now we done all the data definitions now u have to do following to pass it dynamically,

l_tot = 36.

Num = l_tot.

CONCATENATE lwa_table-' 'var' num into text.

ASSIGN (text) to <fs_wa>.

<fs_wa> = num.

UNASSIGN <fs_wa>.

Write : lwa_table-var36.

Output will be 36.

Hope this resolves ur issue,

Regards,

Akash Rana

Edited by: AKASH RANA on Aug 12, 2009 8:53 AM

Read only

0 Likes
1,848

Hello Akash,

Where is this wa_test or lwa_table defined in your example.

This code is not going to resolve this issue.

Please check once again.

Thanks,

Augustin.

Read only

0 Likes
1,848

My Dear Friend Augustarian ,

Kindly Read the post completely and then respond with a comment I have declared both the work ares in the above post, and both the work area are used in two different examples seprated by a line as

"**********************************************"

So the part of code above the line is a example to show how we can work with dynamic assignments.

and the part below is code for the resolution of the issue.

I had even checked the codes at my end in a IDES server they are working perfectly fine, Dynamic assignment work really good.

These codes would 100 % work.

Kindly post after complete review of the codes.

Hope U wont make any such mistakes in future.

Regards,

Akash Rana

Read only

0 Likes
1,848

Hello Akash,

Ok my mistake, sorry for that but still your work areas are static so that means it can only accept those values for which the fields are defined in internal table.

Sorry buddy once agian,

Thanks,

Augustin.

Read only

0 Likes
1,848

Hi Friend Augustarian ,

In the forum Question its mentioned that the user has a work area with fields only till 100 ,has no where mentioned he is using or not using any internal table so the solution i provided was only with the knowledge i got from the forum question.

Regards,

Akash Rana

Read only

0 Likes
1,848

Hello Akash Rana,

My issue is solved..

Thank You..

Regards,

Kumar

Read only

0 Likes
1,848

Hello Akash Rana,

My issue is solved..

Thank You..

Regards,

Kumar

Read only

Former Member
0 Likes
1,848

Hello ABAP,

The big problem I can see in your reqirement is there is no boundry condition for what will the limit for the value generated.

For example you might have value 999 so you will expect it should be moved to lwa_table-var999.

So, that means you lwa_table will be fully dynamic and it's fields will depend up on the value generated.

You can try this way:

1. Your code upto value generation will work as it is. for example value generated through your code is 11.

2. Define lwa_table as DATA law_table type ref to DATA.

2. Fill fieldcatalog of static method create_dynamic_table from cl_alv_table_create class.

for e.g.

concatenate 'var' <your_value> into fieldcatalog_tab-fieldname.

Now call method create_dynamic_table as follow

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = fieldcatalog_tab

importing

p_table = lwa_table.

Now as value generated is 11 it will return lwa_table containing one column with name var11.

now ASSIGN lwa_table->* to <itab>

Now define another field symbol for field <field>

ASSIGN COMPONENT fieldcatalog_tab-fieldname OF STRUCTURE <itab> TO <field>.

Now finally you can move your value i.e. 11 into <field>

<field> = 11.

or

Move 11 to <field>.

You can fine tune above code or as many dynamic fields required for your requirement.

Hope this helps!

Thanks,

Augustin.