# How to Compare two values in an internal array

Author Message
ritnihi

New User

Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

 Posted: Wed Jun 10, 2015 11:49 am 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.
enrico-sorichetti

Senior Moderator

Joined: 14 Mar 2007
Posts: 10712
Location: italy

 Posted: Wed Jun 10, 2015 12:24 pm where are You facing problems, the logic or the code ?
ritnihi

New User

Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

 Posted: Wed Jun 10, 2015 2:25 pm 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.
enrico-sorichetti

Senior Moderator

Joined: 14 Mar 2007
Posts: 10712
Location: italy

Posted: Wed Jun 10, 2015 2:40 pm

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
ritnihi

New User

Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

 Posted: Wed Jun 10, 2015 4:29 pm But I need a code/logic in COBOL. I know it can be done in COBOL.
enrico-sorichetti

Senior Moderator

Joined: 14 Mar 2007
Posts: 10712
Location: italy

 Posted: Wed Jun 10, 2015 4:46 pm 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
Bill Woodger

Moderator Emeritus

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

 Posted: Wed Jun 10, 2015 5:13 pm 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.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Hexadecimal Group compare and write t... DFSORT/ICETOOL 5 Compare two character variables Head ... CLIST & REXX 3 a copybook getting improper values in... COBOL Programming 7 Compare multiple files using JCL/Rexx... JCL & VSAM 4 JDBC Driver -Default Values DB2 1
Search our Forums: