I have the following string:
6103951001#136,00#S0#0#99999999#8000010000#10.12.2019#
31.10.2019#"MATZOURAKIS IOANNISMROA118#OSPh"#99470##APE A 54226#K
What I want is to delete the special character HORIZONTAL_TAB(#) which is between " here is the part of the string: "MATZOURAKIS IOANNISMROA118#OSPh"
How can I do?
Thanks
PS. I am using the following to upload the data from a TAB delimited text file data: data_table type standard table of char255,
wa_data_table like line of data_table.
lv_file = p_file.
cl_gui_frontend_services=>gui_upload(
exporting
filename = lv_file
filetype = 'ASC'
changing
data_tab = data_table
Now I am doing the following in order to catch the problem
loop at data_table into wa_data_table.
find all occurrences of '"' in wa_data_table match count lv_count.
if sy-subrc = 0 and lv_count = 2.
* REPLACE ALL OCCURRENCES OF REGEX
* '(#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))' IN wa_data_table WITH ' '.
split wa_data_table at '"'
into split_data1 split_data2 split_data3.
replace all occurrences of cl_abap_char_utilities=>horizontal_tab
in split_data2 with ' '.
concatenate split_data1 split_data2 split_data3
into wa_data_table.
endif.
endloop.
I think that we must handle the cl_abap_char_utilities=>horizontal_tab not with the character # but in another way.
You can use following in ABAP to find this character and replace it:
data : lv_test type string VALUE '6103951001#136,00#S0#0#99999999#8000010000#10.12.2019# 31.10.2019#"MATZOURAKIS IOANNISMROA118#OSPh"#99470##APE A 54226#K'.
REPLACE ALL OCCURRENCES OF REGEX '(#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))' IN lv_test WITH ''.
write lv_test.
This is the correct solution for this problem.
replace all occurrences of regex
'(\t(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))'
in table data_table with ' '.
replace all occurrences of regex '["]' in table data_table with ''.
Thanks, I will test it today or tomorrow. Can someone explain me the REGEX (#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))?
go to this site: regex101.com. copy the regex in there and on the right it will give you the explanation (it's a bit much to type out in the comments). @ekekakos
It does not work in SAP.
@ekekakos I tested it myseld I created in se38 a new program and just pasted that code in there and executed it without problem. We are using BW 7.4.
Well I found the answer to my problem. As I told you this is a TAB character which is displayed as # by SAP. So we have to replace the # with \t, so the regex will be done: '(\t(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))'. This works fine. Thanks a lot.