Tuesday, April 28, 2009

Appending a header onto a flat file in Informatica

A few weeks ago, I had a project whereby I needed to append a header onto a flat file using Informatica. I'd come across a few posts regarding this topic, but most of them were people asking how to do it - and struggling with a solution.

I don't know what the "preferred" solution is within Informatica, and I'm certain that there are probably multiple "correct" ways in which this can be accomplished (some of the clunkier than others, I'm sure), but the following is a way in which I got it to work, and it's pretty elegant.

Also, you should know that I tried about 20 variations on this before I finally got it to work. So, if you're struggling with this, just try this method. A lot of other ways you think might work, won't actually work. So, this might save you some time and headache.

Also, keep in mind I'm using 8.6.1, so which options you have in your version (if your version is significantly different) might differ slightly.

Ok, brace yourself, this is pretty complicated...

First, write to a flat file target in your mapping. That much should be obvious.

  • Create a .txt file that has your header in it. Be sure to put a carriage return at the end, otherwise your data will append to the end of that line. And be sure not to have empty rows that follow, otherwise you'll have a blank line between your header and your data.
  • Go to the Mapping tab of your Session, and click on your flat file target.
  • For "Header Options" Choose "Use header command output"
  • For the "Header Command" put "type " and then a path where your header file is located.
  • Um.. that's it.
Ok, that wasn't that hard. Keep in mind, I tried a ton of variations on this, and all fell flat. Also, the path of the header file should be on your Informatica server. Informatica doesn't play well with files on other servers. So, keep it simple. I recommend putting all your headers in a single location - I have a "headers" folder under my folder's... er, directory. In fact, the directory structure might be a good topic for a future blog.

But anyway - that it. Piece of cake.

5 comments:

  1. Used to be as simple on turning on a server setting in the pmserver.config file

    OutputMetadataForFF=Yes

    ReplyDelete
  2. Actually, you now set that at the Session level - in the Mapping pane, change the "Header Options" parameter from the default "No Header."

    But there are plenty of ways to skin that cat.

    BTW - you probably meant to "prepend" the header, not "append" it....

    Love your blog!

    ReplyDelete
  3. Ouch - rushed my answer without fully reading yours....yeah, that'll work too.... :-)

    Sorry!

    ReplyDelete
  4. This is *exactly* the information I needed! Thank you! (This works in 9.1.0, too.)

    ReplyDelete
  5. This also worked for me in INFA 8.1, although I use the CAT command instead of TYPE. Thanks for the info!

    ReplyDelete