Application Development and Automation 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: 
Read only

Internal Table!

Former Member
0 Likes
850

Hi!

Whats the diff b'tween declaring internal table using type & like.

and

When we need to ve itab with or without header line.

Thanks.

8 REPLIES 8
Read only

Former Member
0 Likes
828

TYPE is to refer the data type like c ,i ,p etc.

a type i

LIKE is to refer the predefined structure like mara-matnr,lfa1-lifnr

a like mara-matnr.

wa-mara like mara.

if u have header line then u will be able to loop,

if u dont have the header line u have to explictly declare a work area for acessing.

regards

prabhu

Read only

0 Likes
828

Hi prabu!

whats mean by

if u dont have the header line u have to explictly declare a work area for acessing.

Pls explain me how to do that?

Read only

0 Likes
828

Sorry,

To say it political correct (close my heart): This explanation is not very accurate.

TYPE refers to a self-defined (using TYPES statement) type or a basic type or a dictionary type (data element or table field).

LIKE refers to a data object already defined using DATA statement.

For pure compatibilty reasons (in the past there was no TYPE) the LIKE is identical to TYPE for all dictionary types.

TYPE REF TO and LIKE REF TO is analog but defines reference (pointer) fields

Regards,

Clemens

Read only

0 Likes
828

Hi Clemens!

I ve an internal table

Data: begin of itab occurs 0,

mara iike mara-matnr,

......,

end of itab.

Now with like

Data itab1 like itab occurs 0.

Now with type,

Data itab2 like itab occurs 0,

Is this correct whats the difference b'tween the two.

Thanks in Advance

Rahul.

Read only

0 Likes
828

Hi Clemens!

I ve an internal table

Data: begin of itab occurs 0,

mara iike mara-matnr,

......,

end of itab.

Now with like

Data itab1 like itab occurs 0.

Now with type,

Data itab2 type itab occurs 0,

Is this correct whats the difference b'tween the two.

Thanks in Advance

Rahul.

Read only

0 Likes
828

Hi Rahul,

Data itab2 type itab occurs 0

will not pass the syntax check because itab is neither a type defined with TYPES nor a dictionary type nor a ABAP simple type.

Better use:


TYPES:
  begin of ty_itab occurs 0,
  mara iike mara-matnr,
......,
  end of ty_itab,
  ty_t_itab type standard table of ty_itab with default key.

Data:
  lt_itab type ty_t_itab. "WITH HEADER LINE if not OO and if old fashioned
  lt_itab2 like lt_itab
* or lt_itab2 type ty_t_itab.

lt_itab2 = lt_itab. "works for tables without header line

lt_itab2[] = lt_itab[]. "works for tables with or without header line

Regards,

Clemens

Read only

0 Likes
828

TYPE type

Effect

The field f is created with type type. For the type, you can specify either one of the predefined types listed below, a type defined using the TYPES statement, or a type created in the ABAP Dictionary.

The standard length ( SL ) of a field depends on its type.

Type Explanation SL Initial value

C Text (Character) 1 space

N Numeric text 1 '00...0'

D Date (YYYYMMDD) 8 '00000000'

T Time (HHMMSS) 6 '000000'

X Hexadecimal (HeX code) 1 X'00'

I Integer 4 0

P Packed number 8 0

F Floating point number 8 0

STRING Character sequence (string) variable-length empty string

XSTRING Byte sequence (X string)

variable-length empty hexadecimal string

Example

DATA NUMBER TYPE I.

DATA WA_SPFLI TYPE SPFLI.

The field NUMBER is created with type I. You can now use it in the program. In particular, you can assign numeric values to the field and use it in calculations ( ABAP number types).

The field WA_SPFLI is created using the type of the database table SPFLI from the ABAP Dictionary. This field is structured and can be used especially for working with data from database table SPFLI.

Addition 2

... LIKE f1

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.

See Cannot Use LIKE References to Dictionary Types.

Effect

Field f is created with the same field attribtues as the data object f1, which has already been declared. Any data object (field, parameter, structure...) is allowed as long as its type has been fully specified.

f1 can be any ABAP Dictionary reference.

Example

DATA TABLE_INDEX LIKE SY-TABIX.

The field TABLE_INDEX now has the same attributes as SY-TABIX (index field for internal tables).

Note

You should use this addition whenever you can. If the type of a field to which you are referring changes, the ABAP runtime system updates all references automatically. It also stops the system from carrying out unnecessry (and maybe undesirable) type conversions.

regards

prabhu