ABAP Help Document (1): 1.1 Keywords

ABAP Help Document

1.ABAP Reference

ABAP is developed by SAP to build complex applications in the SAP environment. Three-layer structure: presentation layer, where users use GUI and Web Browser; application layer, composed of many application servers, which are the application execution environment; data layer, composed of database.

These three-layer communication components: ICM (Internet Communication Manager) network communication manager provides network communication, such as: Web Dynpro, BSP; RFC Interface, the same server, different servers directly call RFC Function.

SAP supports Unioncode and Non-Unioncode systems. Non-Unioncode means that one character uses one byte, Unioncode, universal code, uniform and unique encoding for all language characters, utf-8 occupies 1 to 4 bytes, utf-16 occupies 2 to 4 bytes, utf- 32 occupies 4 bytes.

Before Unioncode, SAP used ASCII, EBCDIC, etc. to represent characters with only one byte, and SJIS, BIG5, etc. used two bytes to represent characters.

Use Tcode:UCCHECK to check whether non-Unioncode Program can be converted to Unioncode Program.

1.1 ABAP keywords

Use Tcode:ABAPDOCU, open the ABAP help document, ABAP Words, you can view all the keywords of ABAP.

keywords, operands, operators.

Example 1:

"ABAP keywords, operands, operators
FORM f_abap_statement.
  "struct operand -
  DATA: BEGIN OF struc1,
        elem1 TYPE char1,
     END OF struc1.
  "Pass-access to the element under the structure
  struc1-elem1 = 'X'.
  "object operand ->
  DATA: lo_c1 TYPE REF TO c1.
  CREATE OBJECT lo_c1.
  lo_c1->method1( ).
  "Static object operand =>
  c1=>method2( ).
  "Interface operand~
  lo_c1->i1~imethod1( ).

  "Use keywords, add in front!
  DATA !type TYPE char1.
  !type = 'X'.
  MESSAGE !type TYPE 'S'.

  " operator
  "1. Assignment operator, =,?=
  "MOVE {source {TO|?TO} destination}
  " | {EXACT source TO destination}.
  DATA:num1 TYPE char10 VALUE '1234567890'.
  DATA: num2 TYPE char5.
  "Automatically truncate to length
  MOVE num1 to num2.
  num2 = num1.
  "Use EXACT, when the precision is lost, an exception is thrown
  "MOVE EXACT num1 TO num2.
  "?=,MOVE ?TO can only be used for objects
  "MOVE num1 ?TO num2.
  WRITE: /num1,num2.

  "2. Arithmetic operators
  " + |-|*|/|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.
  " divisibility
  cal_num2 = cal_num1 DIV cal_num2.
  WRITE: /cal_num1,cal_num2.
  "exponentiation
* cal_num2 = cal_num1 ** cal_num2.
* WRITE:/cal_num1,cal_num2.
  "remainder
* cal_num2 = cal_num1 MOD cal_num2.
* WRITE:/cal_num1,cal_num2.

  "3. Bit operation
  "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. String operation
  " &
  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. Comparison operation
  "= EQ,<>><NE,<LT,<=LE,>GT,>=GE
  "Character type data comparison relationship
  "CO Contains only, op1 CO op2, op1 only contains the characters in op2.
  "case sensitive, trailing space
  DATA: co_num1 TYPE C LENGTH 10 VALUE 'abcde'.
  DATA: co_num2 TYPE C LENGTH 5 VALUE 'abc'.
  IF co_num1 CO co_num2.
    "If true, the sy-fdpos value is the length of op1, and the defined length is 10
    WRITE:/ 'true:',sy-fdpos.
  ELSE.
    "If false, the value of sy-fdpos is the offset of the first unmatched character in op1
    WRITE:/ 'fasle:',sy-fdpos.
  ENDIF.
  "CN Contains not only, contrary to CO, op1 CN op2, op1 not only includes the characters in op2
  "true, sy-fdpos is the offset of the first unmatched character in op1, false, sy-fdpos returns the length of op1

  "CA Contains Any,op1 CA op2,op1 contains any character in op2
  "case sensitive, trailing space
  DATA:ca_num1 TYPE C LENGTH 10 VALUE 'abc'.
  DATA: ca_num2 TYPE C LENGTH 5 VALUE 'cde'.
  IF ca_num1 CA ca_num2.
    "If true, the value of sy-fdpos is the first matching character offset of op1
    WRITE:/ 'true:',sy-fdpos.
  ELSE.
    "If false, the value of sy-fdpos is the length of op1
    WRITE:/ 'fasle:',sy-fdpos.
  ENDIF.
  "NA Contains not Any, op1 NA op2, op1 does not contain any op2 characters
  "If false, the value of sy-fdpos is the first matching character offset of op1
  "If true, the value of sy-fdpos is the length of op1

  "CS Contains string, op1 CS op2, op1 contains op2
  "Case insensitive, head spaces will be compared
  DATA: cs_num1 TYPE C LENGTH 10 VALUE 'abc'.
  DATA: cs_num2 TYPE C LENGTH 5 VALUE 'ab'.
  IF cs_num1 CS cs_num2.
    "If true, the value of sy-fdpos is the first match character offset of op1
    WRITE:/ 'true:',sy-fdpos.
  ELSE.
    "If false, the value of sy-fdpos is the length of op1
    WRITE:/ 'fasle:',sy-fdpos.
  ENDIF.
  "NS Contains No string, op1 NS op2, op1 does not contain op2
  "If true, the value of sy-fdpos is the length of op1
  "If false, the value of sy-fdpos is the first match character offset of op1

  "CP Cover Pattern, op1 CP op2, op1 matches op2
  "Use * to match a string, + to match any single character
  "case insensitive
  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.
    "If false, the value of sy-fdpos is the length of op1
    WRITE:/ 'fasle:',sy-fdpos.
  ENDIF.
  "NP NO Pattern, op1 NP op2, op1 does not match op2

  "Byte data type relationship comparison, only supports xstring type
  "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 contains op2
  "BYTE-NS, op1 does not contain op2
  DATA: bco_num1 TYPE xstring.
  DATA: bco_num2 TYPE xstring.
  bco_num1 = '0811FE11'. "8011FE11 are all false, the offset is 0
  bco_num2 = '0022FE11'.
  IF bco_num1 BYTE-CO bco_num2.
    "Return op1 length4, every two characters occupy a length
    WRITE:/ 'true:',sy-fdpos.
  ELSE.
    "false, return op1, the first one does not match the byte offset
    WRITE:/ 'fasle:',sy-fdpos.
  ENDIF.

  "Bit relationship comparison, only supports x, xstring type
  "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.

  " Boolean operator
  "AND,OR,NOT,EQUIV
  
  " literal operator
  "'...' & amp; '...' & amp; ... & amp; '...' `...` & amp; `...` & amp ; ... & `...`
  DATA:literal_num1 TYPE C LENGTH 10.
  DATA:literal_num2 TYPE C LENGTH 20.
  " can only operate on characters, not variables
  literal_num1 = 'he' & 'll' & 'o'.
  "literal_num2 = literal_num1 & literal_num1.
ENDFORM.