2007 Aug 23 8:33 PM
What's the difference between
DATA itab TYPE spfli.
and
DATA itab TYPE STANDARD TABLE OF spfli?
2007 Aug 23 8:35 PM
Hi,
The first one will create structure itab and the second one will create internal table itab of type spfli.
Reward points if useful.
Thanks,
David.
2007 Aug 23 8:35 PM
Hi,
The first one will create structure itab and the second one will create internal table itab of type spfli.
Reward points if useful.
Thanks,
David.
2007 Aug 23 8:39 PM
2007 Aug 23 8:41 PM
A structure is a varible which can hold only one record.
An internal table will hold more than one records.
2007 Aug 23 8:41 PM
In a structure you can basically store just one record or value. In a table you can have multiple records. Hope it helpds you.
Reward points if useful.
Thanks,
David.
2007 Aug 23 8:41 PM
DATA itab TYPE TABLE OF spfli.
DATA wa TYPE LINE OF itab.
SELECT SINGLE *
INTO CORRESPONDING FIELDS OF itab
FROM spfli
WHERE carrid EQ 'LH'.
LOOP AT itab INTO wa.
WRITE: / wa-cityfrom, wa-cityto.
ENDLOOP.
For example, why does this code generate an "'ITAB' is not the type of an internal table" error?
2007 Aug 23 8:43 PM
HI,
here the problem is that itab does not have work area so its telling like that to correct his..
DATA itab TYPE TABLE OF spfli.
DATA wa TYPE LINE OF itab.
SELECT SINGLE *
INTO table itab
FROM spfli
WHERE carrid EQ 'LH'.
LOOP AT itab INTO wa.
WRITE: / wa-cityfrom, wa-cityto.
ENDLOOP.
or
SELECT SINGLE *
INTO wa
FROM spfli
WHERE carrid EQ 'LH'.
if sy-subrc eq 0.
WRITE: / wa-ciyfrom, wa-cityto.
endif.
2007 Aug 23 8:50 PM
DATA itab TYPE TABLE OF spfli.
DATA wa LIKE LINE OF itab.
SELECT *
INTO CORRESPONDING FIELDS OF <b>TABLE </b>itab
FROM spfli
WHERE carrid EQ 'LH'.
Why does this statement NOT work when I omit the keyword "TABLE"? Also, if I remove "CORRESPONDING FIELDS OF TABLE" altogether and just have
INTO itab
why do I get an error that says "You cannot use an internal table as a work area.". What exactly is a "work area"?
2007 Aug 23 8:56 PM
Hi,
When you do a select * you are basically getting all the records in the table spfli. If you omit the work table then you are trying to get those values in a structure. Work area is also a structure and not table. If you want to do selection without the keyword 'Table' use the following query
Data wa_itab TYPE spfli.
Select single * From spfli
into wa_itab
WHERE carrid EQ 'LH'.
Hope it helps you.
Thanks,
David
2007 Aug 23 8:57 PM
HI,
internal table is like a table to start with.. but when ever i say i want to put some data into or read data from the internal table i have to have a strucure/header line /work area into which i put the data record by record and insert into the internal table..
work area is like a temporary storage to put data or read data from a table..
you dont need to have work area for a internal table whn using in select with a table option.. but when you loop after this...select its like read record by record but read to where is where ur work area comes into picture...
one more variation is below.. but its old one and is not supported in OOPS abap
<b>*-- this will declare a internal table with header line...</b>
DATA itab TYPE TABLE OF spfli <b>with header line</b>.
DATA wa LIKE LINE OF itab.
<b> *-- here itab i am refereing is the work area of the internal table</b>
SELECT *
INTO CORRESPONDING FIELDS OF itab
FROM spfli
WHERE carrid EQ 'LH'.
if sy-subrc eq 0.
write : itab-id , itab-name.
endif.
or
*-- here the table is considered coz i use table statement.
SELECT *
INTO CORRESPONDING FIELDS OF table itab
FROM spfli
WHERE carrid EQ 'LH'.
if sy-subrc eq 0.
*-- here the name of the internal table and work area is same and with this loop record by record is read into the work area itab ..
looop at itab.
write: itab-id.
endloop
endif.
Thanks
mahesh
2007 Aug 23 9:00 PM
Ok, I'll take a stab at it, First lets understand that ITAB is an interna table, it has rows or a body, WA is a variable which will will use to read a line of the internal table into. So WA is a varaible which has the structure as a line of the ITAB. ITAB can have multple rows, but all look like SPFLI.
Now when you are selecting data into your ITAB, you must use the sytax, INTO TABLE ITAB or INTO CORRESPONDING FIELDS OF TABLE ITAB. Because ITAB is an internal table. If you where selecting only row from SPFLI, you could put that data into WA, but you would need to specify that you are selecing SINGLE, and you want to put the result INTO CORRESPONDING FIELDS OF WA, or INTO WA.
Did I confuse your more?
Regards
Rich Heilman
2007 Aug 23 9:05 PM
Simple answer is Workarea is a structure with only one record and table is with multiple records. When you say table with work area it is nothing but table with header.
When you write SELECT SINGLE * you give a structure in the destination
when you say SELECT * which could have more than 1 entry your destination is a table.
But when you take out INTO CORRESPONDING FIELDS OF TABLE ..you are trying to pass multiple values to single workarea, that's why it gives error.
-Kriss
2007 Aug 23 9:51 PM
Thanks to everyone for your answers. They've all been helpful. Before I abandon this thread though there's one more question if you would be so kind.
I replaced "LIKE LINE OF itab" with "TYPE LINE OF itab" out of curiosity (mainly because I don't understand the difference) and I get a message saying "ITAB is not the type of an internal table". I find this confusing because the line above it specifically declares <b>itab</b> as an internal table. What am I missing?
DATA itab TYPE TABLE OF spfli.
DATA wa TYPE LINE OF itab.
SELECT carrid connid cityfrom cityto
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE itab.
LOOP AT itab INTO wa.
WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ENDLOOP.
2007 Aug 23 10:23 PM
LIKE refers to other declared objects (internal tables, variables, workareas, and so) and takes from it the type it has. "LIKE LINE OF itab" declares a workarea that has the same structure as a line of itab. Thus internally this statement will look at itab definition.
TYPE refers to existing types (either in your program or in data dictionary). "TYPE LINE OF itab" doesn't work because itab is not an internal table type, but just an internal table.
Hope you get it.
Regards
2007 Aug 24 3:23 PM
Got it. Seems like a silly question in retrospect since it's so obvious now but ABAP is quite different than the world I came from (C#). Many thanks for your assistance.
2007 Aug 23 9:03 PM