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



A real easy solution to reuse the same file is to place the file within a Subprocedure for access.

Then you don't need to use either EXTFILE or EXTDESC.

You can even keep the "static" open of the file using the Static keyword. You just have to make sure the Subprocedure handles its own close.


Dcl-ds FileDS_t Extname('ALBUM') Qualified Template End-ds;

Dcl-ds AlbumDS Likeds(FileDS_t);

AlbumDS.id = 1;
If not Get_ALBUM( AlbumDS );
// error
Endif;
AlbumDS.name = 'update';
If Not Update_ALBUM( AlbumDS);
// Error
Endif;

//close
Get_ALBUM( );
Update_ALBUM( );
*inlr= *On;
Return;



Dcl-Proc Get_ALBUM;
Dcl-Pi *N IND;
PData Likeds(FileDS_t) Options(*Nopass);
End-pi;
Dcl-f ALBUM USAGE(*INPUT) KEYED QUALIFIED USROPN STATIC;
Dcl-DS RsFIL EXTNAME('ALBUM':*INPUT) Qualified End-DS;
Dcl-DS kyFil EXTNAME('ALBUM':*Key) Qualified End-DS;

IF %PARMS() < %PARMNUM(PData);
If %Open(ALBUM);
CLOSE ALBUM;
Endif;
RETURN *OFF;
Endif;
If Not %Open(ALBUM);
Open ALBUM;
Endif;

Clear kyFil;
Eval-Corr kyFil = PData;
Chain %Kds( KyFil) ALBUM RsFil;
If %Found( ALBUM );
Eval-Corr PData = RsFil;
Return *On;
Else;
Return *Off;
Endif;

End-proc;


Dcl-Proc Update_ALBUM;
Dcl-Pi *N IND;
PData Likeds(FileDS_t) Options(*Nopass);
End-pi;
Dcl-f ALBUM USAGE(*UPDATE:*OUTPUT) KEYED QUALIFIED USROPN STATIC;
Dcl-DS RsFIL EXTNAME('ALBUM':*INPUT) Qualified End-DS;
Dcl-DS outFIL EXTNAME('ALBUM':*OUTPUT) Qualified End-DS;
Dcl-DS kyFil EXTNAME('ALBUM':*Key) Qualified End-DS;

IF %PARMS() < %PARMNUM(PData);
If %Open(ALBUM);
CLOSE ALBUM;
Endif;
RETURN *OFF;
Endif;
If Not %Open(ALBUM);
Open ALBUM;
Endif;

Clear RsFile;
Clear OutFile;
Eval-Corr OutFil = PData;
Clear kyFil;
Eval-Corr kyFil = PData;
Chain %Kds( KyFil) ALBUM RsFil;
If Not %Found( ALBUM );
Write ALBUM.ALBUM OutFil;

Elseif RsFil <> OutFil;
Update ALBUM.ALBUM OutFil;
Else;
Unlock ALBUM;
Endif;
Return *ON;

End-proc;




--
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.

From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of dfreinkel@xxxxxxxxxxxxxxxxx
Sent: Wednesday, August 17, 2022 8:49 AM
To: 'RPG programming on IBM i' <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Keyword to the F-Spec - How do we add a keyword to point to the actual file and library to use


We are working with some old style programs that use the same file defined

twice in the program. Once for inquiry and the second for update.





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.