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: 

Internal table

Former Member
0 Kudos

HI all,

What is the difference between internal table and field sting.

For ex:

Data itab like MARA. IS this is internal table or field string , plz any body can suggest me how many types we can declare internal table.

8 REPLIES 8

Former Member
0 Kudos

ways to declare internal tables.

1) if you want to create a intenal table same as a standard table in the database then

data : itab like standard table of vbak with header line.

2) if you want to have your own structure to your internal table the.

delcare types : this is how you shold do most of the times. to be more professional

types : begin of ty_tab,

field1,

field 2,

end of ty_tab.

data : x_tab type ty_tab.

data: itab like standard table of x_Tab with header line.

or

3) data : begin of itab occurs 0,

field1,

field 2,

end of itab.

with object oriented programming type 3 declartion is ruled out and also with header line specification is not possible in this oops scenerio you have to do like this

data : itab like standard table of vbak.

x_tab like vbak.

Former Member
0 Kudos

Hi,

1) if you want to create a intenal table same as a standard table in the database then

data : itab like standard table of vbak with header line.

2) if you want to have your own structure to your internal table the.

Thanks.

0 Kudos

nice copy, Viji

Former Member
0 Kudos

Hi,

field string can hold only one record at a time.

for ex,

data:begin of <fs>

empno type i,

empname type c,

end of <fs>.

select * from emp into fs.

endselect

write:/fs.

in this case field string can hold last record only.

where internal tables are enhancement to field string concept.and internal table holda multiple records.u can see more documentation about internal table as follows.

Internal tables are a way to store datasets of a fixed structure in the working memory of ABAP. The data is stored on a row-by-row basis, where each row has the same structure. The individual components of a row are also referred to as the columns of the internal table.

There are two kinds of internal tables in ABAP: data types and data objects. A data type returns the abstract description of an internal table and is used to create concrete data objects.

Data Types

Structures and internal tables represent the two structured data types available in ABAP (see ABAP Type Concept). The data type of an internal table is fully specified by:

Row type

The row type of an internal table can be any ABAP data type (that is, it can also be an internal table).

Key

The key is used to identify table rows. There are two possible keys for internal tables, the standard key and a user-defined key. The key can be defined as unique (UNIQUE) or non-unique (NON-UNIQUE). If a key is unique, no multiple entries exist in internal tables. The uniqueness depends on the table type (see below).

The standard key is made up of all non-numeric components of the associated row type that are no internal tables themselves or do not contain internal tables.

The user-defined key can be made up of any components that are no internal tables themselves or do not contain internal tables, that is, do not have a deep structured type. Internal tables with a user-defined key are called key tables. When you define the key, you must pay attention to the order of the key fields, which is important, for example, for sorting the data based on the key.

Table type

The table type determines how ABAP accesses individual table rows. Based on the table type, internal tables can be subdivided into the following three categories:

In standard tables, a logical index is set up internally. The data can be accessed using the table index or the key. If the data is accessed using the key, the response time depends linearly on the number of table entries. The key of a standard table is always non-unique. When you define the table, you must not specify uniqueness for the key.

Sorted tables are always stored sorted by the key. Also for sorted tables, a logical index is set up internally. The data can be accessed using the table index or the key. If the data is accessed using the key, the response time depends logarithmically on the number of table entries since the data is accessed through a binary search. The key of sorted tables can be unique or non-unique. When you define the table, you must specify whether the key is UNIQUE or NON-UNIQUE.

Standard tables and sorted tables are also commonly referred to as index tables.

In hash tables, no logical index is set up internally. Hash tables can only be accessed by specifying the key. The response time in this case is constant irrespective of the number of table entries since the data is accessed through a hash algorithm. The key of hash tables must be unique. When you define the table, you must specify the key as UNIQUE.

Unlike other user-defined ABAP data types, the data type of an internal table does not need to be fully specified but can be set up generically. This means that if you create a data type for an internal table, you can either leave the key or the row type and the key unspecified.

Data Objects

Data objects created with the data type of an internal table or directly as an internal table are always specified fully with regard to row type, key, and table type. However, they can have any number of rows. Internal tables are consequently dynamic data objects that can contain any number of rows of a fixed type. The number of rows of an internal table is only restricted by the capacity limits of the actual system installation. The row types of internal tables are any ABAP data types and can therefore be elementary, structured, or internal tables themselves. The individual rows of an internal table are called table rows or table entries.

Using Internal Tables

Internal tables offer the functionality of dynamic arrays in ABAP and free the programmer from having to control dynamic memory management in the program. Internal tables are generally used if datasets of a fixed structure are processed internally in the program, for example, if contents of database tables are stored and edited internally in the program. Internal tables are also the most important means to implement highly complex data structures in an ABAP program.

Data Exchange with Internal Tables

There are two ways to handle internal tables. You can either address the entire internal table data object, also called the table body, or you can address individual table entries.

If you access the entire table body, you can use the table name like an elementary field in appropriate ABAP statements such as MOVE and execute the corresponding operation for the entire data object.

When accessing individual table entries, you do not directly operate on the data in the table but use another data object as the work area. The work area is used as an interface to the entries of the internal table and must be at least convertible into the row type of the internal table. Usually, however, you use work areas of the same data type as the rows of the internal table. When data is read from table rows, the contents of the work area are overwritten with the contents of the table row addressed. The contents of the work area can then be used in the program. When data is written into table rows, you must first enter the data into the work area. The system then transfers the data from the work area into the table row.

You can create internal tables with a line known as a header line, which has the same data type as a table row. The header line can be used as the table work area. This table work area and the internal table itself have the same name. ABAP statements for accessing individual table entries can implicitly use the header line as the work area. In ABAP statements that do not implicitly access the entire table body, you must distinguish the work area from the header line by adding angle brackets after the name (for example itab[]). The reason for this is that the system generally interprets the name in such statements as the name of the work area and not as the internal table. So that the table can be distinguished from the work area, you should create internal tables without header lines, if possible. In particular, internal tables must not have header lines if they are part of structures or other internal tables since this would result in ambiguous expressions.

In your case it is internal table.

Reward points if useful.

Thanks,

Usha

Former Member
0 Kudos

Hi srinivas,

Various ways of declaring internal tables.

1. data: begin of it1 occurs 10, "has a header line

f1,

f2,

f3,

end of it1.

2. data it2 like ztxlfa1 occurs 100. "doesn't have a header line

3. data it3 like ztxlfa1 occurs 100 with header line. "it does now

The one you have declared data itab like Mara is internal table and not field string.

Please do reward if useful.

Thanks.

Former Member
0 Kudos

Hi

beter way to represent internal table declaration

declrae structure useing TYPES

TYPES : BEGIN OF ST_OBJID_SH,

OTYPE TYPE HRP1000-OTYPE,

OBJID TYPE HRP1000-OBJID,

END OF ST_OBJID_SH.

declare internal table body like this

DATA : IT_OBJID_SH TYPE STANDARD TABLE OF ST_OBJID_SH.

dclare internal table work area like this

DATA : WA_OBJID_SH TYPE ST_OBJID_SH.

internal table stores the number of records

field string stores the continous string

<b>Convert Intrnal table to string</b>

report zrich_0001 line-size 500.

data: it001 type table of t001 with header line.

data: string type string.

data: fldstr type string.

data: substr type string.

field-symbols: <fs>.

select * into table it001 from t001.

loop at it001.

do.

assign component sy-index of structure it001 to <fs>.

if sy-subrc <> 0.

exit.

endif.

fldstr = <fs>.

concatenate substr fldstr into substr separated by space.

shift substr left deleting leading space.

enddo.

concatenate string substr into string separated by ','.

endloop.

shift string left deleting leading ','.

write:/ string.

Reward if usefull

Former Member
0 Kudos

Hi,

How to declare and use field string :

data : str type string.

SSTRING 1-255 Character string string 
STRING 256-... Character string string

<i>The type SSTRING is available as of release 6.10 and it has a variable length. Its maximum length must be specified and is limited to 255. The advantage of this type compared with CHAR, is that it is assigned to the ABAP type string.</i>

Ways of declaring internal table :


* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF tab_ekpo.
 
*Table declaration (new method)     "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
      wa_ekpo TYPE t_ekpo.                    "work area (header line)
 
* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0,      "old method
      wa_datatab LIKE LINE OF tab_ekpo.
 
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
        INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!
TYPES: bukrs  TYPE ekpo-werks,
       bstyp  TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
      wa_repdata TYPE t_repdata.                 "work area (header line)

regards

Sathish

Former Member
0 Kudos

hi,

field-string is the structure declared inside the ABAP/4 program,which doesnt hold any values,.

But Internal table is a table which holds records till the end of the program, and has values till the program memory exists.