Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

modify the text data

Former Member
0 Likes
626

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
608

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

6 REPLIES 6
Read only

Former Member
0 Likes
609

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

Read only

0 Likes
608

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

Read only

0 Likes
608

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.

Read only

0 Likes
608

thanks,

let me work this and get back to you to award points.

SK

Read only

0 Likes
608

Thanks -:) I'm glad to help -:P

Greetings,

Blag.

Read only

0 Likes
608

Thanks, it worked. Shall award full points here.

SK