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

Passing value to Work area Column dynamically

sanjana_lingras
Active Participant
0 Likes
4,187

Hi Experts,

I have a requirement to pass value to work area field and field name will be dynamic.

Below are details :

1. Loop at string

2. split values according to offset and length

3. now first value for field lifnr is available in w_lifnr.

4. Now move w_lifnr to w_itab-lifnr ...........................            here  field lifnr of w_itab will be dynamic. it will vary in each iteration.

How can we change fields of work area dynamically and move respective values?

like w_itab-(w_field)   and w_field will have different value in each iteration like lifnr,vtweg,vkorg etc.

We cannot hardcode these values ,field name of w_itab needs to be passed dynamically.

Is there any way?

Regards,

Sanjana

Hi Experts,

I have a requirement to pass value to work area field and field name will be dynamic.

Below are details :

1. Loop at string

2. split values according to offset and length

3. now first value for field lifnr is available in w_lifnr.

4. Now move w_lifnr to w_itab-lifnr ...........................            here  field lifnr of w_itab will be dynamic. it will vary in each iteration.

How can we change fields of work area dynamically and move respective values?

like w_itab-(w_field)   and w_field will have different value in each iteration like lifnr,vtweg,vkorg etc.

We cannot hardcode these values ,field name of w_itab needs to be passed dynamically.

Is there any way?

Regards,

Sanjana

5 REPLIES 5
Read only

Former Member
0 Likes
2,211

Hi

You need to upload the defination of the strcuture W_ITAB, you can use the class CL_ABAP_STRUCTDESCR, somthing like


DATA: ABAP_STRUCT TYPE REF TO CL_ABAP_STRUCTDESCR.

ABAP_STRUCT ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA( W_ITAB ).

Now in attribute COMPONENTS you'll have the fieldname of W_ITAB

But how to assign the fields to a certain value depends on your development

Max

Read only

jrg_wulf
Active Contributor
0 Likes
2,211

Hi Sanjana,

w_itab-(w_field) will not work.

Basically there are two options available.

1.

If w_field had not only the fieldname but tablename as well

like w_field = 'W_ITAB-LIFNR'.

then (w_field) = new_value would work.

2.

using a field-symbol

FIELD-SYMBOLS: <fs_field> type any.

ASSIGN COMPONENT w_field OF STRUCTURE w_itab TO <fs_field>.

<fs_field> = new_value.

Best regards - Jörg

Read only

Noorie
Active Participant
0 Likes
2,211

Dear Sanjana,

use field symbols.

Read only

0 Likes
2,211

This is not working.

I have the field name but values needs to be moved w_itab-(fieldname).

w_field = 'VKORG'

Now I want move <fs_string> value to w_itab-w_field (*** w_field will change everytime which will have dynamic values)

Regards

Sanjana

Read only

Former Member
0 Likes
2,211

As Jörg says

you need to use:

ASSIGN COMPONENT W_FIELD OF STRUCTURE W_ITAB TO <FS_FIELD>.

IF SY-SUBRC = 0.

  MOVE <FS_STRING> TO <FS_FIELD>.

ENDIF.

Max