Processing Character Strings

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Process character strings in an application program

Character String Functions

Process Character Strings in a Program

Processing Strings

String templates are ABAP expressions of result type string. You can use string templates in any reading operand position, for example, the right-hand side of a value assignment.

A string template begins and ends with a pipe symbol (|). The simplest possible string template contains nothing but literal text. In this form a string template is not really different from a string literal.

What distinguishes a string template from a string literal is the ability to embed expressions. An embedded expression is an ABAP expression surrounded by a pair of curly brackets ( { } ). At runtime, ABAP evaluates the embedded expression and translates the result into a string. In the result, this string replaces the embedded expression (together with the surrounding curly brackets).

Note
ABAP syntax requires at least one blank after the opening bracket and at least one blank before the closing bracket.

One string template can contain more than one embedded expression.

Inside the curly brackets you can place any kind of ABAP expression: arithmetic expressions, as in the example above, but single variables or eve literals can serve as embedded expressions.

Practice

To Join Strings with Operator &&

You can join fields together using the concatenation operator &&. You can join any combination of data objects and string expressions.

The variables above (Part1 and Part2) of the expression are joined with no space or other separator between them. If you need spaces or another separator or character, you must remember to insert it yourself as part of the expression, as shown in the figure above.

Business Example

Using the string example, users may wish to split their full name so that you can output just the first name. Create a new application program and split the name and adjust the output accordingly.

Steps

  1. Create a new ABAP class with the name, ZCL_S4D100_##_CHAR. Add it to your package and tie it to your transport request.

  2. Activate the application.

  3. Define three variables of type string to hold the full name, first and last names of the user. Name the Variables lv_full_naame, lv_first_name and lv_last_name.

  4. Split the full name into the first name and last name variables.

  5. Use the WRITE statement to output the user’s first name only.

  6. Activate and test the program. The following result appears:

Result

Save progress to your learning plan by logging in or creating an account