I'm trying to convert flat file to CSV file using RPGLE.
As it is a comma separated file for certain fields like description as and when comma is encountered data is written to next column. I need to place each field value in respective columns even if comma is present in a field value. Can some one suggest me how to overcome this?
Software/Hardware used:
AS400-RPGLE
ASKED:
February 16, 2012 5:00 AM
UPDATED:
February 27, 2012 8:29 PM
or perhaps
%XLATE(from:to:string{:startpos})
as
myString = %XLATE(‘,’ ‘:mystring)
Changes every , in mystring to a space.
Phil
It would be much easier if we could see a couple examples of the records. It can be valid to have commas as part of the data in a column. Removing all commas might not be appropriate.
Tom
Sorry .. more like this
myString = %XLATE(’,’:’ ‘:mystring)
Hi Pradeep,Philp and Tom,
Thanks for your assistance.The below code working fine without any issues.
D A S 10A INZ(‘AB,,,,E,FG’)
D B S 10A
C ‘,’:'-’ XLATE A A
C EVAL B = A
C EVAL *INLR = *ON
My final result is B = AB—-E-FG
I need to place each field value in respective columns even if comma is present in a field value.
This part wasn’t quite consistent — “…even if comma is present in a field value.”
You can leave the commas in the field value if you wish. You don’t need to remove them. Just put quotes around the field value when you put that value into the .CSV file. There’s no need to remove embedded commas.
I’m still not clear on what you actually want to accomplish; but if you have it working, that’s okay.
Tom
If you deliniate strings with “”‘s then you need to remove the ” from the strings.
If you deliniate strings with “”’s…
Either remove them or double them. But the OP might notice that after the first one appears in data. (Or potentially other characters that may have meaning to whatever will be using the .CSV as input…)
Of course, it could be a case of “There will never be one of those in there.”
Tom
Depending on what I am doing I usually use the ^ instead of the , as my separator. Then I don’t have to worry about embedded commas.
I have seen them use the | for that same reason.