RPG ILE Scan csv file

45 pts.
Tags:
CSV
IBM iSeries
RPG ILE
I am scanning a comma delimited file for elements to populate a db2 file. However, it is not picking up the last segment because there is no ending comma. How can you recognize the end of a row?

Software/Hardware used:
iSeries - excel csv file

Answer Wiki

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

What are you using to do the scan?

Discuss This Question: 6  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
  • CharlieBrowne
    What are you using to do the scan?
    41,380 pointsBadges:
    report
  • Streeter
    I am using a SQLRPGLE program. Reads in the IFS .csv file and does a %scan to get each segment to update each appropriate field. It works great for all segments except the very last one where there is no comma following it. It loops through each segment by establishing a beginning position right after the comma. Some of the code is as follows: DOW fgets( %addr(string):%size(string):File_i) <> *Null; // Fromulate text line and write record... textln = string; @pos = 1; @fpos = 0; FOR i = 1 to 29; @spos = @pos; IF %subst(textln:@pos:1) = '"'; @spos = @spos + 1; @fpos = %scan('"':textln:@spos) ; @pos = @fpos + 2; ELSE; @fpos = %scan(',':textln:@pos); @pos = @fpos + 1; ENDIF; IF @spos >= @fpos;
    45 pointsBadges:
    report
  • Streeter
    The reason the last segment is not getting written is because, there is a line terminator in this segment. How do I get the date, but not the terminator.
    45 pointsBadges:
    report
  • JLatos
    A temporary solution (until you find a proper fix) would be to open the csv file in notepad++ or other text editor that allows you to record macros. Then you can record a macro of you hitting the END key, placing a comma, and hitting the down arrow. Play the macro to end of file and you're set. Save/close the file and upload as usual. Not a long term solution perhaps, but it could get you going today.
    20 pointsBadges:
    report
  • Streeter
    I figured out what to do. I scan for the carriage return and then use that postion - 1 for the final segment. thanks
    45 pointsBadges:
    report
  • TomLiotta
    It might be better simply to use the '_C_IFS_*()' APIs for all of it. You could use _C_IFS_fgets() to get a line at a time out of the streamfile. You wouldn't need to be as concerned about where lines start and end. The API mostly does it all for you. Tom
    125,585 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