Multiple PDAs with variable Arrays

I have multiple PDAs for different subprograms, which I want to call from a single other subprogram.
Each PDA has an array defined as:

01 MYPDA
02 FILTER-ARRAY (A3/1:V)

Now when using such a PDA as a local data area, the following line has to be declared, with a value of the devs choosing (as per Natural For Mainframes 8.2.7, Array Dimension Definition → very bottom of page):

01 V (N3) CONSTANT <100>
LOCAL USING MYPDA

Now if I have multiple PDAs, each with such a variable array, declared as LDAs in another subprogram, I am bound to one declaration of V as a constant, meaning all variable arrays from the PDAs will have the same length of V.

Is it possible to circumvent this?

Essentially, what I’m trying to do is to enable callers of my subprogram to enter a number of filters of their choosing into my array, without much overhead.

A link to the doc you are mentioning would be more helpful to follow what you are looking at.

This is from the v92 docs, but I don’t think much has changed in the X-Arrays since V82 - X-Arrays

You do not have to use constants to reference/define dynamic arrays. You do have to materialize the array using the EXPAND/RESIZE statements. In your case the calling module (program, subprogram, etc) needs to size the array as needed and pass the array to the called subprogram:

ASSIGN #N = 100

EXPAND FILTER-ARRAY TO (1:#N)

CALLNAT ‘SUB’ FILTER-ARRAY(*)

A constant for #N can be used, but the called subprogram can resize the array as needed. You can see the current bounds of the array with the *LBOUND / *UBOUND system variables - e.g *UBOUND(FILTER-ARRAY) will tell you the size of your array (if your lower bound is 1) or use *OCCURRENCE(FILTER-ARRAY) to see the count of occurrences.

Yes, only one PDA can use the in-stream definition of variable V. The other PDAs must be included in your program as LDAs or in-stream structures, with their own dimension variables. In my example, the second structure is in-stream and the third has been defined in an LDA, with dimensions #V2 and #V3, repectively.

DEFINE DATA
LOCAL
1 V (I4)      CONST <10>
1 #V2 (I4)    CONST <20>
LOCAL USING V-PDAA1  /* #TBL1
LOCAL
1 #TBL2              /* #TBL2
  2 #VAR (A3/1:#V2)
LOCAL USING V-PDAL3  /* #TBL3  30 occ
END-DEFINE
CALLNAT "V-PDAN" #TBL1
CALLNAT "V-PDAN" #TBL2
CALLNAT "V-PDAN" #TBL3.#VAR (1:5)
END

Local V-PDAA1

DEFINE DATA PARAMETER
 1 #TBL1
   2 #VAR (A3/1:V)
END-DEFINE

Local V-PDAL3

DEFINE DATA LOCAL
 1 #V3 (I4)  CONST <30>
 1 #TBL3
   2 #VAR (A3/1:#V3)
END-DEFINE

Subprogram V-PDAN

DEFINE DATA
PARAMETER USING V-PDAA1
END-DEFINE
WRITE *PROGRAM
      'occurrences:' *OCC (#VAR)
END

Program output

Page     1                                                   25-10-02  08:48:01
 
V-PDAN   occurrences:          10
V-PDAN   occurrences:          20
V-PDAN   occurrences:           5