Vous êtes sur la page 1sur 64

SAP R/3

ABAP Programming

ABAP Course Outline


   

Chapter 1 Chapter 2 Chapter 3 Chapter 4

 

Introduction to ABAP List Processing in ABAP Open SQL & Internal Table Event-driven Programming & Selection Screen Chapter 5 : Modularization,Logical DB & Catch Chapter 6 : Authorization,Message, File Transfer,Long Text Programming, Macro and Tip&Technique

: : : :

ABAP Chapter 1
  

Introduction to SAP Architecture ABAP Overview Data Object in ABAP

SAP R/3 Introduction to SAP Architecture

What is SAP?
 

SAP is the leader of ERP software vendor Enterprise Resource Planning is a back office application for Enterprise
ERP MRP II MRP

What is mySAP.com?


The future of ERP software including CRM, SCM, SEM, KM, Web-enable mySAP.com is the future or extended of SAP ERP software
TEI ERP MRP II MRP

mySAP.com
mySAP.com Marketplace BAPI Other Software BAPI CRM KW SCM BAPI BIW SAP R/3 APO SEM SAP R/3

SAP R/3 3 Tier Client/Server


Presentation Logic Presentation Server Application Server

Application Logic Data Logic

Data Service (RDBMS)

Database Server

SAP R/3
 

SID = System Identifier System Number


User
sap*/06071992 DDIC/19920706

Three-tier configuration

Client 000 001 066

Application processes

earlywatch/support Database processes

R/3 R/3 Client/Server (3 Tier Architecture) (3

Presentation Layer

IBM Compatible

IBM Compatible

IBM Compatible

Central Instance

Dialog Instance

Application Layer

message

Application Server

Application Server

Oracle Informix

Database Layer

Database Server

DB2 MS SQL Server ADABUS(SAP DB)

SAP R/3 Configuration


O n e-tie r n fi r ti n r t ti
P re se n ta tio n p ro ce sse s

T w o-tie r o n fi r tio n

T h re e-tie r o n fi r tio n

A p p li

ti
A p p lica tio n p ro ce sse s

t
D a ta b a se D a ta b a se, D a ta b a se, a p p lica tio n, p ro ce sse s p re se n tatio n p ro ce sse s a p p lica tio n p ro ce sse s

R/3 R/3 Instance


Application Server

Dispatcher
Request Queue SAP D WP B WP V WP S WP E WP Buffer Area User Contexts and Buffer

Types of Work Process in R/3


    

D = Dialog B = Background V = Update E = Enqueue S = Spool

Dialog WP
Dispatcher
D WP TaskHandler
ABAP Processor
List buffer

Local Memory
Memory Space

Dynpro Processor DB Interface

Database

SAP R/3 Logon Step


Report ztest. Tables customers. Select single * from

Application Server
2

customers where id = 1. Write: / customers-name.

Dispatcher
SAP Buffer
8 4 3 6

Request Queue

Program Table
Roll Area

D
7

D
5

Database Server

SAP R/3 System Client


000

001 Client Copy 066

800

SAP R/3 Logon

Data in SAP R/3


User Master Customizing 1. Client-dependent Data Application
Transaction

Master

Customizing 2. Client-independent Data Repository

SAP R/3
SD MM PP
Production Planning Sales & Distribution Materials Mgmt.

FI
Financial Accounting

CO
Controlling

AM

R/3 R/3
Client / Server ABAP/4 ABAP/4
IS
Human Resources Industry Solutions

Fixed Assets Mgmt.

QM

Quality ManageManagement PM Plant MainMaintenance HR

TR
Treasury

WF
Workflow

ABAP Overview
FIELDFIELD-SYMBOLS .

FORMAT ... FOVERLAY ...

DATA ...

WRITE ... *Comment...

SEARCH ... SELECT ...

READ ... LOOP AT ...

ABAP Developer Key

SAP R/3

      

OK Code Field - /n<xxxx> - /o<xxxx> - /i - /o - /nex Transaction Code

ABAP/4 ABAP/4 -> ABAP Advanced Business Application Programming


4 = 4 GL -> ABAP Object

ABAP Feature
Declaring data with various types and structure Operational elements for data manipulation Control elements for controlling the program flow Event elements for reacting to external events

ABAP
Operating system-independent programming ABAP/4 contains a subset of SQL called Open SQL for comfortable database access for various database ABAP/4 code is compiled to an intermediate format(generation) which is interpreted by the runtime environment

ABAP Programming
ABAP Report Dialog Programming(Transaction) SAPScript

ABAP Program(Report)

Report Program
: attribute type 1 (executable)

Reading
Data

Database

Reading data

ABAP Program (Dialog Program)


Dialog Program
: attribute type M (Module Pool)

Reading
Data

Writing Database

Reading and changing data

SAPScript

Print Program Composer Form

Layout Set

Data

Database

ABAP Programming Overview

How to create ABAP program

Transaction Code : SE38

ABAP Report Component


    

Source code Attribute Text element Documentation Variants

The Structure of the Language


Each statement must end with a period

DATA tmp TYPE I. WRITE Hello World. WRITE OK.

Chained Statements


Successive statements that have the same string segment can be combined to form a single chained statement To do so, you specify the identical starting segment once and conclude it with a colon (:), the remaining segments are then listed, separated by commas (,) and concluded with a period (.) At runtime, a chained statement is treated like an equivalent sequence of individual ABAP statements

Combining Statements
WRITE Hello World . WRITE OK . = WRITE: Hello World , OK . DATA tmp1 TYPE I. DATA tmp2 TYPE C. = DATA: tmp1 TYPE I, tmp2 TYPE C.

Colon Notation

MOVE sy-subrc TO tmp1. MOVE sy-subrc TO tmp2. MOVE sy-subrc TO tmp3. = MOVE sy-subrc TO: tmp1, tmp2, tmp3.

Chaining Statement

PERFORM cal_1 USING a1 a2. PERFORM cal_1 USING a3 a4. = PERFORM cal_1 USING: a1 a2, a3 a4.

Comments

* This is full line comment WRITE Hello World . Write data (partial line comment) WRITE Test .

Case Sensitivity
ABAP/4 is not case sensitive

WRITE Hello World . WriTe Hello World . wRiTE Hello World .

Data Object in ABAP

Data Object in ABAP


Memory Space
Variable Structure

Table Structure

Internal Table

Constants

<Filed-symbols>

Variable
Variables can be declared at any point in a program Variables can be up to 30 characters in length No variable can have the same name as an ABAP command

ABAP Built-in Data Type BuiltType


C D F I N P T X String xstring

Description
Character Date Floating Point Integer Numeric Text Packed Decimal Time Hexadecimal Variable-length Variable-length

Initial Value
Space 00000000 0.0 0 0 0 000000 0 Space Blank string

Length
1 65535 c. 8 characters 8 bytes 4 bytes 1 1 65535 c. 16 bytes

6 characters 1 65535 b.

Variable Variable

Hexadecimal

Defining Variable with DATA Statement

* Syntax
DATA var[(length)] [Type type] [Decimals number]. DATA var LIKE Table-Filed [VALUE initial value]

Defining Variable with DATA Statement

* Data Declaration
DATA: tmp(10) TYPE C, tmp1 TYPE I, tmp2(8) TYPE P DECIMALS 2 VALUE 1.50. DATA: tmp3(5) TYPE N, tmp4. DATA matnr LIKE mara-matnr. DATA: customerno LIKE customers-id.

Defining Variable with DATA Statement

Data Dictionary Object

DATA customerno LIKE customers-id. Data Element or DATA customerno TYPE s_customer.

Variable


Data Type C,N and X length between 1 65535 (Default 1) Data Type P length between 1 16 (Default 8) and decimals length between 0 31 Data Type I value between 231 to 231 1 or 2,147,483,648 to 2,147,483,647

Data type N
data tmp(5) type N. tmp = Xca9yy23K6 .

ABAP Practice

NonNon-elementary Type

* Data Declaration
TYPE tname(30) TYPE c. DATA: customer_name TYPE tname.

Record Type (Structure)

* Syntax
DATA BEGIN OF <record name>. DATA field1. DATA field2.

DATA END OF <record name>.

Record Type

* Syntax
DATA BEGIN OF material. DATA matno LIKE mara-matnr. DATA qty TYPE P DECIMALS 2. DATA END OF material. MOVE 100 TO material-qty. WRITE material-qty.

Defining Record(Include Structure)

* Include Structure
DATA BEGIN OF customer. INCLUDE STRUCTURE customers. DATA tel(7). DATA END OF customer.

Constants

* Constant variable
CONSTANTS max_no TYPE I VALUE 999. DATA counter TYPE I VALUE max_no. WRITE: max_no, counter.

Value Assignment
* Value assignment
DATA: name1(30), first_num(5) TYPE N, next_num TYPE I. MOVE XXXX TO name1. MOVE 5 TO first_num. COMPUTE next_num = first_num + 5. name1 = SAP. ADD 1 TO next_num.

Value Assignment
* Value assignment
MOVE value TO var. var = value. DATA: tmp1 TYPE I, tmp2 TYPE I. tmp1 = tmp2 = 10.

System Fields


The system fields (structure syst) are filled by the runtime environment. You can use them to query the system status in an ABAP program You should access them only for reading
     

sy-datum sy-uzeit sy-opsys sy-dbsys sy-host sy-subrc

= Current date of application server = Current time of application server = OS of the application server = Database server product name = Host name of application server = Return value of ABAP statement

DATE

* Fixed Length 8 * Include Representation YYYYMMDD


DATA today TYPE D. today = sy-datum. WRITE today. today = 19991231. WRITE today.

09041998

31121999

TIME

* Fixed Length 6 * Format HHMMSS


DATA times TYPE T. times = sy-uzeit. WRITE times. 235015

Record Type TABLES customers. DATA vender LIKE customers. customers-id = 1234. customers-name = Test#1. MOVE customers TO vender. WRITE: customers-id, vender-name.

FieldField-symbols
Data: string(4) Value Test , num Type I Value 10, today Type D Value 19980429. Field-symbols <temp>. Assign string To <temp>. Write <temp>. Assign num To <temp>. Write <temp>. Assign today To <temp>. Write <temp>.

CLEAR Statement
Clear statement sets a field to an initial value appropriate for its type

CLEAR <field>. Example:


DATA tmp type i value 9. tmp = 10. CLEAR tmp.

ABAP Report
Report ztest. *Data declaration data ... data begin of ...

ABAP Practice