Register Login

CONDENSE Statement to Remove, Trim Leading Spaces from a String

Updated Mar 31, 2020

CONDENSE Statement to Remove Spaces in Strings in SAP ABAP

For removing leading and closing blank completely and convert a sequence of blanks into a single blank for a string "CONDENSE statement in ABAP is used".

Syntax Used for it: CONDENSE text [NO-GAPS]

For removing the entire blank spaces the addition NO-GAPS is used.

To Remove Leading Spaces and Trailing Spaces We Can Make Use of CONDENSE

* CONDENSE to remove leading & trailing spaces
DATA: inputText(60) VALUE ' Hello this is test string to check condense statement ',
length TYPE I.

* Check string length before CONDENSE
length = STRLEN( inputText ).
WRITE: 'Before CONDENSE :' , inputText.
WRITE: 'Length: ', length

CONDENSE inputText .
length = STRLEN( inputText ).
WRITE: 'Input :' , inputText.
WRITE: 'Length: ', length.

Output:

Before CONDENSE : Hello this is test string to check condense statement 
Length: 55

After CONDENSE :Hello this is test string to check condense statement
Length: 53

To Remove the Spaces Between Words in the Given Text Use CONDENSE Input Text NO_GAPS

* CONDENSE with NO_GAPS
DATA: inputText(60) VALUE ' Hello this is test string to check condense statement ',
length TYPE I.

CONDENSE inputText NO-GAPS.
length = STRLEN( inputText ).
WRITE: 'Input :' , inputText.
WRITE: 'Length: ', length.

Output:

Input :Hellothisisteststringtocheckcondensestatement
Length: 45

To Remove Leading Spaces in Character Field We Can Use SHIFT ----LEFT---

DATA V_CURR(20) VALUE ' Test string to check shift ',
length TYPE I.

SHIFT V_CURR LEFT DELETING LEADING SPACE.
WRITE 'String LEFT :',V_CURR.

Output:

String LEFT :Test string to check shift

To Remove Trailing Spaces in Character Field We Can Use SHIFT ----RIGHT---

DATA V_CURR(20) VALUE ' Test string to check shift ',
length TYPE I.

SHIFT V_CURR RIGHT DELETING TRAILING SPACE.
WRITE 'String RIGHT :',V_CURR.

Output:

String LEFT : Test string to check shift

Note 
SHIFT V_CURR LEFT DELETING LEADING SPACE.
New String 'Test string to check shift '

SHIFT V_CURR RIGHT DELETING TRAILING SPACE.
New String ' Test string to check shift'


×