‎2007 Jun 25 9:48 PM
hi folks,
I need some help with the logic to eliminate certain piece of code for formatting.
I have line item into which I read this text data 'Location: YACC ,,,, Department: Oral Surgery' I need to remove the comma it can 4 like in this case or 5 or any number, it sometimes comes in the middle of the lineitem or in the end of the line item. how can i do that?
So far I used replace syntax to catch that pattern but the problem is the code works for the first occurence not for many. How can i modify the code so that it can delete as many commas as it appears
data: v_pattern1(2) value ',,'.
data: v_pattern2(4) value ' ,,'.
In this case wa_lines = ''Location: YACC ,,,, Department: Oral Surgery' OR
wa_lines = 'Date Posted ,,,,,,' OR
wa_lines = 'The description of the position goes ,, in the following way'
loop at wa_lines
if wa_lines-tdline ne ' ' or not ( wa_lines-tdline is initial ).
replace v_pattern1 with ' ' into wa_lines-tdline.
replace v_pattern2 with '' into wa_lines-tdline.
concatenate wa_lines-tdline '|' into output.
TRANSFER output TO FNAME length l.
clear: output, l.
endif.
endloop.
Is there a better way to do this?
Thanks,
SK
‎2007 Jun 25 9:53 PM
Maybe you can do it like this...
REPORT ZDUMMY_ATG.
DATA: W_TEXT TYPE STRING,
FLAG TYPE C.
W_TEXT = 'ONE,,,,TWO,,THREE,,,,,'.
WHILE FLAG EQ SPACE.
SEARCH W_TEXT FOR ','.
IF SY-SUBRC EQ 0.
REPLACE ',' WITH SPACE INTO W_TEXT.
ELSE.
FLAG = 'X'.
ENDIF.
ENDWHILE.
WRITE:/ W_TEXT.
Result...
ONE TWO THREE
Greetings,
Blag.
Message was edited by:
Alvaro Tejada Galindo
‎2007 Jun 25 9:53 PM
Maybe you can do it like this...
REPORT ZDUMMY_ATG.
DATA: W_TEXT TYPE STRING,
FLAG TYPE C.
W_TEXT = 'ONE,,,,TWO,,THREE,,,,,'.
WHILE FLAG EQ SPACE.
SEARCH W_TEXT FOR ','.
IF SY-SUBRC EQ 0.
REPLACE ',' WITH SPACE INTO W_TEXT.
ELSE.
FLAG = 'X'.
ENDIF.
ENDWHILE.
WRITE:/ W_TEXT.
Result...
ONE TWO THREE
Greetings,
Blag.
Message was edited by:
Alvaro Tejada Galindo
‎2007 Jun 25 9:58 PM
Thanks for the quick reply. what if i need just one space between ONE TWO and THREE
like ONE TWO THREE inspite of having severla commas between them. How can I modify this?
Thanks in advance,
SK
‎2007 Jun 25 10:00 PM
Just add this line -:)
CONDENSE W_TEXT.
Just after the ENDWHILE....
REPORT ZDUMMY_ATG.
DATA: W_TEXT TYPE STRING,
FLAG TYPE C.
W_TEXT = 'ONE,,,,TWO,,THREE,,,,,'.
WHILE FLAG EQ SPACE.
SEARCH W_TEXT FOR ','.
IF SY-SUBRC EQ 0.
REPLACE ',' WITH SPACE INTO W_TEXT.
ELSE.
FLAG = 'X'.
ENDIF.
ENDWHILE.
CONDENSE W_TEXT.
WRITE:/ W_TEXT.
Result...
ONE TWO THREE
Greetings,
Blag.
‎2007 Jun 25 10:15 PM
thanks,
let me work this and get back to you to award points.
SK
‎2007 Jun 25 10:17 PM
‎2007 Jun 25 11:19 PM