View previous topic :: View next topic
|
Author |
Message |
Ramanan-R
New User
Joined: 21 Mar 2007 Posts: 66 Location: Chennai, Tamilnadu, India
|
|
|
|
Hello All
Using Syncsort, i need to convert PIC S9(12)V99 COMP-3 to PIC 9(7) COMP-3.
Though the field was originally declared as PIC S9(12)V99 COMP-3 it has value only for first 7 integer values so i was told, no need to worry about data truncation. Also the decimal part needs to be stripped off...
Please help me to write a Syncsort code for this...
Thanks!
Ramanan R |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
First of all...what have you tried?
Also, you have been around long enough to know that lots of other information is required for sort queries and you have supplied absolutely none of it. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
As Nic has said, there is not a lot to go on.
So let's assume the only problem you have is this one.
You have an 8-byte Packed Decimal which you want to relocate into a 4-byte Packed Decimal. You have two decimal places to drop. If you can't define decimal places in SYNCSORT (I have no idea) then hopefully you can divide by 100 and put the result in your 4-byte field. If you can define the decimal places on the first field, then they will "fall off" as you put the data in the second location. Truncation, but truncating zeros should be OK.
The fun is in the checking. Not difficult. If you can subtract your new field from your old field and put the result in a new field that is the same size as the old field, and SUM on that, then you will be able to confirm no loss of data (or produce a value of how much, if decimals are being knowingly truncated).
You do mention signs in your definition, so you do have the outside chance, but you have to code for it, that you have +ve and -ve difference that will offset each other giving you a sum of zero when there are actually differences. So, either SUM +ve and -ve seperately or SUM on an unsigned field. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Ramanan-R,
The below Syncsort does what I think you're trying to achieve.
Code: |
//SYSIN DD *
OPTION COPY
INREC BUILD=(1,8,PD,DIV,+100,TO=PDF,LENGTH=4) |
SORTIN
Code: |
8/PS
(1-8)
1----------------
*****************
13.00
23.12
33.34
1024.85
1234567.89 |
SORTOUT
Code: |
4/P
(1-4)
1-------
********
13
23
33
1024
1234567 |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Ramanan,
Are you going to have a go at the automatic checking yourself?
Another way would be to check the first six bytes of the old field for x'000000' (say, OMIT the records, check that all are omitted, and then you even have a file of those that are non-zero truncation).
For the decimals, define the last integer and the decimals as two bytes packed, multiply by 10 (to kill off the integer), divide by 10 to put things back in the right place (unless SYNCSHORT has "shifting" or "anding") and then do either SUM (if the decimals have values, so you know how much is lost - I'll PM you my bank details, just so all the accounts are tidy if it is a help) or do another OMIT if they are supposed to be zero. |
|
Back to top |
|
|
purusothaman
New User
Joined: 17 Feb 2007 Posts: 39 Location: Chennai
|
|
|
|
Hi,
After reading this post, I was wondering how to convert S9(3)v9(2) COMP-3 to S9(3)V9(12) COMP-3?
Input file is of just 3 bytes PD field.
I tried the following thing and it was fine. But I feel this is like a workaround. Please let me know if some other better solution is available.
Code: |
SORT FIELDS=COPY
INREC FIELDS=(1,3,PD,EDIT=(TTT.TT),C'0000000000')
OUTREC FIELDS=(1,16,SFF,TO=PD,LENGTH=8) |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If it works correctly every time, why might you believe this a "workaround"?
What might you prefer? |
|
Back to top |
|
|
Ramanan-R
New User
Joined: 21 Mar 2007 Posts: 66 Location: Chennai, Tamilnadu, India
|
|
|
|
Thanks Arun , Your code worked great...
Bill,
Thanks for your inputs... |
|
Back to top |
|
|
purusothaman
New User
Joined: 17 Feb 2007 Posts: 39 Location: Chennai
|
|
|
|
HI Dick,
I was wondering will there be any other better approach which can convert instead of using those hard coded zeros? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Why did you feel the need to use something other than what Arun suggested? That solution has none of the zeros you don't want anyway? |
|
Back to top |
|
|
purusothaman
New User
Joined: 17 Feb 2007 Posts: 39 Location: Chennai
|
|
|
|
Dick,
Thanks. I would be happy with this. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Ramanan-R,
You're welcome |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Ramanan-R,
No problem. |
|
Back to top |
|
|
|