How to remove comma for individual fields before inserting into comma seperated csv file in RPGLE

70 pts.
Tags:
AS/400 CSV
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 10  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    or perhaps %XLATE(from:to:string{:startpos}) as myString = %XLATE(',' ':mystring) Changes every , in mystring to a space. Phil
    49,830 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    Sorry .. more like this myString = %XLATE(’,’:' ‘:mystring)
    49,830 pointsBadges:
    report
  • ganeshpavi
    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 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    If you deliniate strings with ""'s then you need to remove the " from the strings.
    49,830 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • ISeriesGuyWI
    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 pointsBadges:
    report
  • BigKat
    I have seen them use the | for that same reason.
    8,100 pointsBadges:
    report
  • maguleri
    Use Data structure

    Regards,
    Manjeet

    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following