If I already have an IFS file on the IFS in CCSID 1252 (meaning my RPG program did not create it), what is the proper open() and read() parameters to get ascii data into RPG variables? I cannot seem to get passed the open statement. The file already existing on the IFS is a requirement that I am not wanting to get around. I just want to open a pre-existing IFS file and read it. :-)
Here's my code:
Here's my code:
Code:
d fd s 10i 0 inz
d ifsError s n inz
d len s 10u 0 inz
d flags s 10u 0 inz
d path s 256a inz
d data s 1000a inz
d* Reading Only
d O_RDONLY c 1
*---------------------------------------------------------------------------------------------
* Procedures
*---------------------------------------------------------------------------------------------
d open pr 10i 0 extproc('open')
d path * value options(*string)
d oflag 10i 0 value
d mode 10u 0 value options(*nopass)
d codepage 10u 0 value options(*nopass)
d read PR 10i 0 extproc('read')
d fildes 10i 0 value
d buf * value
d nbyte 10i 0 value
d close pr 10i 0 extproc('close')
d fildes 10i 0 value
*---------------------------------------------------------------------------------------------
* Main Program
*---------------------------------------------------------------------------------------------
/free
// global monitor
monitor;
path = '/a-file-import.csv';
flags = O_RDONLY;
fd = open( path : flags );
if fd < 0;
ifsError = *on;
*inlr = *on;
return;
endif;
len = read( fd : %addr(data) : %size(data) );
callp close( fd );
// global error catch
on-error;
endmon;
// end program
*inlr = *on;
return;
/end-free




Comment