Home > Ask the AS/400 Experts > iSeries Application Development Questions & Answers > Retrieving the system date in a CL program
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Retrieving the system date in a CL program

Tim Granatir EXPERT RESPONSE FROM: Tim Granatir

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 11 February 2004
I have retrieved the system date (QDATE) using RTVSYSVAL in my CL program. I know to advance the date by one date, but how can I achieve this within the CL program? I do not want to make an external call to a program.

>

You would have to use the convert date to convert your date to Julian, add 1 to it, check for leap year and make adjustments and then convert it back. A good example of this technique used to be found in the old TAATools in the ADDDAT command. Here is that example. This command has a six-character date but that can easily be changed with a very slight modification.

/* Add date command source ** 

CMD        PROMPT('Add Date')                          
PARM       KWD(DAYS) TYPE(*DEC) LEN(5) RANGE(-35000 +  
             35000) MIN(1) PROMPT('Nbr of days to +    
             add/sub   (5 0)')                         
PARM       KWD(TOVAR) TYPE(*CHAR) LEN(6) RTNVAL(*YES) +
             MIN(1) PROMPT('New date variable          
             (6)')                                     
PARM       KWD(DATE) TYPE(*DEC) LEN(6 0) DFT(*TODAY) + 
             RANGE(000000 999999) SPCVAL((*TODAY 0)) + 
             PROMPT('Date (sys fmt)           (6 0)')  

 

/* Add date CL source ** 

PGM        PARM(&DAYS &TOVAR &DATE)                        
DCL        &DAYS *DEC LEN(5 0)                             
DCL        &TOVAR *CHAR LEN(6)                             
DCL        &DATE *DEC LEN(6 0)                             
DCL        &WRKDAT *CHAR LEN(6)                            
DCL        &JULIANA *CHAR LEN(5)                           
DCL        &YRD *DEC LEN(2 0)                              
DCL        &DAYSD *DEC LEN(3 0)                            
DCL        &LEAP *DEC LEN(2 0)                             
DCL        &DAYSINYEAR *DEC LEN(3 0)                       
DCL        &NUM5 *DEC LEN(5)                               
DCL        &NUM2 *DEC LEN(2)                               
           /* &DATE=0 is special value *TODAY */           
IF         (&DATE *EQ 0) RTVJOBA DATE(&WRKDAT)             
IF         (&DATE *NE 0) CHGVAR &WRKDAT &DATE              
CVTDAT     DATE(&WRKDAT) TOVAR(&JULIANA) TOFMT(*JUL) +     
             TOSEP(*NONE) /* Convert to Julian */          
MONMSG     MSGID(CPF0555) EXEC(SNDPGMMSG +                 
           MSGID(CPF9898) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) + 
           MSGDTA('DATE parameter value cannot +           
           be converted'))                                 
           /* Substring for year and day */                
CHGVAR     &YRD %SST(&JULIANA 1 2)                         
CHGVAR     &DAYSD %SST(&JULIANA 3 3)  

             CHGVAR     VAR(&NUM5) VALUE(&DAYSD + &DAYS) /* Add days */  
 CHKPLUS:    IF         (&NUM5 *GT 0) GOTO CHKLEAP /* If positive */     
             IF         (&YRD *EQ 00) CHGVAR &YRD 99 /* Year 2000 */     
             ELSE       CHGVAR &YRD (&YRD -1) /* Decrement year */       
 CHKLEAP:    CHGVAR     &NUM2 (&YRD / 4) /* Chk leap year */             
             CHGVAR     &LEAP (&YRD - (&NUM2 * 4))                       
             IF         (&LEAP *GT 0) CHGVAR &DAYSINYEAR 365             
             ELSE       CHGVAR &DAYSINYEAR 366 /* Leap year */           
             IF         (&NUM5 *LE 0) DO /* Days are negative */         
             CHGVAR     &NUM5 (&NUM5 + &DAYSINYEAR)                      
             GOTO       CHKPLUS /* Check for positive days */            
             ENDDO      /* End negative days */                          
             IF         (&NUM5 *GT &DAYSINYEAR) DO /* Ovfl */            
             IF         (&YRD *EQ 99) CHGVAR &YRD -1 /* Year 2000 */     
             CHGVAR     &YRD (&YRD + 1)  /* Bump year */                 
             CHGVAR     &NUM5 (&NUM5 - &DAYSINYEAR) /* Subtract */       
             GOTO       CHKLEAP /* Test for next year */                 
             ENDDO      /* End days greater than days-in-year */         
             CHGVAR     &DAYSD &NUM5  /* Chg to 3 digits */              
                             /* Substring back into Julian date */       
             CHGVAR     %SST(&JULIANA 1 2) &YRD                          
             CH 


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries Application Development
Monitoring escape messages and using RCVMSG for diagnostic messages
Listing contents of multiple FTP directories on AS/400
Chain operation error after converting RPG3 to ILE RPG (RPGIV)
Space offset X'0015FF00' or X'0000000000000000' is outside current limit for object QIGC2424C
Searching fields for values
iSeries application display subfiles with other program windows
Searching part of a name or address in AS/400
Passing parameters in an ILE RPG module
What's happening to my subfile?
What happening to my subfile?

RPG iSeries programming
Enhancing RPG with external SQL stored procedures
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Allow access to data from a stored procedure result set using COBOL or RPG
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
A taste of COMMON: ILE, IBM releases, Web applications and new products
Documenting nested program structures on the AS/400

iSeries ILE programming
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
How to use an embedded SQL statement and display the result in a subfile
Eight steps for creating program documentation using AS/400 utilities
Searching fields for values
Searching part of a name or address in AS/400
Top 10 programmer tips YTD
How to use the binder language to manage service programs -- Part 3: Examples and pitfalls
Top 10 programmer tips of 2005
Understanding the binder language on AS/400

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Report Program Generator  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts