View previous topic :: View next topic
|
Author |
Message |
meteorite
New User
Joined: 31 May 2006 Posts: 2
|
|
|
|
Hi,
I have the following Input File:
Field1 Field2 Field3
AAAA bbbbb 11111
BBBB 33333
DDDD 33235
CCCC bbbbb 23433
<Note: "bbbbb" stands for blanks/spaces.>
I need to reformat it as shown below:
Field1 Field2
AAAA +11111
BBBB -33333
DDDD -33235
CCCC +23433
i.e., the difference in the output is that the values in Field3 of Input File should be preceded with a + sign and those in Field2 should be preceded with a - sign and all of these values should appear in Field2's position in the output file. And, do note that the input file has no fixed pattern in the order of records, i.e., each record can have a value in either the Field2 or the Field3, but only in one of them.
Do let me know if the above can be solved using SYNCSORT? |
|
Back to top |
|
|
Manuneedhi K
Active User
Joined: 07 May 2008 Posts: 115 Location: Chennai
|
|
|
|
This should work. Please try and confirm.
Code: |
OPTION COPY
INREC IFTHEN=(WHEN=(6,5,CH,LT,12,5,CH),
BUILD=(1,5,C'+',12,5)),
IFTHEN=(WHEN=(6,5,CH,GT,12,5,CH),
BUILD=(1,5,C'-',6,5))
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
This should work. Please try and confirm. |
Did you try the code?
The code compares 2 fields in a record and generates a +/- based on the output of the compare. I see nothing like that in the initial request. . . |
|
Back to top |
|
|
Manuneedhi K
Active User
Joined: 07 May 2008 Posts: 115 Location: Chennai
|
|
|
|
Hi Dick,
I should have mentioned this earlier. Sorry.
I assumed that for records where field2 and field3 are present field2 is always alphabetic and field3 is numeric. Similarly for the other record assumed field2 is numeric and field3 is alphabetic/spaces. I have tested with the given data and it works.
For ex. for the first record AAAA bbbbb 11111
BBBBB is less than 111111 hence AAAA +11111 is written to the output
For second record BBBB 33333
333333 is greater than spaces hence BBBB -333333 is written to the output. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Manu,
Thanks for the clarification.
My simple brain was thinking of just checking for non-blank
d |
|
Back to top |
|
|
meteorite
New User
Joined: 31 May 2006 Posts: 2
|
|
|
|
Manu,
Thanks a lot! Your solution worked like a charm
Regards,
m |
|
Back to top |
|
|
|