Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

CONDENSE Statement to Remove, Trim Leading Spaces from a String

|| 0

CONDENSE Statement to Remove, Trim Leading Spaces from a String
Stechies

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'


Advertisement
Advertisement
Advertisement