After Routine & Transform Functions

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
fridge
Premium Member
Premium Member
Posts: 136
Joined: Sat Jan 10, 2004 8:51 am

After Routine & Transform Functions

Post by fridge »

I have inherited some basic code which I am new to. Essentially it is a transform function that extracts all the fields from a link. I want to do a similar thing but to use it in an After routine.

I made the necessary changes so it would run as an After Routine but it fails. It appears to fail at a point which is not a problem in the equivalent Transform function, namely in recognising a Link Name.

The code for the Transform function looks like

Code: Select all

$INCLUDE DSINCLUDE DSD_STAGE.H

      If LinkName = '' Then
         LinkNo = STAGECOM.STAGE<STAGE.HANDLES,1>
      End Else
         CheckLink = Upcase(LinkName)
         LinkList = STAGECOM.STAGE<STAGE.HANDLES>
         LinkNo = 0
         Loop
            Remove PinNo From LinkList Setting MorePinNos
            If UpCase(STAGECOM.PIN(PinNo)<PIN.LOCAL.NAME>) = CheckLink Then
               LinkNo = PinNo
               Exit
            End
         While MorePinNos Do Repeat
         If Not(LinkNo) Then
            Call DSLogFatal(LinkName:' is not a link associated with ':STAGECOM.NAME,'ImpLinkTRAN1')
         End
      End

      LinkColNames = STAGECOM.PIN(LinkNo)<PIN.COL.NAME>

      Call DSLogInfo("1. LinkColNames !!  " :LinkColNames,"ImpLinkTRAN1")
      Return(0)
[/color]

One argument is passed to this code - LinkName.

As mentioned the only changes I have made to this code are those required to allow it to run as an 'After Routine'. In the Transform Function routine all the fields for the relevant link are listed in the log but for the After Routine I get the fatal error "HPLoad_Write is not a link associated with Generic_1..Transformer_2" (HPLoad_Write is the name of the Link).

This would suggest that the code is failing at the line

Code: Select all

If UpCase(STAGECOM.PIN(PinNo)<PIN.LOCAL.NAME>) = CheckLink 
[/color]

I do not why this line would work in the Transform Function Routine but fails in the After Routine. Any ideas/help would be greatly appreciated.



[/code]
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
I'm not sure but I think the after routine is after the transformer is done hence it has no access to the resources it needs.

then again I could be wrong.

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Roy's got it.

If you try to run this as an after-stage routine you may have more success, since the after-stage routine runs in the same process as the transformer stage itself.

The STAGECOM.STAGE and STAGECOM.PIN arrays are declared to be in COMMON (in the header file DSD_STAGE.H) and COMMON variables, as you can determine by searching the Forum, are local to a process.

I would advocate never calling DSLogFatal in routines. Set a flag that the controlling job can detect.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
fridge
Premium Member
Premium Member
Posts: 136
Joined: Sat Jan 10, 2004 8:51 am

Post by fridge »

Roy/Ray,

Thanks very much for taking the time to help with this.

Ray,
I will also take on board your point about the use of flags. What I find confusing about this is that I am already trying to use the code within an After-Stage Routine. I therefore thought that as the after-stage routine runs in the same process as the transformer stage, passing through a relevant LinkName to the transformer stage would allow the code to work. Is there any documentation on the use of header files?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Documentation on the use of header files is in the DataStage BASIC manual (basic.pdf), one of the standard manual set.

I've just looked at the code you posted a bit more closely; it seems to be missing an outer loop where the "all" column names might be incorporated. Is there more to this routine than you posted?

Certainly running it in an after-stage subroutine ought to work, unless receiving the "end of data" token clears the STAGECOM.STAGE and STAGECOM.PIN variables. (You would need access to DSD.StageRun source code to determine whether this is the case; I don't have such access.)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
fridge
Premium Member
Premium Member
Posts: 136
Joined: Sat Jan 10, 2004 8:51 am

Post by fridge »

Ray,

Once again thanks for taking the time with this.

There will be additional code to this eventually, although it does return what I expect as is (at least when ran as a Transform Function). The aim is, once I have matched the incoming Argument/value 'LinkName' with 'UPCASE (STAGECOM.PIN(PinNo)<PIN.LOCAL.NAME>)', to write some additional code that will extract all the column names from the link.

I have seen similar methodology used in another Transform Function which pulls out column names for links using the STAGECOM PIN variables. If there is however a better way to extract the column names for a link (ie the additional outer loop with 'All' column names) please advise, especially if it works in an After Stage routine.


There are two factors which I find puzzling about this problem.

Firstly, what is almost exactly the same code appears to work in a Transform Function routine (triggered in a stage variable) but not as an After Stage Routine (The only difference is I have a line to return a value in the transform function but not the After Stage routine).

In the former case the line

Code: Select all

UpCase(STAGECOM.PIN(PinNo)<PIN.LOCAL.NAME>
returns the relevant Link Name (which allows the code to return the column names to the log) but when ran as an After Stage routine this same line of code returns an empty/blank value to the log.

Secondly, there is no issue in returning STAGECOM.STAGE variables in the After Stage routine (I have since included several other DSLoginfo's to test this and have returned the correct values for STAGECOM.STAGE<STAGE.CONVERTED.NAME> (stage name) and STAGECOM.STAGE<STAGE.OUTPINS> (name of outbound link). Only when I move onto using the PIN variables, in order to extract the column names for the link, does the After Stage routine fail to extract values.

Any further advice/pointers appreciated. If I've bored you to death with this one thats understandable!
Post Reply