Getting Started with TRANSACT (32247-90007)
142 Chapter8
Special Topics
Subprograms
In this example, the main program only contains definitions for the data that it needs and
at the level that it needs access. For example, it does not contain a detail definition of the
array. The subprogram does contain a detail definition of the array.
The main program also specifies how much data the subprogram has access to by way of
the DATA=ORDER-DATE option on the CALL. This protects order-no from being accessed
by the subprogram. The subprogram must be aware of all data being passed to it and
define its storage first. Then it can define its own local storage following this.
We can also use this same array example to illustrate calling a program written in another
language. In this example, the main program does the database access and the
subprogram written in COBOL performs the array handling for us.
Figure 8-21. Calling a COBOL Procedure
The COBOL subprogram looks like this.
1 system ex72,base=orders;
2 define(item) order-table 10 x(50);
3 define(item) end-of-table i(4),init=1;
4 define(item) year-subx 9(2)=order-date:
5 month-subx 9(2)=order-date(3);
6 list order-no:
7 order-date:
8 quantity:
9 order-table,init:
10 end-of-table;
11 find(serial) orderhead,list=(order-no,order-date),
12 perform=100-each-order;
13 display order-table;
14 exit;
15
16 100-each-order:
17
18 set(key) list (order-no);
19 find(chain) orderline,list=(quantity)
20 ,perform=200-each-line;
21 return;
22
23 200-each-line:
24 proc ex72a((order-table),(end-of-table),(year-subx),(month-subx),
25 (quantity));
26 return;