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

Field Symbols problem

Former Member
0 Likes
647

Hi Abappers,

I want to retrieve a field from a program SAPLKEII and the fields are from the internal table it_accit.

If the above functionality needs to be implemented using field symbols

How would I do that.

Code snippet for the field symbols for the above functionality would be very helpful.

Thanks and Regards

P.Srikanth

Edited by: SRIKANTH P on Jan 13, 2010 2:55 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
606

Code for how to use field symbols.

Dynamic DB operations are relatively simpler to do.

Let's say you have to select / insert / update / delete from a DB table and the name of the DB table is not known in advance. The trick here is that since the name of the DB table is not known, the data structures can also be not declared easily. They have to be declared generically. One way is to make use of field symbols. Thus depending upon the DB type, the structures / internal tables will be created and used.

PS: It is important that you are comfortable with the use field symbols in ABAP.

Let's say the name of the DB table is stored in variabe lv_table_name. At run time the lv_table_name can have any value. And I want to select data from this table and store it in a internal table. See the below code snippet. Check out the data declaration and DB operation statements.

FIELD-SYMBOLS : <fs_table_data> TYPE ANY TABLE,

<fs_wa> TYPE ANY.

DATA : lref_data_table TYPE REF TO data,

lref_data_wa TYPE REF TO data.

CREATE DATA lref_data_table TYPE STANDARD TABLE OF (lv_table_name).

ASSIGN lref_data_table->* TO <fs_table_data>.

CREATE DATA lref_data_wa TYPE (lv_table_name)

ASSIGN lref_data_wa->* TO <fs_wa>.

SELECT * FROM (lv_table_name) INTO TABLE <fs_table_data>.

SELECT SINGLE * FROM (lv_table_name) INTO <fs_wa>.

INSERT (lv_table_name) FROM TABLE <fs_table_data>.

MODIFY (lv_table_name) FROM TABLE <fs_table_data>.

DELETE (lv_table_name) FROM TABLE <fs_table_data>.

Here, a field symbol is declared, which can take any type. A data variable which refers to generic data type is declared. Then a object of this generic type is created which is typed to the table name.

Now the field symbol is assigned to the this data object. Now the field symbol works just like a normal internal table (or a work area). After that the DB operations are simple ..

Thanks

Hi Abappers,

I want to retrieve a field from a program SAPLKEII and the fields are from the internal table it_accit.

If the above functionality needs to be implemented using field symbols

How would I do that.

Code snippet for the field symbols for the above functionality would be very helpful.

Thanks and Regards

P.Srikanth

Edited by: SRIKANTH P on Jan 13, 2010 2:55 PM

3 REPLIES 3
Read only

Former Member
0 Likes
607

Code for how to use field symbols.

Dynamic DB operations are relatively simpler to do.

Let's say you have to select / insert / update / delete from a DB table and the name of the DB table is not known in advance. The trick here is that since the name of the DB table is not known, the data structures can also be not declared easily. They have to be declared generically. One way is to make use of field symbols. Thus depending upon the DB type, the structures / internal tables will be created and used.

PS: It is important that you are comfortable with the use field symbols in ABAP.

Let's say the name of the DB table is stored in variabe lv_table_name. At run time the lv_table_name can have any value. And I want to select data from this table and store it in a internal table. See the below code snippet. Check out the data declaration and DB operation statements.

FIELD-SYMBOLS : <fs_table_data> TYPE ANY TABLE,

<fs_wa> TYPE ANY.

DATA : lref_data_table TYPE REF TO data,

lref_data_wa TYPE REF TO data.

CREATE DATA lref_data_table TYPE STANDARD TABLE OF (lv_table_name).

ASSIGN lref_data_table->* TO <fs_table_data>.

CREATE DATA lref_data_wa TYPE (lv_table_name)

ASSIGN lref_data_wa->* TO <fs_wa>.

SELECT * FROM (lv_table_name) INTO TABLE <fs_table_data>.

SELECT SINGLE * FROM (lv_table_name) INTO <fs_wa>.

INSERT (lv_table_name) FROM TABLE <fs_table_data>.

MODIFY (lv_table_name) FROM TABLE <fs_table_data>.

DELETE (lv_table_name) FROM TABLE <fs_table_data>.

Here, a field symbol is declared, which can take any type. A data variable which refers to generic data type is declared. Then a object of this generic type is created which is typed to the table name.

Now the field symbol is assigned to the this data object. Now the field symbol works just like a normal internal table (or a work area). After that the DB operations are simple ..

Thanks

Read only

Former Member
0 Likes
606

Hi Srikanth

You can retrieve the internal table value only if the program SAPLKEII is there in your call stack. In case you have it, below is thre code to access internal table it_accit from program SAPLKEII .


constants : c_prog type char50 value '(SAPLKEII )it_accit[]'.

field-symbols : <fs> type standard table.

assign (c_prog) to <fs>.

Now <fs> will have the contents of the internal table it_accit.

Regards

Ranganath

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
606