Intrinsics [ Getting Started With TRANSACT V ] MPE/iX 5.0 Documentation
Getting Started With TRANSACT V
Intrinsics
The PROC verb can also be used to call intrinsics. These intrinsics can
be the MPE intrinsics, VPLUS intrinsics, IMAGE, KSAM, etc., intrinsics.
The example below illustrates the use of several of the MPE intrinsics.
____________________________________________________________________________
| |
| 1 system ex73; |
| 2 define(item) filerec x(40): |
| 3 fileref x(8): |
| 4 fopt i(4): |
| 5 aopt i(4): |
| 6 bitmap i(4): |
| 7 fnum i(4): |
| 8 icount i(4): |
| 9 icontrol i(4): |
| 10 filesize i(9),init=1023; |
| 11 define(item) comimage x(40): |
| 12 comcr x(1)=comimage(40): |
| 13 ncr i(4): |
| 14 xncr2 x(1)=ncr(2): |
| 15 error i(4): |
| 16 parm i(4); |
| 17 list comimage: |
| 18 ncr: |
| 19 error: |
| 20 parm; |
| 21 move (comimage) = "build ex73f;rec=-40,,,ascii;disc=10"; |
| 22 let (ncr) = 13; <<decimal equivalent of a carriage return>>|
| 23 move (comcr) = (xncr2); |
| 24 proc command(%(comimage),(error),(parm)); |
| 25 list filerec: |
| 26 fileref: |
| 27 fopt: |
| 28 aopt: |
| 29 bitmap: |
| 30 fnum: |
| 31 icount: |
| 32 icontrol: |
| 33 filesize; |
| 34 move (filerec) = "this is test data"; |
| 35 move (fileref) = "ex73f"; |
| 36 let (fopt) = 1; <<bits 14-15 = 01 = old file>> |
| 37 let (aopt) = 1; <<bite 12-15 = 0001 = write only>> |
| 38 let (bitmap) = 7176; << = 1110000001000 = parms 1,2,3,10>> |
| 39 let (icount) = -40; << write 40 bytes>> |
| 40 let (icontrol) =0; <<single space>> |
| 41 proc fopen(%(fileref),#(fopt),#(aopt),,,,,,,#(filesize),,,, |
| 42 #(bitmap),&(fnum)); |
| 43 proc fwrite(#(fnum),(filerec),#(icount),#(icontrol)); |
____________________________________________________________________________
Figure 8-19. Accessing intrinsics with PROC
The example is a program that builds a file using the COMMAND intrinsic
and then writes a record to the file using the FOPEN and FWRITE
intrinsics.
Line 21 sets up the buffer for the COMMAND intrinsic to be the BUILD
command. The buffer for a command has to end with a [[RETURN]] which is
what lines 22 and 23 accomplish.
Line 41 executes the FOPEN intrinsic. This line illustrates several
important points to remember when calling intrinsics. The intrinsics
manual describes the information we need to know about both the intrinsic
and the data being passed to it.
The first parameter passed to the FOPEN intrinsic is the formaldesignator
or filename of the file to be opened. It is a byte array. The % in
front of the first parameter tells Transact that this parameter is to be
passed as a byte array.
The next parameter is the foptions. This is a word that FOPEN interprets
groups of bits as a description of the attributes of the file. The bit
numbering convention is from left to right starting with bit 0 and ending
with bit 15. In line 36, we established a value for fopt with only bit
15 on. This specifies the file domain to be an old permanent file. The
# tells Transact to pass this parameter by value to the intrinsic.
The parameter to satisfy the aoptions is also passed by value.
The remainder of the FOPEN parameters do not need to be specified for our
use of the intrinsic. However, there is one special case parameter which
we need to consider, which is the filesize parameter. This parameter is
a double word parameter that is passed by value. Transact does not know
anything about the data types that intrinsics expect. It expects you to
provide that information. This works great and is easy to do for all
data types except optional double by value. When an option variable
intrinsic contains this kind of parameter, pass the parameter with either
the default value in those cases where you don't care what the parameter
value is or with the needed value in those cases where you do care. This
assures that the correct number of words are passed to the intrinsic when
called.
Another special thing about this intrinsic is that it is an option
variable intrinsic. This means a bit map must be passed to the intrinsic
telling it which parameters are being passed to it. The intrinsic
expects 13 parameters. Thus one word is passed to the intrinsic with the
first 13 bits of the word designating those parameters passed. In our
example, parameters 1, 2, 3, and 10 were passed, so the first three and
the 10th bits of the bit map word are set on in line 38 (1110000001000 to
the base 2 is equal to 7176 to the base 10).
The last special thing about this intrinsic is that it is a function
intrinsic which means it returns a value to you. The very last parameter
we pass it is the parameter to hold this data. The & in front of the
parameter tells Transact that this is where the value returned is to be
placed.
Line 43 executes the FWRITE intrinsic to write the data we specified to
the file opened in line 41.
MPE/iX 5.0 Documentation