‎2006 Jul 17 7:52 AM
Hi.
I need to remove som values in a string if it's longer than 18 char. The logic is as follows. If len > 18 start removing '-' from back of the string until (if possible) the length is 18.
I have probelms reaplcing from behind, any ideas?
/jon
‎2006 Jul 17 8:08 AM
Hi Jon,
Consider these code.
<b>If you want to repalce all '-' with spaces and condense</b>
REPORT zztest_arun_1 .
DATA : string TYPE string.
START-OF-SELECTION.
string = 'sdfsadf--asdf-asd-asd-'.
IF STRLEN( string ) GT 18.
TRANSLATE string USING '- '.
CONDENSE string NO-GAPS.
ENDIF.
WRITE : string.
<b>If you want to repalce only '-' till length 18 form backwards with spaces and condense</b>
REPORT zztest_arun_2 .
DATA : string TYPE string,
len TYPE i,
off TYPE i.
START-OF-SELECTION.
string = 'sdfsadf--asdf-asd-asd-'.
len = STRLEN( string ).
IF len GT 18.
DO.
IF STRLEN( string ) GT 18.
off = len - sy-index.
REPLACE '-' IN SECTION OFFSET off LENGTH -1 OF string WITH space.
CONDENSE string NO-GAPS.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
WRITE : string.
Regards,
Arun Sambargi
Message was edited by: Arun Sambargi
‎2006 Jul 17 7:55 AM
‎2006 Jul 17 7:56 AM
STRING = 'ABDCE'.
LEN = STRLEN( STRING ).
<b>if len > 18.</b>
use logic like that....
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
str(50),
END OF itab.
DATA : cha(50) VALUE 'cha-sek-jskjfsjf',
str(2000).
SPLIT cha AT '-' INTO TABLE itab.
loop at itab.
concatenate str itab-str into str separated by space.
endloop.
write : str.
‎2006 Jul 17 8:00 AM
hi Jon,
try this.
data var_len type i, ch type c.
var_len = strlen of string.
if var_len > 18.
var_len = var_len - 1.
ch = string+var_len(1).
do var_len times.
if ch = '-'.
delete that character.
endif.
enddo.
this is just a rough logic... try this.
regards,
Madan..
‎2006 Jul 17 8:08 AM
Hi Jon,
Consider these code.
<b>If you want to repalce all '-' with spaces and condense</b>
REPORT zztest_arun_1 .
DATA : string TYPE string.
START-OF-SELECTION.
string = 'sdfsadf--asdf-asd-asd-'.
IF STRLEN( string ) GT 18.
TRANSLATE string USING '- '.
CONDENSE string NO-GAPS.
ENDIF.
WRITE : string.
<b>If you want to repalce only '-' till length 18 form backwards with spaces and condense</b>
REPORT zztest_arun_2 .
DATA : string TYPE string,
len TYPE i,
off TYPE i.
START-OF-SELECTION.
string = 'sdfsadf--asdf-asd-asd-'.
len = STRLEN( string ).
IF len GT 18.
DO.
IF STRLEN( string ) GT 18.
off = len - sy-index.
REPLACE '-' IN SECTION OFFSET off LENGTH -1 OF string WITH space.
CONDENSE string NO-GAPS.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
WRITE : string.
Regards,
Arun Sambargi
Message was edited by: Arun Sambargi
‎2006 Jul 17 8:31 AM
Hi Jon
You can use the following code.
data: str(50 )type c.
data: len type i.
data: diff type i.
str = 'njiodjjjiojsjfgj----
'.
len = strlen( str).
diff = len - 18.
if diff > 0.
SHIFT str RIGHT DELETING TRAILING '-'.
endif.
I think this must solve out yor problem. If problem presists do reply.
‎2006 Jul 17 8:41 AM
hi.
and thanks to everyone helping!
this does not quite do what i need.
ie. i could get a string looking like this:
1234-678-12-34-56789
It's 19 char long and i need to remove the last '-' so that the string will be 1234-678-12-3456789
when testing all the possible solutions i'm only able to remove all the '-'.
i was thinking about writing the string in reverse to a temp_string and just replace first occ. of '-', but i cant find a easy way to reverse the string either...
/jon