Download as pdf or txt
Download as pdf or txt
You are on page 1of 83

ABAP and Netweaver

Day 1
Hong Kong, China
3 7 July 2012
* Materials for this workshop are adapted from available resources from SAP UA

Agenda
Introduction to ABAP and Netweaver
What is ABAP?
What is Netweaver?
The R/3 Repository
Introduction to the ABAP workbench
ABAP Editor
ABAP Dictionary
Menu Painter
Screen Painter
Introduction to basic ABAP programming concepts, internal tables and
logical database
Basic ABAP concepts

Local Data
Internal tables and Open SQL
Logical databases
2012 SAP AG. All rights reserved.

Introduction to ABAP and Netweaver

What is ABAP?

What is Netweaver?

The R/3 Repository

What is ABAP?
Features of ABAP

Advanced Business Application Programming:

Is an interpretative 4 GL which supports structured


programming and modularisation.

Has been enhanced as an object-oriented language.

Is capable of handling multi-language applications.

Fully integrates an SQL standard.

Is platform-independent.

2012 SAP AG. All rights reserved.

What is ABAP?
Programming an Application

ABAP Programs can be :

Interactive reports - a program that reads and analyses


data in database tables without changing the database.

Dialog programs - allow you to work interactively with the


system and to change the contents of tables. Each program
has a certain sequence of screens.

2012 SAP AG. All rights reserved.

What is ABAP?
Transporting Developments

2012 SAP AG. All rights reserved.

What is ABAP?
ABAP Program

2012 SAP AG. All rights reserved.

What is ABAP?
Interaction between Server Layers

2012 SAP AG. All rights reserved.

The R/3 Repository

2012 SAP AG. All rights reserved.

The R/3 Repository


SAPs Modules

2012 SAP AG. All rights reserved.

10

What is Netweaver?
SAP Netweaver

2012 SAP AG. All rights reserved.

11

The R/3 Repository


SAP ERP and SAP R/3 Enterprise

SRM
mySAP
SRM

HR
mySAP
HR

SCM
mySAP
SCM

CRM
mySAP
CRM

PLM
mySAP
PLM

FIN
mySAP
Financials

BI
mySAP
BI

21 Industry Solutions

mySAP Services

mySAP.com
Enterprise
Portal
mySAP Enterprise Portals

ERP
SAP R/3 Enterprise

Exchange
mySAP Exchanges

mySAP Technology
2012 SAP AG. All rights reserved.

12

Introduction to the ABAP workbench

ABAP Editor

ABAP Dictionary

Menu Painter

Screen Painter

ABAP Development Workbench Tools

2012 SAP AG. All rights reserved.

14

The Development Workbench

The ABAP Development Workbench is an integrated set


of fourth-generation tools which allows the development and
implementation of client/server applications, or modification
of the existing, standard R/3 modules.
It includes a repository, editor and dictionary, as well as
tools for testing, tuning and debugging, and optimising
performance.

2012 SAP AG. All rights reserved.

15

Exercise 1

Introduction to the ABAP


Development Workbench,
Editor and Syntax

2012 SAP AG. All rights reserved.

16

Menu Painter

Menu path Tools ABAP workbench


Development User Interface Menu Painter (SE41)

Create, edit menus, header's and toolbars in


ABAP programs

Will be used in Day 2 when we discuss dialog


programs

2012 SAP AG. All rights reserved.

17

Screen Painter

Menu path Tools ABAP workbench Development


User Interface Screen Painter (SE51)

Create and edit DynPros

Separate programs which is only installed when using


SAPGui for Windows

Will be used in Day 2 when we discuss dialog programs

2012 SAP AG. All rights reserved.

18

ABAP Editor
Menu path Tools ABAP workbench Development
ABAP Editor
Transaction code: SE38
Run, view, edit, activate, check ABAP code
Integrated into Object Navigator

2012 SAP AG. All rights reserved.

19

Exercise 2

ABAP Editor

2012 SAP AG. All rights reserved.

20

ABAP Dictionary

The ABAP Dictionary allows you to define data objects


such as tables and structures.

A transparent table in the dictionary has a one-to-one


relationship with a table in the database.

2012 SAP AG. All rights reserved.

21

ABAP Dictionary
Accessing the ABAP Dictionary

2012 SAP AG. All rights reserved.

22

ABAP Dictionary
A table definition in the Dictionary

2012 SAP AG. All rights reserved.

23

ABAP Dictionary
Basic Dictionary Objects
Tables are made up of rows containing one or more fields.
When a field is defined its data type is determined by reference to a data
element.
A data element stores semantic properties field label and online
documentation.
(F1 help). A data element also references a domain.
A domain contains technical properties - data type/length.

2012 SAP AG. All rights reserved.

24

ABAP Dictionary
Data Elements & Domains
Customer Table
fields

Data
Elements

Domain

z_phonew
phone_w
phone_f
phone_h

Label: work number


z_phonef
Label: fax number

z_phoneh

zphone

type: char
len: 12

Label: home number

2012 SAP AG. All rights reserved.

25

ABAP Dictionary
SAPs Flight Data Model

2012 SAP AG. All rights reserved.

26

ABAP Dictionary
Summary

The ABAP Dictionary is the central facility in the SAP


system where you can create and maintain tables and
other objects.

To create a table, you first need domains and data


elements. Domains provide the technical characteristics of
a field: data elements provide the field labels and F1 help.
Both are reusable.

2012 SAP AG. All rights reserved.

27

Exercise 3

DATA Dictionary

2012 SAP AG. All rights reserved.

28

Introduction to basic ABAP programming concepts,


internal tables, and logical database

Basic ABAP concepts

Local Data

Internal tables and Open SQL

Logical databases

Basic ABAP concepts


General ABAP Syntax

2012 SAP AG. All rights reserved.

30

Basic ABAP concepts


General ABAP Syntax

2012 SAP AG. All rights reserved.

31

Local Data
Data Type

A data field in ABAP is a variable which cannot be broken


up into smaller parts.

All data fields that are to be used in a program must be


defined before their first use.

Data fields in an ABAP program have a type.

E.g. You can define a data field student_name of type


character and length 25 as:
data student_name(25) type c.

2012 SAP AG. All rights reserved.

32

Local Data
Elementary Data Types

There are ten built-in data types in ABAP.

Since SAP R/3 4.6 ABAP offers two variable length built-in elementary data types
STRING and XSTRING:
DATA: text-string TYPE string
text-string = ABAP programming is FUN!

XSTRING can contain the hexadecimal content of a byte sequence.


2012 SAP AG. All rights reserved.

33

Local Data
Elementary Data Types

data: name(25) type c,


city(25),
flag.

data: student_id(7) type n value 6980.

write student_id.

data: book_price type p decimals 2.

2012 SAP AG. All rights reserved.

34

Local Data
User-defined Data Types

You can make reference to an existing variable using


like.
data: customer_name(25) type c,
vendor_name like customer_name,
carridcode like spfli-carrid.

You can create your own data types and apply them to
variables.
types: t_name(25) type c.
data: customer_name type t_name,
vendor_name type t_name,
carridcode type s_carr_id.
2012 SAP AG. All rights reserved.

35

Local Data
Structure

Structures consist of a series of variables grouped together under a common


name.

Structures are defined using the keywords begin of and end of.
data: begin of customer,
id(8) type n,
fname(12),
lname(15),
end of customer.
customer-id = 12345678.
customer-fname = Christian.
customer-lname = Wong.

write / customer.
write: / customer-id,
customer-fname,
customer-lname.

2012 SAP AG. All rights reserved.

36

Local Data
Structure

You can define a structure type locally using the TYPE


statement.

2012 SAP AG. All rights reserved.

37

Local Data
Structure

Structures can be used to set up a work area to store


database table record.

2012 SAP AG. All rights reserved.

38

Local Data
Input Parameters

A Parameter is a special type of variable. It requires the


value of the variable to be input from a selection screen.

2012 SAP AG. All rights reserved.

39

Control Statements

ABAP has 2 conditional logic statements:


If/Endif and Case/Endcase
2 loops:

Do/Enddo
While/Endwhile

and others such as Continue, Check & Exit.

ABAP does not have a GOTO statement.

Control commands can be nested and/or joined with


logical operators.

2012 SAP AG. All rights reserved.

40

Control Statements
Logical Expressions

2012 SAP AG. All rights reserved.

41

Control Statements
Conditions: If / ElseIf

Syntax:
if logical expression #1.
command lines.
[elseif logical expression #2.
command lines.]
[else.
command lines.]
endif.

Examples.

2012 SAP AG. All rights reserved.

42

Control Statements
Logical Expressions & Operators

IF statements may be joined using the AND, OR or


NOT operators. Logical expressions may use the following
comparative operators :
eq
=
ne
<>
><
gt
>
ge
>=
lt
<
le
<=
between
co, ca, cs, cp (string comparisons)
Examples.

2012 SAP AG. All rights reserved.

43

Control Statements
Evaluating Field Contents: Case/EndCase Vs If/Endif

2012 SAP AG. All rights reserved.

44

Control Statements
Loops : Do/EndDo

An unconditional loop.

Syntax : do [N times].
Commands.
enddo.

The [N times] parameter is optional.


How do you end the loop ?

A system field, sy-index, automatically stores the


number of the current loop pass.

Examples.

2012 SAP AG. All rights reserved.

45

Control Statements
Loops : While/EndWhile

Loop with terminating condition.

Syntax : while logical expression


commands
endwhile

While the logical expression is true, the sequence of


commands is executed.

Examples.

2012 SAP AG. All rights reserved.

46

Control Statements
Other control commands

The CONTINUE statement inside a loop by passes all


subsequent statements within the loop and forces the next
loop to begin.

The CHECK statement has the same effect as


CONTINUE if the specified logical expression is not true.

The EXIT statement within a loop structure stops the


processing of the loop and the program will continue after
ENDDO/ENDWHILE.

Examples.

2012 SAP AG. All rights reserved.

47

Exercise 4

Local Data and Control


Statements

2012 SAP AG. All rights reserved.

48

Internal tables and Open SQL


What is an internal table ?

Internal tables (arrays) are data objects that allow you to retain several data
records within the same structure in working memory.

Internal tables have the same general structure as a database table, but are
held in memory, and initially contain no records.

The number of data records stored in an internal table is only restricted by the
capacity limits the computer system.

An internal table consists of a body and an optional header line.

The header line holds the current line of the table.

Internal tables are used to process large data sets in a structured manner:
Temporarily storing data from database tables for future processing;
Structuring and formatting data for output;
Formatting data for the use of other services.

2012 SAP AG. All rights reserved.

49

Internal tables and Open SQL


What is an internal table ?

2012 SAP AG. All rights reserved.

50

Internal tables and Open SQL


Defining an Internal Table

Basic ways of defining internal tables with and without header lines.

data:

itabsbook like sbook occurs 0. (no header)

data:

itabsbook like sbook occurs 0


with header line.
(header)

data:

begin of itabsbook occurs 0,


f1,
f2,
f3,
end of itabsbook.
(header)

data:

itabsbook type table of sbook,


wa_sbookinfo like line of itabsbook.
(user-defined work area in place of header)

2012 SAP AG. All rights reserved.

51

Internal tables and Open SQL


Filling an internal table
Tables can be filled with data by:
Reading data from a database table e.g.
tables: vendor.
data vendtab like vendor occurs 0
with header line.
select * from vendor into table vendtab.
Or
select * from vendor appending table vendtab.

Appending lines e.g.


data:

begin of vendtab occurs 0,


no(6) type n,
name(20) type c,
end of vendtab.
select * from vendor.
vendtab-no = vendor-no.
vendtab-name = vendor-name.
append vendtab.
endselect.
2012 SAP AG. All rights reserved.

52

Internal tables and Open SQL


Filling an internal table Example 1
A table customers has the following fields :
cnum
customer number
cname
customer name
caddress
customer address
cphone
customer phone no.
report yxxx123.
tables: customers.
data:
begin of itabcust occurs 0,
cnum like customers-cnum,
cname like customers-cname,
end of itabcust.
select * from customers.
move-corresponding customers to itabcust.
append itabcust.
endselect.
2012 SAP AG. All rights reserved.

53

Internal tables and Open SQL


Filling an internal table Example 2
A table customers has the following fields :
cnum
customer number
cname
customer name
caddress
customer address
cphone
customer phone no.
report yxxx123.
tables: customers.
data:
begin of itabcust occurs 0,
cnum like customers-cnum,
cname like customers-cname,
end of itabcust.
select cnum cname from customers
into table itabcust.

2012 SAP AG. All rights reserved.

54

Internal tables and Open SQL


Filling an internal table (contd)

Inserting lines at a specified position.


Single lines or a block of lines can be inserted in a table
before a specified line number. All subsequent entries are
moved down.
Examples :

Insert vendtab index 3.


The contents of the header line will be inserted before
line 3.

Insert lines of new vend


from 2 to 5
into vendtab index 3.
Lines 2 to 5 of the internal table new_vend will be
inserted before line 3 of vendtab.
2012 SAP AG. All rights reserved.

55

Internal tables and Open SQL


Filling an internal table (contd)

Moving complete tables

An internal table can be filled with the contents of


another one in a single step by using the move command.
Examples :
move new_vend to vendtab.
Note :
If an internal table with a header line is involved, this header
line (but not the internal table itself) is copied by move.

2012 SAP AG. All rights reserved.

56

Internal tables and Open SQL


Sorting an Internal Table

Data in an internal table can be sorted in a number of


ways:
Examples:
data stud_tab like student occurs 10
sort stud_tab.
sort stud_tab by studname, studid.
sort stud_tab by stud_id descending.

2012 SAP AG. All rights reserved.

57

Internal tables and Open SQL


Retrieving lines

Once an internal table has been filled, data can be


retrieved by reading each line of the table using a loop, or
reading individual lines.
Examples :
1) loop at stud_tab.
write / stud_tab-studid.
write stud_tab-studname.
endloop.

2) loop at stud_tab
where studname = Smith.
write / stud_tab-studid.
endloop.
2012 SAP AG. All rights reserved.

58

Internal tables and Open SQL


Retrieving lines (contd)
3) read table stud_tab index 5.
if sy-subrc = 0.
write / stud_tab-studid.
else.
write / Record not found.
endif.

4) read table stud_tab


with key studid = 3064537.
if sy-subrc .
5) read table stud_tab
with key studname = Smith
course = BGCC.
6) read table stud_tab with key studid
= 3165432 binary search.
2012 SAP AG. All rights reserved.

59

Internal tables and Open SQL


Changing an internal table

The contents of a given line in an internal table can be


updated using the modify command. For example :
read table stud_tab
with key studid = 3354631.
if sy-subrc = 0.
stud_tab-course = BBBC.
modify stud_tab index sy-tabix.
endif.
Lines can also be inserted into a table and deleted from
a table.

2012 SAP AG. All rights reserved.

60

Internal tables and Open SQL


Changing an internal table - Example.
tables: scustom.
data: cust_info like scustom occurs 0 with header line.
select * from scustom into table cust_info.
sort cust_info by id.
read table cust_info with key id = 00000001 binary search.
if sy-subrc = 0.
cust_info-telephone = '9654-2345'.
modify cust_info index sy-tabix.
endif.

loop at cust_info.
write: / cust_info-ID, cust_info-name, cust_info-telephone.
endloop.
2012 SAP AG. All rights reserved.

61

Internal tables and Open SQL


Other table commands

clear tablename.
Clears the header record of the internal table.
refresh tablename.
Removes all the line records in a table (not the header).
describe table tablename lines lin occurs ini kind knd.
Provides information on attributes of the internal table such
as number of lines used.
free tablename.
Deletes the internal table and releases the storage.

2012 SAP AG. All rights reserved.

62

Exercise 5

Internal Tables

2012 SAP AG. All rights reserved.

63

Internal tables and Open SQL


Sample Problem

Print a list of all customers who will depart after


01/09/2006.

Use the bookings table and the customer table.


BOOKINGS TABLE
Bookid
001
002
003
004

Customid
003
001
001
003

Carrid
UA
UA
UA
QA

Connid
400
401
401
001

Fldate
20061230
20061121
20060622
20060804

CUSTOMER TABLE
Id
001
002
003

2012 SAP AG. All rights reserved.

Name
Smith
Jones
Nguyen

City
Geelong
Prahran
Richmond

Phome
035214252
95294545
95234444

64

Internal tables and Open SQL


Solution 1 - Nested Select Statement

tables: bookings, customer.

select * from sbook


where fldate > 20060901.
select * from scustom
where id = sbook-customid.
write: / scustom-name,
sbook-fldate.
endselect.
endselect.

2012 SAP AG. All rights reserved.

65

Internal tables and Open SQL


Solution 2 - Using a Logical Database

report lec601.

nodes: customers, bookings.


get customers.

write: / customers-name.

get bookings.
write at /3 bookings-fldate.

2012 SAP AG. All rights reserved.

66

Logical databases
A logical database supplies your program with entries from tables. This
means that you only need to program the data processing statements.

Each logical database has a structure containing a hierarchy of those


tables that can be read.

2012 SAP AG. All rights reserved.

67

Logical databases
What is a Logical Database?
Using a logical database is another method for reading data from a
database table.

A logical database is actually a separate program, usually written by


SAP, that provides access to a group of related tables.

The database access has been optimized using Open SQL.

The R/3 system contains about 150 logical databases covering most
of the business processes.

When you run a program that uses a logical database, the program
behind the logical database runs as well. The logical database displays
an automatic selection screen for the user, issues the SELECT
commands and returns the data to the calling program (your program).

2012 SAP AG. All rights reserved.

68

Logical databases
Assigning a Logical Database

2012 SAP AG. All rights reserved.

69

Logical databases
Selection screen of a Logical Database

When you use a logical database in your program, a selection screen is


called automatically, and the user can enter information to limit the data returned
by the logical database.

Selections displayed depends on the nodes statement in the program.

2012 SAP AG. All rights reserved.

70

Logical databases
Event Sequencing: Using the GET event

An event is a keyword that defines a block of code to be executed when the


system detects a certain occurrence.

The GET event is used in a program that uses a logical database.

The GET events in an ABAP program are processed in a tree like order to
match the tree like order relationship of the tables in the logical database.

2012 SAP AG. All rights reserved.

71

Logical databases
Using the GET event

2012 SAP AG. All rights reserved.

72

Logical databases
Using the GET event
The first data record from database table SPFLI is made available to
your program. If your program has a GET spfli, the event block is
processed.

The first data record from SFLIGHT that corresponds to the key of
the current SPFLI record is made available to your program. If your
program has a GET sflight, the event block is processed.

The next corresponding data record from database table SFLIGHT


is made available to your program and the event block is processed
again.

GET sflight: is called again until no further corresponding data


records are found.

The logical database makes the next corresponding data record


from SPFLI available to your program etc.

2012 SAP AG. All rights reserved.

73

Logical databases
Advantages of Logical Databases

Logical Databases simplify the creation of reports where


access to data from multiple tables is required.

A selection screen with appropriate selection criteria is


automatically created. You dont have to define this in your
program.

Logical Databases can be used in more than one


program. Improvements to the database access methods of
the logical database immediately improve the performance
of all programs using it.

2012 SAP AG. All rights reserved.

74

Formatting
Formatting Output - Color

ABAP allows you to use 7 colors in your output lists.

You can activate these colors by specifying a number or a symbolic


name.

To display the colors and their corresponding symbolic names, use


transaction LIBS and select Demo: All Colors.

2012 SAP AG. All rights reserved.

75

Formatting
Formatting Output - Color

2012 SAP AG. All rights reserved.

76

Formatting
Generating Icons, Symbols and Lines

2012 SAP AG. All rights reserved.

77

Formatting
Setting the list format

2012 SAP AG. All rights reserved.

78

Formatting
Page and Column Headers

2012 SAP AG. All rights reserved.

79

Formatting
Header using TOP-OF-PAGE Event

2012 SAP AG. All rights reserved.

80

Formatting
Formatting Output - Solid Lines

The SY-ULINE system field generates a horizontal line, SY-VLINE a vertical


line.

report lec702.
data: square type i,
line_size type i value 40.
uline.
format color col_heading.
write: / sy-vline,
Numbers and their squares,
at line_size sy-vline.
format color off.
uline.
do 10 times.
square = sy-index ** 2.
write: / sy-vline,
sy-index color col_key,
sy-vline,
square,
at line_size sy-vline.
enddo.
uline.
2012 SAP AG. All rights reserved.

81

Exercise 6

Using Logical Databases Formatting Output

2012 SAP AG. All rights reserved.

82

Thank you

Contact information:
Taizan Chan
t.chan@qut.edu.au

You might also like