Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to Compare two values in an internal array

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to Compare two values in an internal array
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Wed Jun 10, 2015 12:24 pm    Post subject: Reply to: How to Compare two values in an internal array
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Wed Jun 10, 2015 2:40 pm    Post subject: Reply to: How to Compare two values in an internal array
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Wed Jun 10, 2015 4:46 pm    Post subject: Reply to: How to Compare two values in an internal array
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Jun 10, 2015 5:13 pm    Post subject: Reply to: How to Compare two values in an internal array
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 www.ibmmainframeforum.com 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.    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Overlaying one set of charater values... Kevin Lindsley SYNCSORT 7 Sat Nov 05, 2016 3:21 am
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts COMPARE command sivatechdrive TSO/ISPF 7 Fri Sep 16, 2016 4:31 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us