ABAP Programming Overview

ABAP Course Outline

 

Chapter Chapter Chapter Chapter

 

Introduction to ABAP List Processing in ABAP Open SQL & Internal Table Event-driven Programming & Selection Screen Chapter 5 : Modularization & Catch Statement Chapter 6 : Message, Debugging, File Transfer and Type Group

1 2 3 4

: : : :

ABAP Chapter 1
  

Introduction to SAP Architecture ABAP Overview Data Object in ABAP

SAP System : 3 Tier Client/Server SAP GUI SAP GUI SAP GUI Presentation Server SAP Application Server DB Server .

SAP SYSTEM (3 Tier Architecture) SAP GUI SAP GUI Presentation Layer (Windows based) SAP Instance Application Layer (Windows Server/UNIX) Request Queue Dispatcher M SAP Buffer (Shared Mem) D D B V S E G Database Layer (Windows Server/UNIX) Oracle Informix DB2 MS SQL Server MaxDB Database Server .

Dialog Processing .

SAP System : Dialog Processing SAP GUI Report zpsm1. Dispatcher Send List 2 9 Search for free WP SAP Buffer Program Table … Request Queue Send request to WP 4 Check Program in Program Buffer 5 7 Execute ABAP statement D 8 D SQL Request D … D 6 Load&Gen Program Database Server . Write: / customers-name. Request Tables customers. Application Server Store request to queue 3 Send Request 1 Generate Screen(List) 10 List Select single * from customers where id = 1.

Dialog Work Process Architecture Dialog Work Process TaskHandler Local Memory Memory Space ABAP Processor List buffer DYNPRO Processor DB Interface Result Set Memory Database Server .

ABAP Programming Overview .

.. WHILE... SEARCH .. . *Comment. DO . LOOP AT ..... WRITE ..ABAP Overview MOVE … DATA .. SELECT ........ IF .

ABAP Advanced Business Application Programming .

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/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 .

Report Listing 4 2. Control-break Report 4.Types of ABAP Report 1 3 1. ALV Report . Drill-down Report 3.

ABAP Program : Dialog Program Dialog Program : attribute type M (Module Pool) Reading Data Writing Database  Reading and changing data .

Dialog Program : Transaction .

ABAP Programming .

How to create ABAP program Transaction Code : SE38 .

Transaction : SE38 .

Program Attribute .

ABAP Editor

The Structure of the Language

Each statement must end with a period

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

DATA tmp TYPE I. WRITE ‘Hello World’. WRITE ’10’. Text Literal
Text Literal

MOVE 9 TO tmp.
Numeric Literal

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

Chained Statements WRITE ‘Hello World’. WRITE ‘OK’. = DATA: tmp1 TYPE I. ‘OK’. . = WRITE: ‘Hello World’. DATA tmp2 TYPE C. DATA tmp1 TYPE I. tmp2 TYPE C.

MOVE sy-subrc TO tmp3. = MOVE sy-subrc TO: tmp1. tmp3. MOVE sy-subrc TO tmp2. tmp2. .Chained Statement MOVE sy-subrc TO tmp1.

a3 a4.Chained Statement PERFORM cal_1 USING a1 a2. PERFORM cal_1 USING a3 a4. = PERFORM cal_1 USING: a1 a2. .

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

WriTe ‘Hello World’. .ABAP Command : Case Sensitivity  ABAP command is not case sensitive WRITE ‘Hello World’. wRiTE ‘Hello World’.

Data Objects in ABAP .

Data Objects in ABAP Memory Space Variable Structure Table Structure Internal Table Constants <Field-symbols> .

Variable .

Variable   Variables can be declared at any point in a program Variables can be up to 30 characters in length REPORT ZTEST. . firstname = ‘John’. DATA firstname TYPE STRING.

0 0 ‘0’ 0 ‘000000’ ’00’ Space Blank string Length 1 – 65535 8 characters 8 bytes 4 bytes 1 – 65535 1 – 16 bytes 6 characters 1 – 65535 Packed Decimal Time Hexadecimal Variable-length Variable-length Hexadecimal Variable Variable .Predefined ABAP Data Types Type C D F I N P T X String xstring Description Character Date Floating Point Integer Numeric Text Initial Value Space ‘00000000’ 0.

Defining Variable with DATA Statement * Syntax DATA var[(length)] [Type type] [Decimals number]. DATA var LIKE Table-Field [VALUE initial value]. .

Defining Variable with DATA Statement * Data Declaration DATA: tmp(10) TYPE C. . tmp4. DATA: tmp3(5) TYPE N. tmp1 TYPE I.50’. tmp2(8) TYPE P DECIMALS 2 VALUE ‘1.

Defining Variable with DATA Statement * Data Declaration DATA customerno LIKE customers-id. DATA customerno TYPE customers-id. DATA matnr TYPE mara-matnr. . DATA matnr LIKE mara-matnr.

STRING and XSTRING) Incomplete Types (C.F.P and X) .ABAP Predefined Data Types ABAP Predefined Data Types Complete Types (I.N.T.D.

Data Type I value between – 231 to 231 – 1 or –2.Variable    Data Type C.147.483.647 DATA tmp TYPE I.648 to 2.483. Data Type P length between 1 – 16 (Default 8) and decimals length between 0 – 31 DATA tmp(5) TYPE P DECIMALS 2. tmp = 1000000.N and X length between 1 – 65535 (Default 1) DATA tmp(10) TYPE C. .147.

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

ABAP Error ABAP Error Syntax Error Runtime Error User Runtime Error System Runtime Error Cannot Allocate Space Time Exceed (10 Minutes) .

result = 10 / 0. .User Runtime Error DATA result TYPE i.

System Runtime Error : Space Allocation .

System Runtime Error : Time Exceed .

. DATA: customer_name TYPE tname.Non-elementary Type * Data Declaration TYPES tname(30) TYPE c. firstname TYPE tname.

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

.Value Assignment * Value assignment DATA: tmp1 TYPE i. tmp1 = tmp2 = 10. tmp2 TYPE i.

ต้ องการให้ สร้ างตัวแปรชื่อ firstname และ lastname โดยให้ ค่าชื่อของคุณกับ ตัวแปร firstname และนามสกุลของคุณให้ กับตัวแปร lastname พร้ อมทั้งแสดง ่ น้ าจอ ค่ าข้ อมูล firstname กับ lastname ออกมาทีห ABAP Practice .

Structure .

Structure * Syntax DATA BEGIN OF <structure name>. . … … DATA END OF <structure name>. DATA field1. DATA field2.

DATA city LIKE customers-city. DATA id LIKE customers-id. DATA name LIKE customers-name.Structure wa id name * Syntax 00000000 DATA BEGIN OF wa. MOVE 9 TO wa-id. city . WRITE wa-id. DATA END OF wa.

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

wa-name. WRITE: wa-id. wa-id = 1. wa-name = ‘John’. .Defining Structure * LIKE option DATA wa LIKE customers.

ต้ องการให้ สร้ าง Structure ชื่อ myname โดยมีฟิลด์ firstname และ lastname โดยให้ ค่าชื่อของคุณกับฟิ ลด์ firstname และนามสกุลของคุณให้ กับฟิ ลด์ lastname ่ ่ือ myname ทั้งฟิ ลด์ firstname และ พร้ อมทั้งแสดงค่ าข้ อมูลของ Structure ทีช ่ น้ าจอ lastname ออกมาทีห ABAP Practice .

Constants .

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

WRITE ctext. WRITE ctext. WRITE ctext.Constants Using Example * Constant variable CONSTANTS ctext(11) TYPE C VALUE ‘Hello World’. . 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     syst-datum   sy-datum sy-uzeit sy-datlo sy-timlo sy-mandt sy-subrc = Current date of application server = Current time of application server = Current date of SAP GUI = Current time of SAP GUI = Current client logon = Return value of ABAP statement .

ABAP System Fields : Structure SYST (SE11) .

today = ‘19991231’. today = sy-datum.DATE * Fixed Length 8 * Include Representation ‘YYYYMMDD’ DATA today TYPE D. . WRITE today. WRITE today.

times = sy-uzeit.TIME * Fixed Length 6 * Format ‘HHMMSS’ DATA times TYPE T. WRITE times. HHMMSS .

wa-id = ‘1234’. MOVE wa TO vender.MOVE Statement DATA wa LIKE customers. DATA vender LIKE customers. . wa-name = ‘Test#1’. “vender = wa. vender-name. WRITE: wa-id.

DATA: begin of wa2.f3.wa2-f1 . . f1. … MOVE-CORRESPONDING wa1 TO wa2.f1.f4. end of wa2. WRITE: wa1-f1.f2. end of wa1.MOVE-CORRESPONDING Statement DATA: begin of wa1. f2.

Field-symbols .

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

Field-symbols : UNASSIGN data: name(4) Value ‘Test’. unassign <temp>. field-symbols <temp>. . write <temp>. assign name To <temp>.

. Example: DATA tmp type i value 9. CLEAR tmp.CLEAR Statement “Clear statement sets a field to an initial value appropriate for its type” CLEAR <data object>. tmp = 10.

CLEAR Structure DATA wa like customers. … CLEAR wa. .

ABAP Report : Program Structure Report ztest. .. *Program Logic(Data objects processing) … write …. *Data objects declaration data .. data begin of ...

ABAP Practice .