Page 1 of 1

How to get source file's name into a transformer?

Posted: Thu Jan 04, 2007 12:16 pm
by mmartin
Hi,
I have a sequential file in source, which name is like FILENAME_YYYYMMDD.
I want to get the "YYYYMMDD" part of the filename in order to load it in a table.
Do you have any idea please?

Thanks in advance.

Posted: Thu Jan 04, 2007 12:31 pm
by chulett
Been discussed a number of times, here is one example.

Posted: Thu Jan 04, 2007 12:33 pm
by DSguru2B
Do it at the OS level. Do a

Code: Select all

ls <dir path>| grep "FILENAME" | awk -F"\_" '{print $2}' > result.txt
Now you have that name in a file. Read it in your job and load it in the table. You can run this command in the before job subroutine 'ExecSH'

Posted: Thu Jan 04, 2007 12:41 pm
by kcbland
Easiest way to do this is on initialization of a Stage Variable in a Transformer. Write a DS Function to do a CALL DSExecute and run the command to get the filename and format the results. This will only be done once when the stage starts. Set the derivation of the stage variable to itself (FRED = FRED). Now just use the stage variable where desired.


:wink:

Posted: Thu Jan 04, 2007 12:50 pm
by chulett
kcbland wrote:Set the derivation of the stage variable to itself (FRED = FRED).
Actually, just leave it blank. :wink:

Posted: Thu Jan 04, 2007 2:30 pm
by trobinson
I get the impression Mr. Bland is referring to a Server job. Seems like overkill to get the filename in a EE job. Why not add the property File Name Column in the Sequential stage?

Posted: Thu Jan 04, 2007 3:11 pm
by kcbland
trobinson wrote:I get the impression Mr. Bland is referring to a Server job.
Did I give a Server answer to a PX question again? :oops:

Posted: Thu Jan 04, 2007 3:11 pm
by chulett
Doh! :lol:

Posted: Thu Jan 04, 2007 3:15 pm
by kcbland
You know, you just sit and read thru about 20 Server posts, then a PX one comes thru and you don't mentally switch gears. It's not like I'm switching between here and other work at the same time :cry:

Posted: Thu Jan 04, 2007 3:21 pm
by kcbland
PX Sequential stage can put the name of the file(s) into a column you specify. You'll have to trim off the unwanted bits to keep just the date portion and then cast it into a properly typed column.

Posted: Fri Jan 05, 2007 2:29 am
by mmartin
I tried to use File Name Column option in the sequential stage with a Read Method set to File Pattern and using a wildcard for my filename as FILENAME* (where my real file name is still FILENAME_YYYYMMDD).

Then I get this result in the output column "FILENAME*". I wonder why it returns me the wildcard, because I want to catch the date instead of the wildcard!!!!

Thank you all.

Posted: Fri Jan 05, 2007 8:17 am
by chulett
Did you read the post I linked to? Did you try everything noted there, including setting APT_IMPORT_PATTERN_USES_FILESET to TRUE? :?

Posted: Fri Jan 05, 2007 8:34 am
by mmartin
chulett wrote:Did you read the post I linked to? Did you try everything noted there, including setting APT_IMPORT_PATTERN_USES_FILESET to TRUE? :? ...
You're right, it works fine!!!!

Thank you very much.