05-24-2010 5:31 AM
Hi,
I am trying to append a structure data to a table type.
For example:
I have a Table Type called ZTABLE_TYPE of Line Type ZSTRUCTURE.
In my program, my declaration is as below:
DATA itab TYPE STANDARD TABLE OF ZTABLE_TYPE.
DATA work_area TYPE ZSTRUCTURE.
work_area-field1 = 'abc'
work_area-field2 = '123'
APPEND work_area TO itab.
However, when I try to activate, I received a syntax error:
"WORK_AREA" cannot be converted to the line type of "ITAB".
Can I get some help on whether I have declared wrongly, or is there a more appropriate way to append data into a table type.
Thanks!
05-24-2010 5:43 AM
Hi,
Try the below code.
DATA itab TYPE ZTABLE_TYPE.
DATA work_area TYPE ZSTRUCTURE.
work_area-field1 = 'abc'
work_area-field2 = '123'
APPEND work_area TO itab.
Hope it helps.
Regards
Shruti
05-24-2010 5:35 AM
Hi Adrian ,
Go for the below declaration
DATA itab TYPE STANDARD TABLE OF ZTABLE_TYPE.
work_area TYPE ZTABLE_TYPE
(or)
DATA itab TYPE STANDARD TABLE OF ZSTRUCTURE..
work_area TYPE ZSTRUCTURE.
05-24-2010 7:04 AM
Thanks Shruti, Santosh and Vijetasap for your help and explanation. Works now.
Prasath and Harsh, sorry I should have explained this in my initial post, but I couldn't declare both the same as I was using the table type as an export parameter for a function. Thanks for the help anyways.
05-24-2010 5:42 AM
Hi Adrian
The TYPE of Work Area as well as the internal table should be the same either ZSTRUCTURE or ZTABLE_TYPE.
Hope this helps.
Harsh
05-24-2010 5:43 AM
Hi,
Try the below code.
DATA itab TYPE ZTABLE_TYPE.
DATA work_area TYPE ZSTRUCTURE.
work_area-field1 = 'abc'
work_area-field2 = '123'
APPEND work_area TO itab.
Hope it helps.
Regards
Shruti
05-24-2010 6:44 AM
Hi,
Declare like this:
DATA itab TYPE ZTABLE_TYPE.
DATA work_area TYPE ZSTRUCTURE.
work_area-field1 = 'abc'
work_area-field2 = '123'
APPEND work_area TO itab.
This is because ZTABLE_TYPE is already a table type. So you need not mention "type table of" in your declaration part.
Thanks and Regards,
Santosh Kumar Mukka.
05-24-2010 6:48 AM
Firstly ZTABLE_TYPE, is it a database table ora table type.
If its a table type then you need to declare it as:-
Data : itab type ZTABLE_TYPE.
and if its a database table then declare:
Data: itab type tbale of ZTABLE_TYPE.