Summary -
In this topic, we described about the below sections -
The string operator put together two or more character-like operands and forms a string expression. The string expression result is a character string.
String expressions can occur on the right side of an assignment with the assignment operator =. The string expressions operands must have character-like data types.
Syntax -
| character-string1 | & | character-string2| & | character-string3|… .
{ operand1 && operand2 [ && operand3 ... ] }… .
- A character string is enclosed in two "|" characters.
- A character string starts with "|" and closed with "|" on the same line of the source code.
- When character strings are combining with &, 255-character restriction applies on it.
- When string expressions are combining with &&, trailing blanks are ignored.
Example -
Below example shows how the string operations coded in the program.
Code -
*&---------------------------------------------------------------------*
*& Report Z_STRING_OPERATORS
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_STRING_OPERATORS.
* Declaring variables
DATA W_R TYPE STRING.
* Concatenation (&) of srings enclosed in two "|"
W_R = | HELLO | & | WORLD..! |.
WRITE : 'Output-1: ',W_R.
* Concatenation (&&) of srings enclosed in two "|"
W_R = | HELLO | && | WORLD..! |.
WRITE : /'Output-2: ',W_R.
* Concatenation (&) of srings enclosed in two "'"
W_R = ' HELLO ' & ' WORLD..! '.
WRITE : /'Output-3: ',W_R.
* Concatenation (&&) of srings enclosed in two "'"
W_R = ' HELLO ' && ' WORLD..! '.
WRITE : /'Output-4: ',W_R.
* Concatenation (&) of srings enclosed in two "`"
W_R = ` HELLO ` & ` WORLD..! `.
WRITE : /'Output-5: ',W_R.
* Concatenation (&&) of srings enclosed in two "`"
W_R = ` HELLO ` && ` WORLD..! `.
WRITE : /'Output-6: ',W_R.
Output -
Explaining Example -
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
W_R = | HELLO | & | WORLD..! |, concatenation (&) of srings enclosed in two "|" and retains all spaces after concatenation. Similarly, all the concatenations retains all spaces from inputs after concatenation execept below.
W_R = ' HELLO ' && ' WORLD..! ', concatenates the strings but retains only one space between the strings and retains strings in all other places.