In its simplest form there are 2 subroutines, internal and external.
Internal subroutines are contained within the primary source code and have
full access to every variable the primary program has. You are not really
leaving the program. You're just in another place with a known place to go
back to (RETURN). The routine's labels are either numeric or alphanumeric
starting with a letter.
A=11 ; GOSUB 100
A=92 ; GOSUB 100
STOP
100 PRINT A+1
RETURN
displays 12 then 93.
External subroutines are themselves separate compiled programs that need to
be registered (cataloged) in a common area, either the VOC (each account's
root directory) or a shared directory system, ie CTLG or CTLGTB.
The major advantage is that the same routine can be shared by one or more
other programs as well as dictionary items. Thus, all the necessary
information must be passed to the subroutine either in a parameter list,
standard COMMON or Named COMMON.
The most obvious is the parameter list. For example
A=5 ; B=13
CALL MULTIPLY(A,B,ANS)
PRINT ANS
A=10 ; B=20
CALL MULTIPLY(A,B,ANS)
PRINT ANS
END
SUBROUTINE MULTIPLY(FIRSTNUM, SECONDNUM, ANSWER)
ANSWER=FIRSTNUM * SECONDNUM
RETURN ;* to calling program
END
If you were to read the source code of a contemporary language, ie VB, the
called subs are non-drop-through parts of the same program. Unless you
incorporate DLL's or other MS magic, you're basically in the same single
program. In MS, CALL and GOSUB are somewhat interchangable. In MV, they're
night and day different with the only similarity being their conclusion with
a RETURN.
As with all parameter lists and COMMONS, the variables must be in sync. MV
has 3 kinds of variables, Dimensioned arrays, File handles and everything
else. We do not have integer, floating, long, alphabetic, boolean or other
tricky variables like other languages offer. If it's not a dimensioned array
or a file handle, it's just a variable.
BTW, the entire database concept in variables is called a dynamic array
which is nothing more than a fancy alpha-numeric string variable with
certain ascii characters as field delimiters. It qualifies as an 'everything
else' as well.
OPEN "INVENTORY" TO F.INVENTORY ELSE STOP (no flames please)
DIM A(100) ; MAT A=""
B="BOY" ; C=39; D="FRED"
CALL WHATEVER(F.INVENTORY, MAT A, B, C, D, TOMMY)
PRINT TOMMY
END
SUBROUTINE WHATEVER(F.INVENTORY, MAT A, B, C, D, TOMMY)
DIM A(100)
MATREAD A FROM F.INVENTORY, B ELSE MAT A=""
TOMMY=A(C):" ":D
RETURN ;* to calling program
I'm sure that there are many programming books to offer examples of these 2
kinds of subroutines. You can also review the existing source code that
you're dealing with and begin developing your MV skillset by learning the
'house rules' methods therein.
Keep in mind that MV is non-standardized and you will be witness to much
discussion in this forum on the various ways to skin a cat.
So to answer your question, you make up your own list of variables to
provide and variables to obtain and place them in the parameter list and let
the sub do its magic. Mine were ANSWER and TOMMY.
My 2 cents
Mark Johnson
----- Original Message -----
From: "Vance, Kathy" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, October 03, 2005 10:15 PM
Subject: [U2] Java calss calls a universe subroutine
> Hi list,
>
> I need you guys help.
>
>
>
> I am a Java programmer and new to Universe. Could anybody show me how to
> call a universe subroutine which returns a list of values?
>
>
>
> Ex. sub1 (var in)
>
> Returns three rows:
>
> a1,b1,c1
>
> a2,b2,c2
>
> a3,b3,c3
>
>
>
> How could I loop through these three rows and get each value?
>
>
>
> Is something like:
>
> UniSubroutine mSub = mSession.subroutine ( "sub1", 10);
> mSub.setArg( 1, "05" );
> mSub.call();
>
> Should I use UniDataSet for the ResultSet returned?
>
> Thanks in advance.
>
> Kathy
> -------
> u2-users mailing list
> [email protected]
> To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/