× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi John,

I'd like to take 1 or more text/csv file(s), on one of our network drives, and append them into a single file on the same network drive.
Ie, file1's last record is followed by file2's first record, etc. I
want to do this using a straight up RPG program.

This is certainly do-able in RPG... though, it's easier yet in QShell. In Qshell, just do this:

cat singlefile.csv >> bigfile.csv

or perhaps

cat file1.csv file2.csv file3.csv >> bigfile.csv


In the first example, 'singlefile.csv' is added on to the end of 'bigfile.csv'. In the second example, file1, file2, and file3 are all added on to the end of bigfile.csv.

Note that the >> operator is what makes it append. If it were just > (one greater than, as opposed to two) it would replace the contents of the file.


I know I could do this using (embedded?) qshell if the files were
on the IFS. (or reading and writing using the IFS apis for that matter)

The files aren't on the IFS? Where are they? Either I'm lost, or you don't have a complete picture of what the IFS is.

IFS includes the ability to store PC-like files on the DASD of your i, but it ALSO includes the ability to access SMB ("Windows Networking"), NFS, NetWare and remote i5/OS systems. It also includes access to optical drives, access to your traditional libraries and objects. All of these different file systems are integrated together into one interface. That's why it's called "Integrated File System"

Access to files on local DASD:

/ = (/ is pronouced "root") Windows-like file system
/QOpenSys = Unix-like (case sensitive) file system
/QDLS = MS-DOS-like, OfficeVision & S/38 shared folders
/QOPT = Optical disks
/QSYS.LIB = traditional libraries & their objects

Network file systems:

/QNTC = SMB (Windows Networking)
/xxxxxx = NFS Networking (you decide the name when you mount
the network drive.)
/QFileSvr.400 = Other AS/400, iSeries, System i5, etc systems over
the network.
/QNetWare = NetWare

The QShell commands, as well as the APIs you can use from RPG (or other ILE languages), provide the ability to access all of these different things.


Is this possible to accomplish in RPG for network drive files?
Can anyone help with some direction, or, better keywords to search on
<g> ?

I explained Qshell, above. Here's the simplest way to do it in RPG (with the caveat that this doesn't take character sets or file formats into consideration -- it also doesn't do any error handling, it just says FIXME where you should include error handling...)

H DFTACTGRP(*NO) BNDDIR('QC2LE')

/copy ifsio_h
/copy errno_h

D inputfile s 500a
D outputfile s 500a
D fdin s 10i 0
D fdout s 10i 0
D len s 10i 0
D wlen s 10i 0
D buf s 65535a

/free

inputfile = 'singlefile.csv';
outputfile = 'bigfile.csv';

fdin = open( %trimr(inputfile)
: O_RDONLY );
if (fdin = -1);
// FIXME: failed, check errno
endif;

fdout = open( %trimr(outputfile)
: O_CREAT + O_WRONLY + O_APPEND + O_SHARE_RDONLY
: S_IRUSR + S_IWUSR + S_IRGRP + S_IROTH );
if (fdout = -1);
// FIXME: failed, check errno
endif;

len = read( fdin : %addr(buf): %size(buf) );
dow ( len > 0 );
wlen = write( fdout: %addr(buf): len );
if (wlen <> len);
// FIXME: not all data could be written!
endif;
len = read( fdin : %addr(buf): %size(buf) );
enddo;

callp close(fdout);
callp close(fdin);

*inlr = *on;

/end-free

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.