Hi Victor.  It looks like you are correct.  My concern was that in some 
programming languages, function parameters cannot (per the language 
specification) be changed by the function.  Of course we know COBOL does not 
have that "restriction" for programs, and it does look like it also does not 
have that restriction for user defined functions.  The 2014 standard says:


5) If  function-prototype-name-1  or  function-pointer-name-1  is  speci?ed,  
the  manner  used  for  passing  each
argument is determined as follows:
  a) BY REFERENCE is assumed when the BY REFERENCE phrase is speci?ed or 
implied for the corresponding
  formal parameter and argument-1 is an identi?er that is permitted as a 
receiving operand, other than an
  object property or object data item.


So that is good news (I think!).  Conceivably the COBOL standards committee 
could have decided that all parameters for a function are passed by content (a 
literal or a copy of the parameter) or by value, in which case the function 
would not have been able to change the value of parameters.  That was all I was 
concerned about, but again it looks like BY REFERENCE is supported.


Frank

________________________________
From: IBM Mainframe Discussion List <[email protected]> on behalf of 
Victor Gil <[email protected]>
Sent: Thursday, July 14, 2016 11:40 AM
To: [email protected]
Subject: Re: Considering Enterprise COBOL 5.2 "exit" enhancements

Yes, thanks for catching the wrong END-PERFORM, I meant to suggest this -

PERFORM UNTIL GET-NEXT-REC(NEXT-RECORD) = 0
    <PROCESS MY RECORD logic>
END-PERFORM

As far as updating parameters passed to functions - there is no real functional 
difference between passing parameters to functions vs called subroutines as 
they are both just entry names to be resolved by either the compiler or the 
linker.

And we all know that subroutines can update passed parameters [e.g. COMMAREA on 
a CICS LINK].

-Victor-

=========================
Indeed, Victor, you are quite correct!  And as soon as Enterprise COBOL 
supports user-written functions I will start using them!


FWIW, I don't think your code would work as-in even then, because END-PERFORM 
is only for inline performs, but you are doing an "out of line" perform.  You'd 
really have to use one of the following:


PERFORM PROCESS-MY-RECORD
    UNTIL GET-NEXT-REC(NEXT-RECORD) = 0


PERFORM UNTIL GET-NEXT-REC(NEXT-RECORD) = 0

    PERFORM PROCESS-MY-RECORD
END-PERFORM


The first option, even if it works, looks (to me) "a bit weird", because 
structurally it looks like PROCESS-MY-RECORD is done prior to GET-NEXT-REC(), 
so I would stick with the second option; even if its a bit more verbose.


Now that I think about it, though, I'm not sure if this would work.  The above 
assumes that function GET-NEXT-REC not only returns a result, where 0 means 
"end of file", but it also assumes that the parameter is passed by reference 
and can be updated by the function.  Are we sure the COBOL standard allows for 
that?  I'll look at some point, but not right this.


Frank

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to