MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cobol between

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Thu Apr 17, 2014 9:11 am    Post subject: Cobol between Reply with quote

Hello
What I am trying to do is to get the amount from the internal table
if input year is a between nDevYrFrom and nDevyrTo.

if the input nDevYr = 10 for example, I should get the amount 300 and if is 1 amount will be 100
Actually input nDevYr a between nDevYrFrom and nDevYearTo
Howe can I code this in Cobol

Working Storage

Code:

03  sX5nC1          OCCURS 10 INDEXED BY Ridx.   
  05  cPc                     PIC  X(15)  VALUE SPACE.
  05  cProcdat                PIC  X(08)  VALUE SPACE.   
  05  sX5nRate      OCCURS 60 INDEXED BY Pidx2.
    07  nAmountTab               COMP-2  VALUE ZERO.       
    07  nDevYrFrom             PIC  9(03) VALUE ZERO.     
    07  nDevYrTo               PIC  9(03) VALUE ZERO.     




My internal table with values
Code:


Amount   nDevYrFrom   nDevyrTo
--------------------------------
100      1            1
300      2            100


My attempt below did not get the required result. Index Ridx is searched in table sX5nC1. This works but the search in the second table does not.

SEARCH sX5nRate
AT END
Display 'Not found'
WHEN nRskDevYrTo(Ridx, Pidx2) <= nDevYr
MOVE nAmountTab (Ridx, Pidx2) TO nAmount
END-SEARCH

Thank you
shuko
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Apr 17, 2014 11:26 am    Post subject: Reply with quote

shuko,

Your are checking nRskDevYrTo variable and the table variable is defined as nDevYrTo.

SEARCH SX5Nrate increments the lowest-level index only. Hence if X is set to 1 initially, the SEARCH will perform a look-up on items in warehouse SXN5nc1, that is (1, 1) through (1, 10). To search all entries, the SEARCH itself must be executed from a PERFORM ... VARYING
ex:
Code:

PERFORM VARYING RIDX FROM 1 BY 1 UNTIL RIDX > 10         
   PERFORM VARYING PIDX2 FROM 1 BY 1 UNTIL PIDX2 > 60   
           IF NDEVYRFROM(RIDX, PIDX2) <= W-SEARCH-KEY   
           AND NDEVYRTO(RIDX, PIDX2)  >= W-SEARCH-KEY   
               MOVE nAmountTab (Ridx, Pidx2) TO nAmount
           END-IF                                       
   END-PERFORM                                           
END-PERFORM                                             

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Thu Apr 17, 2014 11:38 am    Post subject: Reply with quote

You are new to COBOL.

You probably will never need to use COMP-1 or COMP-2 in your COBOL coding. COMP or COMP-3 are going to give you exactly what you want, unless you need values outside about 10**+/-31 (which it doesn't look like from what you have shown).

The IBM Enterprise COBOL manuals are really thorough. If you consult the manual for SEARCH you'll find out what you have not done, which you need to do.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Apr 17, 2014 11:55 am    Post subject: Reply with quote

shuko,

I forgot to add the SEARCH syntax in earlier post

Code:

       PERFORM 1000-SEARCH-RATE VARYING RIDX FROM 1 BY 1     
         UNTIL RIDX > 10 OR MATCH-FOUND = 'Y'               
     
 1000-SEARCH-RATE.                                           
       SET PIDX2 TO 1
       SEARCH SX5NRATE                                       
         WHEN NDEVYRTO (RIDX, PIDX2) >= W-SEARCH-KEY         
              MOVE nAmountTab (Ridx, Pidx2) TO nAmount
              MOVE 'Y'         TO MATCH-FOUND               
       END-SEARCH                                           
       .

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Fri Apr 18, 2014 5:23 am    Post subject: Reply with quote

Thank you Kolusu
I did it like this as I read somewhere that a SEARCH is faster than a PERFORM varying. Maybe for a small table it does not make a difference.

Code:

SET Ridx TO 1
  SEARCH sX5nC1
      AT END DISPLAY "Not found."             
      WHEN  cPc       (Ridx) =  <search key>       
      AND  cProcdat   (Ridx) =  <search key>               
               
            SET Pidx2 TO 1
            SEARCH sX5nRate
                AT END DISPLAY " not found"     
                WHEN  nRskDevYrToCache(Ridx, Pidx2) >= nDevYr               
                        DISPLAY "found "  nAmount (Ridx, Pidx2)                               
              END-SEARCH
   END-SEARCH
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri Apr 18, 2014 11:06 am    Post subject: Reply with quote

shuko wrote:
Thank you Kolusu
I did it like this as I read somewhere that a SEARCH is faster than a PERFORM varying. Maybe for a small table it does not make a difference.


Shuko,

A Binary Search ( SEARCH ALL) might be advantageous but if you are doing serial search(SEARCH), then it wouldn't be any different from PERFORM verb unless you are subscripts. You are using Index variables, so it should be the same performance wise.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group