0% found this document useful (0 votes)
11 views

Education Presentation ABAP Week-7

The document outlines a training program for SAP ABAP, covering key concepts such as data types, internal tables, work areas, and classical reports. It details the structure and usage of various data types, methods for populating and manipulating internal tables, and provides examples of coding practices in ABAP. Additionally, it includes exercises for learners to practice their skills in creating and managing internal tables.

Uploaded by

praveengkumarer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Education Presentation ABAP Week-7

The document outlines a training program for SAP ABAP, covering key concepts such as data types, internal tables, work areas, and classical reports. It details the structure and usage of various data types, methods for populating and manipulating internal tables, and provides examples of coding practices in ABAP. Additionally, it includes exercises for learners to practice their skills in creating and managing internal tables.

Uploaded by

praveengkumarer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

SAP ABAP Training

By: Hamad Ahmad


SAP ABAP Trainer
Table of Contents for 7th Week
Su TYPE STRUCTURE
01

Su INTERNAL TABLE
02

Su WORK AREA
03

Su APPEND VALUES
04

Su LOOP AT ITAB
05

Su CLASSICAL REPORT WITH INTERNAL TABLE


06
Data Data
ABAP Standard predefined types :
Type
Types Elementary
Types They are divided into two groups: Complete and incomplete types.
Fixed Types Complete ABAP Standard:
C D Type for date(D), format: YYYYMMDD, length 8 (fixed)
N T Type for time (T), format: HHMMSS, length 6 (fixed)
I Type for integer (I), length 4 (fixed)
D F Type for floating point number (F), length 8 (fixed)
DECFLOAT16 Type for Decimal Floating point number, length 8
T DECFLOAT34 Type for Decimal Floating point number, length 16
STRING Type for dynamic length character string
X XSTRING Type for dynamic length byte sequence (Hexadecimal string)
P
Incomplete ABAP Standard Types:
I
F Types which fixed length is to be specified:

C
Fixed Length
N
X
String P
XString Data Type Description Default Length Default Value
C Character 1 ‘‘
Complex N Numeric 1 0
Types D Date 8 0
Structure
T Time 6 0
Type
X Hexadecimal 1 X’0′
Table Type
I Integer 4 0
P Packed 8 0
F Float 8 0
LOCAL DATA TYPES

METHOD 1. User defined METHOD 2. User defined


local data types Elementary Data Objects
Use TYPES keyword to define the data types. ABAP Variables are instances of data types.
--------------------------------------------------
TYPES: name(10) TYPE c,
--------------------------------------------------
length TYPE p DECIMALS 2,
DATA: name(10) TYPE c,
counter TYPE i,
length TYPE p DECIMALS 2,
id(5) TYPE n.
counter TYPE i,
--------------------------------------------------
id(5) TYPE n.
--------------------------------------------------
Use DATA keyword to define the data variable and
Assign user define data Types. Constants are used to store a value under a name. We must
--------------------------------------------------
specify the value when we declare a constant and the value
DATA: gv_name TYPE name,
gv_length TYPE length, cannot be changed later in the program.
gv_counter TYPE counter,
gv_id TYPE id. Use CONSTANTS keyword to declare a constant.
-------------------------------------------------- --------------------------------------------------

CONSTANTS: VALUE TYPE p DECIMALS 2 VALUE '3.14',


SUBMIT TYPE c VALUE 'X'.
--------------------------------------------------
INTERNAL TABLE WORK
AREA

WHAT IS WORK AREA ? Internal Tables with Header Line

Work areas are single rows of data. They should • Here the system automatically creates the work area.
have the same format as any of the internal tables. It • The work area has the same data type as internal table.
is used to process the data in an internal table one • This work area is called the HEADER line.
line at a time. • It is here that all the changes or any of the action on the
contents of the table are done. As a result of this, records
can be directly inserted into the table or accessed from the
WHAT IS INTERNAL TABLE ? internal table directly.

INTERNAL TABLE are used to obtain data from a


fixed structure for dynamic use in ABAP. Each line in Internal Tables without Header Line :
the internal table has the same field structure. The
main use for internal tables is for storing and • Here there is no work area associated with the table.
formatting data from a database table within a • Work area is to be explicitly specified when we need to
program.
access such tables.
• Hence these tables cannot be accessed directly.
Two Types of Internal Tables

Internal tables with HEADER line


Internal tables without HEADER line.
DATA TYPES Data
Type
Elementary
Types

Structured data types Fixed Types

C
Structured data type is grouping of several N
simple data types under one name.
D

Use the keywords BEGIN OF and END OF to T


create a structured data type. X
P
--------------------------------------- I
TYPES: BEGIN OF student,
id(5) TYPE n, F
name(10) TYPE c, Fixed Length
dob TYPE d,
place(10) TYPE c, String
END OF student. XString
--------------------------------------------
- Complex
Types
Structure
Type
Table Type
WORK AREA

Structure Variable TYPES STRUCTURE


Similar to structured data type, structured variable can be
LIKE KEYWORD
declared using BEGIN OF and END OF keywords.
We can also declare a structured variable by referring to an
-------------------------------------------------- existing structured data type.
DATA: BEGIN OF WA, --------------------------------------------------
id(5) TYPE n, TYPES: BEGIN OF address,
name(10) TYPE c, name(10) TYPE c,
dob TYPE d, street(10) TYPE c,
place(10) TYPE c, place(10) TYPE c,
END OF WA. pincode(6) type n,
-------------------------------------------------- phone(10) type n,
END OF address.
Each individual field of the structured variable can be accessed
using hyphen (-). For example, name field of the student structure Data: house_address TYPE address,
can be accessed using student-name. office_address LIKE house_address.
--------------------------------------------------
NOTE: Character is the default data type. While declaring a variable or structure we can also refer to an
existing variable or structure instead of data type or type
structure. For that use LIKE instead of TYPE keyword while
declaring a variable or structure.
INTERNAL TABLE

Work Area and ITAB Work Area and ITAB


Similar to structured data type, structured variable can be We can also declare a structured variable AND internal Table
declared using BEGIN OF and END OF keywords. by referring to an existing structured data type.
--------------------------------------------------
-------------------------------------------------- TYPES: BEGIN OF S_TYPES,
DATA: BEGIN OF WA, name(10) TYPE c,
id(5) TYPE n, street(10) TYPE c,
name(10) TYPE c, place(10) TYPE c,
dob TYPE d, pincode(6) type n,
place(10) TYPE c, phone(10) type n,
END OF WA. END OF S_TYPES.

Data: Itab LIKE TABLE OF WA. Data: WA TYPE S_TYPES,


-------------------------------------------------- ITAB TYPE TABLE OF S_TYPES.
Each individual field of the structured variable can be accessed --------------------------------------------------
using hyphen (-). For example, name field of the student structure
can be accessed using student-name.

NOTE: Character is the default data type.


WITH HEADER LINE

ITAB WITH HEADER LINE ITAB WITH HEADER LINE


This variant of the statement list introduced using DATA BEGIN This addition of the statements DATA TABLE OF, DATA RANGE
OF (which is forbidden in classes) declares an internal OF, and the obsolete statement DATA OCCURS (which is not
table itab as a standard table with a structured row type and a allowed in classes) declares a further data object alongside
header line. the internal table, known as the header line. This object has
exactly the same name as the internal table and has the row
An internal table itab is created with the structure of line. type of the internal table as its data type. A header line
Besides declaring the structure of an internal table, the cannot be declared for internal tables with a table-like row
OCCURS clause also defines how many table entries are type. This is possible for structured row types with table-like
maintained in main storage(in this case 10). Extra records are components, however. To address the table body instead of
written out to paging area and can effect performance the header line in statements, [] can be appended to the table
-------------------------------------------------- name:
DATA: BEGIN OF ITAB OCCURS 10, --------------------------------------------------
id(5) TYPE n, TYPES: BEGIN OF S_TYPES,
name(10) TYPE c, name(10) TYPE c,
dob TYPE d, street(10) TYPE c,
place(10) TYPE c, place(10) TYPE c,
END OF ITAB. pincode(6) type n,
phone(10) type n,
-------------------------------------------------- END OF S_TYPES.

Data: ITAB TYPE TABLE OF S_TYPES WITH HEADER LINE.

--------------------------------------------------
Populating Internal
Table

Populating Internal Tables Using COLLECT statement


We have successfully created some internal tables, let us see ITAB
how do we populate them with some records. There are
various methods available to populate tables COLLECT is another form of statement used for populating the internal
tables. Generally COLLECT is used while inserting lines into an internal
Append Data line by line table with unique standard key.
The first method available is the use of the APPEND
--------------------------------------------------
statement.
COLLECT wa INTO itab.
Using the APPEND statement we can either add one line from --------------------------------------------------
another work area to the internal table or we can add one
Incase of tables with Header line, INTO option is omitted. Suppose there is
initial line to the internal table. already an entry having a key same as the one you are trying to append,
then a new line is not added to the table, but the numeric fields of both
-------------------------------------------------- the entries are added and only one entry corresponding to the key is
APPEND wa TO itab. present. Value of SY-TABIX is changed to the row of the original entry. Else
COLLECT acts similar to APPEND and SY-TABIX contains the index of the
--------------------------------------------------
processed line.
Here work area <wa> or the Initial Line is appended to the
internal table <itable>.

The system variable SY-TABIX contains the index of the


Using INSERT statement
appended line. INSERT statement adds a line/work area to the internal table. You can
specify the position at which the new line is to be added by using the
INDEX clause with the INSERT statement.
--------------------------------------------------
INSERT wa INTO itab [index <idx>].
RELATION BETWEEN
INTERNAL TABLE WORK
AREA
CLASSICAL
REPORT
*Type of work area and Internal Table
types: begin of student_type,
id(2) type n,
name(16) type c,
age(2) type c,
end of student_type.

*Work Area.
data: wa type student_type.

*Internal Table.
data itab type table of student_type.

wa-id = '01'.
MOVE 'HAMAD AHMAD' to wa-name.
wa-age = '18'.
append wa to itab.
clear: wa.

wa-id = '02'. wa-name = 'UMER MUNIR'. wa-age = '34'.


append wa to itab. clear wa.

wa-id = '03'. wa-name = 'HAMZA'. wa-age = '32'.


append wa to itab. clear wa.
*****************************************************************
loop at itab into wa. "

write:/ wa-id,
/ wa-name, Classical Report
/ wa-age.
uline.
endloop. (see the above Code). Observe
WRITE: 'Total Number of Records: ', sy-tabix. the code and test in your program.

Assignment

Create the Same program with at


least 5 rows.
Copying and Deleting
Internal Table

Copying Internal Tables Deleting Internal Tables


The contents of one internal table can be copied to another by There are many ways for deleting lines from an internal table.
using the APPEND LINES or INSERT LINES statement. A more
simpler way is to use any of the following syntax's. This is the simplest way for deleting lines.

-------------------------------------------------- --------------------------------------------------
MOVE itab1 To itab2. DELETE ITAB
--------------------------------------------------
OR
This statement works only within a loop. It deletes the current
itab1 = itab2. line. You can delete the lines in a loop conditionally by adding
-------------------------------------------------- the WHERE clause.
These copy the contents of ITAB1 to ITAB2. Incase of internal
tables with header line we have to use [] in order to Deleting lines using the index.
distinguish from work area. So, to copy contents of internal
tables with header line the syntax becomes. This is used to delete a line from internal table at any know
-------------------------------------------------- index.
itab1[] = itab2[].
-------------------------------------------------- --------------------------------------------------
DELETE ITAB INDEX <IDX>
--------------------------------------------------

The line with the index <IDX> is deleted. The index of the
following line is decremented by 1.
Reading Internal
Table

Read Internal Tables using Read Internal Tables using


Read Table loop
We are now familiar with the creation of internal tables and
populating them with data. We will now see how do we
actually use the data or retrieve the data from the internal Using Loop -Endloop
tables.
One of the ways of accessing or reading the internal table is
Using READ by using LOOP-ENDLOOP.
--------------------------------------------------
The method of reading the internal table is by using the READ LOOP AT ITAB INTO WA.
statement.
-------------------------------------------------- --------------------
READ TABLE itab INTO wa INDEX <idx>.
-------------------------------------------------- ENDLOOP.
--------------------------------------------------
This statement reads the current line or line as specified by
index <idx>. The value of SY-TABIX is the index of the line Here when you say LOOP AT ITABLE, then the internal table
read. If an entry with the specified index is found, then SY- ITABLE is read line by line. You can access the values of the
SUBRC is set to 0. If the specified index is less than 0, then columns for that line during any part of the LOOP-ENDLOOP
run-time error occurs. If the specified index exceeds table size structure. The value of the SY-SUBRC is set to 0, even if only
then SY-SUBRC is set to 4. one record is read.
More on Internal
Tables

DESCRIBE TABLE DUPLICATE ENTRIES


We can also delete the adjacent duplicates from an internal
DESCRIBE TABLE is the statement to get the attributes like table by using the following statement.
number of lines, line width of each row etc. of the internal --------------------------------------------------
table. DESCRIBE TABLE statement also fills the system fields
SY-TFILL (Current no. of lines in internal table), SY-TLENG (line DELETE ADJACENT DUPLICATE ENTRIES FROM ITAB
width of internal table) etc. [COMPARING <f1> <f2> ... |ALL FIELDS].
--------------------------------------------------
DESCRIBE TABLE ITAB [LINES <lines>]. DELETE ADJACENT DUPLICATE ITAB.
-------------------------------------------------- OR

SORT ITAB
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING
FIELDNAME.
------------------------------------------------- --------------------------------------------------
SORT ITAB [ASCENDING|DESCENDING]
COMPARING ALL FIELDS is the default. If we do not specify the COMPARING
addition, then the system compares all the fields of both the lines. If we
OR specify fields in the COMPARING clause, then the system compares only
the fields specified after COMPARING of both the lines. If at least one line is
SORT ITAB BY FIELDNAME [ASCENDING|DESCENDING] deleted, the system sets SY-SUBRC to 0, otherwise to 4.
-------------------------------------------------
We can also initialize the internal table using FREE, CLEAR and REFRESH
statements. CLEAR and REFRESH just initializes the internal table where as
FREE initializes the internal table and releases the memory space.
Roll Numbers Roll No.
ABAP-E-3-2-110
Student Name
Muhammad Nawaz
ABAP-E-3-2-259 Asma Shahzad
ABAP-E-3-2-459 Hamza Qayoom
ABAP-E-3-2-144 Muhammad Ismail Zia
ABAP-E-3-2-37 Adeel Saeed
ABAP-E-3-2-343 Saad Mehmood
ABAP-E-3-2-159 Muhammad Awais Aleem
ABAP-E-3-2-168 Muhammad Ayub
ABAP-E-3-2-452 Muhammad Farooq
ABAP-E-3-2-191 Arslan Mazhar
ABAP-E-3-2-451 Waqar Hussain Shahid
ABAP-E-3-2-197 Danish Gul
ABAP-E-3-2-340 Qayyum Ahsan
ABAP-E-3-2-254 Hafiz Muhammad Abubkar
ABAP-E-3-2-397 Umar Farooq
ABAP-E-3-2-398 Mateen Munir
ABAP-E-3-2-400 Fahad Khalid
ABAP-E-3-2-401 Zain ulabdeen
ABAP-E-3-2-357 Muhammad Abubakar Saeed
ABAP-E-3-2-377 Aniya Raees
ABAP-E-3-2-413 Abdul Ahad
ABAP-E-3-2-204 Muhammad Ubaidullah
ABAP-E-3-2-418 Hassan Zulfiqar
ABAP-E-3-2-349 Syed Zia Ud Din Ahmed
ABAP-E-3-2-407 Wajid Yousaf
Roll Numbers Roll No.
ABAP-M-2-1-12
Student Name
Muhammad Jhanzaib
ABAP-M-2-1-208 Taimur Ul Hassan Ghouri
ABAP-M-2-1-294 Maryam Arshad
ABAP-M-2-1-310 Faisal Yasin
ABAP-M-2-1-461 Malik Omer
ABAP-M-2-1-1 Syed Ali Mubashar Kazmi
ABAP-M-2-1-85 Mughees Ahmed Mirza
ABAP-M-2-1-9 Sher Ali
ABAP-M-2-1-31 Muhammad Hamid
ABAP-M-2-1-35 Umer Munir
ABAP-M-2-1-447 Kamil Humayun Mirza
ABAP-M-2-1-148 Nadeem Saleem
ABAP-M-2-1-332 Usman Anwar
ABAP-M-2-1-43 Hafiz Muhammad Ishtiaq
ABAP-M-2-1-47 Zain Khawar
ABAP-M-2-1-50 Hamza Amjad
ABAP-M-2-1-52 Muhammad Raza Liaqat
ABAP-M-2-1-62 Hassan Arif
ABAP-M-2-1-82 Rizwan Saeed Khawaja
ABAP-M-2-1-226 Usama Azeem
ABAP-M-2-1-211 Muhammad Faizan Razzaq
ABAP-M-2-1-104 Safi Ur Rehman
ABAP-M-2-1-84 Hafiz Muhammad Naveed
ABAP-M-2-1-330 Muhammad Sumair
ABAP-M-2-1-395 Muhammad Hussain
For feedback, please write at

[email protected]

Thank you!

*To download application forms, kindly click the below link;


https://cloud.exdnow.com/s/k4Fb52tZfiMf4x5

You might also like