Home The Company Publications Products Links Tips

Tips, Tricks, and Techniques

Last update: 30 April 2004

NATURAL passing array indices to Helproutine

How can you pass the occurence number of the element from the map to the helproutine?

When you are trying to pass the occurence number of the element from the map to the helproutine you can use an example program from the NATURAL Developers Handbook of WH&O. Below is the example:

     >                                       > +  Program     TSTHELP3 Lib
     All    ....+....1....+....2....+....3....+....4....+....5....+....Mode
       0020 1 #OPT(A10/10) INIT
       0030  <'001','002','003','004','005','006','007','008','009','010'>
       0040 1 #IDX(I2)
       0050 END-DEFINE
       0060 INPUT (IP=OFF AD=MI'.' HE='HELP3',#IDX)
       0070  2/5 'OPTIONS:'
       0080  3/5 #OPT(1)
       0090  4/5 #OPT(2)
       0100  5/5 #OPT(3)
       0110  6/5 #OPT(4)
       0120  7/5 #OPT(5)
       0130  8/5 #OPT(6)
       0140  9/5 #OPT(7)
       0150 10/5 #OPT(8)
       0160 11/5 #OPT(9)
       0170 12/5 #OPT(10)
       0180 END

     >                                       > +  Helproutine HELP3
     All    ....+....1....+....2....+....3....+....4....+....5....+....
       0020 1 #PASSED-FIELD(A10)
       0030 1 #OCC(I2)
       0040 END-DEFINE
       0060 SIZE 5*30
       0070 BASE 20/1
       0080 TITLE '- ARRAY HELP -'
       0090 FRAMED ON
       0110  / '>' #OCC (AD=OI)
       0120 END

With the variable #IDX included in the HE= parm, you will get:
NAT0936 Format/length conflict in parameter 1.

If #IDX is omitted from the HE= parm, you will get:
NAT0935 Conflict in number of parameters.

How can you get the index passed to the Helproutine, the programmer wants to use the index to access the corresponding occurrence of another array on the map?

Solution 1

The help routine is defining the #OPT parameter as a scalar field and it should be an array. When you put a help routine on an array field, NATURAL passes the array to the help routine. Then you use the #IDX field to determine which occurrence of the array needs the help.

Solution 2

NATURAL can support your request quite easily, although not very well documented. The list of parameters that passes from the map to the Helproutine include two sets of parameters.

  1. The first one is the list of parameters that were specified directly in the HE= list of parameters, right after the Helproutine name. This list may include up to 20 parameters. Although you can have a number of additional parms, depending on how large your parm field names are, they may not fit in the 2 additional lines you get to define them in.

  2. The automatic parameters that are added at the end, after the first list. This may include up to 4 additional parameters, depending the option usage by the programmer.

The above explanation may indicate that there is no need to define an Index field in the calling program, maintain its value according to the current position in the array and pass it as a separate parameter to the Help routine. This service is offered automatically by NATURAL, but not all are aware to this option....

For more information please see NATURAL Programming Guide, Version 2.2, page 179, manual order number NAT228-021ALL.

Top Page

Back to NATURAL Tips, Tricks, Techniques -- Overview