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

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

RPG IV - V6R1 Enhancements: Template File

View previous topic View next topic Go down

RPG IV - V6R1 Enhancements: Template File

Post  maran on Tue Sep 08, 2009 7:26 pm

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;
avatar
maran
Admin

Posts : 442
Join date : 2009-07-24

View user profile http://pmsinformationsystem.forumotion.net

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