Writing in to a sequential file trhru routine

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

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

Post by ray.wurlod »

You provide your exact code. We will comment upon 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Also verify your Server platform - is it actually Windows or is it UNIX perhaps? Sometimes people mark that incorrectly in their initial post, leading to all kinds of chases of the Wild Geeses. :wink:

As noted earlier, the correct record terminator for DOS/Windows is a CR/LF pair or CHAR(13):CHAR(10) - which you have bass ackwards. UNIX just uses the LF and the CR would show up as data... aka the dreaded ^M.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

If, all you are doing, is to write to a variable to a flat file then try going via the route of OS commands using DSExecute(). Would'nt that be feasible. I think Craig hit the bulls eye, by pointing out, that the error might lie in the fact that you are using DOS line terminator on a unix platform. Is that the case?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Actually, that was sb_akarmarkar, I just mentioned it again. As Ray notes, rather than continue to go round and round, the OP should post the code as it stands right now so it can be commented on directly rather than by inference.
-craig

"You can never have too many knives" -- Logan Nine Fingers
shrinivas
Participant
Posts: 53
Joined: Mon Sep 18, 2006 3:42 am
Location: hyd

Post by shrinivas »

Hi guys , Here I ma puttinf my total code ...My OS is Windows at present . When I will move this code to production , Its going to be Unix ....

Code: Select all

********************************************************************************************************************************
**Input to the routine is a sequntial file which contains job details.The first line of the file must always contains only the 
**Sequence Name which is initiating the jobs. 
**Input file format is :-  JobName , SrcTransformName,SrcLinkName,DestTransformName,DestLinkName
**The output of the routine is a sequntial file contians Job status after each run
**Output file format is :- JobName,JobStartTime,JobEndTime, JobStatus,Warning/Errors, SrcRowCount, DstRowCount 
********************************************************************************************************************************


ErrorCode = 0      ;* set this to non-zero to stop the stage/job

      #Include DSINCLUDE DSD_STAGE.H
      #Include DSINCLUDE JOBCONTROL.H
      #Include DSINCLUDE DSD.H
      #Include DSINCLUDE DSD_RTSTATUS.H

********************************************************************************************************************************
**Arg1 contians Source file path 
**Arg2 contians Destination file path 
********************************************************************************************************************************

Arg1 = Field(InputArg, ',',1)
Arg2 = Field(InputArg, ',',2)


set=''
srcset= Arg1
destset = Arg2
Dest =''
Var1 =  char(13):char(10) ** New line character


********************************************************************************************************************************
**Open the source file and put each line in an array appended with ";"
********************************************************************************************************************************
! Read parameters from file
      OPENSEQ srcset TO FileVar THEN
          LOOP
              READSEQ Ln FROM FileVar ELSE EXIT
              set := trim(Ln):';'
                       REPEAT
          CloseSeq FileVar
      END ELSE
          Call DSLogFatal('File open error on ':srcset:'. Status = ':Status(),SetParams)
      END 

Ans =''

ParamList = Convert(';,',@FM:@VM,set)

ParamCount = Dcount(ParamList,@FM) - 1

********************************************************************************************************************************
** Process each job details  from the  array and get job status
********************************************************************************************************************************

For i = 1 To ParamCount Step 1

	JobName    = ParamList<1,1>
	SrcStgName = ParamList<1,2>
	SrcLnkName = ParamList<1,3>
	DstStgName = ParamList<1,4>
	DstLnkName = ParamList<1,5>
	Del ParamList<1>

**Ans = 0
**ERRORCODE = 0

	RejEntrWarn	= ""
	RejEntrFatal	= ""
	SrcRowCount	= 0
	DstRowCount	= 0
	Flag		= 0

	JOBHANDLE 	= DSAttachJob(JobName,DSJ.ERRWARN)

	JobStartTime  	= DSGetJobInfo (JOBHANDLE, DSJ.JOBSTARTTIMESTAMP)
	JobEndTime   	= DSGetJobInfo (JOBHANDLE, DSJ.JOBLASTTIMESTAMP)

********************************************************************************************************************************
**Check for the Sequence name , If SrcStageName is NULL then it means its a Sequence name 
**If SrcStageName is NOT NULL  then it means its a Job Name . Process Job Details only when JobStarttime > = SeqStartTime
********************************************************************************************************************************
	If SrcStgName = "" Then
		SeqStartTime = JobStartTime  
		SeqEndTime   = JobEndTime 
		Flag = 1
	End
	Else If JobStartTime >= SeqStartTime Then
		Flag = 1
	End     

	If Flag = 1 Then

		LastRunStatus = DSGetJobInfo(JOBHANDLE , DSJ.JOBSTATUS) 

		If ((LastRunStatus = DSJS.RUNFAILED Or LastRunStatus = DSJS.STOPPED Or LastRunStatus = DSJS.CRASHED   Or LastRunStatus = DSJS.RUNWARN   )) Then 

			RejEntrWarn = DSGetLogSummary (JOBHANDLE , DSJ.LOGWARNING, JobStartTime , JobEndTime, 10)

			RejEntrFatal = DSGetLogSummary (JOBHANDLE , DSJ.LOGFATAL, JobStartTime , JobEndTime, 10)

			If LastRunStatus = DSJS.RUNWARN Then 
				JobStat = "Completed with warnings"
			End
			Else 
				JobStat = "Aborted due to some fatal error"
			End 
		End
		Else
			JobStat = "Completed successfully"
			RejEntrWarn = "No error message"
		End

		If SrcStgName <> '' Then 
			SrcRowCount = DSGetLinkInfo(JOBHANDLE ,SrcStgName,SrcLnkName,DSJ.LINKROWCOUNT)

			DstRowCount = DSGetLinkInfo(JOBHANDLE ,DstStgName,DstLnkName,DSJ.LINKROWCOUNT)
		End

********************************************************************************************************************************
** Append the details into a varaible "Dest" . Each line will be terminated with the Charatcer "^"
********************************************************************************************************************************
		
		Dest := JobName : "," : JobStartTime : ",": JobEndTime : "," : JobStat : "," : RejEntrWarn : ";": RejEntrFatal :"," : SrcRowCount : "," : DstRowCount: '^'  

	End
	ErrCode = DSDetachJob(JOBHANDLE) 
Next i
********************************************************************************************************************************
** Trim the last "^" character from the variable
********************************************************************************************************************************

Dest = Trim(Dest,'^',"T")

********************************************************************************************************************************
**Replace each "^" character with new line character i.e Char(13) : Char(10)
********************************************************************************************************************************

Status = EREPLACE(Dest,'^',Var1) 

********************************************************************************************************************************
**Clear the Destination file 
********************************************************************************************************************************
Command = "type " : destset : "> " : destset

Call DSExecute("DOS", Command, Output, SystemReturnCode)
     
********************************************************************************************************************************
**Open the destination file and write the variable "Status" into the file.
********************************************************************************************************************************

OPENSEQ destset TO FileVar1 THEN      

WRITESEQ Status TO FileVar1 ELSE STOP

CLOSESEQ FileVar1

END ELSE

Call DSLogFatal('File open error on ':destset'. Status = ':Status(),SetParams)

END 

shrinivas
Participant
Posts: 53
Joined: Mon Sep 18, 2006 3:42 am
Location: hyd

Post by shrinivas »

One more thing I would like to specify ....
When I am reading the Destiation file (i.e the file created in the routine) in a job I am reading it as Unix file (Line termination Unix style) as I am not able to read it as DOS Style temination.
shrinivas
Participant
Posts: 53
Joined: Mon Sep 18, 2006 3:42 am
Location: hyd

Post by shrinivas »

One more thing I can see only thr CR value thru the Iconv funvtion. and as the last column is numeric in the destination file . the nueric value is becoming character value ...... when i try to read the destination file and insert the data in to a table , it throws an error that "value is an invlaid number "..
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The code looks OK, albeit rather inefficient. For example, why not write a line at a time to the output file within the loop? You don't need to "clear" the output file - WriteSEQ is a destructive overwrite. If you want to be certain, use WeofSEQ immediately after opening.

The line terminators are appropriate to the platform on which the routine is executed if you use WriteSEQ. If you execute the code on a UNIX machine, you will get UNIX line terminators. If you want to specify the actual line terminator you will need to use WriteBLK (and include the line terminator in the character string to be written). Note also that the command "type" is specific to DOS - it won't work on a UNIX machine.

Code: Select all

If System(91) = 0
Then
   Shell = "UNIX"
   Command = "cat "
End
Else
   Shell = "DOS"
   Command = "type "
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.
Post Reply