HP RPG/XL Programmer's Guide (30318-90001)

5- 16
here when the file is read.
3 This line specifies that the second field in the data structure
is PARTNO and its value comes from the field by the same name in
the input record, TRANS.
4 This line defines the third field, TYPE, in the data structure.
Its value comes from the field by the same name in the input
record, TRANS.
5 This line defines the field, PRTKEY. PRTKEY refers to all of the
fields in the data structure (positions 1-16).
Using Data Structures for Interprogram Communication
This section discusses how to receive information from other programs and
how to pass information to them using a standard RPG file, the Local Data
Area file (LDAFILE). To use a Local Data Area file, you must define it
using a data structure.
When you use a Local Data Area in your program, RPG begins by reading the
file into your data structure. You can use that data during the first
cycle (1P) output. When your program ends, RPG automatically writes the
data structure back to the Local Data Area file.
Before you can use a Local Data Area file in a program, you must create
it using the RPGINIT utility (see the
RPG Utilities Reference Manual
for
more detailed information).
Figure 5-12 lists a logon User Defined Command (UDC) that creates a Local
Data Area file automatically. The UDC creates a file consisting of two
records, each containing 256 characters. The records are initialized to
blanks. The FCOPY command copies the file, SYSCTL, to the newly-created
Local Data Area file. SYSCTL contains one record with the company name
in positions 1 to 40. The company name is used in the next example as a
report heading.
_________________________________________________________
| |
| START |
| OPTION LOGON |
| COMMENT INITIALIZE LOCAL DATA AREA AND WRITE|
| COMMENT COMPANY NAME TO POSITION ONE |
| COMMENT OF LDA FOR USE BY REPORT PROGRAMS |
| RUN RPGINIT.PUB.SYS |
| FCOPY FROM=SYSCTL;TO=LDAFILE |
| |
| |
_________________________________________________________
Figure 5-12. Creating a Local Data Area File (LDAFILE) with a UDC
Once you create a Local Data Area file, you can use it in any RPG
program. Figure 5-13 shows how to process the Local Data Area file
created in Figure 5-12. The company name (CNAME), contained in the Local
Data Area file, is used in a report heading. Also, a transaction record
count is accumulated in the field, COUNT. This field is also saved in the
Local Data Area file.