Home SAP ABAP ITAB in SAP ABAP: How to Implement and Configure

ITAB in SAP ABAP: How to Implement and Configure

0
internal table in sap abap types of internal table in sap abap itab in sap abap sap itab abap itab sap abap collect internal table sap abap collect internal table example sap abap modify internal table sap abap sum internal table example sap abap update internal table sap modify internal table sap update internal table table itab
ITAB in SAP ABAP

Syntax of declaring the structure / table in ABAP editor:

Data : Begin of <structure/table name>,
             – – – – – – –
             – – – – – – List of fields – – – – – – –
             ——-
End of <structure/table name> .

Ex: –
Data: Begin of emp,
Eid(10) type c,
Ename(25) type c, Work area
Eadd(35) type c,
End of emp.

Work Area

Work area always holds only one record at a time. So we go for internal tables.

Internal tables:

1. Internal table is the collection of records.
2. Internal tables are temporary tables. That means the data in internal table won’t save anywhere in SAP.
3. Internal tables are dynamic memory location. That means we no need to provide the size of the internal table .based on the data the size of internal table is increased as well as decreased.
4. The scope of the internal table is up to that program

Backend picture of SAP ABAP: 

 

Differences between data base table & internal tables:

Data base table

Internal table

Syntax of declaring the internal table :

Data <internal table name> like table of <work area name>.
Ex:    Data Emp1 like table of Emp.

Object: To display the company code, company name and cities.

REPORT: ZBBST_E_INTERNAL_TABLES1

DATA : BEGIN OF WA,
BUKRS(4) TYPE C, BUTXT(25) TYPE C, ORT01(25) TYPE C, END OF WA.
DATA IT LIKE TABLE OF WA.
SELECT BUKRS BUTXT ORT01 FROM T001 INTO TABLE IT. LOOP AT IT INTO WA.
WRITE :/ WA-BUKRS,
WA-BUTXT, WA-ORT01.
ENDLOOP.

Object: To display the customer numbers, customer names, cities and country.

REPORT : ZBBST_E_INTERNAL_TABLES2.
DATA : BEGIN OF WA,
KUNNR(10) TYPE C, NAME1(35) TYPE C, ORT01(35) TYPE C, LAND1(3) TYPE C, END OF WA.
DATA IT LIKE TABLE OF WA.
SELECT KUNNR NAME1 ORT01 LAND1 FROM KNA1 INTO TABLE IT. LOOP AT IT INTO WA.
WRITE :/ WA-KUNNR,
WA-NAME1, WA-ORT01, WA-LAND1.
ENDLOOP.

Syntax of declaring the field: 

Data <filed name>(<length>) type <data type>
(OR)
Data <filed name> type <data elements>
(OR)
Data <filed name> type <data base table> – <field name>

Ex: – Data BUKRS(4) type C.
                        (OR)
        Data BUKRS type BUKRS .
                       (OR)
        Data Bukrs type T001-Bukrs.

Object:- To Display the company codes, company names & cities.

Data: Begin of WA,
BUKRS type T001-BUKRS,
BUTXT type T001-BUTXT,
ORT01 type T001-ORT01,
End of WA.
Data IT like table of WA.
Select BUKRS BUTXT ORT01 from T001 into table IT.
Loop at IT into WA.
Write:/ WA-BUKRS,
WA-BUTXT,
WA-ORT01.
Endloop.

Object:- To Display the Vendor numbers, Vendor names & cities.

Data: Begin of WA,
LIFNR type LFA1-LIFNR,
NAME1 type LFA1-NAME1,
ORT01 type LFA1-ORT01,
End of WA.
Data IT like table of WA.
Select LIFNR NAME1 ORT01 from LFA1 into table IT.
Loop at IT into WA.
Write:/ WA-LIFNR,
WA-NAME1,
WA-ORT01.
Endloop.

Select-options is the keyword which accepts the single value, multiple single values, single range & multiple ranges.

Syntax of select-options: –
Select-options <name of the select-options> for <variable name>.

Ex: 

Data A type T001-BUKRS.
Select-options S_BUKRS for 

S_BUKRS   ==== to ==== >

Ex2:

Data v1 type KNA1-KUNNR.
Select-options S_KUNNR for v1.

S_KUNNR ===== to ==== >

Syntax of select-options in select query: 

Select <filed1> <filed2> —- from <database table name> into table <Internal Table> where <filed> in <select-options>.

Object:- Based on given company codes, to display the company codes, company names & cities.

Data v1 type T001-Bukrs.
Select-options S_BUKRS for v1.
Data: Begin of WA,
BUKRS type T001-BUKRS,
BUTXT type T001-BUTXT,
ORT01 type T001-ORT01,
End of WA.
Data IT like table of WA.
Select BUKRS BUTXT ORT01 from T001 into table IT where
Bukrs In S_BUKRS.
Loop at IT into WA.
Write: / WA-BUKRS,
WA-BUTXT,
WA-ORT01.
Endloop.

Object: Based on given country to display the customer numbers, customer names,
cities & countries.

Data v1 type KNA1-LAND1.
Select-options S_LAND1 for v1.
Data: Begin of WA,
KUNNR type KNA1-KUNNR,
NAME1 type KNA1-NAME1,
ORT01 type KNA1-ORT01,
LAND1 type KNA1-LAND1,
End of WA.
Data IT like table of WA.
Select KUNNR NAME1 ORT01 LAND1 from KNA1 into table IT where LAND1 in S_LAND1.
Loop at IT into WA.
Write: / WA-KUNNR,
WA-NAME1,
WA-ORT01,
WA-LAND1.
Endloop.

Parameter :

Parameter is the keyword,which accept the single value at run time.

syntax:

PARAMETER <Name of the parameter>(<length>) type <datatype>.
Ex:
PARAMETER P_BUKRS TYPE T001-BUKRS.
Ex:
PARAMETER P_KUNNR TYPE KNA1-KUNNR

Syntax of parameter in select query:

Select <field1> <field2> <field 3> ….. from <DB Table> into table <internal table>
where <field> = <parameter name>.

Object : Based on the given company code to display the company code, company name and city.

Ex:
PARAMETER P_BUKRS TYPE T001-BUKRS.
DATA : BEGIN OF WA,
BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
ORT01 TYPE T001-ORT01,
END OF WA.
DATA IT LIKE TABLE OF WA.
SELECT BUKRS BUTXT ORT01 FROM T001 INTO TABLE IT WHERE BUKRS = P_BUKRS.
LOOP AT IT INTO WA.
WRITE :/ WA-BUKRS,WA-BUTXT,WA-ORT01.
ENDLOOP.

Differences between parameter and select-options

Parameter

1.Parameter is the keyword,which accept the single value at runtime
2.Without providing any input to the parameter,we can’t get the output

Select-options

1.Select-options is the keyword,which accept the single value,multiple single values,single range
and multiple ranges
2.Without providing any input the select-options,we can get the entire data of database table

Object: Manually filling the eid,ename,eadd internal table.

Data: Begin of WA,
Eid(10) type c,
Ename(25) type c,
Eadd(35) type c,
End of WA.
Data IT like table of WA.
WA-Eid = ‘1’.
WA-Ename = ‘sprao’.
WA-Eadd = ‘Swindown’.
Append WA to IT.
WA-Eid = ‘2’.
WA-Ename = ‘Phil’.
WA-Eadd = ‘Maud’.
Append WA to IT.
WA-Eid = ‘3’.
WA-Ename = ‘Mahe’.
WA-Eadd = ‘kphb’.
Append WA to IT.
Loop at IT into WA.
Write: / WA-Eid,
WA-Ename,
WA-Eadd.
Endloop.

To learn our complete ABAP tutorial please clik

To learn ABAP from SAP please click 

Different Types of declaring the Internal tables:-(useful in support project)

1. Declaring the internal table with some of the fields from any one of the database table:-

Syntax:

Data: Begin of <work area name>,


End of <work area name>.
Data <Internal table name> like table of <work area name>.

Ex
Data: Begin of wa_t001, Bukrs type t001-bukrs, butxt type t001-butxt, Ort01 type t001-ort01, end of wa_t001.
Data IT_t001 like table of wa_t001.

2. Declaring the internal table with all the fields from any one of the database table: 

Syntax: –
Data <work area> like <data base table name>.
Data <Internal Table> like table of <work area / database table>.
Ex:-
Data wa_t001 like t001.
Data IT_t001 like table of wa_t001. (OR)
Data IT_t001 like table of t001. Data wa_t001 like line of IT_t001.

Note: – Type is used to refer the data types, data elements, fields in the table & types.
Where as like is used to refer the variable or fields in the table.

 

3. Declaring the internal tables by using types keyword: 

Syntax:-
Types: Begin of <type name>,

End of <type name>.
Data <workarea name > type < type name>. Data <internal table> type table of <type name>.
(or)
Data <internal table> like table of <work area>.

Ex: –
Types: Begin of ty_t001, Bukrs type t001-bukrs, Butxt type t001-butxt, Ort01 type t001-ort01, End of ty_t001.
Data wa_t001 type ty_t001.
Data IT_t001 type table of ty_t001.
(Or)
Data IT_t001 like table of wa_t001.

For complete ABAP tutorial please click here

To learn SAP ABAP from SAP please click here

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version