PPG Tutorial

Creating and Using Templates

The programs you've worked with so far handle singular information: You scan or enter one code at a time, and the data is stored one entry per line. But suppose you wanted to collect sets of different types of data. If you were taking inventory, for example, rather than scanning each item in a group of identical products, you might want to scan only one of them and then use the data keys to record the number of items in the group.

You could add another Input node to the Collect Data frame of your program to store the types of data in different registers, but the data file you would end up with would have code numbers and quantity numbers on alternate lines, as in the following:

3849293

5

9385834

12

9848495

8

This arrangement of data would be difficult for an inventory or database program to interpret. Most programs expect to see related values on the same line, as in the following:

3849293, 5 9385834, 12 984849, 8

In this arrangement, each line is referred to as a record, and each item on the line is called a field. The database program can be set up to treat the first field as an inventory code and the second as a quantity value.

The way you tell a portable program to arrange data as fields in records is with a template. A template defines the structure used to access data. Most often, a template is used to combine values from two different registers as fields in a single register. The fields are either set to a fixed length (so that they appear in columns in the data file), or they are allowed a variable length with a separator (such as a comma) separating them. However, you can also use a template to break apart data stored in a register into separate fields.

You will incorporate a template into the TUTORIAL program to collect and store quantity values along with each item number. To do this, you'll add the following new nodes to the existing TUTORIAL program:

128

PT Program Generator (PPG) v5.0