2014 Sep 17 12:56 PM
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
2014 Sep 17 1:08 PM
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
2014 Sep 17 1:16 PM
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
2014 Sep 17 1:26 PM
2014 Sep 17 1:53 PM
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
2014 Sep 17 2:16 PM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |