Reading data from database Table in SAP ABAP

Reading data from databases tables using OPEN SQL (SELECT) statements in SAP ABAP

+ -

The only way of reading data from a database table is using select statements, in the below example we will read data from the MARA table in various ways.

Operation Explanation
INTO TABLE ITAB Means getting data into an internal table ITAB from database table
INTO WAMeans getting data into WAa work area (Work area can store only one record)
INTO CORRESPONDING FIELDS OF TABLE ITABMeans getting data in the common fields of database table and user defined internal table ITAB (Here ITAB is a user defined internal table )
INTO CORRESPONDING FIELDS OF WAMeans getting data of the common fields of database tables and work areaWA (Here WA is a work area )

Read whole data from MARA

To read all records from MARA table, we use below code

data : it_mara type table of mara . " Declare internal table of type MARA
Select * from MARA into table it_mara . " Read all records from MARA table and store in it_mara internal table

Read single record from MARA based on where condition

data : wa_mara type mara . " Declare work area of type MARA, because we are getting only one record
Select single * from MARA into wa_mara where matnr = '00001' . " Read one records from MARA table and store in wa_mara work area
OR
data : it_mara type table of mara . " Declare internal table of type MARA
select * from MARA into table it_mara where matnr = '00001' . " Read all records from MARA table where MATNR is 00001, MATNR is a key field .

Reading data into the corresponding fields

By using INTO CORRESPONDING FIELDS of statement, we can get data into a user defined internal table.

As per performance standards, this method is not preferable

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MEINS TYPE MARA-MEINS,
        MBRSH TYPE MARA-MBRSH,
        END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA . "Declare internal table of type user defined table.

SELECT * FROM MARA INTO CORRESPONDING FIELD OF TABLE IT_MARA . " Here we are getting data from <code>MARA</code> table into internal table <code>IT_MARA </code> which contains only four fields.

Reading data into user defined internal table

Reading data from a database table into a user defined table.

This method is advisable as it gets limited fields from database table

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MEINS TYPE MARA-MEINS,
        MBRSH TYPE MARA-MBRSH,
        END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA. " Declare a Internal table of user defined type
SELECT MATNR, MTART, MEINS, MBRSH FROM MARA INTO TABLE IT_MARA. " Get list of fields Data Into internal table 
" Now data of four fields is available in IT_MARA 

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 114 People out of 118 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →