Application Development 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: 

Dynamic Data Objects

MarkusKlein
Active Contributor
0 Kudos
97

Hello everybody,

i need to solve the following problem:



data: l_structure type DFIES-FIELDNAME,
      ls_outtab type ref to data,
      lt_outtab type ref to data.
fieldsymbols: <lt_outtab> type standard table,
              <ls_outtab> type any.


l_structure = 'ZZ_TEST'.
* The DDIC Structure ZZ_TEST has 2 fields: A and B both CHAR10.


* Table
create data outtab type standard table of (l_structure).
assign outtab->* to <lt_outtab>.


* Workarea
create data ls_outtab type (l_structure).
assign table field ls_outtab->* to <ls_outtab>

The question now is, how can i assign the workarea <ls_outtab> a value to its field A and to its field B?

The codeline "<ls_outtab>-A = 'xyz'" gives me a syntax error.

best regards

Markus

1 ACCEPTED SOLUTION

former_member185943
Participant
0 Kudos
62

Hi!

You can do it by::

FIELD-SYMBOLS: <field> TYPE ANY.
ASSIGN COMPONENT 'SOME_FIELDNAME' OF STRUCTURE <ls_outtab> TO <field>.
* do whatever you want with <field>

If you want to append fields to your table, you can do:


FIELD-SYMBOLS: <field>     TYPE ANY,
               <ls_outtab> TYPE ANY.
APPEND INITIAL LINE TO <lt_outtab>.
READ TABLE <lt_outtab> ASSIGNING <ls_outtab> INDEX sy-tfill.
ASSIGN COMPONENT 'SOME_FIELDNAME' OF STRUCTURE <ls_outtab> TO <field>.
* do whatever you want with <field>

Note that you don't need to hassle with typing - both your <ls_outtab> and <field> can be TYPE ANY.

Hope this helps.

Regards,

Igor

6 REPLIES 6

former_member185943
Participant
0 Kudos
63

Hi!

You can do it by::

FIELD-SYMBOLS: <field> TYPE ANY.
ASSIGN COMPONENT 'SOME_FIELDNAME' OF STRUCTURE <ls_outtab> TO <field>.
* do whatever you want with <field>

If you want to append fields to your table, you can do:


FIELD-SYMBOLS: <field>     TYPE ANY,
               <ls_outtab> TYPE ANY.
APPEND INITIAL LINE TO <lt_outtab>.
READ TABLE <lt_outtab> ASSIGNING <ls_outtab> INDEX sy-tfill.
ASSIGN COMPONENT 'SOME_FIELDNAME' OF STRUCTURE <ls_outtab> TO <field>.
* do whatever you want with <field>

Note that you don't need to hassle with typing - both your <ls_outtab> and <field> can be TYPE ANY.

Hope this helps.

Regards,

Igor

Former Member
0 Kudos
62

Hello Markus,

After the statement <b>assign outtab->* to <lt_outtab>.</b> in your code, you can do the following -

loop at <lt_outtab> assigning <ls_outtab>.

" do your processing using <b>assign component of</b>

endloop.

Regards,

Anand Mandalika.

0 Kudos
62

Hello,

thanx to for very fast answers

What i want to do is assign content to the different fields of the structure <ls_outtab> and then append this content to the table <lt_outtab>.

so at runtime <ls_outtab> has 2 fields A and B. I want to add content to field A and to field B. Then i want to append this new line to table <lt_outtab>.

regards,

Markus

0 Kudos
62

Thanx Igor,

your lines


APPEND INITIAL LINE TO <lt_outtab>.
READ TABLE <lt_outtab> ASSIGNING <ls_outtab> INDEX sy-tfill.
ASSIGN COMPONENT 'SOME_FIELDNAME' OF STRUCTURE <ls_outtab> TO <field>.
* do whatever you want with <field>

are working great Thanx!

best regards,

Markus

0 Kudos
62

Markus,

This is exactly what my suggestion is doing. Have you tried it? Here it is, once again, a little bit modified to make it more clear:


FIELD-SYMBOLS: <field>     TYPE ANY,
               <ls_outtab> TYPE ANY.
APPEND INITIAL LINE TO <lt_outtab>.
READ TABLE <lt_outtab> ASSIGNING <ls_outtab> INDEX sy-tfill.
ASSIGN COMPONENT 'A' OF STRUCTURE <ls_outtab> TO <field>.
<field> = 'Value of the field A'.
ASSIGN COMPONENT 'B' OF STRUCTURE <ls_outtab> TO <field>.
<field> = 'Value of the field B'.

Regards,

Igor

0 Kudos
62

Sorry, I guess we were typing at the same time. I'm glad it works.

Igor