You are on page 1of 27

Chapter 3: ABAP Programming

Navigation to ABAP Editor


T-Code: SE38 or
ABAP Workbench ->
Development-> ABAP
Editor
ABAP Editor: Program Types
• Executable Programs - Can be started without a transaction code,
either directly or in the background.
• Module Pools for Screen Painter Screens (M) - contain processing steps for screen modules from the transaction and can
only be executed with a transaction code or a menu function.
• Includes (I) - Contain program code that cannot be run on its own. You call them from another program using INCLUDE
statements.
• Subroutines (S) - Contain parts of programs (FORM routines) that can be called
using external PERFORM statements.
• Legacy ( Depends on the client if they have many programs that are legacy)
• Function Groups (F) - Contain function modules. Function groups and function
modules are managed in the Function Builder. Program type F is set by the Function Builder, and cannot be changed in the
program attributes.
• Interface Pools (J) - Contain interfaces. Classes and interfaces are managed (administered).
• Class Pools (K) - Contain interfaces. Classes and interfaces are managed (administered)
General ABAP Syntax

 ABAP Programs are made up of individual statements.


 Each statement ends with a period.
 The first word in a statement is called a keyword.
 Words must always be separated by at least one space.
 Statements can be indented.
 Statements can take up more than one line.
 You may have multiple statements in a single line.
ABAP Keyword
How to create a Simple ABAP Program?

• Go to SE38 and name your


program
How to create a Simple ABAP Program?

• After naming your


program click Create then
a new pop up will show.
How to create a Simple ABAP Program?

After naming your program click


Create then a new pop up will
show.
• Title for Description of the
program
• Type is Executable Program
• Authorization Group: N/A
• Application: N/A
Then click Save
How to create a Simple ABAP Program?

After naming your program click


Create then a new pop up will show.
• Title for Description of the
program
• Type is Executable Program
• Authorization Group: N/A
• Application: N/A
Then click Save. After clicking save a
new popup will show and just click
local object
How to create a Simple ABAP Program?

Once the loading you will


navigate to the editor. You
will notice that it has the
REPORT keyword and the
name of your program
DON’T DELETE that or the
program will not run.
How to comment a Single Statement

• Just put Asterisk (*) or


Quotes (“) to the first
column of the code.
How to comment a Multiple Statement

• If you have a lot to


comment you can also use
the shortcut key “CTRL+ <“
(Before using the shortcut
key please select all the
statement you wanted to
comment)
How to comment a Multiple Statement

• If you have a lot to


comment you can also use
the shortcut key “CTRL+ <“
(Before using the shortcut
key please select all the
statement you wanted to
comment)
ABAP Help Options

• If you wanted to see what does the


Keyword do you can use the ABAP
Help Options. Wherein it contains the
documentation of the Keyword.
• To use this just highlight the keyword
you wanted to know about and find
the button
a new pop will show up and just
press continue
How to access the data from a Table

• First we need to define the


table that we wanted read.
• To access the data from our
database table we will use
the select keyword.
How to access the single field of data from a Table

• Same process as the first


one but the writing process
is slight different.
• We write the specific field
whereas in this sample is the
surname and forname.
Chained Statements
Data Types

Data type is used to describe the technical characteristics the data.


The data type is declared in the program using variables. A variable
is a name that points to reserved memory location to save the data
value. Based on the data type specified during the variable
declaration, operating system allocates the memory and decide how
the data can be stored in the memory.
Data Type Classification
Data Type Description
Elementary types are the smallest individual units of types.
Elementary Types Elementary type is a single data type used to define the data. In
elementary type, only one data type is used to declare a variable
for the data. (samples are P, I, C and etc.)

Complex data types are created with the combination of


elementary types. ABAP supports complex data types. Complex
types allow us to manage and process conceptually-related data
Complex Types under a single name. Complex types can be processed as a whole
or individually (Samples are the structured declaration)

Reference types specifies data objects that contains


Reference Data Types references/pointers to other objects. There are no predefined
references. We must define them in a program.
Elementary Data Types
Elementary Data Types
Data Type Keyword Range Description
Used for regular text information.
C Left justified and spaces padded to
1 to 65535 right.
Default data type when none
specified.

Used for set of digits.


N 1 to 65535 Right justified and zeroes padded to
left.

Used for integers.


I -2147483648 to 2147483647 Right justified and zeroes padded to
left

Numbers stored in compressed


[- 10 ^ (2len -1) + 1] to [+ 10 ^ (2len -1) format.
P + 1] Right justified and zeroes padded to
(where length = fixed length) left.
Can be used for all calculations.

F 1E-307 to IE+307 Specified as floating point.


positive or negative Can be used for all calculations.
Elementary Data Types
Data Type Keyword Range Description
Used for internal representation of
D YYYYMMDD using Georgian
8 characters calendar date.
Can set default format in profile.
Several output formats supported.
Supports arithmetic operations.
Used to store the time.
T 8 characters Format is HHMMSS.
Several output formats supported.
Supports arithmetic operations.
Used to store hexadecimal values in
X Any byte values (00 to FF) binary format.
2 hex digits stored in 1 byte.

STRING Used for any alphanumeric


Any alphanumeric characters characters.
Used for any alphanumeric
XSTRING Any byte values (00 to FF) characters stored in hex decimal
format.
Rules in Declaring a Variable

• variable name should start with a letter


• maximum of 30 characters in declaring a Variable
• variable name shouldn't have plus, comma, colon and parentheses
• you cannot use a reserve words
• make the variable name meaningful
How to Declare a Variable?
• By using the Keyword DATA we can simply declare our variables.
• Then we use the keyword TYPE to define the data type of the variable.
• Then value is what will the variable contain as for the example the value is
100 because the data type is integer.

DATA (variable name) TYPE (data type) VALUE (depends on the type).
Merging Strings and Variables in a WRITE
STATEMENT
• To merge the strings and variables we can use the chain statements for this.
The String should be enclosed in single quotes followed by a comma.

Merging Variable to another Variable in a


WRITE STATEMENT
• To merge the variables to other variables we can use the chain statements
for this.
How to assign a Value with a Decimal or
Character.
• In Defining a Decimal we should use the type P and define on how many
decimal should it show. In assigning a value the decimal should be enclosed
in single quotes.

• In Defining a character string we should use the data type C and define how
many characters it will take. In assigning a value the character string should
be enclosed in single quotes.
How to assign a Value with Date and Time

• In Defining a Date we should use the type D. In assigning a value of the date
we should use the variable then make it equal to the variable SY-DATUM.

• In Defining a TIME we should use the type T. In assigning a value of the time
we should use the variable then make it equal to the variable SY-UZEIT.

You might also like