"Referring To Local Data Type

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

An Internal table is a temporary table gets created in the memory of application server during

program execution and gets destroyed once the program ends. It is used to hold data temporarily.

An internal table can be defined using the keyword TABLE OF in the DATA statement.

Internal table can be defined by the following ways:

TYPES: BEGIN OF ty_student, “ Structure in Runtime

Id(10) TYPE n,

Name(20) type c,

END OF ty_student.

DATA: wa TYPE ty_student.

"Referring to local data type

DATA: itab1 TYPE TABLE OF ty_student. (Or)

"Referring to local data object

DATA: itab2 LIKE TABLE OF wa. (Or)

"Referring to data type in ABAP dictionary

DATA: itab3 TYPE TABLE OF MARA.

Wa-id = 1.
Wa-name = ‘Suneel’.
APPEND wa to Itab1. (itab2 or itab3)

Wa-id = 2.
Wa-name = ‘Nawaz’.
APPEND wa to Itab1. (itab2 or itab3)

Wa-id = 3.
Wa-name = ‘Sandeep’.
APPEND wa to Itab1. (itab2 or itab3)
After the last APPEND statement in the above program, internal table ‘ITAB1’ has the following 3
entries. But the internal table values are not save in DB. The internal table and its values are
discarded once the program ends.

ID Name
1 Suneel
2 Nawaz
3 Sandeep

Usually internal tables are used to hold data from database tables temporarily for displaying on the
screen or further processing. To fill the internal table with database values, use SELECT statement
to read the records from the database one by one, place it in the work area and then APPEND the
values in the work area to internal table.

REPORT  ZSAMPLE.

DATA: wa TYPE zproduct,
      itab  TYPE TABLE OF zproduct.

SELECT * FROM zproduct INTO wa.
  APPEND wa TO itab.
ENDSELECT.

After ENDSELECT the internal table ITAB contains all the records that are present in table
ZPRODUCT.

Using INTO TABLE addition to SELECT statement we can also read multiple records directly into
the internal table directly. No work area used in this case. This select statement will not work in loop,
so no ENDSELECT is required.
SELECT * FROM zproduct INTO TABLE itab.
We can use internal tables in two ways:

1. Internal tables with HEADER line


2. Internal tables without HEADER line.

Internal Tables with Header Line

 Here the system automatically creates the work area.


 The work area has the same data type as internal table.
 This work area is called the HEADER line.
DATA: itab  TYPE  TABLE OF zproduct WITH HEADER LINE.

SELECT * FROM zproduct INTO itab.
ENDSELECT.

Internal Tables without Header Line :

 Here there is no work area associated with the table.


 Work area is to be explicitly specified by the Developer when we need to access
such tables.
DATA: wa TYPE zproduct,
      itab  TYPE  TABLE OF zproduct.

SELECT * FROM zproduct INTO wa.
  APPEND wa TO itab.
ENDSELECT.
Types of Internal Tables
1. Standard
2. Sorted
3. Hashed
Standard Table - The most commonly used type of table. You can sort and resort this table
anytime. You can have duplicate records in them. Recommend that when accessing these
tables, you sort them by a key and then READ via a BINARY SEARCH - better performance.
No need of defining the Key while declaration. Ex: IT_VEN TYPE STANDARD TABLE OF TY_VEN.

Sorted table - this table has a defined sort sequence. You cannot resort. You can have
duplicates. When you READ these tables, SAP automatically tries to use a BINARY SEARCH.
Must and should define the Key (Unique /Non Unique) while declaration. Ex:
IT_VEN TYPE SORTED TABLE OF TY_VEN WITH UNIQUE KEY lifnr.
IT_MAIL TYPE SORTED TABLE OF TY_MAIL WITH NON-UNIQUE KEY ADDRNUMBER.

Hashed Table - this table has a defined key. Hashed table is useful when you have to work with
very big internal table and to read it.
Must and should define the Key (Unique) while declaration. Ex:
IT_VEN TYPE HASHED TABLE OF TY_VEN WITH UNIQUE KEY lifnr.

Example program : ZABCD

Internal Table Operations


Example program : ZSAMPLE1
Using APPEND in SAP ABAP
APPEND statement is used to append or add a record from work area to internal table, the new record
will be added at the end of the internal table.

Syntax: APPEND <WA> TO <ITAB>


DATA : IT_MARA TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.
WA_MARA-MATNR = '00001'.
WA_MARA-MTART = 'FERT'.
WA_MARA-MEINS = 'EA'.
APPEND WA_MARA TO IT_MARA . "APPEND WORK AREA TO INTERNAL TABLE

Using INSERT in SAP ABAP


INSERT statement is used to insert or add a record from work area into internal table at specified
location

Syntax: INSERT <WA> INTO <ITAB> INDEX <index>


DATA : IT_MARA TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.
WA_MARA-MATNR = '00001'.
WA_MARA-MTART = 'FERT'.
WA_MARA-MEINS = 'EA'.
INSERT WA_MARA INTO IT_MARA INDEX 2 . "The record will be inserted into internal
table at 2nd position

Using SORT in SAP ABAP


SORT is used to sort a Internal table data in ascending order or descending order, by default it will
sort data in ascending order. In addition to this we can able to sort data based on specified fields.

Syntax1 : SORT <ITAB> . "Default sorts data in ascending order


Syntax2 : SORT <ITAB> DESCENDING . " Sort in descending order
Syntax3 : SORT <ITAB> BY <FIELD1> <FIELD2>...ASCENDING/DESCENDING ."It sorts data by
specified fields <FIELD1>, <FIELD2>..

Using DESCRIBE TABLE in SAP ABAP


DESCRIBE TABLE is used to count the no of records in a internal table

Syntax: DESCRIBE TABLE <ITAB> LINES <v_lines> ." Count the no. of
records of a internal table, here v_lines stores count
DATA : V_LINES TYPE I. "Type integer
DESCRIBE TABLE IT_MARA LINES V_LINES ." Count the no. of record of a internal table
Write : v_lines .

Using READ TABLE WITH KEY in SAP ABAP


READ TABLE WITH KEY .. BINARY SEARCH is used to read a single record from an internal table into
work area specified by field name and field value .
BINARY SEARCH is a search mechanism which is used to read a record from internal table into work
area very fast, the functionality of binary search it divides the into parts and searches. The internal
table must be sorted in ascending order before using binary search.

Syntax: READ TABLE <ITAB> INTO <WA> WITH KEY <FIELD1> = <FIELD1 VALUE> <FIELD1> =
<FIELD1 VALUE>
BINARY SEARCH.
" Read a record into work area where some field = some value
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = '0001' BINARY SEARCH. "Read a
record into work area where MATNR is '0001'
Using READ TABLE WITH INDEX in SAP ABAP
READ TABLE WITH INDEX is used to read a single record from an internal table into work area
specified by index.

Syntax: READ TABLE <ITAB> INTO <WA> INDEX <index_no>


." Read a record into work area using index ( position )
READ TABLE IT_MARA INTO WA_MARA INDEX '2'. "Read a record into work area where

index is 2.

Using LOOP....ENDLOOP. in SAP ABAP


Loop...Endloop. is also used to read data from a internal table into work area, this is used to read
multiple records serially one after one .

Syntax1: LOOP AT <ITAB> INTO <WA>.

ENDLOOP.

Syntax2: LOOP AT <ITAB> INTO <WA> WHERE <FIELDS1> = <VALUE> .

ENDLOOP.

Syntax3: LOOP AT <ITAB> INTO <WA> FROM <INDEX1> TO <INDEX2>.

ENDLOOP.

Using MODIFY in SAP ABAP


MODIFY is used to modify single or multiple internal table records based on condition.

TRANSPORTING is a keyword which is used to specify list particular fields to be modified instead of all
fields.

Syntax1: MODIFY <ITAB> FROM <WA> INDEX <INDEX NO> TRANSPORTING <FIELD1> <FIELD2>

Syntax1: MODIFY <ITAB> FROM <WA> TRANSPORTING <FIELD1>


<FIELD2> WHERE <CONDITION>

SY-TABIX is a key word which stores the index no of currently processed record.
DATA : IT_MARA TYPE TABLE OF MARA.
DATA : WA_MARA TYPE MARA.

SELECT * FROM MARA INTO TABLE IT_MARA . " GET DATA INTO ITAB IT_MARA

WA_MARA-MTART = 'FERT'; "ASSIGN A VALUE TO WORKAREA TO MODIFY INTERNAL TABLE

MODIFY IT_MARA FROM WA_MARA INDEX SY-TABIX TRANSPORTING MTART. " NOW THE VALUE OF

FIELD MTART WILL BE MODIFIED FOR CURRENT RECORD IN IT_MARA

DATA : IT_MARA TYPE TABLE OF MARA.


DATA : WA_MARA TYPE MARA.

SELECT * FROM MARA INTO TABLE IT_MARA . " GET DATA INTO ITAB IT_MARA

WA_MARA-MTART = 'FERT'; "ASSIGN A VALUE TO WORKAREA TO MODIFY INTERNAL TABLE

MODIFY IT_MARA FROM WA_MARA TRANSPORTING MTART WHERE MATNR = '0001'. " NOW THE

VALUE OF FIELD MTART WILL BE MODIFIED WHERE MATNR = '0001' IN ITAB

Using DELETE in SAP ABAP


DELETE is used to delete single or multiple records from an internal table from work area based on
some condition.

Syntax1: DELETE <ITAB> INDEX <INDEX NO>.

Syntax2: DELETE <ITAB> WHERE <FIELD1> = <FIELD1 VALUE>

<FIELD2> = <FIELD2 VALUE>.


DELETE IT_MARA INDEX 3. "3rd RECORD WILL BE DELETED IN IT_MARA
DELETE IT_MARA WHERE MTART = 'FERT'. "MATERIALS WITH MTART = 'FERT' WILL BE DELETED

Using DELETE ADJACENT DUPLICATES in SAP ABAP


DELETE ADJACENT DUPLICATES is used to delete duplicate records which are adjacent to each-other.
Pre-requisite for this is the internal table must be sorted in ascending order

Syntax1: DELETE ADJACENT DUPLICATED FROM <ITAB> ."ADJACENT DUPLICATED WILL

BE DELETED IN INTERNAL TABLE COMPARING ALL FIELDS

Syntax2: DELETE ADJACENT DUPLICATES FROM <ITAB> COMPARING <FIELD1>

<FIELD2> . "ADJACENT DUPLICATES WILL BE DELETED COMPARING SPECIFIED FIELDS


SORT IT_MARA ASCENDING.
DELETE ADJACENT DUPLICATES FROM IT_MARA . "3rd RECORD WILL BE DELETED IN IT_MARA

SORT IT_MARA ASCENDING.


DELETE ADJACENT DUPLICATES IT_MARA COMPARING MATNR, MTART. "DUPLICATES WILL BE

DELETED BY COMPARING MATNR AND MTART

Using CLEAR, REFRESH, FREE in SAP ABAP


CLEAR is used to clear a value in a work area or in a variable.

REFRESH is used to clear all values in a internal table.

FREE is used to clear (free) memory of a internal table or work area. We all know when ever we
declare a internal table or work area, 8kb memory will be allocated.

Syntax clear : CLEAR <WA> "CLEAR WORK AREA OR VARIABLE

Syntax REFRESH : REFRESH <ITAB> "CLEAR ALL RECORDS OF INTERNAL TABLE BUT

MEMORY WILL BE THERE

Syntax FREE : FREE <WA> "FREE INTERNAL TABLE MEMORY


CLEAR WA_MARA.

REFRESH IT_MARA.

FREE IT_MARA.

Using APPEND LINES OF in SAP ABAP


APPEND LINES OF is used to append multiple records to an internal table from another internal table .

Syntax : APPEND LINES OF <ITAB1> FROM <index no> TO <index no2>

TO <ITAB2>.

DATA : IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE


DATA : IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE

APPEND LINES OF IT_MARA FROM 3 TO 5 TO IT_MARA1 . "DATA IN IT_MARA WILL BE APPENDED

TO IT_MARA1 FROM INDEX 3 TO INDEX 5 .

Using INSERT LINES OF in SAP ABAP


INSERT LINES OF is used to INSERT multiple records to an internal table from another internal table
at specified location .

Syntax : INSERT LINES OF <ITAB1> FROM <index no> TO <index no2>

INTO <ITAB2> INDEX <index no>.

DATA : IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE


DATA : IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE

INSERT LINES OF IT_MARA FROM 3 TO 5 INTO IT_MARA1 INDEX 3 . "DATA IN IT_MARA WILL

BE INSERTED INTO IT_MARA1 FROM INDEX 3 TO INDEX 5 AT INDEX 3 LOCATION .


Using MOVE in SAP ABAP
MOVE keyword is used to move one internal table data to another.

Syantax : <ITAB2> = <ITAB1> . "Move ITAB1 to ITAB2

Using COLLECT in SAP ABAP


COLLECT is slimier to APPEND, the difference is it (COLLECT) will check whether the work area
record already exists with the same key, if exists it will add numerical fields (sum) to the existing
record, if work area record does not exists it will append a new record .

Syntax: COLLECT <WA> INTO <ITAB>.

  Check statement

If the condition satisfies or true then only it goes to


next statement.
*DO 4 TIMES.
*write:/ sy-index.
*check sy-index <= 2.
*write 'JUMBLE'.
*ENDDO.
o/p: 1 JUMBLE
2 JUMBLE
3
4

Continue statement
If the condition Not satisfies or False then only it
goes to next statement.
*DO 4 TIMES.
*write:/ sy-index.
*if sy-index <= 2.
*  CONTINUE.
*endif.
*write 'JUMBLE'.
*ENDDO.

o/p: 1
2
3 JUMBLE
4 JUMBLE

The behavior of EXIT keyword is depends on where you use it.

 If you use EXIT keyword inside IF .. ENDIF., it will comes out of the program.
 If you use EXIT inside LOOP .. ENDLOOP., it will come out of loop.
 If you use EXIT inside FORM .. ENDFORM., it will comes out of form (subroutine).

*DATA: IT_MARA TYPE TABLE OF MARA,
      WA_MARA TYPE MARA.
PARAMETERS: P_MATNR TYPE MARA-MATNR.
  SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = P_MATNR.
  IF WA_MARA IS INITIAL.
    EXIT. "exit program
  else.
  WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
  endif.

STOP
STOP is a statement which is used to stop processing an event block, ex: If I have two events
START-OF-SELECTION and END-OF-SELECTION in my program, If I use STOP keyword in
START-OF-SELECTION, the keyword will exits start-of-selection and goes to END-OF-SELECTION.

DATA: IT_MARA TYPE TABLE OF MARA,


WA_MARA TYPE MARA.

START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.
STOP.

LOOP AT IT_MARA INTO WA_MARA.


WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
ENDLOOP.

Result: NO OUTPUT

DATA: IT_MARA TYPE TABLE OF MARA,


WA_MARA TYPE MARA.

START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.
STOP.
END-OF-SELECTION.
LOOP AT IT_MARA INTO WA_MARA.
WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
ENDLOOP.

RESULT: OUTPUT WILL BE DISPLAYED

Control break statements :


Control break statements are statements which are used to control the sequence of execution of
statements with in loop.....endloop.

These statements are executed only with in loop...endloop.


Control break statements are
AT FIRST - This statement is executed/triggered for the first iteration of loop (SY-TABIX = 1 ).

AT LAST - This statement is executed/triggered for the last iteration of loop.

AT NEW <FIELD> - This is executed whenever there is a new value on specified field.

AT END OF - This statement is executed whenever the new value ends on specific field.

ON CHANGE OF <FIELD> - It is same as AT NEW and is obsolete in ECC 6.0.

Report ZCONTROL_BREAK1
TYPES : BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
END OF TY_VBAP.
DATA : IT_VBAP TYPE TABLE OF TY_VBAP.
DATA : WA_VBAP TYPE TY_VBAP.
PARAMETERS : P_DATE TYPE VBAP-ERDAT .
START-OF-SELECTION.
SELECT VBELN MATNR ZMENG NETPR
FROM VBAP INTO TABLE IT_VBAP
WHERE ERDAT = P_DATE.
LOOP AT IT_VBAP INTO WA_VBAP.

AT FIRST .
WRITE :/2 'SALES DOC', 18 'MATRIAL', 28'QUANTITY', 40 'PRICE'.
ENDAT.

AT NEW VBELN.
WRITE :/2 WA_VBAP-VBELN, 18 WA_VBAP-MATNR, 28 WA_VBAP-ZMENG, 40 WA_VBAP-NETPR.
ENDAT.
AT END OF VBELN.
SUM.
WRITE :/23 'SUB TOTAL IS :' COLOR 6, WA_VBAP-NETPR.
ENDAT.
AT LAST.
SUM.
WRITE:/23 'Total is:', WA_VBAP-NETPR .
ENDAT.

ENDLOOP.

What is a Field Symbols in SAP ABAP ?

Field symbols are similar to pointers in C language, field symbols does not have any memory
instead they will be pointing to a memory location.
The concept of field symbols is very important in order to increase the performance of SAP
applications.
Field symbol name should always be within <>, example:.
Syntax for declaring a field symbol.

FIELD-SYMBOLS : <FIELD_SYMBOL> TYPE MARA-MATNR. "here MARA-MATNR is a variable type


FIELD-SYMBOLS : <FIELD_SYMBOL> TYPE MARA. "here MARA is a structure
FIELD-SYMBOLS : <FIELD_SYMBOL> TYPE REF TO DATA . "here DATA is a reference type
ASSIGNING and ASSIGN are the keywords which are used to assign a value to the field symbol.

Example of using field symbol as work area

In the below example we are going to use field symbol as work area.

REPORT ZSAPN_FIELDSYMBOLS.

DATA : IT_MARA TYPE TABLE OF MARA.


DATA : WA_MARA TYPE MARA.
FIELD-SYMBOLS : <FS_MARA> TYPE MARA.
SELECT * FROM MARA
INTO TABLE IT_MARA UP TO 50 ROWS.

LOOP AT IT_MARA ASSIGNING <FS_MARA>.


IF <FS_MARA> IS ASSIGNED.
WRITE :/ <FS_MARA>-MATNR, <FS_MARA>-MTART, <FS_MARA>-MEINS.
ENDIF.
ENDLOOP.

Check weather the field symbol is assigned or not before processing field symbol, it is very
important to check field symbol, if it is not assigned it will get a run-time error, 

Increase performance using field symbols in SAP ABAP


I belive there are always performance differences between reference variables(work area) and
memory pointing(field symbols), here I wants to add some proof for that.
Below you will find two programs one with work area and another one with field symbols, execute
them and see time difference at the end of the program( will display at the bottom of output), you will
find difference.
program1

REPORT ZSAPN_FIELDSYMBOLS1.
DATA : IT_MARA TYPE TABLE OF MARA. "internal table
FIELD-SYMBOLS : <FS_MARA> TYPE MARA. "field symbols
DATA : LV_TIME_START TYPE TIMESTAMPL. "time at start of loop
DATA : LV_TIME_END TYPE TIMESTAMPL. "time at the end of loop
DATA LV_TIME_TAKEN TYPE P DECIMALS 8. "time difference

SELECT * FROM MARA "select data from MARA


INTO TABLE IT_MARA UP TO 20000 ROWS.

GET TIME STAMP FIELD LV_TIME_START. "get time at start of loop


LOOP AT IT_MARA ASSIGNING <FS_MARA>. "loop start
WRITE :/ <FS_MARA>-MATNR, <FS_MARA>-MTART, <FS_MARA>-MEINS.
ENDLOOP.

GET TIME STAMP FIELD LV_TIME_END. "get time at the end of loop
LV_TIME_TAKEN = LV_TIME_END - LV_TIME_START. "time taken
WRITE:/ 'Time taken: ', LV_TIME_TAKEN. "display time taken

Program2

REPORT ZSAPN_FIELDSYMBOLS2.
DATA : IT_MARA TYPE TABLE OF MARA. "internal table
DATA : WA_MARA TYPE MARA. "work area
DATA : LV_TIME_START TYPE TIMESTAMPL. "time at start of loop
DATA : LV_TIME_END TYPE TIMESTAMPL. "time at the end of loop
DATA LV_TIME_TAKEN TYPE P DECIMALS 8. "time difference

SELECT * FROM MARA "select data from MARA


INTO TABLE IT_MARA UP TO 20000 ROWS.

GET TIME STAMP FIELD LV_TIME_START. "get time at start of loop


LOOP AT IT_MARA INTO WA_MARA.
WRITE :/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS.
ENDLOOP.

GET TIME STAMP FIELD LV_TIME_END. "get time at the end of loop
LV_TIME_TAKEN = LV_TIME_END - LV_TIME_START. "time taken
WRITE:/ 'Time taken: ', LV_TIME_TAKEN. "display time taken
See the time take to process loop in both programs.

REPORT  ZCONTROL_BREAK.
TYPES: BEGIN OF ty_marc,
        matnr TYPE marc-matnr,
        werks TYPE marc-werks,
       END OF ty_marc.
DATA: it_marc TYPE STANDARD TABLE OF ty_marc,
      wa_marc TYPE ty_marc,
      wa_temp TYPE ty_marc.
data: itab type STANDARD TABLE OF marc,
      wa type marc.
SELECT matnr werks FROM marc INTO TABLE it_marc UP TO 10 ROWS WHERE matnr gt '
000000000000000040'.
SORT it_marc BY matnr.
FIELD-SYMBOLS : <matnr> type matnr.
WRITE:/ 'FULL TABLE'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  WRITE: / sy-tabix , wa_temp-matnr,  wa_temp-werks.
ENDLOOP.
clear wa_temp.
WRITE:/ 'AT FIRST AND LAST'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  AT FIRST.
    WRITE:/ 'First Entry'.
    WRITE:/  wa_temp-matnr,  wa_temp-werks.
  ENDAT.
  AT LAST.
    WRITE:/ 'Last Entry'.
    WRITE:/  wa_temp-matnr,  wa_temp-werks.
  ENDAT.
ENDLOOP.
WRITE:/ 'AT END OF'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  AT END OF matnr.
    WRITE: / sy-tabix , wa_temp-matnr,  wa_temp-werks.
  ENDAT.
ENDLOOP.
WRITE:/ 'AT NEW'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  AT NEW matnr.
    WRITE: / sy-tabix , wa_temp-matnr,  wa_temp-werks.
  ENDAT.
ENDLOOP.
WRITE:/ 'ON CHANGE OF'.
LOOP AT it_marc INTO wa_marc.
  wa_temp = wa_marc.
  ASSIGN wa_marc-matnr TO <matnr>.
  ON CHANGE OF wa_marc-matnr.
    WRITE: / sy-tabix ,wa_temp-matnr,  wa_temp-werks.
  ENDON.
ENDLOOP.

REPORT  ZSAMPLE1.
*DATA: itab  TYPE TABLE OF zproduct WITH HEADER LINE.
*
*SELECT * FROM zproduct INTO itab.
*ENDSELECT.

**APPEND statement is used to append or add a record from work area to inte
rnal table,
**the new record will be added at the end of the internal table.

*DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*WA_MARA-MATNR = '00001'.
*WA_MARA-MTART = 'FERT'.
*WA_MARA-MEINS = 'EA'.
*APPEND WA_MARA TO IT_MARA . "APPEND WORK AREA TO INTERNAL TABLE
*
*WA_MARA-MATNR = '00002'.
*WA_MARA-MTART = 'ROH'.
*WA_MARA-MEINS = 'MA'.
*APPEND WA_MARA TO IT_MARA .
*
*loop. " this is mentioned to see Internal table data in Debugging
*  endloop.
*****************************************************************************
*******************

**INSERT statement is used to insert or add a record from work area into in
ternal
*table at specified location

*  DATA : IT_MARA TYPE TABLE OF MARA,
*         WA_MARA TYPE MARA.
*
*select * from mara into table it_mara.
*WA_MARA-MATNR = '00001'.
*WA_MARA-MTART = 'FERT'.
*WA_MARA-MEINS = 'EA'.
*INSERT WA_MARA INTO IT_MARA INDEX 2. "The record will be inserted into inte
rnal table at 2nd position
*loop.
*  endloop.
*****************************************************************************
********************

**SORT is used to sort a Internal table data in ascending order or descendi
ng order,
*by default it will sort data in ascending order. In addition to this we ca
n able to sort data based on specified fields.
*
*DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*select * from mara into table it_mara.
*SORT IT_MARA . "Default sorts data in ascending order
*SORT IT_MARA DESCENDING . " Sort in descending order
**SORT IT_MARA BY MATNR DESCENDING ."It sorts data by specified fields <FIEL
D1>, <FIELD2>..
*loop.
*  endloop.
*****************************************************************************
*********************

**DESCRIBE TABLE is used to count the no of records in a internal table

*DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*DATA : V_LINES TYPE I. "Type integer
*select * from mara into table it_mara.
*DESCRIBE TABLE IT_MARA LINES V_LINES ." Count the no. of record of a inter
nal table
*Write : v_lines .
*****************************************************************************
********************

*READ TABLE WITH KEY .. BINARY SEARCH is used to read a single record from 
an
* internal table into work area specified by field name and field value .

*DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*select * from mara into table it_mara.
**READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = '000000000000000001' BINA
RY SEARCH. "Read a record into work area where MATNR is '0001'
*READ TABLE IT_MARA INTO WA_MARA INDEX '2'. "Read a record into work area w
here index is 2.
*loop.
*  endloop.
*****************************************************************************
*********************

**Loop...Endloop. is also used to read data from a internal table into work 
area,
**   this is used to read multiple records serially one after one .

* DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*select * from mara into table it_mara.
*  LOOP AT IT_MARA INTO WA_MARA.
*ENDLOOP.
*LOOP AT IT_MARA INTO WA_MARA WHERE MATNR = '000000000000000004' .
*ENDLOOP.
*  LOOP AT IT_MARA INTO WA_MARA FROM 6 TO 8.
* ENDLOOP.
*****************************************************************************
**********************

**MODIFY is used to modify single or multiple internal table records based o
n
* condition.
**TRANSPORTING is a keyword which is used to specify list particular fields 
to be
* modified instead of all fields.

*DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*select * from mara into table it_mara.
*  WA_MARA-MATNR = '000000000000000004'.
**  loop at it_mara into wa_mara.
*  WA_MARA-MTART = 'FERT'.
**MODIFY IT_MARA FROM WA_MARA INDEX 3 TRANSPORTING MATNR MTART.
**MODIFY IT_MARA FROM WA_MARA INDEX sy-tabix TRANSPORTING MTART.
*MODIFY IT_MARA FROM WA_MARA TRANSPORTING MATNR MTART WHERE MATNR = '0000000
00000000006'.
*loop.
*  endloop.
*****************************************************************************
************************

**DELETE is used to delete single or multiple records from an internal table
* based on some condition.

*DATA : IT_MARA TYPE TABLE OF MARA.
**       WA_MARA TYPE MARA.
*select * from mara into table it_mara.
**DELETE IT_MARA INDEX 3. "3rd RECORD WILL BE DELETED IN IT_MARA
**DELETE IT_MARA WHERE MTART = 'FERT'. "MATERIALS WITH MTART = 'FERT' WILL B
E DELETED
*loop.
*  endloop.
*****************************************************************************
*************************

**DELETE ADJACENT DUPLICATES is used to delete duplicate records which are a
djacent to each-other.
**Pre-requisite for this is the internal table must be sorted in ascending o
rder

*DATA : IT_MARA TYPE TABLE OF MARA,
*       WA_MARA TYPE MARA.
*select * from mara into table it_mara.
*SORT IT_MARA ASCENDING.
*DELETE ADJACENT DUPLICATES FROM IT_MARA.
*DELETE ADJACENT DUPLICATES IT_MARA COMPARING MATNR, MTART. "DUPLICATES WILL 
BE DELETED BY COMPARING MATNR AND MTART
*LOOP.
*ENDLOOP.
*****************************************************************************
*************************

**APPEND LINES OF is used to append multiple records to an internal table f
rom another internal table .

*DATA : IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE
*DATA : IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE
*select * from mara into table it_mara.
*APPEND LINES OF IT_MARA FROM 3 TO 5 TO IT_MARA1 . "DATA IN IT_MARA WILL BE 
APPENDED TO IT_MARA1 FROM INDEX 3 TO INDEX 5 .
*LOOP.
*ENDLOOP.
*****************************************************************************
**************************
*DATA : IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE
*DATA : IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE
*select * from mara into table it_mara.
***INSERT LINES OF IT_MARA INTO TABLE IT_MARA1.
*INSERT LINES OF IT_MARA FROM 3 TO 8 INTO TABLE IT_MARA1.
*INSERT LINES OF IT_MARA FROM 1 TO 3 INTO IT_MARA1 INDEX 4.
*LOOP.
*ENDLOOP.
*****************************************************************************
**************************
**MOVE keyword is used to move one internal table data to another.

*DATA : IT_MARA TYPE TABLE OF MARA. "FIRST INTERNAL TABLE
*DATA : IT_MARA1 TYPE TABLE OF MARA. "SECOND INTERNAL TABLE
*select * from mara into table it_mara.
*IT_MARA1 = IT_MARA . "Move IT_MARA to IT_MARA1
*LOOP.
*ENDLOOP.
*****************************************************************************
*************************

** Check statement
*DO 4 TIMES.
*write:/ sy-index.
*check sy-index <= 2.
*write 'JUMBLE'.
*ENDDO.

** Continue statement
*DO 4 TIMES.
*write:/ sy-index.
*if sy-index <= 2.
*  CONTINUE.
*endif.
*write 'JUMBLE'.
*ENDDO.

** Exit statement

*DATA: IT_MARA TYPE TABLE OF MARA,
*      WA_MARA TYPE MARA.
**PARAMETERS: P_MATNR TYPE MARA-MATNR.
*  SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = '000000000000000006'
. "P_MATNR.
*  IF WA_MARA IS INITIAL.
*    EXIT. "exit program
*  else.
*  WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
*  endif.
** STOP statement
*DATA: IT_MARA TYPE TABLE OF MARA,
*      WA_MARA TYPE MARA.
*
*START-OF-SELECTION.
*  SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.
*  STOP.
*
*  LOOP AT IT_MARA INTO WA_MARA.
*    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
*ENDLOOP.

***** output will display to this program

*DATA: IT_MARA TYPE TABLE OF MARA,
*      WA_MARA TYPE MARA.
*
*START-OF-SELECTION.
*  SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.
*  STOP.
*
*END-OF-SELECTION.
*  LOOP AT IT_MARA INTO WA_MARA.
*    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
*ENDLOOP.

You might also like