Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
ritnihi

New User

Joined: 30 Jul 2010
Posts: 7
Location: Bangalore

 Posted: Wed Jun 10, 2015 11:49 am    Post subject: How to Compare two values in an internal array 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 Member

Joined: 14 Mar 2007
Posts: 10701
Location: italy

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

Joined: 14 Mar 2007
Posts: 10701
Location: italy

Posted: Wed Jun 10, 2015 2:40 pm    Post subject: Reply to: How to Compare two values in an internal array

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    Post subject: But I need a code/logic in COBOL. I know it can be done in COBOL.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10701
Location: italy

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

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

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Compare two character variables Head ... Harold Barnes CLIST & REXX 3 Fri Aug 28, 2020 12:38 am a copybook getting improper values in... Mahammad Musthafa COBOL Programming 7 Sat Jul 18, 2020 12:58 am Compare multiple files using JCL/Rexx... tanvi110788 JCL & VSAM 4 Tue May 19, 2020 5:47 pm JDBC Driver -Default Values yogi.47eie DB2 1 Mon May 18, 2020 7:27 pm Compare Two datasets and Override Mat... ArunkumarGanesan DFSORT/ICETOOL 7 Mon Apr 27, 2020 7:45 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us