Dynamic Array Size

One of our Development Groups posed this Question and I am trying to Coordinate responses for her. Thanks in Advance. Tom

I need to learn how to build a dynamic array – where the number of records can change depending on how many records I read in from an Adabas file. So if anyone has some advice or code samples of that, I would appreciate that too.

Tom;

What platform and version of Natural will this be for? Natural has a new facility called X-tensible arrays which is the easiest solution to this “problem”. However, earlier releases of Natural have DYNAMIC lengthed alpha and binary variables which can be used to address the problem, but are not as straight forward.

Let us know which solution you are loking for.

steve

Steve,

Actually this is MF Natural Here is our TECH Display below. I have been out of Natural Development for a couple of years and in the DBA World, so I am none too sure this can be done at all or should be done for that matter.

Thanks again, Tom

13:46:13 2007-01-29

User … AVE0003
Library … CISPROD

Version / SM Level … 4.1 / 0003
Startup Transaction …
Natural Security … No
Operating System … z/OS
Oper. Sys. Version … 01.07.00
Machine Class … MAINFRAME
Hardware … 2094
TP Monitor … CICS
Device Type … COLOR
Terminal ID … @279

Last Command … CISHELLO

Steve - I am the developer Tom was referring to. If I had known he was going to post here, I would have included more details. He sent you the system info; here is my issue:

I have an Adabas file to hold table values to be used as selection criteria when reading another Adabas file. In my program which uses the table, I wanted to save I/O to the file and only read it once, putting all the records into an internally defined array. But since the number of records on the table could change at any time, I want to make sure that my program won’t abend in trying to load the array.

Someone here gave me some code - I have changed the names to be generic, so I hope I didn’t typo anything:

DEFINE DATA LOCAL

  • 01 #MAX-ARRAY (N4) CONST <300>
    01 #MAX-ARRAY (N4) INIT <300>
    01 #INTERNAL-ARRAY (A9/1:#MAX-ARRAY)
    01 REDEFINE #INTERNAL-ARRAY
    02 #ARRAY-ITEM (A9/1:#MAX-ARRAY)
    1 TABLE-VIEW VIEW OF ADABAS-TABLE-FILE
    2 TABLE-TYPE
    2 TABLE-ITEM
    1 TABLE-HIST VIEW OF ADABAS-TABLE-FILE
    2 TABLE-TYPE
    01 #I (N4)
    01 #KEY-START (A16) INIT<‘MY-TABLE’>
    01 #KEY-END (A16) INIT<‘MY-TABLE’>
    END-DEFINE
    HISTOGRAM TABLE-HIST FOR TABLE-TYPE STARTING #KEY-START
    THRU #KEY-END
    MOVE *NUMBER TO #MAX-ARRAY
    END-HISTOGRAM
    READ TABLE-VIEW BY TABLE-TYPE STARTING FROM #KEY-START
    THRU #KEY-END
    ADD 1 TO #I
    #ARRAY-ITEM(#I) := TABLE-ITEM
    END-READ
    WRITE ‘TOTAL ARRAY ITEMS LOADED:’ #I
    END

If I leave #MAX-ARRAY defined as a constant, the code works. But I want it to be dynamic, so I added the Histogram to count the records, then stored that in #MAX-ARRAY as a variable. Of course it won’t stow because you can’t use a variable to define an array.

So, my options are these:

  1. Figure out how to make dynamic arrays work
  2. Leave it defined as a CONST and have my batch job send me an email when the number of records gets within XX% of the MAX-ARRAY value, so I can schedule a migration to increase it before it blows.
  3. Don’t load an array - just use the Adabas file itself - don’t worry about the I/O. By the way, It is a daily job reading 30 million records and using this table as criteria to select about 200 of those records. There are about 250 records in the table.

So - thanks for your help. I am interested in figuring this out, but if it’s too much work, then I can use one of the other options.

Cathy

Hi Cathy;

How far away (timewise) are you from V4.2? Xtensible arrays are just what you need. Here is a simple program:

  • THIS PROGRAM DEMONSTRATES A “EXTENSIBLE ARRAY”
  • WHICH WILL ALSO BE CALLED AN “X-ARRAY”
  • NOTE THAT THE RESIZING OF THE ARRAY USES A
  • VARIABLE AS THE UPPER BOUND.

DEFINE DATA LOCAL
1 #ARRAY (A1/1:)
1 #UPPER (P3) INIT <10>
END-DEFINE
*
INCLUDE AATITLER
INCLUDE AASETC
*
RESIZE ARRAY #ARRAY TO (1:#UPPER)
*
MOVE ‘A’ TO #ARRAY (1)
MOVE ‘B’ TO #ARRAY (2)
MOVE ‘C’ TO #ARRAY (3)
*
PRINT 5T ‘ARRAY VALUES ARE’ #ARRAY (
)
// 5T ‘=’ *LBOUND (#ARRAY)
/ 5T ‘=’ *UBOUND (#ARRAY)
/ 5T ‘=’ *OCCURRENCE (#ARRAY)
*
END

PAGE #   1                    DATE:    Apr 02, 2004
PROGRAM: XRAY03               LIBRARY: INSIDE

ARRAY VALUES ARE A B C

LBOUND           1
UBOUND          10
OCC          10

This would be exactly what you want.

If 4.2 is not in your immediate future, I would pick an array size that would suffice until it will appear; then change the code to Xtensible arrays. The changes will be minimal.

steve

Thanks for the help - that is exactly what I am looking for.
Acording to our Project Management database, we have already completed the project to upgrade to 4.2, but our systems still show 4.1 :oops:

I guess I have some follow-up to do. I’ll use one of my other options in the meantime.

thanks again for spending the time to help me out.