ClassBook-Lessons-ABAP Part I Lesson2
ClassBook-Lessons-ABAP Part I Lesson2
Programming
Lesson Objectives
ABAP/4 is a 4 generation programming language that you can use multiple ways:
▪ You can select and edit data you want to process in traditional ways via the screens that guide you.
▪ You can write reports using the interactive reporting facility.
ABAP/4 (Advanced Business Application Programming-4) language was developed by SAP to
provide optimal working conditions for application programmers.
It is the sole tool used by SAP to develop its own applications.
SAP customers use ABAP/4 to adapt R/3 standard solutions to specific problems.
Multi-Language Support
Supports business data types and operations
Open SQL
Use of sub routines
Purpose:
Reports are Programs that read data from the database, processes the data and displays the
data in the required format.
Use:
Reports are used in day to day business environment.
Example:
•Displaying the purchase orders vendor wise.
•Displaying the balance of vendors to be paid till a particular date.
1 or E Executable Program
I INCLUDE Program
F Function-Pool
S Subroutine Pool
K Class-Pool
J Interface-Pool
T Type Pool
▪The purpose of a report is to read data from the database and write it out.
▪It consists of only two screens.
▪ The first screen is called the selection screen.
• It contains input fields allowing the user to enter criteria for the report.
▪ The second screen is the output screen.
• It contains the list.
▪The list is the output from the report, and usually does not have any input fields.
▪The selection screen is optional. Not all reports have one. However, all reports generate a list.
▪ E.g.
WRITE XYZ.
MOVE SALES TO TOTAL_SALES.
▪ The first word of statement (the reserved word) determines the meaning of the whole statement.
ABAP/4 report program can be created from the ABAP/4 editor (Transaction Code: SE38).
REPORT Z.
DATA NAME(25) TYPE C VALUE 'Leena'.
DATA NUMBER TYPE I VALUE 1.
WRITE NUMBER.
WRITE NAME.
Chained Statements
REPORT Z.
DATA: NUMBER TYPE I VALUE 1,
NAME(25) TYPE C VALUE 'Leena'.
REPORT z.
DATA DOJ(8) TYPE D VALUE '20181231'. "YYYYMMDD
DATA EXITTIME(6) TYPE T VALUE '235945'. "HHMMSS
DOJ = SY-DATUM. “System data
EXITTIME = SY-UZEIT. “System Time
WRITE: 'The Date is ', DOJ. "DDMMYYYYY
WRITE:/'The Time is ', EXITTIME. "HHMMSS
ABAP Standard Data Type(built-in) data types are divided into two groups:
▪ Complete
▪ Incomplete
The built-in ABAP standard data types that already contain a type-specific, fixed-length byte
sequence (Hexadecimal string )
The standard types that do not contain a fixed length are considered incomplete data types.
When they are used to define data objects, you need to specify the length of the variable.
Using standard data types, you can declare local data types in the program
They are local to the program in which they are defined and cannot be reused in other programs
The declaration is made using the TYPES statement.
Example:
▪ TYPES number TYPE I.
• DATA num1 TYPE number.
▪ TYPES length TYPE p decimals 2.
• DATA mylen TYPE length
▪ TYPES code(3) TYPE c.
• DATA mycode TYPE code.
▪ TYPES: text10 TYPE c LENGTH 10,
text20 TYPE c LENGTH 20,
number TYPE p LENGTH 8 DECIMALS 2.
REPORT Z.
TYPES GENNAME(20) TYPE C. "USER DEFINED DATA TYPE
"cannot be assigned a value
DATA FIRSTNAME TYPE GENNAME VALUE 'Leena'.
DATA LASTNAME TYPE GENNAME VALUE 'Agarwal'.
WRITE: / FIRSTNAME, LASTNAME.
A data type defined in the ABAP Dictionary is called global, as it can be used throughout the
entire SAP system concerned.
Reference Types
▪ Describes Data Objects that contain references to other objects
▪ No predefined references
Complex Types
▪ Are composed of other types
▪ Allow to manage and process related data under a single name
▪ No predefined complex Type in ABAP
▪ Further divided into
• Structures – Field strings
• Internal Tables
Structures
▪ Sequence of any elementary types, reference types or complex data types
▪ Used in ABAP Programs to group work areas that logically belong together
▪ Example:
Numeric Literals
Examples of numeric literals:
123
-93
+456
Numeric literals in ABAP statements:
DATA number TYPE i VALUE -1234.
WRITE 6789.
MOVE 100 TO number.
Character Literals
Character literals are sequences of alphanumeric characters in the source code of an ABAP
program enclosed in single quotation marks.
Character literals enclosed in quotation marks have the predefined ABAP type c and are described
as text field literals.
Examples of text field literals:
'Antony Smith'
'69190 Walldorf'
A text symbol is a named data object of an ABAP program that is not declared in the program
itself and instead is defined as a part of the text elements of the program.
Variables are data objects whose contents can be changed using ABAP statements.
Variables are declared using the DATA, CLASS-DATA, STATICS, PARAMETERS, SELECT-OPTIONS,
and RANGES statements.
• Example:
• DATA name(20) TYPE c.
• Name = ‘Rupal’.
• Name = ‘Rohan’.
Demo of Constants
Two statements are usually used to define field strings in an ABAP/4 program:
▪ data
▪ tables
Assigning Values
▪ MOVE
• MOVE source TO destination
▪ Examples
− MOVE ‘5.7’ TO number.
− DATA : num1 TYPE i, num2 TYPE i.
− num1 = 10.
− MOVE num1 TO num2.
Assigning Values
▪ MOVE-CORRESPONDING
▪ MOVE-CORRESPONDING sourcestru TO deststru
• Examples
DATA : BEGIN OF address,
fname(15) TYPE c VALUE ‘Robert’,
lname(15) TYPE c VALUE ‘David’,
compname(30) TYPE c VALUE ‘ CapGemini Tech’,
number TYPE i VALUE ’72’,
street(30) TYPE c VALUE ‘WhiteField’,
city(10) TYPE c VALUE ‘BANGALORE’,
END OF address.
DATA : BEGIN OF name,
lname(15) TYPE c ,
fname(15) TYPE c ,
END OF name.
MOVE-CORRESPONDING address TO name.
CLEAR var.
▪ Resets var to appropriate initial value for its type
▪ Cannot use CLEAR to reset a CONSTANT
▪ Has different effect for different Data Types
▪ Output : 10 0
Operato Meaning
r
+ Addition
_ Subtraction
* Multiplication
/ Division
DIV Integer division
MOD Reminder of Integer Division
** Powers
SY-UNAME
▪ Logon name of the user
SY-DATUM:
▪ Current System Date
SY-UZEIT:
▪ Current System Time
SY-TCODE
▪ Current Transaction
SY-INDEX
▪ Number of the current loop pass
Syntax
WRITE AT [/][<POS>][(<LEN>)] <f>.
<pos> is a number or variable up to three digits long denoting the position on the screen.
<Len> is a number or variable up to three digits long denoting the output length.