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

replace command

Former Member
0 Likes
721

Hi experts,

See the following code.

DATA STR(1000) TYPE C VALUE '1#02.11.2006#02.11.2006#1061#AUD##7#SA#Legacy data transfer1#Reference1'.

replace all occurrences of '#' in str with space.

if sy-subrc = 0.

write:/ str.

endif.

So the o/p is

102.11.200602.11.20061061AUD7SALegacy data transfer1Reference1

But the Actual o/p should be like this:

1 02.11.2006 02.11.2006 1061 AUD 7 SA Legacy data transfer Reference1

it should contain 10 fields in o/p...

Can anybody tell me what may be the problem in the code?

y it is not taking space?

Regrads

Ravi.

7 REPLIES 7
Read only

Former Member
0 Likes
682

Pleae try using translate instead.

DATA: STR(1000) TYPE C VALUE '1#02.11.2006#02.11.2006#1061#AUD##7#SA#Legacy' 
translate  str using  '# '.
IF SY-SUBRC = 0.
WRITE:/ STR.
ENDIF.

Read only

0 Likes
682

Hi,

Thanks..it is working...but see the below code.

TYPES: TY_D_ITABVALUE TYPE ALSMEX_TABLINE-VALUE,

TY_T_ITAB TYPE ALSMEX_TABLINE OCCURS 0,

BEGIN OF TY_S_SENDERLINE,

LINE(4096) TYPE C,

END OF TY_S_SENDERLINE,

TY_T_SENDER TYPE TY_S_SENDERLINE OCCURS 0 .

DATA: EXCEL_TAB1 TYPE TY_T_SENDER.

DATA : WA_EXCELTAB1 LIKE LINE OF EXCEL_TAB1.

data: str(2000) type c.

LOOP AT EXCEL_TAB1 INTO WA_EXCELTAB1.

str = WA_EXCELTAB1-line.

translate str using '#'.

MODIFY EXCEL_TAB1 FROM WA_EXCELTAB1.

CLEAR WA_EXCELTAB1.

ENDLOOP.

So here the same translate statement is not working..

WA_EXCELTAB1-line has value:1#02.11.2006#02.11.2006#1061#AUD##7#SA#Legacy data transfer1#Reference1

What may be the problem?

Regards

Read only

0 Likes
682

ur logic looking very clumsy..

try this way...ur modify EXCEL_TAB1 using WA_EXCELTAB1

but doing translate to str.

LOOP AT EXCEL_TAB1 INTO WA_EXCELTAB1.
*str = WA_EXCELTAB1-line.
translate WA_EXCELTAB1-line using '#'.
MODIFY EXCEL_TAB1 FROM WA_EXCELTAB1.
CLEAR WA_EXCELTAB1.
ENDLOOP.

Read only

0 Likes
682

May be u need to reassign str to WA_EXCELTAB1-line.

Read only

0 Likes
682

Try with the following code:

data: l_separator TYPE c.

l_separator = cl_abap_char_utilities=>horizontal_tab.

REPLACE ALL OCCURRENCES OF l_separator IN wa_data WITH space.

Read only

Former Member
0 Likes
682

Hi,

in ur code posted 2nd time

TYPES: TY_D_ITABVALUE TYPE ALSMEX_TABLINE-VALUE,

TY_T_ITAB TYPE ALSMEX_TABLINE OCCURS 0,

BEGIN OF TY_S_SENDERLINE,

LINE(4096) TYPE C,

END OF TY_S_SENDERLINE,

TY_T_SENDER TYPE TY_S_SENDERLINE OCCURS 0 .

DATA: EXCEL_TAB1 TYPE TY_T_SENDER.

DATA : WA_EXCELTAB1 LIKE LINE OF EXCEL_TAB1.

data: str(2000) type c.

LOOP AT EXCEL_TAB1 INTO WA_EXCELTAB1.

str = WA_EXCELTAB1-line.

<b>translate str using '# '.</b> <<make sure here u give 1 space after # inside the quotes,it will not work otherwise>>

MODIFY EXCEL_TAB1 FROM WA_EXCELTAB1.

CLEAR WA_EXCELTAB1.

ENDLOOP.

Read only

0 Likes
682

Hi all,

Thanks.