Can a method return an indeterminate array?

Posted by Jeff Ledbetter on 28-Aug-2019 14:15

Hi.

The documentation has the example (below) for passing indeterminate arrays.


DEFINE VARIABLE x AS INTEGER EXTENT. RUN foo (OUTPUT x). PROCEDURE foo: DEFINE OUTPUT PARAMETER x AS INTEGER EXTENT. EXTENT(x) = 4. /* Fixes the extent to 4 */ END.


 Doing something similar for a method though doesn't seem to work.

"** An array was specified in an expression, on the right-hand side of an assignment, or as a parameter when no array is appropriate or expected. (361)"

DEFINE VARIABLE cList AS CHARACTER EXTENT.

myObject = NEW Object().

cList = myObject:getList().

/* method from class */
METHOD PUBLIC CHARACTER EXTENT getList (): DEFINE VARIABLE cList AS CHARACTER EXTENT NO-UNDO. EXTENT(cList) = 4. RETURN cList. END METHOD.

Posted by Peter Judge on 28-Aug-2019 14:30

That should work. It does in a bunch of places in the HTTP client and webhandler code (one example is at github.com/.../DataObjectService.cls ).
 
I'd argue that you should  *always* define arrays in return values and parameters as indeterminate, but that's another conversation.
 

All Replies

Posted by Peter Judge on 28-Aug-2019 14:30

That should work. It does in a bunch of places in the HTTP client and webhandler code (one example is at github.com/.../DataObjectService.cls ).
 
I'd argue that you should  *always* define arrays in return values and parameters as indeterminate, but that's another conversation.
 

Posted by Fernando Souza on 28-Aug-2019 14:31

Yes, it should work, What version are you running with? I tried 11.7 for instance with your sample and it compiled fine.

Posted by Jeff Ledbetter on 28-Aug-2019 14:46

Ah. We now see the error of our ways.

Posted by Laura Stern on 28-Aug-2019 14:57

And the error of your ways was....?  Are you going to leave us hanging?  HA HA.

Posted by Jeff Ledbetter on 28-Aug-2019 15:20

Stupidity in our test code. I'll leave it there. :)

This thread is closed