Page 1 of 1

rundate from header record of the file

Posted: Thu Apr 14, 2011 8:43 am
by vikibemech
I need to take the batch rundate from the header record of the file and use it as a column vlaue in my job. ie Start date (column name in transformer) will be the run date in the transformer stage

Job design will be

Seq file -> Transformer->Dataset

Header record will be XXXXXXX20110414XXXXXXXXXX. Here I need to take the chars from lenght 8 to 15.
But not sure how to define in transformer (ie how to define he record starts with H). Please advice to achieve

Posted: Thu Apr 14, 2011 9:04 am
by GJ_Stage
Please use below in Transformer stage. Assue Record is field name coming from Seq file.

if left(trim(DSLink2.Record,3) = "HDR" then
DSLink2.Record[8,3] else DSLink2.Record

Posted: Thu Apr 14, 2011 9:20 am
by vikibemech
Thanks but not clear for me. Can you more specific. I am not clear how to define the header record in transformer.. then how to cut the data from the header record and populate the value

Header record will look similar like

HIAgree20110414000000004

Posted: Thu Apr 14, 2011 9:44 am
by GJ_Stage
Record is field name from Seq file and you need to do in Transformer stage is as below assign this value to one variable.

if DSLink2.Record[1] = 'H' then
DSLink2.Record[8,3] else DSLink2.Record

Posted: Thu Apr 14, 2011 9:48 am
by Ravi.K
Define Stage Variable

If Inputcol[1,7]="HIAgree" Then Inputcol[8,8] Else svHEADERDATE

Posted: Thu Apr 14, 2011 9:52 am
by GJ_Stage
Sorry for the confusion:

DSLink2.Record is field name from Seq file:

Sorry It is :

if DSLink2.Record[1,1] = 'H' then
DSLink2.Record[8,8] else DSLink2.Record

assign the above value to one variable.

Posted: Thu Apr 14, 2011 10:22 am
by vikibemech
We came closer now. As you mentioned
if DSLink2.Record[1,1] = 'H' then
DSLink2.Record[8,8] else DSLink2.Record

My question starts here only, how can I define the column DSLink2.Record since this is a Header record.

I can use as below

if record type = H then ....... not sure how to define then statement since we dont have specific column

Posted: Thu Apr 14, 2011 10:59 am
by samsuf2002
Does your file contain only header and no data ?

Posted: Thu Apr 14, 2011 12:44 pm
by MarkB
You haven't said much about the data in your file. Is it always one header record followed by detail records? If so, then one way to do this is to call your job from a Sequence job. Your job would have a parameter - call it RunDate. Create a Sequence. The sequence would be an Execute Command. The command would be something like head -1 C:\\somefilename.txt|awk '{print substr($0,8,8 )}' | tr -d '\n' . This would parse out the date. This (the Command.Output) would be passed to a Job Activity that runs your job as the value for the parameter Rundate. In the transformer of your job, constrain so that the first row (i.e. header row) does not get output, and set the StartDate column to the parameter RunDate. Of course, you need to make sure checks are in place to validate that the data you parse is the date. Again, this is one way to approach it.

Posted: Thu Apr 14, 2011 1:28 pm
by jwiles
If the file is a basic text file, delimited or not, just read the entire record into one column ("Record" in the earlier posts) for all of the rows in the file. You can parse the data records later using Column Import.

Regards,

Posted: Thu Apr 14, 2011 1:51 pm
by MarkB
jwiles wrote:If the file is a basic text file, delimited or not, just read the entire record into one column ("Record" in the earlier posts) for all of the rows in the file. You can parse the data records later using Column Import.

Regards,
Like I said, more than one way to do it :D

Posted: Thu Apr 14, 2011 4:44 pm
by ray.wurlod
Copy the stream and use a Head stage to extract the first row. It can be parsed appropriately downstream of that.

Posted: Fri Apr 15, 2011 4:11 am
by vikibemech
Sam,

No. Input file is a txt file. File has header and data as well.

Posted: Fri Apr 15, 2011 5:43 am
by GJ_Stage
Again Today :D

Step 1:
Seq file Stage:

Reading record line by line in Seq file and assign each line as Record (this is variable name defined in columns field and declared as varchar 1000)

Step 2:
Transformer Stage:
Assume Link came from Seq Stage called DSLink2.

Do the below statement in Transformer Stage in Derivation part and assign this to BATCH_RUN_DATE

if DSLink2.Record[1,1] = 'H' then
DSLink2.Record[8,8] else DSLink2.Record

Step 3:
link the same to your Final DataSet.