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

How to read unstructured data

Former Member
0 Likes
1,102

Hi all,

I need to create a FM with an interface like this:

IMPORTING

strucname

CHANGING

ls_data.

ls_data is unstructured, I think it will be TYPE ANY, in the field STRUCNAME I will receive the name of the structure in order to read and change the content of ls_data.

How can I manage this?

I cannot use something like:

CASE strucname.

when 'EKKO'.

when 'VBAK'.

ENDCASE.

because I don't know in advance which are the structures that will be used to call the function.

Thank you for any support

Bye

Paola

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
966

1. validate the structure name and create a data reference of the structure dynamically and assign values

to the dynamic structure

2. check the following sample code which helps to achieve ur requirement

DATA dref TYPE REF TO data.

FIELD-SYMBOLS: <wa> TYPE ANY,

<comp> TYPE ANY.

CREATE DATA dref TYPE (strucname).

ASSIGN dref->* TO <wa>.

DO.

ASSIGN COMPONENT sy-index

OF STRUCTURE <wa> TO <comp>.

IF sy-subrc = 0.

<comp> = assign values according to the datatype.

ELSE.

EXIT.

ENDIF.

ENDDO.

Message was edited by:

Rajesh

6 REPLIES 6
Read only

former_member189629
Active Contributor
0 Likes
966

Paola,

Use the strucname as an include structure for your table instead of writing a condition as u never know what structure your ls_data will be of and if u write case, u will have to consider all tables...

Reward if helpful,

Karthik

Read only

Former Member
0 Likes
966

Hi Karthik,

sorry but I cannot understand your point.

Con you please attach some code example?

Thank you very much

Bye

Paola

Read only

Former Member
0 Likes
967

1. validate the structure name and create a data reference of the structure dynamically and assign values

to the dynamic structure

2. check the following sample code which helps to achieve ur requirement

DATA dref TYPE REF TO data.

FIELD-SYMBOLS: <wa> TYPE ANY,

<comp> TYPE ANY.

CREATE DATA dref TYPE (strucname).

ASSIGN dref->* TO <wa>.

DO.

ASSIGN COMPONENT sy-index

OF STRUCTURE <wa> TO <comp>.

IF sy-subrc = 0.

<comp> = assign values according to the datatype.

ELSE.

EXIT.

ENDIF.

ENDDO.

Message was edited by:

Rajesh

Read only

Former Member
0 Likes
966

Hi Rajesh

sorry: it seemed all clear at the beginning, but now I cannot understand how to assign the values I have in ls_data before changing them.

Thanks

Paola

Read only

Former Member
0 Likes
966

I found a little problem with the code, so I asked for a new explanation

Read only

Former Member
0 Likes
966

Problem solved,

thanks