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

Assign component with table

rainer_hbenthal
Active Contributor
0 Likes
4,521

I have problem with assign component:

in a method, i have an exporting parameter type any table.

Therefore i do not know the structure of this. Now i want to fill this table with


  assign component 1 of structure it_example[] to <p>.

  <p> = "xyz".

Having a structure this is no problem, but a table is not a structure and therefore im getting result code of 4.

Outsite methods i can use tables with headerlines, and the headerline has a structure so with the assign i can fill the header line.

In OO context, tables with headerlines are not allowed. So how can i fill the table if i do not have a glue what the structure looks like? Any idea?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,634

Hi Rainer,

You can use this format.

DATA: dref TYPE REF TO DATA.

FIELD-SYMBOLS: <fs> TYPE ANY.

CREATE DATA dref TYPE <table>.

ASSIGN dref->* TO <fs>.

Here 'create data' creates anonymous data object of the table.The dref points to the work area of the table.

Then assign the workarea to the field symbol.

Regards.

Lavanya.

9 REPLIES 9
Read only

Former Member
0 Likes
2,634

HI Rainer,

i think you have to define a structure and use this.

E.g.

data wa_example type "same type of it_example".

Use the assign with this structure, and after append it to the table.

Bye

enzo

Read only

0 Likes
2,634

I really want to avoid haveing an additional paramter in the siganture of the method.



DATA:

 wa_internal like line of <imported_table>

didnt worked either

Read only

Former Member
0 Likes
2,634

hi,

try with this

assign component 1 of structure it_example to <p>.

cheers,

sasi

Read only

0 Likes
2,634

Works neither -> sy-subrc = 4.

Read only

Former Member
0 Likes
2,634

Hi,

Use something similar to the following,

FIELD-SYMBOLS: <fs>, <fval>.

ASSIGN LOCAL COPY OF INITIAL LINE OF it_example

TO <fs>.

IF <fs> IS ASSIGNED.

ASSIGN COMPONENT 1 OF STRUCTURE <fs> TO <fval>.

IF <fval> IS ASSIGNED.

<fval> = 'xyz'.

ENDIF.

APPEND <fs> TO it_example.

ENDIF.

Hope this helps..

Sri

Read only

Former Member
0 Likes
2,634

Hi Rainer,

check with this code.Hope it works.

LOOP AT datatab.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE

datatab TO <fs>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

reward me if this works.

Thanks,

Vamsi.

Read only

Clemenss
Active Contributor
0 Likes
2,634

Hi,

as you want to fill the table - not any non-existing header line, you must populate the table record by record, that means LOOP.

field-symbols:

<fs> type any.

loop at it_example assigning <fs>.

assign component 1 of structure <fs> to <p>.

<p> = "xyz".

endloop." at it_example assigning <fs>.

fast. efficient.

C.

Read only

Former Member
0 Likes
2,635

Hi Rainer,

You can use this format.

DATA: dref TYPE REF TO DATA.

FIELD-SYMBOLS: <fs> TYPE ANY.

CREATE DATA dref TYPE <table>.

ASSIGN dref->* TO <fs>.

Here 'create data' creates anonymous data object of the table.The dref points to the work area of the table.

Then assign the workarea to the field symbol.

Regards.

Lavanya.

Read only

0 Likes
2,634

Hi,

assign local copy solved it too, but is not allowed in OO context.

Yours is the solution except that


  CREATE DATA dref like line of datatable. 
  ASSIGN dref->* TO <fs>.

is the 100% solution

Otherwise youre getting problems with


  insert <fs> into table datatable.

Thanks a lot to you both.