Scenario : I have 5 source files which I am planning to load using indirect file as they all are of same format and go to same target table. One requirement is to capture the source file name in the target. Is there any simple way to achieve this? The filename column is there only for file targets, not for file sources.
Sol 1.
Effective with PowerCenter 8.5 there is an option called Add Currently Processed Flat File Name Port.
If this flat file source option is selected, the file name port will be added in the ports of the source.
To add the CurrentlyProcessedFileName port:
1. Open the flat file source definition in the Source Analyzer.
2. Click the Properties tab.
3. Select Add Currently Processed Flat File Name Port.
The Designer adds the CurrentlyProcessedFileName port as the last column on the Columns tab.
The CurrentlyProcessedFileName port is a string port with default precision of 256 characters.
4. Click the Columns tab to see your changes.
You may change the precision of the CurrentlyProcessedFileName port if you wish.
5. To remove the CurrentlyProcessedFileName port, click the Properties tab and clear the Add Currently Processed Flat File Name Port check box.
For previous versions a shell script or batch file can be used in a pre-session command task.
------- Short desc
Double click flat file source and Go to Properties tab and check "Add Currently Processed Flat File Name Port" check box. This will add a column "CurrentlyProcessedFileName" in flat file columns list. So simple, Isn't it?
or
Sol 2.
You can append Filename to the file using Shell script...
-
#!/bin/ksh
for a in $(ls *.CSV)
do
fname=$( echo $a | tr Hi, You can append Filename Hi, You can append Filename )
sed -i -e "s/$/
t$/g" $
done;
exit 0
-
This adds file name for all .CSV files. Here the delimiter is TAB. you can change the script according to your spec.
Solution:
Sol 1.
Effective with PowerCenter 8.5 there is an option called Add Currently Processed Flat File Name Port.
If this flat file source option is selected, the file name port will be added in the ports of the source.
To add the CurrentlyProcessedFileName port:
1. Open the flat file source definition in the Source Analyzer.
2. Click the Properties tab.
3. Select Add Currently Processed Flat File Name Port.
The Designer adds the CurrentlyProcessedFileName port as the last column on the Columns tab.
The CurrentlyProcessedFileName port is a string port with default precision of 256 characters.
4. Click the Columns tab to see your changes.
You may change the precision of the CurrentlyProcessedFileName port if you wish.
5. To remove the CurrentlyProcessedFileName port, click the Properties tab and clear the Add Currently Processed Flat File Name Port check box.
For previous versions a shell script or batch file can be used in a pre-session command task.
------- Short desc
Double click flat file source and Go to Properties tab and check "Add Currently Processed Flat File Name Port" check box. This will add a column "CurrentlyProcessedFileName" in flat file columns list. So simple, Isn't it?
or
Sol 2.
You can append Filename to the file using Shell script...
#!/bin/ksh
do
sed -i -e "s/$/
t$/g" $
exit 0
-
This adds file name for all .CSV files. Here the delimiter is TAB. you can change the script according to your spec.
Comments
Post a Comment