Character data to binary conversion

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sb2212
Participant
Posts: 36
Joined: Mon Apr 28, 2008 1:22 am

Character data to binary conversion

Post by sb2212 »

Hi,

I have a situation wherein I am reading Ebcidic data from a CFF stage. 1 of the field is defined as FLAG (PIC(X1)) ie it is read as char(1). This field is being sent to a target sequential file and the data type of this field in the sequential file is "binary" which means the output is expected as combination of 0's and 1's. Is there a way to convert the char to binary data. I know about the oconv function in basic transformer but I have to use the parallel transformer.


Regards,
Shilpa
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

First I'd convert the Char(1) to a number using "Seq(In.Column)". Now it is a simple loop to convert this to a string of 1's and 0's. Which version of DS do you have, i.e. can you loop in transform stages? If not, then you might have to write a simple c++ function to do this.

Alternatively, since you have a text file source, you could do this with sed / awk / perl or the like, these have inbuilt functions to do this.
sb2212
Participant
Posts: 36
Joined: Mon Apr 28, 2008 1:22 am

Post by sb2212 »

Thanks ArndW for the reply. I am using datastage 8.7.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Then you can loop through the number constructing its binary equivalent into a string which can be written into a text file.

Iteratively divide the remainder by 2 until there is no remainder, using integer arithmetic.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sb2212
Participant
Posts: 36
Joined: Mon Apr 28, 2008 1:22 am

Re: Character data to binary conversion -- resolved

Post by sb2212 »

Hi All,
This issue is resolved. I tried Seq(In.Column) and then used a bitexpand function. It worked.
Just a brief: As I mentioned it was an ebcidic file, I was getting "?" for this column and then when I used a Seq function, it gave me the decimal representation of it which was 26 and after using bitexpand, it gave me the binary form of it --- 11010.
Hence, moving this to resolved.

Regards,
Shilpa
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The "bitexpand" isn't inside DataStage, is it?
sb2212
Participant
Posts: 36
Joined: Mon Apr 28, 2008 1:22 am

Post by sb2212 »

Yes ArndW. The BitExpand function is under /Function/Logical.

BTW the datastage version is 8.7
Post Reply