SAP ABAP Programming Overview
SAP ABAP Programming Overview
SAP
Application
Server
DB Server
SAP SYSTEM (3 Tier Architecture)
SAP GUI SAP GUI
Presentation Layer
(Windows based)
SAP Instance
Application Layer
Dispatcher M
(Windows Server/UNIX)
Request SAP Buffer
Queue
(Shared Mem)
D D B V S E
G
Oracle
Database Layer
Informix
(Windows Server/UNIX)
DB2
Database Server
MS SQL Server
MaxDB
Dialog Processing
SAP System : Dialog Processing
SAP GUI
Report zpsm1.
Request Tables customers.
List Select single * from
Generate
1 customers where id = 1.
Screen(List)
10
Application Server Send Request Write: / customers-name.
Store request to
queue 3 Dispatcher
Send List 2 Search for SAP Buffer
9 free WP
Request Check Program in 7
Program
Queue Send request to Program
5 Buffer Execute
WP4 ABAP
Table statemen
D D D … D t
…
8 6
SQL Load&Gen
Database Server Request Program
Dialog Work Process Architecture
Dialog Work Process Local Memory
Memory Space
TaskHandler
ABAP Processor
List buffer
DYNPRO Processor
DB Interface
Result Set Memory
Database Server
ABAP Programming Overview
ABAP Overview
MOVE … IF ...
DATA ...
WHILE...
Advanced
Business
Application
Programming
ABAP Feature
Operating/Database system-independent
programming
ABAP contains a subset of SQL called Open
SQL for comfortable database access for
various database
ABAP Programming
ABAP Report
Dialog Programming(Transaction)
ABAP Program : Report
Report Program
: attribute type 1
(executable)
Reading
Data
Database
Reading data
Types of ABAP Report
1. Report Listing
4 2. Drill-down Report
3. Control-break Report
4. ALV Report
ABAP Program : Dialog Program
Dialog Program
: attribute type M
(Module Pool) Reading
Data
Writing
Database
Constants <Field-symbols>
Variable
Variable
REPORT ZTEST.
DATA firstname TYPE STRING.
firstname = ‘John’.
Predefined ABAP Data Types
Type Description Initial Value Length
C Character Space 1 – 65535
I Integer 0 4 bytes
* Syntax
DATA var[(length)] [Type type] [Decimals number].
* 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.
Defining Variable with DATA Statement
* Data Declaration
DATA customerno LIKE customers-id.
DATA matnr LIKE mara-matnr.
Syntax Runtime
Error Error
* Data Declaration
TYPES tname(30) TYPE c.
DATA: customer_name TYPE tname,
firstname TYPE tname.
Value Assignment
* Value assignment
DATA: name1(30),
first_num TYPE I,
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
DATA: tmp1 TYPE i,
tmp2 TYPE i.
tmp1 = tmp2 = 10.
ต้องการให้สร ้างตัวแปรชือ่ firstname และ lastname โดยให้คา่
ตัวแปร firstname และนามสกุลของคุณให้กบั ตัวแปร lastnam
ค่าข้อมู ล firstname กับ lastname ออกมาทีหน้่ าจอ
ABAP Practice
Structure
Structure
* Syntax
DATA BEGIN OF <structure name>.
DATA field1.
DATA field2.
…
…
DATA END OF <structure name>.
Structure
wa
id name city
* Syntax
00000000
DATA BEGIN OF wa.
DATA id LIKE customers-id.
DATA name LIKE customers-name.
DATA city LIKE customers-city.
DATA END OF wa.
MOVE 9 TO wa-id.
WRITE wa-id.
Defining Structure (Include Structure)
* Include Structure
DATA BEGIN OF wa.
INCLUDE STRUCTURE customers.
DATA tel(7).
DATA END OF wa.
Defining Structure
* LIKE option
DATA wa LIKE customers.
wa-id = 1.
wa-name = ‘John’.
WRITE: wa-id, wa-name.
ต้องการให้สร ้าง Structure ชือ่ myname โดยมีฟิลด ์ firstname
่
โดยให้คา่ ชือของคุ ณกับฟิ ลด ์ firstname และนามสกุลของคุณให
้
พร ้อมทังแสดงค่ ่ อ่ myname ทังฟิ
าข้อมู ลของ Structure ทีชื ้ ลด
lastname ออกมาทีหน้ ่ าจอ
ABAP Practice
Constants
Constants
* Constant variable
CONSTANTS max_no TYPE I VALUE 999.
DATA counter TYPE I VALUE max_no.
WRITE: max_no, counter.
Constants Using Example
* Constant variable
CONSTANTS ctext(11) TYPE C VALUE ‘Hello World’.
WRITE ctext.
WRITE ctext.
WRITE ctext.
WRITE ctext.
WRITE ctext.
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 = Current date of application server
syst- sy-uzeit = Current time of application server
datum sy-datlo = Current date of SAP GUI
sy-timlo = Current time of SAP GUI
sy-mandt = Current client logon
sy-subrc = Return value of ABAP statement
ABAP System Fields : Structure SYST (SE11)
DATE
* Fixed Length 8
* Include Representation ‘YYYYMMDD’
DATA today TYPE D.
today = sy-datum.
WRITE today.
today = ‘19991231’.
WRITE today.
TIME
* Fixed Length 6
* Format ‘HHMMSS’
DATA times TYPE T.
times = sy-uzeit.
WRITE times.
HHMMSS
MOVE Statement
Example:
DATA tmp type i value 9.
tmp = 10.
CLEAR tmp.
CLEAR Structure
Report ztest.
*Data objects declaration
data ...
data begin of ...
*Program Logic(Data objects processing)
…
write ….
ABAP Practice