Files go Locally
Page 1 of 1
Files go Locally
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)
/Free
(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
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)
/Free
(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
Similar topics
» More than one REF files
» What is the difference between REF and CPT files?
» Open fILES
» DLTF Files
» Can we journal the files are in IFS?
» What is the difference between REF and CPT files?
» Open fILES
» DLTF Files
» Can we journal the files are in IFS?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum