Strings are character fields, which don't really have a size. As field type in a (DDIC) table that's not possible - but in Abap memory it is ! If you are not used to strings yet, you will be soon. They reflect a certain freedom to the developer. Instead of an internal table of 100-character fields holding 1000 lines, the same table defined as strings consumes a lot less memory space. How ? Smart SAP memory management.
The length of a text field or string can be determined with STRLEN
or with the DESCRIBE FIELD
statement.
If you get into a little more than average detail concerning strings, you'll come across blanks or spaces in your string. The CONDENSE
statement can be used to clean up the string. Can more be said about blanks ? Or rather: White-space ?
The Regular Expression or RegEx is very common in many programming languages and it is also available in ABAP.
When using strings (or character fields), a nice alternative to the CONCATENATE
statement is the &&
operator. The example shows it all.
str = 'Hello' &&
' my' && ' friend'.
There is also the & literal, which does something very similar, but with a maximum of 255 characters (performed at compile time).
Would you like to get rid of spêciãl characters ? Here's how to do that using TRANSLATE
.
SAP has this simple short and sweet function module called STRING_CENTER
which does what it's name implies. Center a string, align in the middle. However: the function module is marked as obsolete and I can't find it's replacement/successor.. So here's the coding.
If a number or non-printable character is placed in a CHAR
-variable, it will be displayed as a #.
Here's a routine that shows ABAP/4 is not really 4GL. Sometimes it could be useful to add 1 to a character string.
Adding 1 to "B" would result in "C". The use of TRANSLATE
can come in quite handy here.
Large strings: type XSTRING
can be used to hold large XML file content or even in the process of creating a PDF file. XSTRING
is a predefined data type in Abap/4. It works pretty much like a string, but with no limits to it's size. Both STRING
and XSTRING
have a variabele maximum size.