Parsing fields from flat file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Parsing fields from flat file

Post by pradkumar »

Hi

I am having a flat file which is having data like:
1 record: 470E|Hyd! 3721|Hyd! Consolidated||Intl||Asia Pacific||North Asia||Total China w/ JV||Total China||470E|Hyd! 3721

2 record: 471E|Hyd! 3722|Hyd! Consolidated||Intl||Total China w/ JV ||Total China || 471E|Hyd!3722



I want to detach the code which is at end of each record into separte column "alt_text" and palce at the end of record. The output should look like

OUTPUT :
CODE | TEXT|.... |ALT_TEXT (=TEXT)
470E | HYD!3721|...|HYD!3721
471E|HYD!3722|.....|HYD!3722
How to do this?

My job is something like seq -> transformer->table
Pradeep Kumar
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Confused. What is the delimiter of your flat file. Is it double pipes? How did you specify that in your sequential file stage in the first place?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

The delimiter is pipe
I am sorry for not being clear.
Pradeep Kumar
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi,


1. Are you able to read the flat-file using sequential file stage?

2. Your example sometimes shows two "|" pipe characters, Is this because you have an empty field?

If you are able to read the flat-file successfully, then I think this should be pretty much a straight map.

It is tough to decipher your example.

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Thanks for the reply

I am able to read the flat file successfully.
But the problem is : the last tag is coming in different column number in different records. I want it to send to one last column known as alt_text.

We don't have any knowledge in which column that particular tag appears.
Pradeep Kumar
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

I think your issue is unncessary pipes which are there in your file ans hence the data is not coming in the correct places. Can you open the file in EXL and confirm that the data is not shifted to other columns etc.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

pradkumar wrote: But the problem is : the last tag is coming in different column number in different records. I want it to send to one last column known as alt_text.

We don't have any knowledge in which column that particular tag appears.
- Does this tag have a specific format?
- Does this tag repeat in a given Record?

Need more explaination on the Input you have and the output you want
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

No the tag does not repeat
Pradeep Kumar
shilpa79
Participant
Posts: 131
Joined: Thu Jan 20, 2005 5:59 pm
Location: Virginia

Parsing fields from flat file

Post by shilpa79 »

Delimited Substrings is the one You can extract using this syntax:

string [ delimiter, instance, fields ]

string is the string containing the substring.

delimiter specifies the character that delimits the substring.

instance specifies the instance of delimiter where the extraction is to start.

fields specifies the number of fields to extract.


you can also use field function 'field'
Field (string, delimiter, instance [ ,number] )
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

If the number of columns that you are receiving is variable and you have to get the last column you could try an amalgamation of a couple of functions.
Read the input row in as one field, and use an amalgamation of the Field and Count functions eg:

Code: Select all

Field(input.string,'|',(Count(input.string,'|')+1),1)
Not sure if the +1 is required, you would have to tinker. You could also use the functions separately. Put the count function in a stage variable and pass it to the field function.
NB this is for the last field only. How you extract other fields is up to you.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That construction is so useful I store it as a reuseable component, a Transform called FinalDelimitedSubstring.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply