Tutorialspoint ABAP教程小结
教程链接: https://www.tutorialspoint.com/sap_abap/
1. Home:
ABAP is a fourth-generation programming language for SAP. Java and ABAP are currently main languages in SAP. This tutorial explains the key concepts of SAP ABAP.
2.Overview:
ABAP: Advanced Business Application Programming
3-tier Client/Server Architecture:
-
Presentation
-
Application
-
Database
ABAP works in application tier. Technical distribution of software is independent of its physical distribution (different levels can be installed in the same computer. A level can be installed in different computers).
ABAP programs reside the SAP database. They execute under the control of the runtime system that is a part of SAP kernel. But unlike java, ABAP programs are not stored in separate external files.
ABAP code exists in two forms:
-
Source
-
Generated Code : binary representation, like byte code in java
3.Environment:
How?
-
Open ABAP editor: SE38
-
Name the program Z…… (Z ensures the customer namespace)
-
Create
-
Execute
4.Basic Syntax:
-
Begin with REPORT
-
End with period.
-
Colon notation: Combine different states.
-
Comments:
Full: *
Partial line: “
-
No-Zero: to delete zero( 00000520 ----> 520)
-
SKIP: inserting blank line on the page
-
Message
Numeric types, Character types, Hexadecimal type
-
X : byte field
-
C : Text field
-
I : Integer
-
F : Floating point
If you don’t care about rounding error
-
P : Packed number : 压缩存储,a number’s every digit are represented as a number.
If you should ensure the accuracy
-
STRING: Text String
6.Variables
Data <f> TYPE <type> VALUE <val> .
Data <val2> LIKE <val>.
Kinds of variables:
-
Static Variables:
-
Reference Variables:
-
System Variables: predefined in SAP
7. Constant & Literal
Literal:
-
Numeric literal: 183, 143
-
Character literal:
Constant:
-
CONSTANT <f> TYPE <type> VALUE <val>
8. Operator:
Four categories;
-
Arithmetic operators :
-
Comparison:
<> NE
A1 BETWEEN a2 AND a3
IS INITIAL
IS NOT INITIAL
-
Bitwise operators:
BIT-NOT
BIT-AND
BIT-XOR
BIT-OR
-
Character String Operator: There are many string operators we can use.
9. Loop control:
-
WHILE
-
Do
-
Nested loop
Loop control statement:
-
Continue
-
CHECK: if the condition is wrong, skip to another loop.
-
EXIT
10. Decisions:
-
IF :
11. String:
-
STRLEN() : length of a string
-
There are also other operations to manipulate strings
12. Date&Time:
13. Formatting data
14. Exception:
TRY…...CATCH
15. Directory:
The directory is used to create and manage data definition and to create Tables, Data Elements, Domains, Views and Types.
Basic Types in ABAP Directory
-
Data elements
-
Structure
-
Table types
16. Domain
17. Structures:
18. Views
A view acts like a database table only. But it will not occupy storage space.
19. Search help
20. Lock Objects
Synchronize access to the same data by more than one program.
21. Modularization
Modularization involves the organization of programs into modular units, also known as logical blocks.
Different types of modulation units called from ABAP program:
-
Macros : 只能在被定义的program里reuse.
-
Include Program : 在不同的programs里复用,
-
Subroutine : 一般也是用在同一个program里, 但是也可以被外部program调用
-
Function module : 储存在central library. 可以被所有programs调用,甚至可以被外部non-SAP系统调用
-
Methods : 面向对象编程
Different types of modulation units called from ABAP runtime:
-
Event Block :
-
Dialog Modules :
22. Subroutine:
Subroutine在一个program里定义,可以被自己和其他的program调用(一般只被自己调用)
23. Macros
我们可以在同一个program里定义宏。一个宏可以有9个占位符。
24. Function module
-
Build function module: SE37
25. Include Program
Include program不能单独运行,它在原理上就是复制粘贴。
Include program 不能传递参数, 不能调用自身。
用的时候,其实就相当于复制粘贴了一段代码,既不能传递参数,又不能调用自身。
26. Open SQL:
Open SQL 是SAP系统中用于操作SQL数据库的一组statements(read, modify, delete, etc)。它不依赖与数据库的种类,可以为我们提供统一的数据操作指令。
各个操作语句的使用可以参考: http://www.saphub.com/abap-tutorial/
操作语句如下:
27. Internal tables:
Internal tables是一个临时表(生命周期是从program开始到结束)。 用来临时存储数据,操作数据。
定义: 利用DATA + TABLE OF来定义内部表。
我们也可以用APPEND来给内部表直接赋值(定义一个与内部表 I_T结构相同变量 tmp-->填充 tmp --> tmp赋给I_T)
通常内部表用到的场景就是:从数据库中取出数据放到内部表用来 1)打印 2)进一步处理。我们可以利用Select来进行。
两种方法:
-
利用临时tmp
-
直接将table导入
可以找到关于内部表的所有操作详情:
http://www.saphub.com/abap-tutorial/
28. Object Orientation
ABAP开始是过程性语言,但后来按照面向对象进行了改造,像是JAVA和C++一样有了面向对象的一套东西(类,多态, etc)
-
声明类:
-
创建实例:
-
继承
-
多态
-
封装
-
接口
29. Report programming
30. Dialog programming
31. Smart forms
32. SAPscripts
33. Customer Exits
34. User Exits
35. Business Add-Ins
36. Web Dynpro