Method return value

Is there another way of returning a value back to the calling method other than using the set statement.  For example

method-id GetUserTypes() returning #list as type List[type TO_Queue] public
       local-storage section.
       01  userType type List[type TO_Queue] value new Type List[type TO_Queue].

           perform using conn as type MySqlConnection = new MySqlConnection(type DALUtility::GetSQLConnection("conn"))
           invoke conn::Open()
               perform using cmd as type MySqlCommand = new MySqlCommand("UserRights", conn)
                   set cmd::CommandType to type CommandType::StoredProcedure
                       perform using rdr as type MySqlDataReader = cmd::ExecuteReaderExtended()
                           perform until not rdr::Read
                               invoke userType::Add(new TO_Queue
                                           property UserTypes = rdr::GetString("Type")
           set #list to userType


versus like we do in C# by simply writing    return userType.

  • Verified Answer

    No, the only available syntax is as you say to define a RETURNING item in the method-id header (or procedure division header), and to set its value in some way before the method exit.
  • Out of curiosity, why would you want one?

    Various conventions have been used by different programming-language families for specifying a function's return value. (The concept of "return value" is pretty widespread, though there are exceptions, such as stack-oriented languages like Forth, function-oriented ones like APL, and various esoteric languages.)

    Languages in the ALGOL family, such as ALGOL itself, Pascal, and Modula-2, return a value by assigning to the name of the function. In ALGOL 60:

    real procedure A(k);
    integer k;
       A := k 1;

    In COBOL, you have the luxury or additional labor, depending on how you see it, of picking a different name for the return value, and assigning to that instead. Some COBOL dialects (including some of the dialects supported by MF COBOL for native code, but not managed code) let you use GOBACK RETURNING to return from a (sub)program.

    Fortran currently lets you use a COBOL-like method, with the result() clause to name the return variable; but it also permits ALGOL-style assignment to the function name. FORTRAN 77, which introduced the result() clause, also added a RETURN statement similar to the one in the C language family; but FORTRAN's RETURN can only be used from subroutines (not functions) and can only return integer values. Fortran 90 made RETURN (with a value) obsolescent.

    In the LISP-like languages, every expression evaluates to something, so there is no explicit return mechanism. This is generally true of functional languages; in the ML family the return value of a function is also the value of the final expression in the function body (which may be a tuple rather than a single value), but since ML languages automatically curry, the return "value" is often in fact another function.

    BASIC (the real language, not various almost-but-not-quite-exactly-unlike-BASICs such as VB) didn't let you return anything at all. You had to use global variables for everything.

    The "return" keyword as the generic mechanism for specifying a function's value is really peculiar to the C family. C's ancestor BCPL used the keyword RESULTIS, which was a contraction of its ancestor CPL's key-phrase RESULT IS. (I don't know what C's immediate ancestor language B, a simplified BCPL, used.) The C language family is large and widely used, but its conventions are certainly not universal.