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

String Processing with Pipe Separators==> '|'

Former Member
0 Likes
3,416

Hi,

I have a requirement as below. I have a long string to be updated based on the database values. The String:

1|10-1234 |009|||||KE| |HALB|M|051399||IN| ||||PRMS|||||||||||||||||||0001||15||0||||||||0|0|0|||||||||||||||||||||||KE||P ||20060729||||||||||||||00|||||NORM||||||||||||||||||||

Value 051399, 0 , 0 , 0 are to be modified with a values of different size. But the total no of pipe separators to be maintained. I need to update the value between the pipe separator but without affecting the exact location of the pipe separator as the data is processed further based on the '|' separator. Can you please suggest me a good solution for this.

Thanks and Regards,

Kannan.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,463

I agree with Ravi but if not wrong you want is that the number of pipes should not change ...correct ?

U can try the below logic.

data : begin of itab occurs 0,

f1(10),

f2(10),

.... f50(10),

end of itab.

split lstr at '|' into table itab.

move lnewf10 to itab-f10.

move lnewf13 to itab-f13.

....

concatenate itab-f1 itab-f2.....itab-f50 into lstr

separated by '|'.

5 REPLIES 5
Read only

Former Member
0 Likes
1,463

<i> need to update the value between the pipe separator but without affecting the exact location of the pipe separator</i> ..

this is not possible.

if you replace an existing text with some other text of different length, the position of the pipe will obviosly change.

Id the replaced string is smaller than the existing string, then it is possible.

split v_str at '|'into table itab .

read table itab with key data = '0156789'.

if sy-subrc = 0.

itab-data = '987666'.

modify itab index sy-tabix.

endif.

loop at itab.

concatenate v_str2 itab-data into v_str2 separated by '|'.

endloop.

Regards,

ravi

Message was edited by: Ravi Kanth Talagana

Read only

0 Likes
1,463

Hi Ravi / Anurag,

Thanks for your reply. I am sorry!. The position of the Separator '|' will get changed while updating the String but without affecting the number of the '|' Separator. I hope i made my question correct. Please let me know your suggestion.

Thanks and Regards,

Kanan.

Read only

0 Likes
1,463

We have already passed our suggestions !!

Read only

Former Member
0 Likes
1,464

I agree with Ravi but if not wrong you want is that the number of pipes should not change ...correct ?

U can try the below logic.

data : begin of itab occurs 0,

f1(10),

f2(10),

.... f50(10),

end of itab.

split lstr at '|' into table itab.

move lnewf10 to itab-f10.

move lnewf13 to itab-f13.

....

concatenate itab-f1 itab-f2.....itab-f50 into lstr

separated by '|'.

Read only

Former Member
0 Likes
1,463

Hi Kannan,

1)The string with pipe separator may get from an internal table.

2)Declare an work area for this internal table.

3) Move this string into work area by spliting at pipe symbol.

4)Now modify the required fields in the structure and concatenate the structre back to a string.

V_STRING contains your original string.

DATA WA_RECORD TYPE ITAB.

DATA ITAB1 TYPE ITAB OCCURS 0 WITH HEADER LINE.

SPILT V_STRING AT '|' INTO TABLE ITAB1.

READ ITAB1 INDEX 1 INTO WA_RECORD.

WA_RECORD-FIELD4 = 'NEW VALUE-4'.

WA_RECORD-FIELD5 = 'NEW VALUE-5'.

WA_RECORD-FIELD6 = 'NEW VALUE-6'.

CONCATENATE WA_RECORD-F1 ..... WA_RECORD-F15 INTO V_STRING.

Thanks,

Vinay