calling user defined subroutines

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

calling user defined subroutines

Post by Pavan_Yelugula »

Hi All
I am working on subroutines.i rote a small subroutine with name CalledSub.it just adds to numbers and returns Ans.i compiled it and Tested it.

Now i have another Subroutine CallingSub which needs to call this subroutine. and use the value what it returns.

I have searched the forum and found two ways of doing this.

One way:DEFFUN CalledSub(Arg1,Arg2) Calling "DSU.CalledSub"

Arg11=10
Arg12=20

Ans=CalledSub(Arg11,Arg12)

Second Way:Call DSU.CalledSub(Ans,10,12)

1st Ques: Are there any other ways in which i can call Subroutines
2nd Ques:Which method to use when.Is there any trade off in using any of the above 2 methods.
3rd ques:The above methods are working great for calling subroutines.when i try the same for User defined Transforms it is not working.how can i do this?
4th ques:The Documentation of DataStage for "CALL" Statement says
Variable='Name of the SubRoutine'
Call @Variable(Arguments) will also work
I tried using the same like below
Addition='CalledSub'
Call @Addition(10,12)
This didn't work out.what is the problem with this?
5thQues:There is also this concept of using DSX.Subroutinename when should i use this?

I guess i asked a lot of questions

Any inputs will be really helpful for me in going forward in the study of DataStage

Thanks and Regards
Pavan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

A1. The only other way for BASIC subroutines is the Subr() function.

A2. The methods are identical when implemented.

A3. Transforms are not independent components in the same way that Routines are. When Transforms are used in expressions, the Transform definition (not a reference to the Transform) becomes in-line code within the expression.

A4. Since you used CALL, you must reserve the first argument position for the result, as you did earlier.

Code: Select all

Call @Addition(Ans,10,12) 
A5. There are DSX, DSG, DSR, DSD, and DSJ routines as well as DSU. DSU are user-written. The others are part of DataStage. For example, DSX are used by supplied Transforms, DSD are internal functions such as those used as methods exposed by passive stage types, DSR are the "helper subroutines" invoked by DataStage clients. If you want to call one of the DSX routines, you need its all-upper-case, DSX-prefixed name in the CALLING clause of your DEFFUN statement.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Hi Ray
The A4 Solution didn't work out even though i dedicated the first argument for the returning value

Can you also please elobrate on the subr() function which you said can be used for calling user defined subroutines.

Thanks for the help

Thanks and Regards
Pavan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Did you do exactly the following?

Code: Select all

Addition='DSU.CalledSub' 
Call @Addition(Ans,10,12) 
Remember that user-written routines are catalogued with a "DSU." prefix to their name. It is the catalogue name that one must use in a CALL, whether using the indirect ("@") method or not.

Code: Select all

Ans = Subr("DSU.CalledSub",10,12)
has the same effect. The SUBR function is primarily used for creating virtual column definitions for hashed files and UV tables.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

hi Ray
Both the solution worked great Thanx a lot.

Are all the types of calling User subroutines applicable for only Subroutines?
if i want to call an user defined Transforms how do i do it?

Can you also tell me what are various kinds of transforms and how they can be called from a user defined sub-routine?

None of the above methods are working?

Any inputs will be really helpful


Thanks and Regards
Pavan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

See answer A3 above.

There is only one kind of Transform. It is a simple (one-line) expression, stored as a re-usable component in the Repository.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Or maybe you're asking about transform functions, another kind of Routine.

A user-written transform function is, as noted earlier, implemented as a subroutine with the first argument position reserved for the result.

Therefore, the indirect CALL mechanism and the DEFFUN mechanism and the SUBR() function can be used. Again, though, it is the Catalog name (with "DSU.") prefix that has to be specified.

It's all in the DataStage BASIC manual. :wink:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply