Usage of Operator +n and (n) to pass data in ABAP

The +n and (n) operators in ABAP are powerful tools for string manipulation and substring extraction. These operators allow you to specify string offsets and lengths to extract specific portions of character data.

If my date format is in the form DDMMYYYY then Z_Period(4) equals DDMM so (4) means first four characters.

If my date format is in the form DDMMYYYY then Z_Period +4 equals YYYY so +4 means after the first four characters.

So if I say Z_PERIOD+2(2) then this would result MM ? i.e. 2 characters after first 2.

Understanding the Operators

"+n" specifies a string offset ? it tells ABAP to start from the nth position in the string.

"(n)" specifies length of the string ? it tells ABAP how many characters to extract.

"+n(m)" combines both ? start from position n and extract m characters.

Example

Let us see how to use them in a program ?

*Sample program to understand use of +n and (n) operators

DATA: lv_text(10) TYPE c,
      lv_date(8)  TYPE c.

lv_text = 'HelloWorld'.
lv_date = '25122023'.

WRITE: / 'Original text: ', lv_text.
WRITE: / 'First 5 chars: ', lv_text(5).
WRITE: / 'After 5th char: ', lv_text+5.
WRITE: / '2 chars from 3rd position: ', lv_text+2(2).

WRITE: / 'Date: ', lv_date.
WRITE: / 'Day: ', lv_date(2).
WRITE: / 'Month: ', lv_date+2(2).
WRITE: / 'Year: ', lv_date+4(4).

The output of the above code is ?

Original text: HelloWorld
First 5 chars: Hello
After 5th char: World
2 chars from 3rd position: ll
Date: 25122023
Day: 25
Month: 12
Year: 2023

Conclusion

The +n and (n) operators provide efficient string manipulation capabilities in ABAP, allowing precise extraction of substrings through offset and length specifications.

Updated on: 2026-03-13T18:26:14+05:30

379 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements