Debug a routin

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
gulshanr
Participant
Posts: 14
Joined: Thu Feb 26, 2004 1:08 pm

Debug a routin

Post by gulshanr »

Hi, I am new to writing routine in Datastage. I created the one, logic looks fine to me, But I want to know how to Debug this routine. I checked the manual and they say use DEBUG statement. I am not sure where to use this statement. Any help on this will be highly appreciated.

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

Post by ray.wurlod »

The DEBUG statement really relates to UniVerse rather than to DataStage. It causes execution to be transferred to the source code debugger for UniVerse (the name of the debugger is RAID) and hand manual control to you.
Unfortunately, DataStage routines are invoked from DataStage jobs, which run as background processes (with no tty mapped onto stdin) so that, if a DEBUG statement were executed, the background process would abort with a message about keyboard/terminal input being requested.

To debug a DataStage routine in situ, about the only thing you can do is to log informational entries into the log file, and inspect these. You can conditionally compile the calls to DSLogInfo(), so that they are compiled in the development environment but not for a test/production version. See $DEFINE and $IFDEF in the BASIC manual for more details.

The other way to debug DataStage routines is to create a DataStage BASIC program on the server than invokes the routine. In this case you could use the DEBUG statement or, indeed, the RAID debugger directly. But you would need to establish the location of the routine source code (which is not, by default, suitably located for RAID). I suspect this is all beyond your current skill set. It can be done, but there's a lot of knowledge needed about how DataStage Engine works to accomplish it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gulshanr
Participant
Posts: 14
Joined: Thu Feb 26, 2004 1:08 pm

Post by gulshanr »

Ray, Thanks for your reply. I have written following code.
DEBUG
ErrorCode = 0 ; * set this to non-zero to stop the stage/job
infilename = Field(TmpFileDirectory_PHSCO, ",",1,1):"/MMR_XREF_S1.DAT":Field(TmpFileDirectory_PHSCO, ",",2,1)
outfilename = Field(TmpFileDirectory_PHSCO, ",",1,1):"/MMR_XREF_S1EX.DAT":Field(TmpFileDirectory_PHSCO, ",",2,1)

OpenSeq "infilename" to infile
Else
Call DSLogWarn("Cannot open input file ":infilename,"sbrtxfmExpl")
End

OpenSeq "outfilename" to outfile
Else
Call DSLogWarn("Cannot open Output file ":outfilename,"sbrtxfmExpl")
End

Loop
ReadSeq line1 From infile
On Error
Call DSLogWarn("Cannot read input file ":infilename,"sbrtxfmExpl")
End
Then
in_phsco = substrings(line1,1,2)
in_hic_num = substrings(line1,3,12)
in_subscbr_num = substrings(line1,15,10)
in_mbr_suffix = substrings(line1,25,2)
in_adj_beg_date = substrings(line1,27,8)
in_adj_end_date = substrings(line1,35,8)
yr1= substrings(line1,27,4)
mth1=substrings(line1,31,2)
yr2=substrings(line1,35,4)
mth2=substrings(line1,39,2)

If yr1 = yr2
Then
nom = mth2 - mth1 + 1
End
Else
nom = (yr2 - yr1 - 1) * 12 + (12 - mth1) + mth2 + 1
End
yr = yr1
mth = mth1 + 0
For i = 1 to nom Step 1
If mth < 10
Then
oline = in_phsco : yr : mth : in_hic_num:in_subscbr_num:in_mbr_suffix
End
Else
oline = in_phsco : yr : mth : in_hic_num:in_subscbr_num:in_mbr_suffix
End
WriteSeq oline to outfile Else
Call DSLogFatal("Cannot write to output","sbrtxfmExpl")
End
If mth < 12
Then
mth = mth + 1
End
Else
if yr < yr2
Then
yr = yr + 1
mth = 1
End
Else
mth = 1
End
End
Next i
End
Repeat
CloseSeq infile
CloseSeq outfile

Code Looks fine, I am calling this routine from Before stage of Xformer, This components execution takes forever, I hve to stop the job. Even after sending the command to stop the job it takes about 1-2 minues to stop the job again it abort the job NOT stop the job.
Any help will be highly appreciated
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You need to go back, edit your post and use the "Code" tags to preserve the formatting that used to be there. It's very hard to following without that.

That being said, I don't see any way for your loop to end. Somewhere between the Loop and the Repeat, you need an Exit. Or add an Until or While construct.
-craig

"You can never have too many knives" -- Logan Nine Fingers
gulshanr
Participant
Posts: 14
Joined: Thu Feb 26, 2004 1:08 pm

Post by gulshanr »

I figred out that I need an exit and modified code as per below.

Code: Select all

      DEBUG
      ErrorCode = 0                      ; * set this to non-zero to stop the stage/job
      infilename = Field(TmpFileDirectory_PHSCO, ",",1,1):"/MMR_XREF_S1.DAT":Field(TmpFileDirectory_PHSCO, ",",2,1)
      outfilename = Field(TmpFileDirectory_PHSCO, ",",1,1):"/MMR_XREF_S1EX.DAT":Field(TmpFileDirectory_PHSCO, ",",2,1)

      OpenSeq "infilename" to infile
      Else
         Call DSLogWarn("Cannot open input file ":infilename,"sbrtxfmExpl")
      End

      OpenSeq "outfilename" to outfile
      Else
         Call DSLogWarn("Cannot open Output file ":outfilename,"sbrtxfmExpl")
      End

      Loop
         ReadSeq line1 From infile
         On Error
            Call DSLogWarn("Cannot read input file ":infilename,"sbrtxfmExpl")
         End
         Then
            in_phsco = substrings(line1,1,2)
            in_hic_num = substrings(line1,3,12)
            in_subscbr_num = substrings(line1,15,10)
            in_mbr_suffix = substrings(line1,25,2)
            in_adj_beg_date = substrings(line1,27,8)
            in_adj_end_date = substrings(line1,35,8)
            yr1= substrings(line1,27,4)
            mth1=substrings(line1,31,2)
            yr2=substrings(line1,35,4)
            mth2=substrings(line1,39,2)

            If yr1 = yr2
            Then
               nom = mth2 - mth1 + 1
            End
            Else
               nom = (yr2 - yr1 - 1) * 12 + (12 - mth1) + mth2 + 1
            End
            yr = yr1
            mth = mth1 + 0
            For i = 1 to nom Step 1
               If mth < 10
               Then
                  oline = in_phsco : yr : mth : in_hic_num:in_subscbr_num:in_mbr_suffix
               End
               Else
                  oline = in_phsco : yr : mth : in_hic_num:in_subscbr_num:in_mbr_suffix
               End
               WriteSeq oline to outfile Else
                  Call DSLogFatal("Cannot write to output","sbrtxfmExpl")
               End
               If mth < 12
               Then
                  mth = mth + 1
               End
               Else
                  if yr < yr2
                  Then
                     yr = yr + 1
                     mth = 1
                  End
                  Else
                     mth = 1
                  End
               End
            Next i
         End
          Else
            Exit
          End
      Repeat
CloseSeq infile
CloseSeq outfile
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What exactly do you want to debug? What condition is occurring that you feel to be abnormal?
Am I correct to assume that you're using TmpFileDirectory_PHSCO as the first (input) argument, and ErrorCode as the second (output) argument?
The main problem I can see in the design is that it keeps going even though it fails to open either of the files. Probably what you are seeking to do is:

Code: Select all

OpenSeq inputfile To infile
Then
   OpenedOK = @FALSE
   OpenSeq outputfile To outfile
   Then
      OpenedOK = @TRUE
   End
   Else
      If Status() = 0 
      Then 
         OpenedOK = @TRUE
      End
      Else
         Call DSLogWarn("Cannot open output file for writing", "Routine")
         ErrorCode = 1  ; * abort job on return
      End
   End
   If OpenedOK
   Then
      * remainder of processing
   End
End
Else
   Call DSLogWarn("Cannot open source file", "Routine")
   ErrorCode = 1  ; * abort job on return
End
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gulshanr
Participant
Posts: 14
Joined: Thu Feb 26, 2004 1:08 pm

Post by gulshanr »

I am trying to read a line from file and then generate 2-6 rows from same line. I have two fields Begin Date and end-Date, For each month between Begin Date and end Date, I have to generate a row. I have written this procedure, and calling from after stage of Transfarmer.
This component execution is forever, When I stop this component It ends with abort note but no error code/Message. I tried executing in after/before Job properties also. I trying to figure out whats wrong with this procedure.
Thanks,
Gulshan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Does anything get written to the output file at all?
Near the beginning of the routine add the following calls:

Code: Select all

Call DSLogInfo("Value of infilename is " : Quote(infilename), "*Debug*")
Call DSLogInfo("Value of outfilename is " : Quote(outfilename), "*Debug*")
Note, too, from my earlier post, that you can take the ELSE clause of OPENSEQ even though the file is opened successfully for writing; this indicates that the file does not yet exist. In your code, you abandon processing under these circumstances.
The logic of your loop to process the file, generating nom output rows, appears to be OK.
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