View previous topic :: View next topic
|
Author |
Message |
ritnihi
New User
Joined: 30 Jul 2010 Posts: 7 Location: Bangalore
|
|
|
|
Hi,
How can I compare two values from one field.
Example: I have the below internal array. If the deal numbers are same the subtract the first row amount from second row amount .
Deal Amount
1515310002 400
1515310002 200
1515310003 250
1515310004 100
1515310004 150
The output should be:
Deal Amount
1515310002 -200
1515310003 250
1515310004 50
Thanks. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
where are You facing problems,
the logic or the code ? |
|
Back to top |
|
|
ritnihi
New User
Joined: 30 Jul 2010 Posts: 7 Location: Bangalore
|
|
|
|
It would be great if you can share either Logic or code. I want to implement this in my COBOL program. What should be the logic to achieve the output. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
do You realize that it cannot be done in place
here is a proof of concept written in Rexx
Code: |
#! /usr/bin/rexx
/* REXX
*/
Trace "O"
numeric digits 32
signal on novalue
i.1 = "1515310002 400"
i.2 = "1515310002 200"
i.3 = "1515310003 250"
i.4 = "1515310004 100"
i.5 = "1515310004 150"
i.0 = 5
o.0 = 0
/* initialize before the first round
*/
c = 0
p = 1
parse value space(i.p) with fk fv
p = p + 1
do while ( p <= i.0 )
parse value space(i.p) with nk nv
p = p + 1
select
when ( nk < fk ) then do
signal logic_error
end
when ( nk = fk ) then do
if c > 0 then ,
signal logic_error
c = c + 1
fv = nv - fv
end
when ( nk > fk ) then do
o = o.0 + 1
o.o = fk right(fv,5)
o.0 = o
fk = nk
fv = nv
c = 0
end
otherwise do
signal logic_error
end
end
end
o = o.0 + 1
o.o = fk right(fv,5)
o.0 = o
do o = 1 to o.0
say o o.o
end
exit
/* error handlers
*/
logic_error:
say "++"copies(" -",35)
say "++ Logic error at line '"sigl"' "
say "++"copies(" -",35)
exit
novalue:
say "++"copies(" -",35)
say "++ Novalue trapped, line '"sigl"' var '"condition("D")"' "
say "++"copies(" -",35)
exit
|
Code: |
1 1515310002 -200
2 1515310003 250
3 1515310004 50
|
|
|
Back to top |
|
|
ritnihi
New User
Joined: 30 Jul 2010 Posts: 7 Location: Bangalore
|
|
|
|
But I need a code/logic in COBOL. I know it can be done in COBOL. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
the logic does not change whatever the programming language...
I know that it can be done in ANY programming language
here is a hint...
initialise the loop logic by setting aside the values of the first row ....
the loop
extract the data from the current row
if the current key is less than the previous key ==> logic error... rows out of sequence
if the current key equal to the previous key
check the numbers of keys...
if less than 2 then compute the difference
if the current key is greater than the previous key ==>
output the previous key with the computed difference
...
...
...
really if You are not able to discover such a simple sequencing logic
You should meditate about a career shift |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
As enrico alludes, the usual way to do this is "control break" processing, no table needed.
If the table only exists for this purpose, forget the table. You'll need control-break processing many times in your career, so you may as well start now.
If you haven't learned control-break processing in your COBOL course, then you should start researching.
If you still can't get it, please register at Use [URL] BBCode for External Links which is specifically for Mainframe Beginners and Students. Explain there what you have found in your research, and the problems you still have. |
|
Back to top |
|
|
|