PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Files go Locally

View previous topic View next topic Go down

Files go Locally

Post  maran on Fri Jan 13, 2012 6:02 pm

From V6 onwards we can define the files in subprocedures

By default, local files are opened each time the subprocedure is called and closed when the subprocedure returns to its caller. Since opening and closing files is a resource-intensive process, you can force the file to remain open by coding the STATIC keyword as shown at (A) below.

If you choose this option, you’re responsible for closing the file yourself. One common approach to handling this requirement is to call the subprocedure with no parameters and have the subprocedure logic treat this as a file close request.

The other effect of the STATIC keyword is that you lose the recursive ability of the file. In other words, the same instance of the file will be used at all invocation levels of the subprocedure—in other words, the same basic rules that apply to a variable defined with the STATIC keyword.

As you can see the F-spec follows the P-Spec and, as you would expect, must precede any D-specs.
P GetCustData B

(A) FCustMast IF E K Disk STATIC

D GetCustData PI N
(B) D custData LikeRec(CustMast: *Input)

(C) Chain custData.CustKey CustMast custData;
One important thing you need to be aware of when defining files in subprocedures is that no I or O specs are generated. As a result all I/O operations must use the DS result field approach. You can see this at (C) where the DS custData is being used to receive the record retrieved by the Chain operation. In this particular instance, the actual record area was passed in as a parameter and is defined in the procedure interface (PI) with the use of the LikeRec keyword. You can see this at (B). Note that since we’re reading the file, we also need to specify the *Input keyword to keep the compiler happy. You might also note that the key we used for the Chain was passed to us in this LikeRec DS. We did this just to point out that by definition anything created with the LikeRec keyword is implicitly qualified

Posts : 442
Join date : 2009-07-24

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum