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
 

 

MIN-, MAX-function with arrays

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Auryn

New User


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

PostPosted: Fri Oct 25, 2013 7:45 pm    Post subject: MIN-, MAX-function with arrays
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: 1771
Location: Bloomington, IL

PostPosted: Fri Oct 25, 2013 7:55 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Fri Oct 25, 2013 8:57 pm    Post subject: Reply to: MIN-, MAX-function with arrays
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 25, 2013 9:20 pm    Post subject: Reply to: MIN-, MAX-function with arrays
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    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 What is the Extract Function in JCL dharmaraok JCL & VSAM 3 Wed Jun 14, 2017 9:12 am
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am


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