|
FilNamPath ='QSYS.LIB/'+ %Trim(inLibrary)+'.LIB/'+ %TRIM(inFile) +'.FILE/' + %TRIM(inFile) +'.MBR' + x'00';
There are two types of pathnames that can be used in the IFS: Absolute and Relative. A relative pathname starts with whatever the user's current directory is, and goes forward from there.
The way the system knows whether you're using a relative pathname or an absolute, is that absolute pathnames start with a slash in the first character. So if you had started FilNamPath with the '/' character, it'd be an absolute pathname. Since you didn't, it's a relative pathname.
That means that a user could type CHDIR DIR('/test') and your program would add that directory to the start of the pathname. In other words, it would look in '/test/QSYS.LIB/whatever.LIB/whatever.FILE/whatever.MBR'. If the user typed CHDIR DIR('/QSYS.LIB/MYLIB.LIB') then your program would look for the member in '/QSYS.LIB/MYLIB.LIB/QSYS.LIB/whatever.LIB/whatever.FILE/whatever.mbr'
Hopefully it's now clear that with the way your code is written, you REALLY wanted to use an absolutel pathname not a relative one. Please insert a leading slash into FilNamPath.
Furthermore, your prototype for open() should have options(*string) on the first parameter. Assuming that it does (and therefore is correct), there's no reason to add x'00' to the end of the pathname. Adding x'00' is just confusing.
OpenFlag = O_RDONLY; RC = Open(%Trim(FilNamPath):OpenFlag);
Since you used a VARYING field for FIlNamPAth there's absolutely no reason to %trim() it here.
TempStmfFile = 'QSYS.LIB/GGPRD.LIB/TMPSTMF.FILE/TMPSTMF.MBR' + x'00';
This has the same problems as FilNamPath.
OpenFlag2 = O_CREAT + O_RDWR + O_APPEND + O_TEXTDATA + O_CODEPAGE + S_IWUSR+S_IRUSR+S_IRGRP+S_IROTH;
This isn't legal. The flags for the file's permissions (or "mode") go into a separate parameter from the open flags.
Therefore, you should have: OpenFlag2 = O_CREAT + O_RDWR + O_APPEND + O_TEXTDATA + O_CODEPAGE; ModeFlags = S_IWUSR + S_IRUSR + S_IRGRP + S_IROTH;
RC2=unlink(TempStmfFile); RC2 = Open(%Trim(TempStmfFile):OpenFlag2);
Again, there's no need to use %trim(). Also, you need to add the ModeFlags parameter. Also, because you specified O_CODEPAGE, you have to add the codepage to the parameters.
RC2 = Open(TempStmfFile: OpenFlag2: ModeFlags: CodePage);Also, I'm a bit baffled why you'd specify O_TEXTDATA on a file that you're just creating now. The system doesn't know what codepage to translate to, so the O_TEXTDATA will effectively be ignored.
As to whether it's possible to create a PF this way, I really doubt it. You might be able to add a member to an existing PF, but I really doubt that you can create the PF itself, the APIs just don't have enough info about the file format.
plus, these APIs are really designed for stream files, not physical files. So they're not geared up for what you're trying to do.
Is there a particular reason you aren't using RPG's extensive capabilities for working with database files instead of trying to use APIs intended for stream files?
As an Amazon Associate we earn from qualifying purchases.
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.