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:
- Billable report for Corp,
- Nonbillable report for Corp,
- Billable report for Partnership
- Nonbillable report for Parnership
In each report will look like
Asssessment type Tax Interest Discharge
Return 999,999.99
Amend
NPA
Other
somehow when I post all spaces was indented, report should look like
Assessment-------------------Tax------------------Interest-------------------Discharge
Type
Return---------------------99,999.99
Amend
NPA
Other
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
Hope it will help you.
Best regards,
Nikolay
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:
DEFINE DATA LOCAL
1 #ARRAY (1:10, 1:10, 1:10) /* for a 10 x 10 x 10 array
You might use it like:
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.
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.
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…
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
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.
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.