RPG IV - V6R1 Enhancements: Template File
Page 1 of 1
RPG IV - V6R1 Enhancements: Template File
Templates for Files
The TEMPLATE keyword may be specified for files. Files defined with the TEMPLATE keyword are not included in the program; the file definition is used only at compile time. The template file can only be used as a basis for defining other files later in the program using the new LIKEFILE keyword. The LIKEFILE keyword also allows you to pass a file as a parameter.
Let's look at an example:
(1) FCustomer IF E K Disk Template
P GetCustomer B
D GetCustomer PI N
(2) D customerFile LikeFile(Customer)
(3) D customerData LikeRec(CustomerR)
D customerKey Like(customerData.CustNo)
D Const
/Free
(4) Chain customerKey customerFile customerData;
If %Found(customerFile);
If customerData.Status <> 'D';
Return *On;
EndIf;
EndIf;
Return *Off;
/End-Free
P E
Here's a subprocedure to get a customer record.
Figure 5 shows a portion of a member containing a subprocedure (GetCustomer) that retrieves customer data. This member is compiled and placed in a service program. The main points to note are these (refer to the numbers above):
1. The TEMPLATE keyword is specified for the customer file. This means that the File specification is for reference purposes only, and the file definition may not be used for processing.
2. The LIKEFILE keyword identifies the first parameter as a file with the same characteristics as the Customer file.
3. The second parameter is the customer record that will be returned by the subprocedure.
4. The file parameter name is used to identify the file to be processed (i.e., customerFile not Customer). Since Input and Output specs are not generated for a template file or a file identified by LIKEFILE, you must use a result data structure for the CHAIN operation.
How do you call the GetCustomer subprocedure? Figure 6 shows a snippet of a program that performs a call. The file to be processed (CustFile) is simply passed as the first parameter. The format of the file CustFile must be the same as the Customer file.
FCustFile IF E K Disk
D custData DS LikeRec(CustFileR)
/Free
If GetCustomer(CustFile: CustFileR: 'THISCUST');
// DO cool things with data
EndIf;
The TEMPLATE keyword may be specified for files. Files defined with the TEMPLATE keyword are not included in the program; the file definition is used only at compile time. The template file can only be used as a basis for defining other files later in the program using the new LIKEFILE keyword. The LIKEFILE keyword also allows you to pass a file as a parameter.
Let's look at an example:
(1) FCustomer IF E K Disk Template
P GetCustomer B
D GetCustomer PI N
(2) D customerFile LikeFile(Customer)
(3) D customerData LikeRec(CustomerR)
D customerKey Like(customerData.CustNo)
D Const
/Free
(4) Chain customerKey customerFile customerData;
If %Found(customerFile);
If customerData.Status <> 'D';
Return *On;
EndIf;
EndIf;
Return *Off;
/End-Free
P E
Here's a subprocedure to get a customer record.
Figure 5 shows a portion of a member containing a subprocedure (GetCustomer) that retrieves customer data. This member is compiled and placed in a service program. The main points to note are these (refer to the numbers above):
1. The TEMPLATE keyword is specified for the customer file. This means that the File specification is for reference purposes only, and the file definition may not be used for processing.
2. The LIKEFILE keyword identifies the first parameter as a file with the same characteristics as the Customer file.
3. The second parameter is the customer record that will be returned by the subprocedure.
4. The file parameter name is used to identify the file to be processed (i.e., customerFile not Customer). Since Input and Output specs are not generated for a template file or a file identified by LIKEFILE, you must use a result data structure for the CHAIN operation.
How do you call the GetCustomer subprocedure? Figure 6 shows a snippet of a program that performs a call. The file to be processed (CustFile) is simply passed as the first parameter. The format of the file CustFile must be the same as the Customer file.
FCustFile IF E K Disk
D custData DS LikeRec(CustFileR)
/Free
If GetCustomer(CustFile: CustFileR: 'THISCUST');
// DO cool things with data
EndIf;
Similar topics
» RPG IV - V6R1 Enhancements: 2) Template Datastructure
» RPG IV - V6R1 Enhancements: 3) LIKEFILE
» RPG IV - V6R1 Enhancements: 1) Increased Length
» Copy Spool File to PF/Flat file
» Physical File & Logical File
» RPG IV - V6R1 Enhancements: 3) LIKEFILE
» RPG IV - V6R1 Enhancements: 1) Increased Length
» Copy Spool File to PF/Flat file
» Physical File & Logical File
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum