DataTypePicComp
Moderators: chulett, rschirm, roy
DataTypePicComp
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 ?
Is it possible to do the reverse (i.e. convert a CHAR field into a COBOL PIC COMP) within datastage ?
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.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Premium Member
- Posts: 224
- Joined: Tue Sep 24, 2002 7:32 am
- Location: Denver, CO USA
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:
Good luck,
John
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
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
JezT:
Sorry about that; I did a Windows Ctrl-V without having anything in the buffer. Here is the code:
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.
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
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
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.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
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:
If I then test the built in routine "DataTypePicComp" with these values one at a time, it brings back the correct numbers:
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 ?
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
Code: Select all
40
44
74
102
104
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')
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.
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.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
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
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
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
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
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.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')
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>