Application Development 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: 

What's the difference?

Former Member
0 Kudos
138

What's the difference between

DATA itab TYPE spfli.

and

DATA itab TYPE STANDARD TABLE OF spfli?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
113

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.

15 REPLIES 15

Former Member
0 Kudos
114

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.

0 Kudos
113

Dumb question: what's the difference? I'm royally confused.

0 Kudos
113

A structure is a varible which can hold only one record.

An internal table will hold more than one records.

0 Kudos
113

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.

0 Kudos
113

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?

0 Kudos
113

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.

0 Kudos
113

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"?

0 Kudos
113

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

0 Kudos
113

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

0 Kudos
113

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

0 Kudos
113

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

0 Kudos
113

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.

0 Kudos
113

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

0 Kudos
113

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.

Former Member
0 Kudos
113

Thanks guys. Got it now!