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

small doubt in internal table

Former Member
0 Likes
792

hi abapers

how to define internal table with header line and without header line could plz provide exmple.

thanks and regards

hi abapers

how to define internal table with header line and without header line could plz provide exmple.

thanks and regards

5 REPLIES 5
Read only

Former Member
0 Likes
716

Hi,

See these examples:

<b>With Header line:

-


</b>

DATA: BEGIN OF itab1 OCCURS 0,
        field1(1),
      END OF itab1.
DATA: lit_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.

<b>Without Header line:

-


</b>


DATA: lit_vbak LIKE vbak OCCURS 0.
DATA: lit_vbrk LIKE STANDARD TABLE OF vbrk.

Refer this link for more info on internal tables

http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3660358411d1829f0000e829fbfe/frameset.htm

Regards,

RS

Read only

Former Member
0 Likes
716

hi sayeed,

V can declare the internal table in two ways. one is with header line and another one is without header line.

<b>With header line :</b>

data : begin of itab occurs 0,

kunnr like kna1-kunnr,

name1 like kna1-name1,

end of itab.

begin of along with occurs 0 addition itself creates the header line implicitly.

data : itab like kna1 occurs 0 with header line.

<b>Without header line:</b>

This kind of internal table description is used for nested internal table.

data : begin of itab,

a like kna1-kunnr,

b like kna1-name1,

end of itab.

data : wa_itab type standard table of itab.

Regards....

Arun.

Reward points if useful.

Read only

Former Member
0 Likes
716

Hi

Internal table with header line:

Data : itab like mara occurs 0 with header line.

OR

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE mara.

DATA : END OF itab.

Internal table without header line:

data : itab type table of mara.

please reward points to all useful answers.

regards,

rajesh.

Read only

Former Member
0 Likes
716

Internal tables

Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for storing and formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program.

Like all elements in the ABAP type concept, internal tables can exist both as data types and as data objects A data type is the abstract description of an internal table, either in a program or centrally in the ABAP Dictionary, that you use to create a concrete data object. The data type is also an attribute of an existing data object.

Internal Tables as Data Types

Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type, key, and table type.

Line type

The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the structure is a column in the internal table. However, the line type may also be elementary or another internal table.

Key

The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.

If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.

The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.

Table type

The table type determines how ABAP will access individual table entries. Internal tables can be divided into three types:

Standard tables have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries.

Sorted tables are always saved sorted by the key. They also have an internal index. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique or non-unique. When you define the table, you must specify whether the key is to be unique or not. Standard tables and sorted tables are known generically as index tables.

Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique. When you define the table, you must specify the key as UNIQUE.

Generic Internal Tables

Unlike other local data types in programs, you do not have to specify the data type of an internal table fully. Instead, you can specify a generic construction, that is, the key or key and line type of an internal table data type may remain unspecified. You can use generic internal tables to specify the types of field symbols and the interface parameters of procedures . You cannot use them to declare data objects.

Internal Tables as Dynamic Data Objects

Data objects that are defined either with the data type of an internal table, or directly as an internal table, are always fully defined in respect of their line type, key and access method. However, the number of lines is not fixed. Thus internal tables are dynamic data objects, since they can contain any number of lines of a particular type. The only restriction on the number of lines an internal table may contain are the limits of your system installation. The maximum memory that can be occupied by an internal table (including its internal administration) is 2 gigabytes. A more realistic figure is up to 500 megabytes. An additional restriction for hashed tables is that they may not contain more than 2 million entries. The line types of internal tables can be any ABAP data types - elementary, structured, or internal tables. The individual lines of an internal table are called table lines or table entries. Each component of a structured line is called a column in the internal table.

Choosing a Table Type

The table type (and particularly the access method) that you will use depends on how the typical internal table operations will be most frequently executed.

Standard tables

This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.

Sorted tables

This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.

Hashed tables

This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.

Creating Internal Tables

Processing Internal Tables

Creating Internal Tables

Like other elements in the ABAP type concept, you can declare internal tables as abstract data types in programs or in the ABAP Dictionary, and then use them to define data objects. Alternatively, you can define them directly as data objects. When you create an internal table as a data object, you should ensure that only the administration entry which belongs to an internal table is declared statically. The minimum size of an internal table is 256 bytes. This is important if an internal table occurs as a component of an aggregated data object, since even empty internal tables within tables can lead to high memory usage. (In the next functional release, the size of the table header for an initial table will be reduced to 8 bytes). Unlike all other ABAP data objects, you do not have to specify the memory required for an internal table. Table rows are added to and deleted from the table dynamically at runtime by the various statements for adding and deleting records.

Internal Table Types

Internal Table Objects

Standard Keys in Internal Tables

The standard key in internal tables basically consists of all the table fields with the character-type type ( C, STRING, D, T, N, X, XSTRING). In particular, components with a numeric type and table components in general do not belong to the standard key.

In internal tables with a nested line structure, the standard key results from linearization of the line structure, that is, all substructures are resolved recursively until only unstructured table fields are left to be considered. Of these fields, only those fields that are neither numeric fields nor tables are included in the key.

The linearization is explained in the following example:

TYPES: BEGIN OF PERSONNEL_DATES,

NAME TYPE STRING,

BIRTHDAY TYPE D,

WEIGHT TYPE F,

END OF PERSONNEL_DATES,

BEGIN OF ADDRESS,

STREET TYPE STRING,

CITY(30) TYPE C,

END OF ADDRESS,

BEGIN OF PERSON_RECORD,

NUMBER(10) TYPE P,

DATES TYPE PERSONNEL_DATES,

ADR TYPE ADDRESS,

END OF PERSON_RECORD.

DATA: ITAB TYPE PERSON_RECORD OCCURS 100.

The standard key for the internal table ITAB is composed of the fields ITAB-DATES-NAME, ITAB-DATES-BIRTHDAY, ITAB-ADR-STREET, and ITAB-ADR-CITY. The fields ITAB-NUMBER and ITAB-DATES-WEIGHT do not belong to the standard key.

For tables of non-structured types (that is,tables with an elementary line type, for example C, I, P, REF TO etc.), the whole line is used as a standard key.

In contrast, for tables over tables, the standard key is empty.

see this example report this gives more idea

REPORT demo_int_tables_move .

  • move

DATA: BEGIN OF line,

col1(1) TYPE c,

col2(1) TYPE c,

END OF line.

DATA: etab LIKE TABLE OF line WITH HEADER LINE,

ftab1 LIKE TABLE OF line.

line-col1 = 'A'. line-col2 = 'B'.

APPEND line TO etab.

MOVE etab[] TO ftab1.

LOOP AT ftab1 INTO line.

WRITE: / line-col1, line-col2.

ENDLOOP.

SKIP.

ULINE.

  • =

DATA: ftab2 TYPE SORTED TABLE OF f

WITH NON-UNIQUE KEY table_line,

itab1 TYPE HASHED TABLE OF i

WITH UNIQUE KEY table_line,

fl TYPE f.

DO 3 TIMES.

INSERT sy-index INTO TABLE itab1.

ENDDO.

ftab2 = itab1.

LOOP AT ftab2 INTO fl.

WRITE: / fl.

ENDLOOP.

SKIP.

ULINE.

  • The following Conversin is not allowed in an Unicode System

*DATA: BEGIN OF iline,

  • num TYPE i,

  • END OF iline,

*

  • BEGIN OF fline,

  • num TYPE f,

  • END OF fline,

*

  • itab2 LIKE TABLE OF iline,

  • ftab3 LIKE TABLE OF fline.

*

*DO 3 TIMES.

  • iline-num = sy-index.

  • APPEND iline-num TO itab2.

*ENDDO.

*

*ftab3 = itab2.

*

*LOOP AT ftab3 INTO fline.

  • WRITE: / fline-num.

*ENDLOOP.

reward if it help full

Message was edited by:

sunil kumar

Read only

Former Member
0 Likes
716

HI,

To create internal table without header line

*************************************************************

data: begin of itab

data1 type data element,

data2 type data element,

data3 type data element,

end of itab.

************************************************************

To create internal table without header line

*************************************************************

data: begin of itab occurs 10 with header line

data1 type data element,

data2 type data element,

data3 type data element,

end of itab.