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

MIN-, MAX-function with arrays


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Auryn

New User


Joined: 11 Jan 2006
Posts: 83
Location: Lower Saxony (DE)

PostPosted: Fri Oct 25, 2013 7:45 pm
Reply with quote

While researching for my other problem I stumbled across the MIN-, MAX-, MEAN-, SUM- and other intrinsic functions. So there's acute need, just because I'm inquisitive:
Some manuals tell, that the MEAN or the SUM function can be used with arrays appending the (ALL) option.
But no manual does so when explaining the MIN-, MAX- and other functions which might be useful here as well.

According to my COBOL-Book functions supporting the (ALL) option are MEAN, MEDIAN, MIDRANGE, STANDARD-DEVIATION, VARIANCE, SUM

Functions that don't are MAX, MIN, ORD-MAX, ORD-MIN, RANGE.

Are my book and other online documentations incomplete or does IBM Enterprise COBOL for z/OS 4.2 not support these options (yet)?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Fri Oct 25, 2013 7:55 pm
Reply with quote

ALL is supported in 4.2; indeed, the examples that the manuals give for using it refer to ALL.
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: Fri Oct 25, 2013 8:57 pm
Reply with quote

The 4.2 manual has a detailed explanation of ALL in relation to Intrinsic Functions. If you still have problems after digesting and experimenting, show us what you tried, what happened, and what you thought would happen, please.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 25, 2013 9:20 pm
Reply with quote

SUM is really handy when programmatically calculating the OCCURS in an ARRAY (numerics only) which is not associated with a group. EG:
Code:

03  WS-NUMERIC-TBL OCCURS 100 TIMES
                   INDEXED BY X-WS-NT, X-WS-NT-MAX
                   PIC  9(07).
03  WS-FWORD       PIC  9(08) BINARY.

INITIALIZE WS-NUMERIC.
INITIALIZE WS-NUMERIC-TBL REPLACING NUMERIC DATA BY 1.
COMPUTE WS-FWORD = SUM(WS-NUMERIC-TBL (ALL)).
SET X-WS-NT-MAX TO WS-FWORD.

The value in X-WS-NT-MAX is 100, matching the defined OCCURS.

Updated 2013/11/15 -

Apologies, but the example above will NOT work. Alternatively, the following will, providing that your COBOL version is a minimum of COBOL for OS/390 & VM V2R2 (introduced about 13 years ago), which supports ADDRESSes in WORKING-STORAGE.

Code:

           03  WS-NUMERIC-TBL      OCCURS 100 TIMES                     
                                   INDEXED BY X-WS-NT, X-WS-NT-MAX     
                                   PIC  9(07).                         
           03  WS-NUMERIC-TBL-END  PIC  X(01).                         
           03  WS-FWORD            PIC  9(08)      BINARY.             
           03  WS-START-POINTER    POINTER.                             
           03  WS-START-FWORD      REDEFINES WS-START-POINTER           
                                   PIC  9(08)      BINARY.             
           03  WS-END-POINTER      POINTER.                             
           03  WS-END-FWORD        REDEFINES WS-END-POINTER             
                                   PIC  9(08)      BINARY.             
      *                                                                 
           SET  WS-START-POINTER       TO ADDRESS OF WS-NUMERIC-TBL (1).
           SET  WS-END-POINTER         TO ADDRESS OF WS-NUMERIC-TBL-END.
           SUBTRACT WS-START-FWORD     FROM WS-END-FWORD             
                                       GIVING WS-FWORD.                 
           DIVIDE WS-FWORD             BY LENGTH OF WS-NUMERIC-TBL (1) 
                                       GIVING WS-FWORD.                 
           SET  X-WS-NT-MAX            TO WS-FWORD.                     

The value in X-WS-NT-MAX is 100, matching the defined OCCURS.

HTH....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts INSYNC option with same function as I... JCL & VSAM 0
Search our Forums:

Back to Top