Subprograms [ Getting Started With TRANSACT V ] MPE/iX 5.0 Documentation
Getting Started With TRANSACT V
Subprograms
Transact allows you to call other programs from within Transact. We have
already seen an example of calling a Report/V program from Transact. You
can also call another Transact Program, Inform report, or a program
written in another language such as COBOL or Pascal.
The CALL verb is used to call another Transact, Report/V, or Inform
program. The PROC verb is used to call a program written in another
language.
Calling a Transact program is easily demonstrated by taking the example
program listed in Figure 8-9 and dividing it into a main program which
does all the database access and a subprogram that takes care of the
array processing. The following two programs result.
__________________________________________________________________
| |
| 1 system ex70,base=orders; |
| 2 define(item) order-table 10 x(50): |
| 3 ot-yr-indx x(50) = order-table: |
| 4 ot-year 9(2)=ot-yr-indx: |
| 5 ot-mo-indx 12 9(4)=ot-yr-indx(3): |
| 6 ot-mo 9(4)=ot-mo-indx; |
| 7 define(item) date x(6): |
| 8 date-yy 9(2)=date: |
| 9 date-mm 9(2)=date(3): |
| 10 indx i(4): |
| 11 end-of-table i(4),init=1; |
| 12 define(item) dun i(4): |
| 13 no i(4),init=0: |
| 14 yes i(4),init=1; |
| 15 list dun: |
| 16 no: |
| 17 yes; |
| 18 list order-table,init: |
| 19 end-of-table: |
| 20 indx: |
| 21 date: |
| 22 order-no: |
| 23 order-date: |
| 24 quantity; |
| 25 find(serial) orderhead,list=(order-no,order-date),|
| 26 perform=100-each-order; |
| 27 display order-table; |
| 28 exit; |
| 29 |
| 30 100-each-order: |
| 31 |
| 32 move (date) = (order-date); |
| 33 set(key) list (order-no); |
| 34 find(chain) orderline,list=(quantity) |
| 35 ,perform=200-each-line; |
| 36 return; |
| 37 |
| 38 200-each-line: |
| 39 call ex70a; |
| 40 return; |
__________________________________________________________________
Figure 8-12. Calling a subprogram
___________________________________________________________________
| |
| 1 system ex70a,base=orders; |
| 2 define(item) order-table 10 x(50): |
| 3 ot-yr-indx x(50) = order-table: |
| 4 ot-year 9(2)=ot-yr-indx: |
| 5 ot-mo-indx 12 9(4)=ot-yr-indx(3): |
| 6 ot-mo 9(4)=ot-mo-indx; |
| 7 define(item) date x(6): |
| 8 date-yy 9(2)=date: |
| 9 date-mm 9(2)=date(3): |
| 10 indx i(4): |
| 11 end-of-table i(4); |
| 12 define(item) dun i(4): |
| 13 no i(4): |
| 14 yes i(4); |
| 15 list dun: |
| 16 no: |
| 17 yes; |
| 18 list order-table: |
| 19 end-of-table: |
| 20 indx: |
| 21 date: |
| 22 order-no: |
| 23 order-date: |
| 24 quantity; |
| 25 let (indx) = 0; |
| 26 let (dun) = (no); |
| 27 while (dun) = (no) |
| 28 do |
| 29 let (indx) = (indx) + 1; |
| 30 if (ot-year((indx))) = (date-yy) |
| 31 then let (dun) = (yes) |
| 32 else |
| 33 if (indx) = (end-of-table) |
| 34 then |
| 35 do |
| 36 let (end-of-table) = (end-of-table) + 1; |
| 37 let (ot-year((indx))) = (date-yy); |
| 38 let (dun) = (yes); |
| 39 doend; |
| 40 doend; |
| 41 let offset(ot-mo) = [(date-mm) - 1] * 4; |
| 42 let (ot-mo((indx))) = (ot-mo((indx))) + (quantity);|
| 43 exit; |
___________________________________________________________________
Figure 8-13. The called subprogram
In this example, the main program and subprogram share the same data.
The two programs do not have to define the data storage identically, but
both must be aware that they are working with the same space. In our
example, both programs do define the data storage the same way.
The example can be modified so that the two programs only share the data
that both need.
__________________________________________________________________
| |
| 1 system ex71,base=orders; |
| 2 define(item) order-table 10 x(50); |
| 3 define(item) end-of-table i(4),init=1; |
| 4 list order-no: |
| 5 order-date: |
| 6 quantity: |
| 7 order-table,init: |
| 8 end-of-table; |
| 9 find(serial) orderhead,list=(order-no,order-date),|
| 10 perform=100-each-order; |
| 11 display order-table; |
| 12 exit; |
| 13 |
| 14 100-each-order: |
| 15 |
| 16 set(key) list (order-no); |
| 17 find(chain) orderline,list=(quantity) |
| 18 ,perform=200-each-line; |
| 19 return; |
| 20 |
| 21 200-each-line: |
| 22 call ex71a,data=order-date; |
| 23 return; |
__________________________________________________________________
Figure 8-14. Calling a subprogram using DATA=
___________________________________________________________________
| |
| 1 system ex71a,base=orders; |
| 2 define(item) order-table 10 x(50): |
| 3 ot-yr-indx x(50) = order-table: |
| 4 ot-year 9(2)=ot-yr-indx: |
| 5 ot-mo-indx 12 9(4)=ot-yr-indx(3): |
| 6 ot-mo 9(4)=ot-mo-indx; |
| 7 define(item) date x(6): |
| 8 date-yy 9(2)=date: |
| 9 date-mm 9(2)=date(3): |
| 10 indx i(4): |
| 11 end-of-table i(4); |
| 12 define(item) dun i(4): |
| 13 no i(4),init=0: |
| 14 yes i(4),init=1; |
| 15 list date: |
| 16 quantity: |
| 17 order-table: |
| 18 end-of-table: |
| 19 indx: |
| 20 dun: |
| 21 no: |
| 22 yes; |
| 23 let (indx) = 0; |
| 24 let (dun) = (no); |
| 25 while (dun) = (no) |
| 26 do |
| 27 let (indx) = (indx) + 1; |
| 28 if (ot-year((indx))) = (date-yy) |
| 29 then let (dun) = (yes) |
| 30 else |
| 31 if (indx) = (end-of-table) |
| 32 then |
| 33 do |
| 34 let (end-of-table) = (end-of-table) + 1; |
| 35 let (ot-year((indx))) = (date-yy); |
| 36 let (dun) = (yes); |
| 37 doend; |
| 38 doend; |
| 39 let offset(ot-mo) = [(date-mm) - 1] * 4; |
| 40 let (ot-mo((indx))) = (ot-mo((indx))) + (quantity);|
| 41 exit; |
___________________________________________________________________
Figure 8-15. The called subprogram with DATA=
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.
_________________________________________________________________________________
| |
| 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; |
_________________________________________________________________________________
Figure 8-16. Calling a COBOL procedure
The COBOL subprogram looks like this.
_______________________________________________________________________________
| |
| 1 $control dynamic |
| 1.1 identification division. |
| 1.2 program-id. ex72a. |
| 1.3 environment division. |
| 1.4 data division. |
| 1.5 working-storage section. |
| 1.6 01 i pic 9(4) comp. |
| 1.7 linkage section. |
| 1.8 01 yr pic 99. |
| 1.9 01 mo pic 99. |
| 2 01 data-table. |
| 2.1 02 yrs occurs 10. |
| 2.2 04 tab-yr pic 99. |
| 2.3 04 tab-qty pic 9(4) occurs 12. |
| 2.4 01 end-tab pic 9(4) comp. |
| 2.5 01 qty pic 9(6) comp. |
| 2.6 procedure division using data-table end-tab yr mo qty. |
| 2.7 100-start. |
| 2.8 perform 200-find varying i from 1 by 1 until yr = tab-yr (i)|
| 2.9 or i = end-tab. |
| 3 if i = end-tab |
| 3.1 move yr to tab-yr (i) |
| 3.2 compute end-tab = end-tab + 1. |
| 3.3 compute tab-qty (i, mo) = tab-qty (i, mo) + qty. |
| 3.4 goback. |
| 3.5 |
| 3.6 200-find. |
_______________________________________________________________________________
Figure 8-17. The called COBOL procedure
The subprogram can only be accessed from an SL. A way to load the COBOL
subprogram into an SL is:
_________________________________________________________________________
| |
| :cobol ex72a |
| PAGE 0001 HP32213C.02.12 (C) HEWLETT-PACKARD CO. 1983 |
| |
| |
| |
| DATA AREA IS %000172 WORDS. |
| CPU TIME = 0:00:01. WALL TIME = 0:00:03. |
| END COBOL/3000 COMPILATION. NO ERRORS. NO WARNINGS. |
| END OF COMPILE |
| |
| |
| :segmenter |
| HP32050A.01.09 SEGMENTER/3000 (C) HEWLETT-PACKARD CO 1983 |
| -buildsl sl,1000,100 |
| -usl $oldpass |
| -listusl |
| |
| USL FILE $OLDPASS.HOWTO.MILLER |
| |
| EX88A' |
| EX88A' 230 P A C N R |
| EX88A |
| EX88A 525 P A C N R |
| EX88A'S CP A C R |
| |
| FILE SIZE 377600( 1777. 0) |
| DIR. USED 311( 1.111) INFO USED 1027( 4. 27)|
| DIR. GARB. 0( 0. 0) INFO GARB. 0( 0. 0)|
| DIR. AVAIL. 37267( 175. 67) INFO AVAIL. 336751( 1573.151)|
| -addsl ex72a' |
| -addsl ex72a |
| -exit |
| END OF PROGRAM |
| |
| |
| :run transact.pub.sys |
| TRANSACT/3000 HP32247A.01.09 - (C) Hewlett-Packard Co. 1983 |
| |
| SYSTEM NAME> ex72 |
| |
| PASSWORD FOR ORDERS> |
| |
| |
| ORDER-TABLE: |
| 860600 |
| 850900 1200 |
| |
| |
| END OF PROGRAM |
_________________________________________________________________________
Figure 8-18. Adding a COBOL procedure to an SL
MPE/iX 5.0 Documentation