# Syntax for 3 dimensional array

**URL:** <https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [October 4, 2011, 7:05pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573 "2011-10-04T19:05:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thy\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@Thy\_Nguyen](https://techcommunity.softwareag.com/u/Thy_Nguyen)\
**Post date:** [October 4, 2011, 7:05pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/1 "2011-10-04T19:05:20Z")

</div>

Please help me with the syntax for 3 dimension array  
I have Billable indicator with value of Billable, Non-Billable  
Account type: corp, partnership  
Assessment type: return, amended, npa, other.

In every input record, I have data tax, interest, discharge, indicator for Billable, Account type, assessment type.

I will have 4 report totals:

1. Billable report for Corp,
2. Nonbillable report for Corp,
3. Billable report for Partnership
4. Nonbillable report for Parnership

In each report will look like

Asssessment type Tax Interest Discharge

Return 999,999.99  
Amend  
NPA  
Other

---

<div class="post-metadata">

**Author:** ![Thy\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@Thy\_Nguyen](https://techcommunity.softwareag.com/u/Thy_Nguyen)\
**Post date:** [October 4, 2011, 7:08pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/2 "2011-10-04T19:08:16Z")

</div>

somehow when I post all spaces was indented, report should look like

Assessment-------------------Tax------------------Interest-------------------Discharge  
Type

Return---------------------99,999.99  
Amend  
NPA  
Other

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [October 4, 2011, 8:05pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/3 "2011-10-04T20:05:34Z")

</div>

Hi Thy Nguyen,  
Well, it is not that difficult, to my opinion: Syntax for 3 dimensional array

[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat426mf/pg/pg\_defi\_array.htm](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat426mf/pg/pg_defi_array.htm)

Hope it will help you.  
Best regards,

Nikolay

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [October 4, 2011, 8:05pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/4 "2011-10-04T20:05:35Z")

</div>

I will try to answer your first question. The syntax for 3 dimensional arrays is simply array (index1, index2, index3).

You define one like this:

```auto
DEFINE DATA LOCAL
1 #ARRAY (1:10, 1:10, 1:10) /* for a 10 x 10 x 10 array
```

You might use it like:

```auto

RESET #ARRAY (*,*,*)
MOVE 'Hello' TO #ARRAY (1,1,1)
MOVE 'World' TO #ARRAY (1,1,2)
FOR I = 1 TO 10
  FOR J = 1 TO 10
    FOR K = 1 TO 10
      WRITE #ARRAY(I,J,K)
```

Keeping track of 3 dimensions yourself and trying to figure out what someone else wrote using a 3D array is challenging. And I don’t see any need for this complexity in your example. A 2-dimensional array will do all you need. The first dimension will be the report type, and the second dimension will be the assessment type.

```auto

DEFINE DATA LOCAL
1 #TOTALS (1:5,1:5)  
  2 TAX-TOTAL (N7.2)
  2 INTEREST-TOTAL (N7.2)
  2 OTHER-TOTAL (N7.2)
1 #RPT-IX (I4)
1 #TYPE-IX (I4)
...
END-DEFINE
*
READ DATA .....
...
  DECIDE FOR FIRST CONDITION
    WHEN BILLABLE = 'Y' AND TYPE = 'CORP'
      MOVE 1 TO #RPT-IX
    WHEN BILLABLE = 'N' AND TYPE = 'CORP'
      MOVE 2 TO #RPT-IX
    WHEN BILLABLE = 'Y' AND TYPE = 'PARTNERSHIP'
      MOVE 3 TO #RPT-IX
    WHEN BILLABLE = 'N' AND TYPE = 'PARTNERSHIP'
      MOVE 4 TO #RPT-IX
    WHEN NONE
      MOVE 5 TO #RPT-IX
  END-DECIDE
*
  DECIDE ON FIRST VALUE OF ASSESSMENT-TYPE
      VALUE 'RETURN'
        MOVE 1 TO #TYPE-IX
      VALUE 'AMENDED'
        MOVE 2 TO #TYPE-IX
      VALUE 'NPA'
        MOVE 3 TO #TYPE-IX
      VALUE 'OTHER'
        MOVE 4 TO #TYPE-IX
      NONE VALUE 
        MOVE 5 TO #TYPE-IX
  END-DECIDE
*
  ADD TAX TO #TOTALS.TAX-TOTAL (#RPT-IX, #TYPE-IX)
  ADD INTEREST TO #TOTALS.INTEREST-TOTAL (#RPT-IX, #TYPE-IX)
  ADD DISCHARGE TO #TOTALS.DISCHARGE.TOTAL (#RPT-IX, #TYPE-IX)
  ...
END-READ
...
```

There is an extra occurrence in each dimension of the array to accommodate the NONE conditions.

---

<div class="post-metadata">

**Author:** ![Thy\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@Thy\_Nguyen](https://techcommunity.softwareag.com/u/Thy_Nguyen)\
**Post date:** [October 4, 2011, 8:15pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/5 "2011-10-04T20:15:51Z")

</div>

Thanks Jerome for your detail reply, I might follow your instruction and do 2 dimension array.

Thanks Nikolay, I will check out the link you provided.

Please stay tune for more questions as I get further into coding and detail…lol…

---

<div class="post-metadata">

**Author:** ![Thy\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@Thy\_Nguyen](https://techcommunity.softwareag.com/u/Thy_Nguyen)\
**Post date:** [October 6, 2011, 8:08pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/6 "2011-10-06T20:08:23Z")

</div>

I coded and got this error during execution, please help!  
BEP5001R 4080 NAT1316 Index not within array structure.  
FLSH FIN  
NAT9978 Error occurred during execution/compilation.

\*\*\* PROGRAM ABENDED \*\*\* BEP5001R  
JOB STREAM NAME: TN1715X  
JOB STEP: S1  
PROGRAM: BEP5001R  
SUBROUTINE:  
LIBRARY: BETSUNIT  
DATE AND TIME OF ABEND: 10/06/11 11:03:52.9  
ERROR CONDITION NO: 1316  
ERROR LINE NUMBER: 4080

Here is my codes:

here is my define table  
1 #RPT-ARRAY (1:10,1:11)  
2 AM-TAX (N11.2)  
2 AM-PEN-INT (N11.2)  
2 AM-PEN (N11.2)  
2 AM-INT (N11.2)  
2 AM-CAN-TAX (N11.2)  
2 AM-CAN-PEN-INT (N11.2)  
2 AM-CAN-PENALTY (N11.2)  
2 AM-CAN-INTEREST (N11.2)  
2 AM-COLL-ACCRUAL (N11.2)  
2 AM-COLL-PRE-ACCRU (N11.2)  
2 AM-DISCHARGES (N11.2)  
1 #RPT-IX (I4)  
1 #ASMT-IX (I4)

here how the MOVE statement  
**--------------------------------------**  
DEFINE SUBROUTINE COMPUTE-DETAIL-LINE-ITEM  
**--------------------------------------**  
ADD WS-AM-TAX-DUE TO #RPT-ARRAY.AM-TAX(#RPT-IX,#ASMT-IX) -------------------\> this is the line got error  
ADD WS-AM-PEN-INT-TOTAL TO  
#RPT-ARRAY.AM-PEN-INT(#RPT-IX,#ASMT-IX)  
ADD WS-AM-PEN-TOTAL TO #RPT-ARRAY.AM-PEN(#RPT-IX,#ASMT-IX)  
ADD WS-AM-INT-TOTAL TO #RPT-ARRAY.AM-INT(#RPT-IX,#ASMT-IX)  
ADD WS-AM-CAN-TAX TO #RPT-ARRAY.AM-CAN-TAX(#RPT-IX,#ASMT-IX)  
ADD WS-AM-CAN-PEN-INT TO #RPT-ARRAY.AM-CAN-PEN-INT(#RPT-IX,#ASMT-IX)  
ADD WS-AM-CAN-PENALTY TO #RPT-ARRAY.AM-CAN-PENALTY(#RPT-IX,#ASMT-IX)  
ADD WS-AM-CAN-INTEREST TO #RPT-ARRAY.AM-CAN-INTEREST(#RPT-IX,#ASMT-IX)  
ADD WS-AM-COLL-ACCRUAL TO #RPT-ARRAY.AM-COLL-ACCRUAL(#RPT-IX,#ASMT-IX)  
ADD WS-AM-COLL-PRE-ACCRU TO  
#RPT-ARRAY.AM-COLL-PRE-ACCRU(#RPT-IX,#ASMT-IX)  
ADD WS-AM-DISCHARGES TO #RPT-ARRAY.AM-DISCHARGES(#RPT-IX,#ASMT-IX)  
END-SUBROUTINE

and here is how I set up my table

**---------------------------------------**  
DEFINE SUBROUTINE DETERMINE-ASSESSMENT-TYPE  
**---------------------------------------**  
DECIDE ON FIRST VALUE OF WS-CD-TYPE-ASSESSMENT  
VALUE 01  
MOVE 1 TO #ASMT-IX  
VALUE 02  
MOVE 2 TO #ASMT-IX  
VALUE 12  
MOVE 3 TO #ASMT-IX  
VALUE 10  
MOVE 4 TO #ASMT-IX  
VALUE 15  
MOVE 5 TO #ASMT-IX  
VALUE 14  
MOVE 6 TO #ASMT-IX  
VALUE 13  
MOVE 7 TO #ASMT-IX  
VALUE 19  
MOVE 8 TO #ASMT-IX  
VALUE 04  
MOVE 9 TO #ASMT-IX  
VALUE 03,15,20,999  
MOVE 10 TO #ASMT-IX  
NONE VALUE  
MOVE 11 TO #ASMT-IX  
END-DECIDE  
\*  
END-SUBROUTINE  
**-----------------------------------**  
DEFINE SUBROUTINE DETERMINE-REPORT-TYPE  
**-----------------------------------**  
DECIDE FOR FIRST CONDITION  
WHEN WS-IN-BILLABLE = ‘Y’ AND WS-CD-TYPE-ACCT-GROUP =‘1’  
MOVE 1 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘Y’ AND WS-CD-TYPE-ACCT-GROUP = ‘2’  
MOVE 2 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘Y’ AND WS-CD-TYPE-ACCT-GROUP = ‘3’  
MOVE 3 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘N’ AND WS-CD-TYPE-ACCT-GROUP = ‘1’  
MOVE 4 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘N’ AND WS-CD-TYPE-ACCT-GROUP = ‘2’  
MOVE 5 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘N’ AND WS-CD-TYPE-ACCT-GROUP = ‘3’  
MOVE 6 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘Z’ AND WS-CD-TYPE-ACCT-GROUP = ‘1’  
MOVE 7 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘Z’ AND WS-CD-TYPE-ACCT-GROUP = ‘2’  
MOVE 8 TO #RPT-IX  
WHEN WS-IN-BILLABLE = ‘Z’ AND WS-CD-TYPE-ACCT-GROUP = ‘3’  
MOVE 9 TO #RPT-IX  
WHEN NONE  
MOVE 10 TO #RPT-IX  
END-DECIDE  
\*  
END-SUBROUTINE

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [October 7, 2011, 2:38am UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/7 "2011-10-07T02:38:11Z")

</div>

Jerome, I suggest that the ‘extra’ occurrence be placed at the other end, to make it easier to extend to make it easier to extend the array when necessary.

```auto
1 #TOTALS (0:4,0:4) 
...
    WHEN NONE  
      MOVE 0 TO #RPT-IX
```

Thy, the NAT1316 likely means that one of your indexes (#RPT-IX or #ASMT-IX) is zero. See if the change above helps.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:01pm UTC](https://techcommunity.softwareag.com/t/syntax-for-3-dimensional-array/98573/8 "2021-04-02T15:01:03Z")

</div>


