70 pts.
 How to remove comma for individual fields before inserting into comma seperated csv file in RPGLE
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

Answer Wiki:
Yeah, I did the similar one for my project. Easy approach will be, having a common procedure, which will take string(which includes commas) as input and which should return a string without comma. Here, You may want to replace the Comma(,) with Blanks or Dot(.). You should be using %REPLACE Built in Function for replacing comma with Space. Sample Procedure might help you. <pre>PCheckComma B DCheckComma PI /Free Wk_Pos = %Scan(',':Wk_Field); Dow Wk_Pos > 0 ; Wk_Field = %Replace(' ':Wk_Field:Wk_Pos) ; Wk_Pos = *Zeros ; Wk_Pos = %Scan(',':Wk_Field); EndDo ; /End-free PCheckComma E </pre> Wk_Field is my string. Wk_Pos is the position where comma is existing in string. You can call this procedure for every character value by passing into Wk_Field. Pradeep.
Last Wiki Answer Submitted:  February 16, 2012  9:01 am  by  deepu9321   3,370 pts.
All Answer Wiki Contributors:  deepu9321   3,370 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

or perhaps
%XLATE(from:to:string{:startpos})
as
myString = %XLATE(‘,’ ‘:mystring)

Changes every , in mystring to a space.
Phil

 44,130 pts.

 

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

 107,985 pts.

 

Sorry .. more like this
myString = %XLATE(’,’:’ ‘:mystring)

 44,130 pts.

 

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

 70 pts.

 

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

 107,985 pts.

 

If you deliniate strings with “”‘s then you need to remove the ” from the strings.

 44,130 pts.

 

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

 107,985 pts.

 

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.

 80 pts.

 

I have seen them use the | for that same reason.

 7,175 pts.