You are on page 1of 64

ADVANCED BUSINESS

APPLICATION PROGRAMMING

-An Introduction

01/27/10 Prepared By SUSHEEL THAKUR(2658) 1


Objectives:
ØSAP Architecture- An Overview
ØABAP Workbench Tools
ØABAP Programming- An
Overview
ØCreating a sample Program

01/27/10 Prepared By SUSHEEL THAKUR(2658) 2


What is SAP R/3 ?
Ø SAP= System, Application & Products in data
processing(R/3 = Runtime System Three).
Ø Name of company & software.
Ø SAP is an ERP (Enterprise Resource Planning)
system
Ø Used to plan, organize, integrate and manage their
various operations like accounting, finance,
manufacturing and human resources.
Ø AIM: Improve efficiency and accuracy.


01/27/10 Prepared By SUSHEEL THAKUR(2658) 3
SAP SYSTEM (3 Tier Architecture)
SAP GUI SAP GUI

Presentation Layer
(Windows based)

SAP Instance
Application Layer
Dispatcher M
(Windows Server/UNIX)
Requ
est SAP Buffer
Queu (Shared
e Mem)
D D B V S E
G

Oracle
Database Layer
Informix
(Windows Server/UNIX)
DB2
Database Server
MS SQL Server
MaxDB
01/27/10 Prepared By SUSHEEL THAKUR(2658) 4
SAP ARCHITECTURE
Ø Based on client/server architecture and uses
a relational database to track all
information.
Ø Made up of small programs called
transactions.
Ø R/3 gathers related transactions together
into groups and call them modules.
Ø Module- set of transactions that deal with
the same area of business functionality.
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 5
ABAP
Advanced
Business

Application

Programming

01/27/10 Prepared By SUSHEEL THAKUR(2658) 6


ABAP Contd……..
Ø Fourth-generation programming language.
Ø Allows variables to be defined, modulation of
programs via subroutines and function calls,
access to the database via open SQL and some
event-oriented programming.
Ø Used by SAP developers to build transactions that
make up the R/3 application.
Ø Used by companies to customize the R/3
application i.e. providing additional business
functionality.
Ø
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 7
Common Uses:
Ø Custom reports – a program that reads specific data from
the database and then displays the data via the
computer screen or printer.
Ø Custom Transaction – a program similar to SAP
transactions to fulfill some business function not
provided by SAP – Dialog Programming.
Ø Interface – a program that moves data into SAP – BDC,
Call Transaction or reads data from SAP and writes it
to a system file to be transferred to an external
computer system
 e.g. a legacy mainframe – DATA EXTRACT
Ø
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 8
ABAP Development Workbench
Tools

01/27/10 Prepared By SUSHEEL THAKUR(2658) 9


1.ABAP Editor
Ø A tool that you use to write ABAP programs, class
methods, function modules, screen flow logic,
type groups and logical databases.
Ø ABAP Editor can be accessed in two ways
Ø 1.Menu Path:
 SAP Main Screen > Tools > ABAP Workbench
> Development > ABAP Editor (Double Click) Or
2. Simply use transaction code SE38 to start ABAP

Editor
Ø
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 10
01/27/10 Prepared By SUSHEEL THAKUR(2658) 11
2. MENU PAINTER:
Ø A tool with which you design user interfaces
for your ABAP programs.
Ø An instance of the user interface, consisting
of a menu bar, a standard toolbar, an
application Toolbar, and a function key
setting, is called a GUI status. The GUI
status and GUI title defines how the user
interface will look and behave in an
ABAP program.
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 12
01/27/10 Prepared By SUSHEEL THAKUR(2658) 13
3. SCREEN PAINTER
Ø A ABAP Workbench tool that allows to create screens for
transactions.
Ø SCREEN PAINTER MODES:
 The Screen Painter has a layout editor that you use to
design your screen layout. It works in two modes:
 -Graphical mode and
 - Alphanumeric mode.
Ø Both modes offer the same functions but use different
interfaces. In graphical mode, you use a drag and drop
interface similar to a drawing tool. In alphanumeric
mode, you use your keyboard and menus.
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 14
To start the Screen Painter, choose the corresponding pushbutton on the
initial screen of the ABAP Workbench or enter Transaction SE51

01/27/10 Prepared By SUSHEEL THAKUR(2658) 15


4. DATA DICTIONARY
Ø Contains all definitions for Domains, Data Elements,
Structures, Tables, Views, Search Helps, Lock Objects,
Match code Objects, The Table Maintenance Generator,
and the Table Description Generator.

Ø With these objects in its repository, the ABAP Dictionary:


 -Enforces data integrity
 -Manages data definitions without redundancy
 -Is tightly integrated with the rest of the ABAP/4
Development Workbench.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 16


The Three Levels of Dictionary

TABLE Represent database tables, made up


DATA Each
of onefield of a table
or more fields.or structure ,
DOMAIN
ELEMENT Specifies
describes the
thetechnical
meaning properties
of the field.of a
table field, Specifies the set of
allowed data values for that field and
its output characteristics

01/27/10 Prepared By SUSHEEL THAKUR(2658) 17


ABAP/4 SYNTAX
Ø An ABAP/4 program consists of individual statements
Ø Each statement must end with a period.
Ø The first word of a statement is known as the key word.
Ø Words are separated from each other by at least one blank.
Ø Statements can be indented.
Ø Statements can extend over several lines.
Ø You can concatenate several consecutive statements with
an identical key word (e.g. WRITE: ).
Ø Follow the key word with a colon.
Ø Separate each concatenated part with a comma.
Ø End the lines of the concatenated statements with a period.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 18


ABAP/4 Syntax (cont.)
Ø You can insert comments into a program in
two ways:
Ø1. An asterisk (*) in column 1 flags the
whole line as a comment.
Ø2. A quotation mark (“) within a line flags
the remainder of the line as a comment.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 19


Example: COMMENT
* PROGRAM SAPMTEST *
V ARIABLE DECLARATION
 DATA tmp TYPE I.
 WRITE ‘Hello World’. WRITE ‘OK’.

=
* PROGRAM SAPMTEST *
CHAINED STATEMENT
 DATA tmp TYPE I.
 WRITE :‘Hello World’,‘OK’.


01/27/10 Prepared By SUSHEEL THAKUR(2658) 20
01/27/10 Prepared By SUSHEEL THAKUR(2658) 21
ELEMENTARY DATA TYPES

Predefined
Type Descri
C Charac
01/27/10 Prepared By SUSHEEL THAKUR(2658)
Date
22
DEFINING DATA TYPES

01/27/10 Prepared By SUSHEEL THAKUR(2658) 23


TYPE ADDITION:
ØSyntax:
 TYPES <t> ... [TYPE <type
ØExample:
 TYPES: number
TYPE I,
 length TYPE P.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 24


Structure Types
ØSyntax: TYPES: BEGIN OF <structure>,
 ..............
 <ti> ...,
 ..............
 END OF <structure>.

ØExample:
 TYPES: BEGIN of address,
 name TYPE surname,
 code TYPE zip_code,
 town TYPE city,
 str TYPE street,
 END OF address.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 25


Defining Variable with
DATA Statement
ØSyntax:
 DATA var[(length)] [Type type] [Decimals number].

ØExample:
 DATA: tmp(10) TYPE C,
 tmp1 TYPE I,
 tmp2(8) TYPE P DECIMALS 2 VALUE ‘1.50’.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 26


Literals


DATA tmp TYPE I. Text Literal


WRITE ‘Hello World’.

WRITE ’10’. Text Literal

MOVE 9 TO tmp.
Numeric Literal
PROCESSING DATA:
Move Statement
ØSyntax:
Ø MOVE <f1> TO <f2>.
ØExample:
 DATA: T(10) TYPE C,
 NUMBER TYPE P DECIMALS 2,
 COUNT TYPE I.
 T = 1111.
 MOVE '5.75' TO NUMBER.
 COUNT = NUMBER.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 28


Assigning Values Between
Components of Structures
 MOVE-CORRESPONDING <struct1> TO
<struct2>.
 Example:
 DATA: BEGIN OF ADDRESS,
 FIRSTNAME(20) VALUE 'Fred',
 SURNAME(20) VALUE 'Flintstone',
 INITIALS(4) VALUE 'FF',
 STREET(20) VALUE 'Cave Avenue,
 NUMBER TYPE I VALUE '11'.
 POSTCODE TYPE N VALUE '98765'.
 CITY(20) VALUE 'Bedrock',
 END OF ADDRESS.

 DATA: BEGIN OF NAME,


 SURNAME(20),
 FIRSTNAME(20),
 INITIALS(4),
 TITLE(10) VALUE 'Mister',
 END OF NAME.
 MOVE-CORRESPONDING ADDRESS TO NAME.


01/27/10 Prepared By SUSHEEL THAKUR(2658) 29
Assigning Values with WRITE
TO Statement
Ø Converts the contents of the source field into a field with type C.
Ø Syntax:
Ø WRITE <f1> TO <f2> [<option>].
Ø Example:
 DATA: NUMBER TYPE F VALUE '4.3',
 TEXT(10),
 FLOAT TYPE F,
 PACK TYPE P DECIMALS 1.
 WRITE NUMBER.
 WRITE / TEXT.
 WRITE NUMBER TO FLOAT.
 WRITE / FLOAT.
 WRITE NUMBER TO PACK.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 30


Numerical Operations
Ø To assign the result of a mathematical calculation to a
variable, use the COMPUTE statement or the
assignment operator (=).

ØSyntax: COMPUTE <n> = <expression>.


 COMPUTE is optional

ØExample:
 DATA: COUNTER TYPE I.
 COMPUTE COUNTER = COUNTER + 1.
 COUNTER = COUNTER + 1.
 ADD 1 TO COUNTER.

Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 31
Arithmetic Calculations

01/27/10 Prepared By SUSHEEL THAKUR(2658) 32


Mathematical Functions
 Syntax: [COMPUTE] <n> = <func>( <m> ).




 Example: DATA N TYPE P DECIMALS 2.
 DATA M TYPE P DECIMALS 2 VALUE '-5.55'.
 WRITE: 'ABS: ', N.
 N = SIGN( M ). WRITE: / 'SIGN: ', N.
 N = CEIL( M ). WRITE: / 'CEIL: ', N

01/27/10 Prepared By SUSHEEL THAKUR(2658) 33


Processing Character Strings
Ø Shifting a String by a Given Number of
Positions
Ø SHIFT <c> [BY <n> PLACES]
[<mode>].
Ø Example:
 DATA: T(10) VALUE 'abcdefghij',
 STRING LIKE T.
 STRING = T.
 WRITE STRING.
 SHIFT STRING.
 WRITE / STRING.

Ø Output: abcdefghij
 bcdefghij
01/27/10 Prepared By SUSHEEL THAKUR(2658) 34
ØConverting to Upper or Lower Case
Ø TRANSLATE <c> TO UPPER CASE.
Ø TRANSLATE <c> TO LOWER CASE.

ØReplacing Field Contents


Ø To replace a string in a field with a different string, use the
REPLACE statement.
Ø REPLACE <str1> WITH <str2> INTO <c>

ØFinding Character Strings


Ø To search a character field for a particular pattern, use the
SEARCH statement as follows:
Ø SEARCH <c> FOR <str>

01/27/10 Prepared By SUSHEEL THAKUR(2658) 35


Ø Finding the Length of a Character String
Ø [COMPUTE] <n> = STRLEN( <c> ).
Ø Concatenating Character Strings
Ø CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED
BY <s>].

ØExample:
 DATA: INT TYPE I,
 WORD1(20) VALUE '12345'.
 INT = STRLEN( WORD1 ).

WRITE INT .

01/27/10 Prepared By SUSHEEL THAKUR(2658) 36


Controlling the Program Flow
Branching Conditionally

-The IF Control Structure

 Syntax:
 IF <condition1>.
 <statement block>
 ELSEIF <condition2>
 <statement block>.
 ELSEIF <condition3>.
 <statement block>
 .....
 ELSE.
 <statement block>
 ENDIF.


01/27/10 Prepared By SUSHEEL THAKUR(2658) 37
Example:
 DATA: TEXT1(30) VALUE 'This is the first text',
 TEXT2(30) VALUE 'This is the second text',
 TEXT3(30) VALUE 'This is the third text',
 STRING(5) VALUE 'eco'.
 IF TEXT1 CS STRING.
 WRITE / 'Condition 1 is fulfilled'.
 ELSEIF TEXT2 CS STRING.
 WRITE / 'Condition 2 is fulfilled'.
 ELSEIF TEXT3 CS STRING.
 WRITE / 'Condition 3 is fulfilled'.
 ELSE.
 WRITE / 'No condition is fulfilled'.
 ENDIF.

• OUTPUT: Condition 2 is fulfilled.


• Here, the second logical expression TEXT2 CS STRING is true because the string
• "eco" occurs in TEXT2.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 38


The CASE Control Structure
 Syntax:

CASE <f>.
 WHEN <f11> [OR <f12> OR ...].
 <Statement block>
 WHEN <f21>.[OR <f22> OR ...]
 <Statement block>
 WHEN <f31> [OR <f32> OR ...].
 <statement block>
 WHEN ...
 ......
 WHEN OTHERS.
 <statement block>
 ENDCASE.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 39
Loops
Ø Unconditional Loops
Ø DO [<n> TIMES] [VARYING <f> FROM <f1> NEXT
<f2>].
 <Statement block>
 ENDDO.
Ø Conditional Loops
Ø WHILE <condition> [VARY <f> FROM <f1> NEXT
<f2>].
 <statement block>

 ENDWHILE.

 <condition> can be any logical expression .

01/27/10 Prepared By SUSHEEL THAKUR(2658) 40


Example:

DATA: LENGTH TYPE I VALUE 0,
 STRL TYPE I VALUE 0,
 STRING(30) TYPE C VALUE 'Test String'.
 STRL = STRLEN( STRING ).
 WHILE STRING NE SPACE.
 WRITE STRING(1).
 LENGTH = SY-INDEX.
 SHIFT STRING.
 ENDWHILE.
 WRITE: / 'STRLEN: ', STRL.
 WRITE: / 'Length of string:', LENGTH.
 The output appears as follows:
 TestString
 STRLEN: 11
 Length of String: 11

01/27/10 Prepared By SUSHEEL THAKUR(2658) 41
Internal tables
Ø Provide a means of taking data from a fixed
structure and storing it in working
 memory in ABAP.
Ø Data is stored line by line in memory.
Ø CREATING INTERNAL TYPES
 TYPES <t> TYPE|LIKE <tabkind> OF <linetype> [WITH <key>]
 [INITIAL SIZE <n>].

Ø
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 42


We can specify the table type <tabkind> as follows:

01/27/10 Prepared By SUSHEEL THAKUR(2658) 43


Ø Sorting Internal Tables
Ø SORT <itab> [ASCENDING|DESCENDING] [AS TEXT]
[STABLE].

Ø Determining the Attributes of Internal Tables


Ø DESCRIBE TABLE <itab> [LINES <l>]
[OCCURS <n>] [KIND <k>].

Ø Inserting a Single Line


Ø INSERT <line> INTO TABLE <itab>.
Ø <line> is either a work area that is compatible with
the line type
Ø
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 44
• Inserting Several Lines
INSERT LINES OF <itab1> [FROM <n1>] [TO <n2>] INTO TABLE <itab2>.
<itab1> and <itab2> are tables with a compatible line type.

 EXAMPLE:

DATA: BEGIN OF LINE,
 LAND(3) TYPE C,
 NAME(10) TYPE C,
 AGE TYPE I,
 WEIGHT TYPE P DECIMALS 2,
 END OF LINE.
 DATA ITAB LIKE SORTED TABLE OF LINE
 WITH NON-UNIQUE KEY LAND NAME AGE WEIGHT.
 LINE-LAND = 'G'. LINE-NAME = 'Hans'.
 LINE-AGE = 20. LINE-WEIGHT = '80.00'.
 INSERT LINE INTO TABLE ITAB.
 LINE-LAND = 'USA'. LINE-NAME = 'Nancy'.
 LINE-AGE = 35. LINE-WEIGHT = '45.00'.
 INSERT LINE INTO TABLE ITAB. LOOP AT ITAB INTO LINE.
 WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.
 ENDLOOP.
 The output is: F Michele 30 60.00


01/27/10 Prepared By SUSHEEL THAKUR(2658) 45


ØReading Lines of Tables
ØREAD TABLE <itab> <key> <result>.
Ø Deleting a Line Using the Table Key
Ø DELETE TABLE <itab> FROM <wa>.
 or
Ø DELETE TABLE <itab> WITH TABLE
KEY <k1> = <f1> ... <kn> = <fn>.
ØAppending a Single Line
ØAPPEND <line> TO <itab>.
Ø
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 46
Open SQL
• Consists of a set of ABAP statements
that perform operations on the
central database in the R/3 System
• provides a uniform syntax and
semantics for all of the database
systems supported by SAP.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 47

• Reading Data

The Open SQL statement for reading data from database


tables is:
 SELECT <result>
 INTO <target>
 FROM <source>
 [WHERE <condition>]
 [GROUP BY <fields>]
 [HAVING <cond>]
 [ORDER BY <fields>].

01/27/10 Prepared By SUSHEEL THAKUR(2658) 48


ØInserting Lines into Tables
Ø INSERT INTO <target> <lines>.
Ø It allows you to insert one or more lines into the
database table <target>.
ØSpecifying a Database Table
Ø To specify the database table statically, enter the
following for <target>:
Ø UPDATE <dbtab> [CLIENT SPECIFIED]
<lines>.
Ø where <dbtab> is the name of a database table
defined in the ABAP Dictionary.
Ø
01/27/10 Prepared By SUSHEEL THAKUR(2658) 49
Committing Database Changes
Ø
Ø Open SQL contains the statements
Ø COMMIT WORK.
 and
Ø ROLLBACK WORK.
 for confirming or undoing database
updates.
Ø

01/27/10 Prepared By SUSHEEL THAKUR(2658) 50


HOW TO CREATE A
ABAP PROGRAM
 Transaction Code :
SE80

01/27/10 Prepared By SUSHEEL THAKUR(2658) 51


STEPS:
Ø 1. Start the object navigator by typing se80 in
the command field from the SAP Main
screen.
Ø 2. Select Programs in the first input field.
Ø 3. Type in the desired name of the new
program, e.g. ZKKPROG1 in the second
input field. Click on display button.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 52


01/27/10 Prepared By SUSHEEL THAKUR(2658) 53
click on YES another dialog box pops open querying about
the program structure either as an individual file or a
framework program for includes.





• For now deselect the “With TOP INCL” flag.
Click on Enter to continue

01/27/10 Prepared By SUSHEEL THAKUR(2658) 54


If you are creating an ABAP program first time, another dialog window will pop
open requesting you to enter the Access Key so this user can be added as a Developer. Enter
your 20 Character access key here and click on continue.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 55


A new template pops up where you will define the important attributes of
the new application- Title, Program Type, Application:

01/27/10 Prepared By SUSHEEL THAKUR(2658) 56


When you save a new object for the first time, the system displays a correction
and transport dialog box. Here the Development Class field needs to be
maintained. For now click the local object pushbutton.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 57


You will be returned to the opening screen of the object
navigator. Go to the course code screen by double clicking on
the object name

01/27/10 Prepared By SUSHEEL THAKUR(2658) 58


THE ABAP EDITOR

01/27/10 Prepared By SUSHEEL THAKUR(2658) 59


Place cursor after the period at the end of first sentence and
press enter to get you to the next line. Type WRITE ‘Hello
World!’.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 60


Activate the program by going to Programs >
Activate

01/27/10 Prepared By SUSHEEL THAKUR(2658) 61


Press F8 to test the program

01/27/10 Prepared By SUSHEEL THAKUR(2658) 62


A list is produced. To go back to the editor from the
report output window, click on the back arrow or F3
function key.

01/27/10 Prepared By SUSHEEL THAKUR(2658) 63


THANK YOU
01/27/10 Prepared By SUSHEEL THAKUR(2658) 64

You might also like