IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to Compare two values in an internal array


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
ritnihi

New User


Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

PostPosted: Wed Jun 10, 2015 11:49 am
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Jun 10, 2015 12:24 pm
Reply with quote

where are You facing problems,
the logic or the code ?
Back to top
View user's profile Send private message
ritnihi

New User


Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

PostPosted: Wed Jun 10, 2015 2:25 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Jun 10, 2015 2:40 pm
Reply with quote

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
View user's profile Send private message
ritnihi

New User


Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

PostPosted: Wed Jun 10, 2015 4:29 pm
Reply with quote

But I need a code/logic in COBOL. I know it can be done in COBOL.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Jun 10, 2015 4:46 pm
Reply with quote

the logic does not change whatever the programming language...

I know that it can be done in ANY programming language icon_cool.gif


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 icon_evil.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jun 10, 2015 5:13 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts Compare two files with a key and writ... SYNCSORT 3
Search our Forums:

Back to Top