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: 2) Template Datastructure

View previous topic View next topic Go down

RPG IV - V6R1 Enhancements: 2) Template Datastructure

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

Templates

The TEMPLATE keyword allows you to define template data structures, standalone fields, and files.

Templates for Data Structures
The concept of a template for data structures is not new. Figure 3 shows the traditional way of defining and using a virtual template. The data structure Phone contains the definition of a phone number (complicated things, really); the data structure is based on a pointer (DummyPtr), which is never set, so it does not occupy any storage in the program. The data structures to be used in the program, HomePhone, CellPhone and WorkPhone, are all defined using LIKEDS(PHONE). Any required subfield initialization is performed in the program. The main problem with this method is that you have to initialize the subfields in the calculation code of the program.





D Phone DS Based(DummyPtr) Qualified

D CountryCode 5i 0

D NDDPrefix 5

D AreaCode 5

D Number 9

D Extension 4

D IDDPrefix 5

D HomePhone DS LikeDS(Phone)

D CellPhone DS LikeDS(Phone)

D WorkPhone DS LikeDS(Phone)

/Free

HomePhone.CountryCode = 353;

CellPhone.CountryCode = 353;

WorkPhone.CountryCode = 353;

This virtual template uses BASED and LIKEDS.


At first glance, they are fairly similar, the major difference being the use of the INT keyword on the DS definition of PHONE and the INZ(353) for the CountryCode subfield in Phone. The use of the INZ keyword with the template data structure means the same initialization may be applied to any dependent data structures (defined using LIKEDS) by specifying INZ(*LIKEDS).


D Phone DS Template Inz

D CountryCode 5i 0 Inz(353)

D NDDPrefix 5

D AreaCode 5

D Number 9

D Extension 4

D IDDPrefix 5

D HomePhone DS LikeDS(Phone)

D Inz(*LikeDS)

D CellPhone DS LikeDS(Phone)

D Inz(*LikeDS)

D WorkPhone DS LikeDS(Phone)

D Inz(*LikeDS)

Use the TEMPLATE keyword to define a data structure.



The TEMPLATE keyword may also be applied to a standalone field.


A definition defined with a TEMPLATE keyword may only be used as a parameter for the LIKE or LIKEDS keywords or the %SIZE, %LEN, %ELEM, or %DECPOS BIFs; it may not be used as a normal data structure or field.
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