2

I write a program to read the physical file:

0002.00      A                                      REF(USRMF)                                                                
0002.01      A          R TSREC                                                                                               
0005.00      A            USRID     R        *user ID                                                                                     
0006.00      A            USRDT     R        *date                                                                                 
0007.00      A            USRTI     R        *time IN                                                                                 
0008.00      A            USRTO     R        *time OUT                                                                                 
0009.00      A          K USRID         

Where I allow the user to enter the date, time in and time out.

Ofcourse it will duplicate the USRID:

Where on my program I check the previous max value like this:

0019.01 C     *LOVAL        SETLL     USRTS                                                                                  
0019.03 C     USRID         READE     USRTS                                  45                                               
0019.04 C                   DOW       (*IN45='0')                                                                            
0019.05 C                   IF        (USRDT>=MIN)                                                                           
0019.06 C                   MOVE      USRTO         MAX                                                                       
0019.07 C                   MOVE      USRDT         MIN                                                                       
0019.08 C                   ENDIF                                                                                             
0019.09 C     USRID         READE     USRTS                                  45                                               
0019.10 C                   ENDDO                                                                                             
0029.00 C                   ENDSR

I have the following users:

Opt USR ID    User Name  
A0000001    SAMSUL ARIPIN MISDAR                                             
A0000002    NUR QISTINA SAFIYYAH                                             
A0000003    LEE TSAE YUN                                                     
A0000004    SOFFUAN SAURI   

But when I try to compare with previous value. My program only can check for user A000000001, not the other users.

How can I modify the progrtam so that all users are checked?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
user1516536
  • 23
  • 2
  • 5

2 Answers2

3

At line 19.01, why are you using *LOVAL to set the lower limit? Seems to me you'd be better served with "USRID ... SETLL", and that should solve your problem. When you SETLL, you are positioning the cursor to the value in Factor 1. When Factor 1 is *LOVAL, this positions to the beginning of the file.

The next (READE) operation then retrieves, the record after/at the current position, and compares its key value against the key specified in factor 1. Since you are positioning to the beginning of the file, the READE will ONLY match the first (lowest-order) key in the file, so the effect is that only the lowest key will appear to work.

Out of curiosity, why are you not writing in free form? Compare/contrast...

SETLL usrid USRTS ;
READE usrid USRTS ;
DOW Not %EOF(USRTS) ;
   IF USRDT >= MIN ;
      MAX = USRTO ;
      MIN = USRDT ;
   EndIF ;
   READE usrid USRTS ;
EndDO ;
EndSR ;
Dennis
  • 1,071
  • 2
  • 17
  • 38
  • This is only going to read records that match the USRID field. %EOF will turn on only when USRID changes. Is that what is desired? – David G Jul 30 '12 at 22:53
  • BTW, +1 on the free form comment. – David G Jul 30 '12 at 22:53
  • @david - Not sure if that's what's desired (though it does look like it, based upon content). I only emulated the code above. Or at least it looks like it to me. – Dennis Jul 31 '12 at 23:25
  • I thought the OP wanted to process ALL the user records in the file. – David G Aug 01 '12 at 14:26
0

If you want to read ALL user records from the file, change the READE to just READ (and remove the key parameter).

David G
  • 3,940
  • 1
  • 22
  • 30