02 - Abap
02 - Abap
Development
Management
SAP ABAP
Introduction
ABAP Stands for Advanced Business Application
Programming. ABAP is a programming language created and
used by SAP for the development of application programs
including: Reports, Screens, Interfaces & Data conversions.
ABAP is an event driven programming language. User
actions and system events control the execution of an
application.
1 2 3 4
D ATA STRUCTURES TA B L E S
DOMAINS
ELEMENTS
Domains
Describes the technical characteristics of a table field
Ensures consistency
◌ ◌ ◌
VIEWS SEARCH LOCK
HELP OBJECTS
VIEWS
Views in SAP ABAP are used to summarize data which is
distributed among several tables
Used to display all the possible values for a field in the form
of a list.
LOCK OBJECTS
• Simultaneous accessing of the same data record by two
users in the SAP system is synchronized by a lock
mechanism.
• Locks are set and released by calling certain function
modules. These function modules are generated
automatically from the definition of so-called lock
objects in the ABAP/4 Dictionary
On the ABAP Editor initial screen, enter the program name, select the
Source Code radio button, and click the Create button. Because this
program will be a repository object, it should be in a customer
namespace starting with Z or Y
You’ll see the Program Attributes window to maintain the attributes for
your program. Program attributes allow you to set the runtime
environment of the program.
Here, you can maintain a title for your program and other attributes. The Title and Type are mandatory fields; the others are optional.
Attributes and their significance
Type Allows you to select the type of program you want to create. This is the
most important attribute and specifies how the program is executed. It's a
mandatory field.
From within the ABAP editor, you can only choose from the following
program types:
• Executable Program
• Module Pool
• Subroutine Pool
• Include Program
All other program types aren't created directly from within ABAP Editor
but created with the help of special tools such as Function Builder for
function groups or the Class Builder for class pools.
Attributes and their significance
Status Allows you to set the status of the program development, for example,
production program or test program
Application Allows you to set the program application area so tha the system can allocate the
program to the correct business area, for example, SAP ERP Financial
Accounting (FI)
Authorization Enter the name of a program group. This allows you to group different programs
Group together for authorization checks
Selection Screen Visible only when the program type is selected as an executable program. This
attribute allows you to specify the selection screen of the logical database that
should be used.
Attributes and their significance
Logical Visible only when the program type is selected as an executable program. This
Database attribute determines the logical database used by the executable program and is
used only when creating reports using a logical database.
Logical databases are special ABAP program created using Transaction SLDB
that retrieve data and make it available to application programs.
Editor lock If set, other users can't change, rename, or delete your program. Only you can
change the program, its attributes, test elements, and documentation, or release
the lock.
Attributes and their significance
Fixed point If set for a program, the system rounds types p fields according to the number of
arithmetic decimal places or pads them with zeros.
The decimal sign in this case is always the period(.) regardless of the user's
personal settings. SAP recommends that this attribute is always set.
Unicode Checks Allows you to set whether the syntax checker should check for non-Unicode-
Active compatible code and display a warning message.
The decimal sign in this case is always the period(.) regardless of the user's
personal settings. SAP recommends that this attribute is always set.
Unicode Checks Allows you to set whether the syntax checker should check for non-Unicode-
Active compatible code and display a warning message.
Start using Applicable only for executable programs. If you set this attribute, other users
variant can only start your program using a variant. You must then create at least one
variant before the report can be started.
Under the Attributes section, provide the following values as shown in
the figure below:
• Type: Executable program
• Status: Test Program
• Application: Unknown application
Check the Unicode Checks Active and Fixed point arithmetic
checkboxes.
Write the following code in the program and activate the program:
Whatever input was entered on the selection screen was transferred to the program
and stored in the variable p_input, which was then processed by the WRITE statement
to display in the output.
Control Statements
Decision control statements are used to execute block of statements only when certain
conditions are met
The block of statements under decision control statements always executes when the
condition is determined as true
The block of statements executes only once when condition/s is/are determined true.
Decision control statements can be coded with one or more conditions together
Control Statements
IF Statement
IF-ELSE Statement
IF….ELSEIF….ELSE Statement
CASE Statement
LOOP Statements
IF Statement
A simple control statement that is used to verify one or more logical
expressions/conditions
IF-ELSE Statement
If the expression evaluates to true then the IF block of code will be executed. Otherwise,
ELSE block of code will be executed
IF….ELSEIF….ELSE Statement
When using IF, ELSEIF and ELSE statements there are a few points to consider:
• An IF statement can have zero or one ELSE statement and it must come after any
ELSEIF statement.
• An IF statement can have zero to many ELSEIF statements and they must come
before the ELSE statement.
• If an ELSEIF statement succeeds, none of the remaining ELSEIF statements or
ELSE statement will be tested.
CASE Statement
Used to validate one operand value with multiple values at a time. Each comparison value
has its own set of statements to execute
LOOP Statements
·A loop statement allows us to execute a statement or group of statements multiple times
CHECK
If the condition is false, then the remaining statements after the CHECK are just ignored and the
system starts the next loop pass
EXIT
Terminates the loop entirely and transfers execution to the statement immediately following the
loop
Logical Operators
Operators are symbols used to perform various types of functions.
Logical/ Comparison Operators - Logical operators are used for comparison between two
values. They are usually used as tests between two variables
Types of Operators in SAP ABAP
·Character String Operators - compare characters (single character text) with strings
(multiple character text) and evaluate results according to its presence or absence in the
string.
A SAP report is an executable program that reads data
from the database and generates output based on the
filter criteria selected by the end user.
They are used when data from several tables must be selected
SAP Reports and processed before presenting
Load-of-program
Triggers the associated event in an internal session after loading a program of type 1, M, F, or
S.
Also runs the associated processing block once and once only for each program and internal
session.
The processing block LOAD-OF-PROGRAM has roughly the same function for an ABAP
program of type 1, M, F or S as a constructor has for classes in ABAP Objects
Basic Events in an ABAP Report
Initialization
This event is executed before the selection screen is displayed.
Initialization of all the values.
You can assign different values other than the values defaulted on the selection screen.
You can fill your selection screen with some values at runtime
At Selection-Screen
The event is processed when the selection screen has been processed
Validation & Checks of inputted values happen here
Basic Events in an ABAP Report
Start-of-Selection
Here the program starts selecting values from tables.
End-of-Selection
After all the data has been selected this event writes the data to the screen.
Types of Reports
These are the simplest reports. Programmers
learn this one first. It is just an output of data
using the WRITE statement
ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our
ABAP reports. ALV is created by a set of standard function modules provided by SAP.
ALV provides a lot of inbuilt functions to our reports and some of the functions are listed below.
• Sorting of records
• Filtering of records
• Totals and Sub-totals
• Download the report output to Excel/HTML
• Changing the order of the columns in the report
• Hide the unwanted columns from the report
Because of the above functions, ALV substantially decreases the report development time. ALV takes
care of rendering the list and we can concentrate only on the data retrieval part.
SAP ABAP SQL OVERVIEW
• SELECT Statement
• JOINS
• INTO Table
• APPENDING Table
SELECT statement
SELECT * FROM <table_name> INTO TABLE <local_table>
Syntax Description
SELECT Specify that you are going to select
records in a table
* Indicate that you are going to fetch
all fields
FROM <table_name> Indicate which database table you
are fetching the records
INTO TABLE <local_table> Indicate which internal table you
are going to save the fetched
records
JOINS
• INNER JOIN
• OUTER JOIN
INNER JOIN
• Returns records that have matching values in both tables
LEFT OUTER JOIN
• Returns all records from the left table, and the matched records from the right table
RIGHT OUTER JOIN
• Returns all records from the right table, and the matched records from the left table
INTO TABLE
Form is a document with spaces (also named fields or placeholders) in which to write or select,
for a series of documents with similar contents. The documents usually have the printed parts in
common, except, possibly, for a serial number.
Tools used in ABAP Forms
• SAP Scripts
• Smart forms
• Adobe forms
Sap Scripts
SAP Scripts is used to generate formatted documents and for external purposes to print and
transfer business documents. Formatted document contains logos, tables, and other
formatting objects. You can print preformatted text in forms which are not possible with
normal ABAP codes.
Tcode: SE71
• OPEN_FORM
• START_FORM
• WRITE_FORM
• END_FORM
• CLOSE_FORM
Smart forms
• SAP Smart Forms have been introduced by SAP to enhance the capabilities and key
features over SAP Scripts. In Smart Forms, you need minimum coding when you compare
it with SAP Scripts.
• SAP recommends to replace SAP Script by Smart Forms as smart forms provide various
advantages over Scripting.
Tcode: Smartforms
Smartforms vs Sap Scripts
• Multiple page formats are possible in SmartForms which is not the case in SAPScripts
• It is possible to have a SmartForm without a main window.
• Routines can be written in SmartForms tool.
• SmartForms generates a function module when activated.
• Labels cannot be created in SmartForms.
Adobe Forms
• Open standard or PDF
• Interactive behavior can be achieved
• Supports scripting
• Interface can be reused
• No Smart Style or separate object is required for formatting
ADS Prerequisites
Adobe Lifecycle Designer
ADS connection configured
Person responsible: SAP BASIS