Sequential File update based on field list

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
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Sequential File update based on field list

Post by ShaneMuir »

Hi again to everybody in DSXchange land,

Is it possible to 'filter' which fields are written to a sequential file output based on a list which contains the field names?

What I currently have is a job which creates a sequential output containing some 163 fields which is written to a fixed width file. (Simple) I have a request to make the output somewhat dynamic, to allow the fields written to that file be switched on or off, so either it writes a value to write to the file or leaves it blank and writes to the file to create the same fixed length output. (Not so simple?)

I am hoping that it is possible using a simple lookup somehow, as this will only be a temporary requirement (6 mths tops) before all fields will be just switched 'ON'?

Any suggestions? Thanks in advance.

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

Post by ray.wurlod »

You're right, not simple.

Where are you going to keep your flags? Does the on/off setting affect the location of a field in the text file record?

I'd probably consider a routine, with two arguments, one of them being a dynamic array of your column data values and the other being a 163-character string of flags. The return is the record ready to write to the text file as a single "column". (Or the routine itself could do the writing and return a success code.)

In combination with the above, a hashed file with 163 records, one for each field (key could be ordinal position of field or field name or anything else). Non-key columns are the start position and length of the field within the text file record. Use substring assignment to replace part of a string.

Something like this (apologies for the lack of documentation - it's already past my bedtime!):

Code: Select all

FUNCTION ShaneText(Arg, Flags)
$INCLUDE UNIVERSE.INCLUDE FILEINFO.H
COMMON /ShaneText/Flags.fvar
If FileInfo(Flags.fvar, FINFO$IS.FILEVAR)
Else
   Open "Flags" To Flags.fvar
   Else
      Call DSLogWarn('Cannot open "Flags" hashed file.', 'ShaneText')
   End
End

Ans = @NULL

If FileInfo(Flags.fvar, FINFO$IS.FILEVAR)
Then

   Ans = Space(800)  ; * whatever your length is

   ClearSelect 9
   SSelect Flags.fvar To 9

   ColumnNumber = 0

   Loop
   While ReadNext FlagKey From 9

      ColumnNumber += 1

      If Flags[ColumnNumber, 1] = "Y"
      Then

         Read FlagRecord From Flags.fvar, FlagKey
         Then
            StartPos = FlagRecord<2>
            Length = FlagRecord<3>
            Ans[StartPos, Length] = Arg<ColumnNumber>
         End

      End

   Repeat

End

RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
prabu
Participant
Posts: 146
Joined: Fri Oct 22, 2004 9:12 am

Re: Sequential File update based on field list

Post by prabu »

ShaneMuir wrote:Hi again to everybody in DSXchange land,

Is it possible to 'filter' which fields are written to a sequential file output based on a list which contains the field names?
IMHO, if the seq file is defined as a stage , then it is static. means that you cannot conditionally remove a column from it. 1)try OpenSeq and create the file dymanically.
2) put some constant value(or keep it as the default null) for the colums you dont want to appear in the Seq file . connect the Seqfile to a transform and trim those fields having the constant value(or null), then create a new file.

at any cost option1 is best adviced.

all the best
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

I think what I would do is create a new link and output the fields you want. It sounds like this is more for debugging than a perm solution. This way your original link still has all the columns it needs.
Mamu Kim
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Thanks for all your input guys it is most appreciated. :!:

Thanks for the code Ray, it probably would work (after all its you :wink: ) for what i need - but the focus here was on simple. I was hoping to acheive it using standard stages and not coding.

My original thoughts were along the lines of Kim's, just create a new link and update as necessary, but was hoping there may have been a simple way to control it without having to alter the job every week.

Thanks again for all your help on this!

Shane
Post Reply