Page 1 of 1
Variable Length input file EBCDIC with a Record length field
Posted: Thu Jan 11, 2007 4:05 pm
by DAndres
[size=12][/size]
I am trying to read in a file that is variable length, EBCDIC, contains a record length in the first field of the record, no end of line delimiter, and also has 'OCCURS DEPENDING ON' in the COBOL layout.
1. How can I setup the CFF to read in a file that is variable length that references a field within the file to denote it's length?
2. I've seen in other messages that multi 'OCCURS DEPENDING ON' can not be done, and you can only handle one at a time. How do you handle one at a time? How would the layout be setup to let this happen?
Any help would be greatly appreciated. Even if to say, it can't be done.
Posted: Thu Jan 11, 2007 8:40 pm
by ray.wurlod
Welcome aboard. :D
The Complex Flat File in server jobs simply does not handle OCCURS DEPENDING ON (though it does handle OCCURS n TIMES).
Because it's my background, I'd create a before-job subroutine to convert this file to ASCII and line terminated. The following code is written without access to DataStage, so may need some tweaking.
Code: Select all
SUBROUTINE ConvertFile(InputAtg, ErrorCode)
* Convert unterminated EBCDIC file to terminated ASCII
* Each record has a four-byte record length designator.
Equate RECLENSZ To 4
$INCLUDE UNIVERSE.INCLUDE FILEINFO.H
DEFFUN OpenSeqFile(PathName, OpenMode, WriteMode, LogEntry) Calling "DSU.OpenSequentialFile"
SourceFilePath = Field(InputArg, " ", 1, 1)
TargetFilePath = Field(InputArg, " ", 2, 1)
hInputFile = OpenSeqFile(SourceFilePath, "R", "A", "Y")
If FileInfo(hInputFile, FINFO$IS.FILEVAR)
Then
hOutputFile = OpenSeqFile(TargetFilePath, "W", "O", "Y")
If FileInfo(hOutputFile, FINFO$IS.FILEVAR)
Then
Loop
While ReadBlk EbcdicRowLength From hInputFile, RECLENSZ
AsciiRowLength = Ascii(EbcdicRowLength)
ReadBlk DataRecord From hInputFile, AsciiRowLength
Then
WriteSeq Ascii(DataRecord) To hOutputFile
Else
Call DSLogWarn("Can not write to " : OutputFile, RoutineName)
ErrorCode = 1 ; * prevent job execution
Exit
End
End
Repeat
CloseSeq hOutputFile
End
CloseSeq hInputFile
End
RETURN
Posted: Fri Jan 12, 2007 11:48 am
by DAndres
I have found out that there does seem to be an EOL marker at the end of each record. Would this change your recommendation then?
I would then be just faced with the 'DEPENDING ON' piece. Also, would flattening out of the OCCURS be useful here when loading in the layout?
The subroutine you noted ... would this be placed in the Xfrm connected to the CFF stage? This is the only area that I know of to put something like this ... placing it with ExecSh and the code into a Unix Script.
Thank you for your response.
Posted: Fri Jan 12, 2007 3:18 pm
by ray.wurlod
If there is a line terminator, then you can read using ReadSeq rather than ReadBlk, or even without the routine. If you do use a routine, it would be selected as the Before Job subroutine (or Before Stage subroutine in the Transformer stage being fed by the Sequential File stage).
But you can read without a routine simply by using a Sequential File stage, reading the entire row as a single VarChar column. In the Transformer stage parse the records into ASCII then split the record types onto separate outputs. Split out the section containing the multiple values as a substring and use Fold() to generate a delimited string that you can then work with.