DataTypePicComp

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

JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

DataTypePicComp

Post by JezT »

The SDK Routine DataTypePicComp converts a COBOL PIC COMP into an integer.

Is it possible to do the reverse (i.e. convert a CHAR field into a COBOL PIC COMP) within datastage ?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Yes, it is possible to convert an integer or a numeric CHAR variable into the binary COBOL representation COMP. The actual conversion used depends upon your platform and compiler - the ANSII standard for COMP is left open. Once you know what format you need (and whether or not you are going to have negative numbers) you can use a combination of the ICONV/OCONV functions and the "MB" (masked binary) conversion code. What is your PICture definition and compiler, then someone here (or myself if I see it first) will certainly help you.
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

The PICture definition of the source field is PIC10(10).

What do you mean by compiler ?

And there won't be any negative numbers in the source field.
ds_developer
Premium Member
Premium Member
Posts: 224
Joined: Tue Sep 24, 2002 7:32 am
Location: Denver, CO USA

Post by ds_developer »

No doubt about it - it's Earn and Learn time...

1. you won't be able to use the CFF - it is only a source stage
2. you will need to learn about COBOL data. Here is a web site that has some good information:
3. use a HEX editor to look at the data. I recommend UltraEdit (www.UltraEdit.com) has a free evaluation download. It can also look at EBCDIC which I think you will need for the non-comp fields.

Good luck,
John
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

Is there not a simple answer as to how to do it within DataStage and then I can do the "earn and learn" later. It's just that we are working to a pretty tight deadline and this requirement has only just been discovered !!
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

JezT,

Here is some quick-and-dirty code that should work for you:
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

I think you may have forgotten to add the code (unless that is really the quick and dirty way to do it !!!!!!!!) :D
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

JezT:

Sorry about that; I did a Windows Ctrl-V without having anything in the buffer. Here is the code:

Code: Select all

WorkString = OCONV(Arg1,"MX")
IF LEN(WorkString)/2 # INT(LEN(WorkString)/2) THEN WorkString= "0":WorkString
PRINT WorkString
Ans = ""
LOOP UNTIL NOT(WorkString)
   TempString = WorkString[1,2]
   Ans := CHAR(ICONV(TempString,"MX"))
   WorkString = WorkString[3,999]
REPEAT
I thought it would just be an imbedded ICONV(OCONV()) but it didn't work, so I did a quickie function to see where my error was. Now that it works I am satisfied, you can pick it apart and make it work better if you wish.
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

Arnd

Thanks for your reply. Once our system is back up and running again (as we are currently having system problems !!) I will try it out and let you know how I get on.

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

Post by ArndW »

JezT - good luck with your system.... I tested it against the built-in COMP function; so if that function works for you on input, then this will work on output. I just remembered that you had a fixed column width, so you will have to left pad the string with binary 0's.
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

Arnd

I have removed that Print line - thanks for letting me know.

However, I am a bit confused. I have run my DS Job with your routine added to convert the values. On my ooutput file I am getting the following figures in my first few lines:

Code: Select all

(
,
J
f
h
If I then test the built in routine "DataTypePicComp" with these values one at a time, it brings back the correct numbers:

Code: Select all

40
44
74
102
104
However, if I try and run my entire output file through a transformer and add the DataTypePicComp Routine to the relevant field, my new output file does not have the correct values stated above so I am unsure whether or not the routine works or not !!

Any suggestions ? Is it not possible to just reverse the DataTypePicComp routine as it only contains 2 lines of code (as the 3rd line relates to negative numbers which I will not have ?

Code: Select all

InString = OCONV(Arg1,'MB0C')
  Ans      = ICONV(InString,'MB')
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Hello JezT,

A Cobol computational field is a binary type data field, so if you try to display the values on screen you will get gibberish at best. Which is what is happening. Perhaps I misunderstood you - I thought you wanted a routine that will take a number and convert it into a PIC 9 COMP; i.e. a routine that does the exact opposite of the built-in "DataTypePicComp". The resultant data is pure binary and might also contain terminators.

I tested my routine by feeding a series of numbers and passing the output back through "DataTypePicComp" and the result was identical to the input. So you've gotten the answer in this forum to the questions you asked - now it seems that it's not what you wanted.
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

Arnd

We have a Customer Number:

0123456789
0122222222
0999999999

We need to convert these within DS to be in the format:

PIC S9(9) COMP.

(I understand these will be gibberish, but want to then re-run this file through the inbuilt conversion to check before we send the file off).

Any ideas Welcome, like how does COMP work?

Cheers

JezT
JezT
Participant
Posts: 75
Joined: Wed Sep 15, 2004 1:52 am

Post by JezT »

Arnd

We have a Customer Number:

0123456789
0122222222
0999999999

We need to convert these within DS to be in the format:

PIC S9(9) COMP.

(I understand these will be gibberish, but want to then re-run this file through the inbuilt conversion to check before we send the file off).

Any ideas Welcome, like how does COMP work?

Cheers

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

Post by ArndW »

Jezt
JezT wrote: ...
Any suggestions ? Is it not possible to just reverse the DataTypePicComp routine as it only contains 2 lines of code (as the 3rd line relates to negative numbers which I will not have ?

Code: Select all

InString = OCONV(Arg1,'MB0C')
  Ans      = ICONV(InString,'MB')
I am assuming that your question was rhetorical. It takes less than a minute to write & test this hypothesis and see that it doesn't work, so you must have done so and found out the hard way. 8)
Post Reply