Showing newest posts with label Internal table. Show older posts
Showing newest posts with label Internal table. Show older posts

Internal Tables and Types

STANDARD table

Key access to a standard table uses a linear search. This means that the time required
for a search is in linear relation to the number of table entries.

You should use index operations to access standard tables.



SORTED table

Defines the table as one that is always saved correctly sorted.

Key access to a sorted table uses a binary key. If the key is not unique, the system takes
the entry with the lowest index. The runtime required for key access is logarithmically
related to the number of table entries.

HASHED table

Defines the table as one that is managed with an internal hash procedure

You can only access a hashed table using the generic key operations or other generic
operations ( SORT, LOOP, and so on). Explicit or implicit index operations (such as
LOOP ... FROM oe INSERT itab within a LOOP) are not allowed.


INDEX table

A table that can be accessed using an index.

Index table is only used to specify the type of generic parameters in a FORM or
FUNCTION. That means that you can't create a table of type INDEX.

Standard tables and sorted tables are index tables.

Syntax :
DATA itab TYPE table type of line type [WITH UNIQUE/NON-UNIQUE KEY ]
[Iinitial size n] [WITH HEADER LINE]

Read the Complete Post!

Latest SAP Jobs and Walkins

Internal Table and Types Of Internal Table



INTERNAL TABLE:

An internal table is a temporary table stored in RAM of the application server. It is created and filled by a program during execution and is discarded when the program ends.



Types of Internal Table:
1. Internal table without Header line.
2. Internal Table with header line.

INTERNAL TABLE MANIPULATIONS:

1. READ:
READ TABLE WITH KEY < fieldname =" ‘’">.

2. INSERT:
INSERT index .

3. MODIFY:
MODIFY index

4. DESCRIBE:
DESCRIBE TABLE lines OCCURS .

5. APPEND:
APPEND .

6. CLEAR
CLEAR .

7. REFRESH
REFRESH .


INTERNAL TABLE WITHOUT HEADER LINE:

DATA: BEGIN OF HEADER,
BOOKNO(4) TYPE N,
BOOKNAME(5) TYPE C,
BOOKADD(10) TYPE C,
END OF HEADER.

DATA: BODY LIKE HEADER OCCURS 0.

HEADER-BOOKNO = '1234'.
HEADER-BOOKNAME = 'SAP'.
HEADER-BOOKADD = 'TNAGAR'.
APPEND HEADER TO BODY.
CLEAR HEADER.

HEADER-BOOKNO = '1235'.
HEADER-BOOKNAME = 'ABAP'.
HEADER-BOOKADD = 'ANNANAGAR'.
APPEND HEADER TO BODY.
CLEAR HEADER.

HEADER-BOOKNO = '1236'.
HEADER-BOOKNAME = 'ERP'.
HEADER-BOOKADD = 'ADYAR'.
APPEND HEADER TO BODY.
CLEAR HEADER.

LOOP AT BODY INTO HEADER.
WRITE:/ HEADER-BOOKNO,HEADER-BOOKNAME,HEADER-BOOKADD.
ENDLOOP.



Output :


INTERNAL TABLE WITH HEADER LINE WITH MANIPULATIONS:

REPORT ZKA_INTTABWITHITAB .

DATA: BEGIN OF ITAB OCCURS 0,
BOOKNO(4) TYPE N,
BOOKNAME(5) TYPE C,
BOOKADD(10) TYPE C,
END OF ITAB.

ITAB-BOOKNO = '1234'.
ITAB-BOOKNAME = 'SAP'.
ITAB-BOOKADD = 'TNAGAR'.
APPEND ITAB.
CLEAR ITAB.

ITAB-BOOKNO = '1235'.
ITAB-BOOKNAME = 'ABAP'.
ITAB-BOOKADD = 'ANNANAGAR'.
APPEND ITAB.
CLEAR ITAB.


ITAB-BOOKNO = '1236'.
ITAB-BOOKNAME = 'ERP'.
ITAB-BOOKADD = 'ADYAR'.
APPEND ITAB.
CLEAR ITAB.


LOOP AT ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.
ENDLOOP.

SKIP 2.

READ TABLE ITAB WITH KEY BOOKNO = '1235'.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.

SKIP 2.

READ TABLE ITAB INDEX 3.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.

SKIP 2.

ITAB-BOOKNO = '9876'.
ITAB-BOOKNAME = 'ORACLE'.
ITAB-BOOKADD = 'TAMBARAM'.


INSERT ITAB INDEX 2.
LOOP AT ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.
ENDLOOP.

SKIP 2.

ITAB-BOOKNO = '4567'.
ITAB-BOOKNAME = 'BASIS'.
ITAB-BOOKADD = 'AVADI'.
MODIFY ITAB INDEX 2.
LOOP AT ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.
ENDLOOP.


SKIP 2.

DELETE ITAB INDEX 2.
LOOP AT ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.
ENDLOOP.

SKIP 2.

CLEAR ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.


SKIP 2.

FREE ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.


SKIP 2.

REFRESH ITAB.
LOOP AT ITAB.
WRITE:/ ITAB-BOOKNO,ITAB-BOOKNAME,ITAB-BOOKADD.
ENDLOOP.






Output :










Read the Complete Post!

Latest SAP Jobs and Walkins

Example of Dynamic Internal table

see the example program :

REPORT abc.

*------------- COMPULSORY
FIELD-SYMBOLS: TYPE ANY TABLE.
FIELD-SYMBOLS: TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: TYPE ANY.
DATA : fldname(50) TYPE c.



*--------------------
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.

START-OF-SELECTION.
*------------------- GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
.

*------------- CONSTRUCT FIELD LIST

LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.

*-------------- PERFORM

PERFORM mydyntable USING lt.

BREAK-POINT.


*---------------------------------------------------------------
* INDEPENDENT FORM
*---------------------------------------------------------------

FORM mydyntable USING lt TYPE lvc_t_fcat .


*-------------- Create Dyn Table From FC

FIELD-SYMBOLS: TYPE REF TO data.
FIELD-SYMBOLS: .
FIELD-SYMBOLS: TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.


ASSIGN lt_data TO .

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table =
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.


*------------- Assign Dyn Table To Field Sumbol

ASSIGN ->* TO .
ASSIGN TO .
ASSIGN TO .

ENDFORM. "MYDYNTABLE

Read the Complete Post!

Latest SAP Jobs and Walkins

Some important ABAP sample Code

SAP Expert