2016 Mar 19 8:49 PM
I have a file on the sap server which looks something like this:
0001#Text#gfdkgh#
0002#more#ljjpoir#
0003#then#ljddpoiw#
I want a program to remove the last hash character from each line.
I can read this file with OPEN DATASET etc, then REVERSE the line, and REPLACE FIRST CHAR with SPACE. This works fine but I wanted to find out if it could be done with REGEX as it might be more economical?
All help greatly appreciated. Thank you.
2016 Mar 19 9:10 PM
You could use
REPLACE FIRST OCCURRENCE OF REGEX '(.*)#$' IN line WITH '$1'.
but a simply
SHIFT line RIGHT DELETING TRAILING '#'.
should also do the job.
BR,
Gábor
2016 Mar 19 9:10 PM
You could use
REPLACE FIRST OCCURRENCE OF REGEX '(.*)#$' IN line WITH '$1'.
but a simply
SHIFT line RIGHT DELETING TRAILING '#'.
should also do the job.
BR,
Gábor
2016 Mar 19 9:40 PM
2016 Mar 20 2:23 AM
Could it be that your server is UNIX and the file from Windows? I'd check the last character in debug - if it is x13 (CR), the file was likely FTPed in binary mode, not ASCII mode. Check the addition 'smart line feed' in 'open dataset'. It ignores CR.
I know, not a direct answer to your question, but it may save you some hassle...
Wolfgang
2016 Mar 21 1:39 PM
Well well well......
Mr Propfe - A very long time no see. I hope you are doing well ?
Regards,
Rich
Oh - and to answer the question, a # is not always a # - it's a non-printable character with an ascii code less than $0F.
Rich
2016 Mar 20 11:40 AM
Hi Glen,
regex is extremely powerful but quite slow. Test the perfromance difference of
REPLACE FIRST OCCURRENCE OF REGEX '(.*)#$' IN line WITH '$1'
against
SHIFT line RIGHT DELETING TRAILING CL_ABAP_CHAR_UTILITIES=>NEWLINE. "or CR_LF
The character displayed as '#' is probably a contraol character, check out the CL_ABAP_CHAR_UTILITIES attributes.
Regards Clemens
.