45 pts.
 RPG ILE Scan csv file
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
ASKED: July 14, 2011  1:20 PM
UPDATED: March 31, 2012  9:27 PM
  Help
 Approved Answer - Chosen by carlosdl

I figured out what to do. I scan for the carriage return and then use that postion - 1 for the final segment.

thanks

ANSWERED:  Jul 14, 2011  4:18 PM (GMT)  by carlosdl

 
Other Answers:

What are you using to do the scan?

Last Wiki Answer Submitted:  July 14, 2011  1:25 pm  by  CharlieBrowne   32,785 pts.
Latest Answer Wiki Contributors:  CharlieBrowne   32,785 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


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


 

What are you using to do the scan?

 32,785 pts.

 

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 pts.

 

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 pts.

 

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 pts.

 

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

 107,765 pts.