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

create data daynamic from field length

Former Member
0 Likes
1,254

HI All

There is a way to create data dynamically if i have in parameter field length

like char10 or KUNNR or char25.

Thanks,

Joy

1 ACCEPTED SOLUTION
Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
1,224

field-symbol: <fs_dyn_wa> TYPE ANY.

loop at lt_tab INTO ls_tab.

CREATE DATA kunnr TYPE (ls_tab-fieldname).

or if you have a fixed strucutre for the fields in the internal table, define the workarea and use the below code to push the values

MOVE ls_tab-fieldname TO ls_fieldname.

ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_dyn_wa> TO <fs_val>.

endloop.

Edited by: ssm on Jul 26, 2011 7:51 PM

HI All

There is a way to create data dynamically if i have in parameter field length

like char10 or KUNNR or char25.

Thanks,

Joy

8 REPLIES 8
Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
1,224

DATA: lv_kunnr TYPE kunnr.

DATA: kunnr TYPE REF TO data.

field-symbols: <fs_kunnr> TYPE ANY.

CREATE DATA kunnr TYPE kunnr.

lv_kunnr = '123'.

ASSIGN kunnr->* TO <fs_kunnr>.

move lv_kunnr to <fs_kunnr>.

write: <fs_kunnr>.

Edited by: ssm on Jul 26, 2011 7:30 PM

Edited by: ssm on Jul 26, 2011 7:34 PM

Read only

Former Member
0 Likes
1,224

HI SSM,

thanks ,

but i have table itab like as follows

and i want to create the data dynamic

Field name  type 
SORTL	    000010
PSTLZ	    000010
MCOD3	    000025
MCOD1	    000025
KUNNR	    000010

Thanks,

Joy

Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
1,224

you can use the field symbol <fs_kunnr> further with the abve example

Read only

aditya_avadhanula
Participant
0 Likes
1,224

Check the Forums for RTTS and RTTC , this will help you in the issue .

Read only

0 Likes
1,224

https://wiki.sdn.sap.com/wiki/display/Snippets/StepstoCreateTypeDynamically

Please check this link

Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
1,224

Do you have any fixed structure for these fields which you have in our internal tbale?

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,224

You can create data using dynamic reference or type/length

* Common data
DATA dref TYPE REF TO data. 
FIELD-SYMBOLS <fs> TYPE ANY. 
*
DATA name TYPE TYPE c LENGTH 10.
CREATE DATA dref TYPE (name). " from the body part of your post
* OR
DATA: integer TYPE I.
CREATE DATA dref TYPE 'c' LENGTH integer. " from the header of your post
* Assign to a field symbol
ASSIGN dref->* TO <fs>.

Regards,

Raymond

Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
1,225

field-symbol: <fs_dyn_wa> TYPE ANY.

loop at lt_tab INTO ls_tab.

CREATE DATA kunnr TYPE (ls_tab-fieldname).

or if you have a fixed strucutre for the fields in the internal table, define the workarea and use the below code to push the values

MOVE ls_tab-fieldname TO ls_fieldname.

ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_dyn_wa> TO <fs_val>.

endloop.

Edited by: ssm on Jul 26, 2011 7:51 PM