Showing posts with label EXPRESSION. Show all posts
Showing posts with label EXPRESSION. Show all posts

Friday, February 3, 2017

SAP Basic Operators, Keywords, Functions

Arithmetic Operators

Operator Using Operator Using Keyword
Less than a < b a LT B
Greater than a > b a GT b
Less than or equal a <= b a LE b
Greater than or equal a >= b a GE b
Equal a = b a EQ b
Not equal a <> b a NE b

Comparison Operators

Operator
Using Operator
Using Keyword
Addition
 p = n + m.
ADD n TO m.
Subtraction
 P = m – n.
SUBTRACT n FROM m.
Multiplication
 P = m * n.
MULTIPLY m BY n.
Division
 P = m / n.
DIVIDE m BY n.
Integer division
 P = m DIV n.
---
Remainder of division
 P = m MOD n.
---
Powers
 P = m ** n.

Logical Expressions

Expression Usage
AND (a<b) and (a<c)
OR (a<b) or (a<c)
NOT a NOT b
BETWEEN a BETWEEN b AND c
IS a IS (NULL/ASSIGNED/BOUND/INITIAL)

Numeric Data Types Functions

DATA

DATA n TYPE p DECIMALS 2.
DATA m TYPE p DECIMALS 2 VALUE '-5.55'.

Function Usage Output
ABS n = abs( m ).  WRITE:  'ABS: ', n. ABS: 5.55
SIGN n = sign( m ). WRITE: / 'SIGN: ', n. SIGN:  1.00-
CEIL n = ceil( m ). WRITE: / 'CEIL: ', n. CEIL:  5.00-
FLOOR n = floor( m ). WRITE: / 'FLOOR:', n. FLOOR: 6.00-
TRUNC n = trunc( m ). WRITE: / 'TRUNC:', n. TRUNC: 5.00-
FRAC n = frac( m ). WRITE: / 'FRAC: ', n. FRAC:  0.55-

Floating-Point Functions

Function Meaning
acos, asin, atan; cos, sin, tan Trigonometric functions.
cosh, sinh, tanh Hyperbolic functions.
exp Exponential function with base e (e=2.7182818285).
log Natural logarithm with base e.
log10 Logarithm with base 10.
sqrt Square root.


String Logical Expression

CO str1 only contains characters from <str2>;
CN  str1 contains characters not only from str2 (corresponds to NOT str1 CO str2);
CA  str1 contains at least one character from str2;
NA  str1 does not contain any characters from str2;
CS  str1 contains the string str2;
NS  str1 does not contain the string str2;
CP  str1 contains the pattern str2;
NP  str1 does not contain the pattern str2;

String Functions

DATA: title(15) TYPE c VALUE 'Mr',
surname(40) TYPE c VALUE 'Smith',
Forename(40) TYPE c VALUE 'Joe',
sep,  "an empty character by default"
Destination(200) TYPE c,
spaced_name TYPE STRING VALUE 'Joe Smith',
len TYPE i.

Function Usage Output
CONCATENATE DATA: title(15) TYPE c VALUE 'Mr',
      surname(40) TYPE c VALUE 'Smith',
      forename(40) TYPE c VALUE 'Joe',
      sep,  "an empty character by default"
      destination(200) TYPE c.
CONCATENATE title surname forename INTO destination SEPARATED BY sep. Mr Smith Joe 
CONDENSE DATA spaced_name TYPE string VALUE 'Joe         Smith'.
CONDENSE spaced_name. Joe Smith
CONDENSE NO GAPS CONDENSE spaced_name NO-GAPS. JoeSmith
STRLEN DATA len TYPE i.
len = strlen( surname ).
WRITE / len.
strlen( surname ). 5
REPLACE REPLACE ' ' WITH '-' INTO destination. Mr-Smith Joe
REPLACE ' ' WITH '-' INTO destination. Mr-Smith-Joe
REPLACE ALL OCCURRENCES REPLACE ALL OCCURRENCES OF '-' IN destination WITH '+'. Mr+Smith+Joe
SEARCH destination = 'Mr. Smith Joe'.
SEARCH destination for 'Joe   '. sy-fdpos 10
SEARCH destination for  '*ith'. sy-fdpos 4
SEARCH destination for 'John'. sy-subrc 4
SHIFT DATA empl_num TYPE STRING VALUE '0000654321'.
SHIFT empl_num. "become 000654321 000654321
SHIFT DELETE LEADING empl_num = '0000654321'.
SHIFT empl_num left deleting leading '0'. "become 654321 654321
SHIFT CURCULAR empl_num = '0000654321'.
SHIFT empl_num CIRCULAR. 0006543210
SPLIT DATA mystring TYPE string VALUE '1234** ACBD **6789'.
DATA: a(10) TYPE c,
      b(10) TYPE c,
      c(10) TYPE C, a 1234 
      sep2(2) TYPE c VALUE '**'. b  ABCD
SPLIT mystring AT sep2 INTO a b c. c 6789
SUBFIELDS DATA: int_tel_num(17) TYPE c VALUE '+62-812345678',
      country_code(3) TYPE c,
      tel_num(14) TYPE c.
country_code = int_tel_num(3). 62
tel_num = int_tel_num+4(13). 812345678


Formatting String Functions

Function Description
LEFT-JUSTIFIED Specifies that the output is left-justified.
CENTERED Denotes that the output is centered.
RIGHT-JUSTIFIED Specifies that the output is right-justified.
UNDER <g> The output starts directly under the field <g>.
NO-GAP Specifies that the blank after field <f> is rejected.
USING EDIT MASK <m> Denotes the specification of the format template <m>. Using No EDIT Mask: This specifies that the format template specified in the ABAP Dictionary is deactivated.
NO-ZERO If a field contains only zeroes, then they are replaced by blanks.

Formatting Numeric Functions

FunctionDescription
NO-SIGN Specifies that no leading sign is displayed on the screen.
EXPONENT <e> Specifies that in type F (the floating point fields), the exponent is defined in <e>.
ROUND <r> The type P fields (packed numeric data types) are first multiplied by 10**(-r) and then rounded off to an integer value.
CURRENCY <c> Denotes that the formatting is done according to the currency <c> value that is stored in the TCURX database table.
UNIT <u> Specifies that the number of decimal places is fixed according to the <u> unit as specified in the T006 database table for type P.
DECIMALS <d> Specifies that the number of digits <d> must be displayed after the decimal point.