ABAP Help Document(1):1.1关键字
ABAP Help Document
1.ABAP Reference
ABAP是SAP开发的用来在SAP环境构建复杂应用。三层结构:表示层,用户使用GUI,Web Browser;应用层,许多应用服务器组成,应用服务器为应用执行环境;数据层,数据库组成。
这三层通信组件:ICM(Internet Communication Manager)网络通信管理器提供网络通信,例如:Web Dynpro,BSP;RFC Interface,同一服务器,不同服务器直接调用RFC Function。
SAP支持Unioncode和Non-Unioncode系统。Non-Unioncode表示一个字符使用一个字节,Unioncode,万国码,对所有语言字符进行统一唯一的编码,utf-8占1到4个字节,utf-16占2到4个字节,utf-32占4个字节。
在Unioncode之前,SAP使用ASCII,EBCDIC等只用一个字节表示字符,SJIS,BIG5等使用两个字节表示字符。
使用Tcode:UCCHECK,检查非Unioncode Program是否能够转换为Unioncode Program。
1.1 ABAP 关键字
使用Tcode:ABAPDOCU,打开ABAP帮助文档,ABAP Words,可以查看ABAP的所有关键字。
关键字,操作数,操作符。
示例1:
"ABAP 关键字,操作数,操作符 FORM f_abap_statement. "结构体操作数- DATA:BEGIN OF struc1, elem1 TYPE char1, END OF struc1. "通过-访问结构体下element struc1-elem1 = 'X'. "对象操作数-> DATA: lo_c1 TYPE REF TO c1. CREATE OBJECT lo_c1. lo_c1->method1( ). "静态对象操作数=> c1=>method2( ). "接口操作数~ lo_c1->i1~imethod1( ). "使用关键字,在前面加上! DATA !type TYPE char1. !type = 'X'. MESSAGE !type TYPE 'S'. "操作符 "1.赋值操作符, =,?= "MOVE {source {TO|?TO} destination} " | {EXACT source TO destination}. DATA:num1 TYPE char10 VALUE '1234567890'. DATA:num2 TYPE char5. "自动截断长度 MOVE num1 TO num2. num2 = num1. "使用EXACT,当精度丢失时,抛异常 "MOVE EXACT num1 TO num2. "?=,MOVE ?TO只能用于对象 "MOVE num1 ?TO num2. WRITE:/ num1,num2. "2.算术操作符 "+|-|*|/|DIV|MOD|** DATA:cal_num1 TYPE I. DATA:cal_num2 TYPE float. cal_num1 = 10. cal_num2 = '3.0'. * cal_num2 = cal_num1 + cal_num2. * WRITE:/ cal_num1,cal_num2. * cal_num2 = cal_num1 - cal_num2. * WRITE:/ cal_num1,cal_num2. * cal_num2 = cal_num1 * cal_num2. * WRITE:/ cal_num1,cal_num2. cal_num2 = cal_num1 / cal_num2. WRITE:/ cal_num1,cal_num2. "整除 cal_num2 = cal_num1 DIV cal_num2. WRITE:/ cal_num1,cal_num2. "幂运算 * cal_num2 = cal_num1 ** cal_num2. * WRITE:/ cal_num1,cal_num2. "取余 * cal_num2 = cal_num1 MOD cal_num2. * WRITE:/ cal_num1,cal_num2. "3.位运算 "BIT-NOT,BIT-AND,BIT-OR,BIT-XOR DATA:bit_num1 TYPE x VALUE 'E0'. DATA:bit_num2 TYPE x VALUE '0E'. DATA:bit_num3 TYPE x. bit_num3 = BIT-NOT bit_num1. WRITE:/ bit_num3. bit_num3 = bit_num1 BIT-AND bit_num2. WRITE:/ bit_num3. bit_num3 = bit_num1 BIT-OR bit_num2. WRITE:/ bit_num3. bit_num3 = bit_num1 BIT-XOR bit_num2. WRITE:/ bit_num3. "4.字符串运算 "& DATA:str_num1 TYPE char1 VALUE '1'. DATA:str_num2 TYPE string VALUE 'string'. DATA:str_num3 TYPE char20. str_num3 = str_num1 && str_num2. WRITE:/ str_num3. "5.比较运算 "= EQ,<> >< NE,< LT,<= LE,> GT,>= GE "字符类型数据比较关系 "CO Contains only, op1 CO op2,op1仅包含op2中字符. "大小写敏感,末尾空格 DATA:co_num1 TYPE C LENGTH 10 VALUE 'abcde'. DATA:co_num2 TYPE C LENGTH 5 VALUE 'abc'. IF co_num1 CO co_num2. "如果true,sy-fdpos值为op1的长度,定义的长度10 WRITE:/ 'true:',sy-fdpos. ELSE. "如果false,sy-fdpos的值为op1第一个不匹配字符偏移量 WRITE:/ 'fasle:',sy-fdpos. ENDIF. "CN Contains not only,和CO相反,op1 CN op2,op1不仅包号op2中字符 "true,sy-fdpos为op1第一个不匹配字符偏移量,false,sy-fdpos返回op1长度 "CA Contains Any,op1 CA op2,op1 包含任意op2中字符 "大小写敏感,末尾空格 DATA:ca_num1 TYPE C LENGTH 10 VALUE 'abc'. DATA:ca_num2 TYPE C LENGTH 5 VALUE 'cde'. IF ca_num1 CA ca_num2. "如果true,sy-fdpos的值为op1第一个匹配字符偏移量 WRITE:/ 'true:',sy-fdpos. ELSE. "如果false,sy-fdpos的值为op1长度 WRITE:/ 'fasle:',sy-fdpos. ENDIF. "NA Contains not Any,op1 NA op2,op1不包含任意op2字符 "如果false,sy-fdpos的值为op1第一个匹配字符偏移量 "如果true,sy-fdpos的值为op1长度 "CS Contains string,op1 CS op2,op1包含op2 "大小写不敏感,头部空格会比较 DATA:cs_num1 TYPE C LENGTH 10 VALUE 'abc'. DATA:cs_num2 TYPE C LENGTH 5 VALUE 'ab'. IF cs_num1 CS cs_num2. "如果true,sy-fdpos的值为op1第一个开始匹配字符偏移量 WRITE:/ 'true:',sy-fdpos. ELSE. "如果false,sy-fdpos的值为op1长度 WRITE:/ 'fasle:',sy-fdpos. ENDIF. "NS Contains No string,op1 NS op2,op1不包含op2 "如果true,sy-fdpos的值为op1长度 "如果false,sy-fdpos的值为op1第一个开始匹配字符偏移量 "CP Cover Pattern,op1 CP op2,op1匹配op2 "使用*匹配字符串,+匹配任意单个字符 "大小写不敏感 DATA:cp_num1 TYPE C LENGTH 10 VALUE 'deabc'. DATA:cp_num2 TYPE C LENGTH 8 VALUE '*abc*'. IF cp_num1 CP cp_num2. "sy-fdpos contains the offset of operand2 in operand1 WRITE:/ 'true:',sy-fdpos. ELSE. "如果false,sy-fdpos的值为op1长度 WRITE:/ 'fasle:',sy-fdpos. ENDIF. "NP NO Pattern,op1 NP op2,op1不匹配op2 "字节数据类型关系比较,只支持xstring类型 "BYTE-CO,op1 BYTE-CO op2,op1 contains bytes only out of op2. "BYTE-CN,op1 contains bytes not only out of op2 "BYTE-CA,op1 contains any bytes out of op2 "BYTE-NA,op2 contains not any bytes out of op2 "BYTE-CS,op1 包含 op2 "BYTE-NS,op1 不包含op2 DATA:bco_num1 TYPE xstring. DATA:bco_num2 TYPE xstring. bco_num1 = '0811FE11'. "8011FE11都false,偏移量为0 bco_num2 = '0022FE11'. IF bco_num1 BYTE-CO bco_num2. "返回op1 length4,每两个字符占一个长度 WRITE:/ 'true:',sy-fdpos. ELSE. "false,返回op1,第一个不匹配字节偏移量 WRITE:/ 'fasle:',sy-fdpos. ENDIF. "Bit关系比较,只支持x,xstring类型 "O,Z,M DATA:b_num1 TYPE xstring VALUE '1111'. DATA:b_num2 TYPE xstring VALUE 'FFFF'. "Ones: True if the bits that are 1 in operand2, are also 1 in operand1. "If operand2 contains only zeroes, the logical expression is always true. IF bit_num1 O bit_num2. WRITE:/ 'true'. ELSE. WRITE:/ 'false'. ENDIF. "Zeros: True, if the bits that are 1 in operand2 are 0 in operand1. "If operand2 contains only zeroes, the logical expression is always true. IF bit_num1 Z bit_num2. WRITE:/ 'true'. ELSE. WRITE:/ 'false'. ENDIF. "Mixed: True, if of the bits that are 1 in operand2, at least one is 1 and one is 0 in operand1. "If operand2 contains only zeroes, the logical expression is always false. IF bit_num1 M bit_num2. WRITE:/ 'true'. ELSE. WRITE:/ 'false'. ENDIF. "布尔操作运算符 "AND,OR,NOT,EQUIV "文字运算符 "'...' & '...' & ... & '...' `...` & `...` & ... & `...` DATA:literal_num1 TYPE C LENGTH 10. DATA:literal_num2 TYPE C LENGTH 20. "只能运算字符,不能是变量 literal_num1 = 'he' & 'll' & 'o'. "literal_num2 = literal_num1 & literal_num1. ENDFORM.
本文来自博客园,作者:渔歌晚唱,转载请注明原文链接:https://www.cnblogs.com/tangToms/p/14686882.html