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: 

Generic assignment of a table to a field symbol

Former Member
0 Kudos

Hi,

I'm trying to do a function that receives the name of a table (not the table) and then list its content. How can I assign the table to a field symbol. I think in something like this:

perform compara using 'kna1'.

FORM compara USING tabl.

FIELD-SYMBOLS: <table> TYPE ANY.

ASSIGN (tabl) TO <table>.

WRITE <table>-kunnr.

ENDFORM.

But it doesn't work, something like "the data object <table> has no structure and therefore no component called KUNNR"

In fact the real purpose of the function is to receive a structure of the same type of the table and a the header of the table, compare its fields and then return if all fields have the same value.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

change the code as

perform compara using 'kna1'.

FORM compara USING tabl.

FIELD-SYMBOLS: <table> TYPE ANY.

*<b>ASSIGN (tabl) TO <table>.</b>

<b> Assign tabl to <table>.</b>

WRITE <table>-kunnr.

ENDFORM.

Refer to example prog in ABAPDOCU

REPORT demo_field_symbols_assign_comp .

DATA: BEGIN OF line,

col1 TYPE i VALUE '11',

col2 TYPE i VALUE '22',

col3 TYPE i VALUE '33',

END OF line.

DATA comp(5) TYPE c VALUE 'COL3'.

FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE ANY, <f3> TYPE ANY.

ASSIGN line TO <f1>.

Regards,

Sailaja.

5 REPLIES 5

Former Member
0 Kudos

Hi,

change the code as

perform compara using 'kna1'.

FORM compara USING tabl.

FIELD-SYMBOLS: <table> TYPE ANY.

*<b>ASSIGN (tabl) TO <table>.</b>

<b> Assign tabl to <table>.</b>

WRITE <table>-kunnr.

ENDFORM.

Refer to example prog in ABAPDOCU

REPORT demo_field_symbols_assign_comp .

DATA: BEGIN OF line,

col1 TYPE i VALUE '11',

col2 TYPE i VALUE '22',

col3 TYPE i VALUE '33',

END OF line.

DATA comp(5) TYPE c VALUE 'COL3'.

FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE ANY, <f3> TYPE ANY.

ASSIGN line TO <f1>.

Regards,

Sailaja.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

perform compara tables itab.

form compara tables itab type table.

field-symbols: <fs> type any,

<fs1> type any.

loop at itab assigning <fs>.

do.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <fs1>.

write <fs1>.

if sy-subrc ne 0.

exit.

endif.

enddo.

new-line.

endloop.

endform.

Kindly reward points if it helps.

Former Member
0 Kudos

Hi

You can't indicate the field name, because the system can know the structure only at run time, so you get the sintax error. you should dymanically indicate the the field:

perform compara using 'kna1'.

FORM compara USING tabl.

FIELD-SYMBOLS: <table> TYPE ANY,

<field> TYPE ANY.

ASSIGN (tabl) TO <table>.

ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <TABLE> TO <FIELD>.

WRITE <FIELD>.

ENDFORM.

0 Kudos

IF i want to change the (not to write) ' kuner ' and update the table

how t do it any help pls.....

0 Kudos

Hi,

For changing the field, you assign the new value to <FIELD>

i.e instead of Write <FIELD> use,

<FIELD> = 'New Value'.

Field symbol accesses the memory directly. So changes made to field symbol will automatically reflect in the assigned field's value.

Note: Create new thread whenever you ask new queries. I responded without seeing the initiator name of the thread. Please take care of this!

Thanks,

Lakshmi

Edited by: Santhanalakshmi V on Dec 3, 2008 5:19 PM