Array in Natural

I have seen only the use of /1:10 in defining an array. Is the 1 in it having any specific meaning? Why it is used? Does it have any implied meaning? Can we change that to any other number and will it change its features? Please help me out :slight_smile: :slight_smile:

The size of an array dimension is defined by two integers, a start and an end, such as #A (1:10). Natural will provide a start value of 1 by default, so #A (10) is equivalent.

Depending on your requirements, other start values may be used. (3:5) and (6:8) both allocate 3 occurrences. These examples are more common when using Adabas Periodic Groups.

Even negative integers and zero may be used.

(-4:-2)  3 occurrences
(-5:1)   7 occurrences
(0:10)  11 occurrences

Hi Joseph,

Well, I suspect you have some advanced skills in Java where the first array`s index is 0 :slight_smile:
Meanwhile, Natural also can handle it; you may take a look at the following very simple code which shows you some “similar” behavior in Natural. My point: you may even use negative indexes, but do you really need them? :slight_smile:

Best regards.
0020 1 #ARRAY (A3/-5:*)
0030 1 #DIMEN (I4)
0040 1 #INCREASE (I4) CONST <10>
0050 1 #TWENTY (I4) CONST <20>
0060 1 #ITEM (A3) CONST <‘abc’>
0070 1 #I (I2)
0090 #DIMEN := 5
0110 FOR #I = -5 TO #TWENTY
0120 IF #I > #DIMEN
0150 END-IF
0160 #ARRAY (#I) := #ITEM
0170 END-FOR
0180 FOR #I = -5 TO #DIMEN
0200 END-FOR
0210 END

Actually what is the need for these if 3:5 and 4:6 are actually containing 2 occurences

Let’s take a financial application for example. We retrieve the 2nd quarter values from an Adabas file.

2 MONTHLY (4:6)

These are values for April, May, and June. We need temporary storage.

1 #MTH (P7.2/1:3)

But coding would be much simpler if we could use the same index values for both arrays, so

1 #MTH (P7.2/4:6)

Ralph and Nicolay, Thanks for the response and making me clear of the actual use of it

Just to address the negative indices part of the answer as it seems to be the only part not given an exaple reason for using them.

I can recall only one situation where I defined an array with negative indices and that was i an application where it help to visualize the array(s) in terms of and X and Y axis and where I needed to know which quadrant a particular array occurrence/point/coordinate was.

I’ve also ofter used occurrence zero as a total line entry where it summed the occurrences of the other entries in the array.

That said; both of these scenarios could also have been achieved without using negative indices or zero. It was just easier to keep straight in my head as I coded.

Thanks Mick. I didn’t expect this much detailed help here. I am new to Natural and Adabas. I am on my training period in which I am not having a good resource to clarify my doubts. Also I am not aware of the advantages of studying these. I am learning as the buisness needs more resources