AIV Array Processing

I have a system that can have up to 200 AIV fields. It works but is bulky. I’ve tried in a small test program creating an AIV array of five entries. This would greatly reduce the amount of code, making it much nicer to work with. Here are my two test programs:

Program MDH0451
0010 DEFINE DATA
0020 LOCAL
0030 1 #A (N5)
0040 INDEPENDENT
0050 1 +AIV-ARRAY (A20/5)
0060 END-DEFINE
0070 *
0080 +AIV-ARRAY (1) := ‘#FIELD1
0090 +AIV-ARRAY (2) := ‘#FIELD2
0100 +AIV-ARRAY (3) := ‘#FIELD3
0110 +AIV-ARRAY (4) := ‘#NO-FIELD
0120 +AIV-ARRAY (5) := ‘#NO-FIELD
0130 RUN ‘MDH0451P’
0140 *
0150 END

Program MDH0451P
0010 DEFINE DATA
0020 LOCAL
0030 1 #A (N2)
0040 1 #FIELD-A (A5)
0050 1 #FIELD1 (A5) INIT<‘AAA’>
0060 1 #FIELD2 (A5) INIT<‘BBB’>
0070 1 #FIELD3 (A5) INIT<‘CCC’>
0080 1 #NO-FIELD (A5)
0090 END-DEFINE
0100 *
0110 WRITE ‘BEFORE’
0120 FOR #A 1 TO 5
0130 IF +AIV-ARRAY (#A) = ’ ’ THEN
0140 ESCAPE TOP
0150 END-IF
0160 WRITE ‘=’ +AIV-ARRAY (#A)
0170 END-FOR
0180 *
0190 WRITE / ‘AFTER’
0200 FOR #A 1 TO 5
0210 IF +AIV-ARRAY (#A) = ’ ’ THEN
0220 ESCAPE TOP
0230 END-IF
0240 #FIELD-A := &AIV-ARRAY (#A)
0250 WRITE ‘=’ #FIELD-A
0260 END-FOR
0270 *
0280 END

If I comment out my “RUN” statement and execute the first program, my AIV array is created. When I type AIV on the command line I see:

C Variable F Length


__ +AIV-ARRAY A 20 (5)

However, when I put my RUN statement back in and execute the first program I get the following error:

“NAT0280 Index entry incorrectly specified for field.” marking 0240 #FIELD-A := &AIV-ARRAY (#A).

My question is, how numeric field do I need to use to reference the AIV array? My #A (N2) doesn’t work. I’ve tried (I2) and (I4).

Thanks for the help.

Mike

There is a typing error: the variable &AIV-ARRAY should be +AIV-ARRAY.

For performance reasons array indexes should always be defined as I4. (see manual Natural for Mainframes -> Natural Optimizer Compiler -> Performance Considerations)

The manual clearly states “A global variable with index must not be used within a program that is invoked via a RUN statement.”

  • Natural 9.1.1
  • Statements
  • RUN
  • Dynamic Source Text Creation/Execution

Thanks for the two quick replies. I really appreciate the time taken to respond to my question. A couple of comments…

Ralph, thanks for the bad news. LOL! I was really hoping to make that work. When I originally wrote this new system, I did so only using numeric fields which is the vast majority of our fields in this system. It works great but it will eventually expand to other files and other fields with definitions other than numeric (A,D,T, etc.) and they’ll need to be processed. I’ll figure it out. That’s what’s fun about programming. Solving problems.

Helmut, &AIV-ARRAY is not a typo. The +AIV-ARRAY and &AIV-ARRAY are treated differently in a program called by a RUN command which is pretty cool. Since I can’t use the AIV array field like I was hoping to do, I’ll use +AIV as my field in this example, defined as an A20 field with the text “#FIELD1” in it. In the RUN program the statement “WRITE +AIV” gives you the text “#FIELD1.” “WRITE &AIV” gives you “AAA.” #FIELD1 in the RUN program was defined as (A5) INIT<‘AAA’>. Natural sees &AIV and converts it to code so “WRITE &AIV” becomes “WRITE #FIELD1.” I hope this makes sense.

Again, thanks for the responses.

Mike