abap commands
TRANSCRIPT
![Page 1: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/1.jpg)
ABAP COMMANDS
Logical Expressions– Comparison between Data Types.
EQ (or) = Equal To
NE (or) <> (or) >< Not Equal To
LT (or) < Less Than
LE (or) <= Less Than or Equal to
GT (or) > Greater Than
GE (or) >= Greater Than or Equal To
-Comparison between Strings.
CO Contains Only
CN Contains Not Only
CA Contains Any
NA Contains Not Any
CS Contains String
NS Contains No String
CP Matches pattern
NP Does not Matches pattern
• The special statements for processing strings, there are special comparisons that you can apply to strings with types C, D, N, and T.
• There are no conversions with these comparisons. Instead, the system compares the characters of the string.
![Page 2: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/2.jpg)
Examples
f1 operator F2 Result
'BD ' CO 'ABCD ' true
'BD ' CO 'ABCDE' false
'ABC12' CN 'ABCD ' true
'ABABC' CN 'ABCD ' false
'ABcde' CA 'Bd ' true
'ABcde' CA 'bD ' false
'ABAB ' NA 'AB ' false
'ababa' NA 'AB ' true
'ABcde' CS 'bC ' true
'ABcde' CS 'ce ' false
'ABcde' NS 'bC ' false
'ABcde' NS 'ce ' true
'ABcde' CP '*b*' true
'ABcde' CP '*#b*' false
'ABcde' NP '*b*' false
'ABcde' NP '*#b*' true
![Page 3: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/3.jpg)
- Comparing Bit Sequences
O bits are one
Z bits are Zero
M bits are Mixed
• The above three operators to compare the bit sequence of the first operand with that of the second.
• The second operand must have type X. • The comparison takes place over the length of the second operand. • The first operand is not converted to type X.
Example :REPORT demo_log_expr_bits .DATA: text(1) TYPE c VALUE 'C', hex(1) TYPE x, i TYPE i.
hex = 0.
DO 256 TIMES. i = hex. IF text O hex. WRITE: / hex, i. ENDIF. hex = hex + 1.ENDDO.
The output is as follows:
00 001 102 203 340 6441 6542 6643 67
![Page 4: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/4.jpg)
- Checking whether a field belongs to a range
• The following logical expression to check whether the value of a field lies within a particular range:
.... <f1> BETWEEN <f2> AND <f3> .....
Example:
DATA: NUMBER TYPE I,FLAG....
NUMBER = ...
...
IF NUMBER BETWEEN 3 AND 7. FLAG = 'X'.ELSE. FLAG = ' '.ENDIF.
In this example, the value of the field FLAG is set to X if the value of NUMBER is between 3 and 7.
- Checking for the Initial Value
• The following logical expression to check whether the value of a field is initial: .... <f> IS INITIAL .....
• This expression is true if the field <f> contains the initial value for its type.
• To set the initial value of an elementary or aggregate field, use the statement CLEAR <f>.
![Page 5: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/5.jpg)
Example:
DATA FLAG VALUE 'X'.
IF FLAG IS INITIAL. WRITE / 'Flag is initial'. ELSE. WRITE / 'Flag is not initial'. ENDIF.
CLEAR FLAG.
IF FLAG IS INITIAL. WRITE / 'Flag is initial'. ELSE. WRITE / 'Flag is not initial'.ENDIF.
The output is as follows:
Flag is not initial
Flag is initial.
- Checking Selection Criteria
• The following logical expression to check whether the contents of a field satisfy the criteria in a selection table:
... <f> IN <seltab> ....
DATA WA TYPE SPFLI.
SELECT-OPTIONS S_CARRID FOR WA-CARRID.
IF 'LH' IN S_CARRID. WRITE 'LH was selected'.ENDIF.
The logical expression in the IF statement is true if the user entered a selection on the selection screen containing the value ‘LH’.
![Page 6: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/6.jpg)
Field Symbols
Field symbols are symbolic names declared with field-symbols to which a memory area can be assigned during program runtime. A field symbol can be used instead of data objects at operand positions of statements.
- Checking Whether a Field Symbol is Assigned
• To check whether a field is assigned to a field symbol, use the following logical expression: ... <FS> IS ASSIGNED.
FIELD-SYMBOLS <FS>.
DATA TEXT(10) TYPE C VALUE 'Assigned!'.
ASSIGN TEXT TO <FS>.
IF <FS> IS ASSIGNED. WRITE <FS>.ENDIF.
The output is:
Assigned!
since the logical expression in the IF statement is true.
![Page 7: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/7.jpg)
- Combining Several Logical Expressions
• You can combine several logical expressions together in one single expression by using the logical link operators AND and OR:
• To combine several logical expressions together in one single expression which is true only if all of the component expressions are true, link the expressions with AND.
• To combine several logical expressions together in one single expression which is true if at least one of the component expressions is true, link the expressions with OR.
• To negate the result of a logical expression, NOT operator can be used.
DATA: F TYPE F VALUE '100.00',N(3) TYPE N VALUE '123',C(3) TYPE C VALUE '456'.
WRITE 'The following logical expression is true:'.
IF ( C LT N ) AND ( N GT F ). WRITE: / '(',C,'lt',N,') AND (',N,'gt',F,')'.ELSE. WRITE: / '(',C,'ge',N,') OR (',N,'le',F,')'.ENDIF.
The output is:
The following logical expression is true:
( 456 ge 123 ) OR ( 123 le 1.000000000000000E+02 )
The logical expression in the IF statement is true, and the inverted expression is displayed.
![Page 8: Abap Commands](https://reader036.vdocuments.mx/reader036/viewer/2022082502/54e862f54a7959ac7a8b4619/html5/thumbnails/8.jpg)
- BASIC ABAP COMMANDS