2010 Jan 13 9:25 AM
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
2010 Jan 13 9:28 AM
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
2010 Jan 13 9:28 AM
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
2010 Jan 13 9:29 AM
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
2010 Jan 13 9:34 AM