07-01-2011 9:49 PM
Hi All,
I am selecting some data from a table, after processing the data I need to populate this data into an internal table represented by a field-symbol.
For example:
I have ITAB as:
ITAB
MATNR MTART MATKL MEINS MAKTX
1000 ZPRA 40000000 EA Test Material 1
1001 ZPRA 40000001 EA Test Material 2
1002 ZPRA 40000002 EA Test Material 3
I am able to create a dynamic internal table <F_ITAB> of the structure[This structure is dynamic and is not from se11]:
MATNR MTART MATKL MEINS MAKTX
Now, the problem am facing is, how will I populate the data of ITAB into <F_ITAB>?
Regards
Raj
Edited by: Rajasekhar Dinavahi on Jul 2, 2011 2:25 AM
07-01-2011 10:52 PM
Here is a working example. Just rename "it_mara" for your internal table name. If the internal table has work area you will get an error.
The key is declare the field symbol with TYPE ANY TABLE
DATA: it_mara TYPE TABLE OF mara.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE.
SELECT * UP TO 10 ROWS
FROM mara
INTO TABLE it_mara.
ASSIGN it_mara TO <fs>.
Here is the SAP help about this.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm
07-01-2011 10:52 PM
Here is a working example. Just rename "it_mara" for your internal table name. If the internal table has work area you will get an error.
The key is declare the field symbol with TYPE ANY TABLE
DATA: it_mara TYPE TABLE OF mara.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE.
SELECT * UP TO 10 ROWS
FROM mara
INTO TABLE it_mara.
ASSIGN it_mara TO <fs>.
Here is the SAP help about this.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm
07-01-2011 11:24 PM
Hi Rodrigo,
Thank you...
Once I change my internal table declaration [no header line], am able to assign the internal table(along with data) to field symbol...
Regards
Raj
07-02-2011 3:04 PM
Hi Rajasekhar Dinavahi,
if I understand you right, your dynamic table has at least some fields the existing itab has also. Then it should be
field-symbols:
<rec_old> type any,
<rec_new> type any.
* loop at existing data
loop at ITAB assigning <rec_old> .
* create an initil record in the dynamic table and assign it to a field-symbol
append initial line to <F_ITAB> assigning <rec_new>.
* fill the new record with fields of ITAB
move-corresponding <rec_old> to <rec_new>.
endloop.
Regards,
Clemens