RPG date calculations

265 pts.
Tags:
RPG
RPG Programs
I need to add 28 days from the system date and output it into a file in the format mmddyyyy. I can not use free RPG or RPGLE. Could you help, please?

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 28  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • CharlieBrowne
    You say you cannot use RPG or RPGLE, what can you use?We need to know that before we can give you the best answer.Also can you give us more information as tpo how this is suppose to happen. Like it it just a CL that retrieves today's date? Are you reading a file to get the initial date?  Can you use SQL?
    41,370 pointsBadges:
    report
  • philpl1jb
    I think he/she was saying they cannot use Free.  But I would suppose they can use RPGLE.  Now what is the type of the output .. a numeric, character or date field?
    49,590 pointsBadges:
    report
  • TomLiotta
    The question needs to be explained better. I would also guess that it is the [/FREE] directive that can't be used, though it doesn't make sense to say so unless the release is too old. And if a specific format is needed, it wouldn't make sense for it to be a DATE data type unless it was a DSPF or PRTF. DATE fields in PFs or LFs aren't written with formats; the values are stored in internal format. -- Tom
    125,585 pointsBadges:
    report
  • BigKat
    also sounds like a homework question, so the poster should show what they have tried and what they are getting that is wrong.  We'll help you learn, but we don't do your work for you.
    7,935 pointsBadges:
    report
  • Larisagas
    Thanks for all responces. I meant I cannot use free RPG. It's old RPG Program. I wrote the code, but it's adds 28 to the year. Please help me to learn.    
    265 pointsBadges:
    report
  • Larisagas
    It's should add to todays date in format 113020 +28, convert new date to 031713. I just need to print new date on the paper. Thanks again  
    265 pointsBadges:
    report
  • philpl1jb
    So in RPGLE it might look like this
    
    D    DateC10       10 A
    
    C     Eval  DateC10 = %Char(%date() + %days(28)) : *USA)
    
    This takes the current date %Date()
    adds 28 days .. + %days(28)
    Then converts it to a character string of format *USA (mm/dd/yyyy)
    
    
    49,590 pointsBadges:
    report
  • Larisagas
    Thanks Philp1.jb, I'll try that.
    265 pointsBadges:
    report
  • Larisagas
    The problem with the date, I have to pass 7 digits date format, for exapmle today is 1130220, I have to add 28 days to this date.  
    265 pointsBadges:
    report
  • Splat
    Your from date is in a *CYMD format, and your to date is in a *USA format.  Something like this might meet your requirements:
    *CYMD         MOVE      FROM          DATEFLD
                  ADDDUR    28:*DAYS      DATEFLD 
    *ISO          MOVE      DATEFLD       TO
    6,875 pointsBadges:
    report
  • Splat
    Sorry, left out the field definitions:
    D FROM		  S              7  0
    D DATEFLD         S               D   
    D TO              S              8  0
    6,875 pointsBadges:
    report
  • TomLiotta
    The problem is still insufficiently described. We don't yet know the OS version nor whether it's RPG II, RPG III or RPG IV. We only know that it's an "old" program and that for some reason /FREE supposedly can't be used. If things are really that old and that restricted, then there is no ADDDUR op-code nor %DATE() function. We still don't know how to answer because we aren't being told what the actual problem is. -- Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Perhaps it's time for you to show us how.  Here's a bit of reading but you can find plenty more.http://www.itjungle.com/fhg/fhg051904-story01.htmlorhttp://pmsinformationsystem.forumotion.net/t211-date-conversion-tips  
    49,590 pointsBadges:
    report
  • philpl1jb
    %date(Mydate : *CYMD) 
    49,590 pointsBadges:
    report
  • Larisagas
    Operation system is V6R1. Program in RPGIII. Date represents in system files: 1130221 for today. I guess I can call program in free RPG to calculate date, but how I can return parametr to old program? Thanks.  
    265 pointsBadges:
    report
  • BigKat
    you say that you wrote code but it is adding the 28 to the year.  Show us what you have written, and we can help you correct it.
    7,935 pointsBadges:
    report
  • philpl1jb
    Are you actually writing in RPG not RPGLE/RPG IV?  What is the member type.Free or fixed format allows practically the same code.  Programs can switch between free and fixed and back at any time .. start the free section with the compiler directive /Free and end it with /End-Free.The code I've been providing you can be used in either Fixed or Free but not in RPG .. in members of type RPGLE. 
    49,590 pointsBadges:
    report
  • Larisagas
       OEDTE4    ADD  28        WKSHDT              MOVE *BLANKS   DHLD                MOVE WKSHDT    DHLD                CALL 'CSYDTC'  PFYMD     MOVELDHLD      SHPDAT I am modifeing RPG III program with QRPGSRC    
    265 pointsBadges:
    report
  • philpl1jb
    Ah, so  "I can not use free RPG or RPGLE" should have been interpereted as "I can not use free RPG or any form of RPGLE".  Please desregard my previous responses, they were basedd on RPGLE.In RPG III or RPG/400 this can be a bit of an issue.  Perhaps the issues are handled in your program  ‘CSYDTC’  but we don't know.   The problem .. adding 28 days to Dec 5, 2013 will be Dec 33, 2013 ..
    49,590 pointsBadges:
    report
  • philpl1jb
    Given that you are committed to RPGIII .. 
    If you could change to sQLRPG then
    you can use the SQL date functions.
    
    If it's the system date plus 28 then this SQL commad might do it..
    
    C/Exec SQL Set :CvtDate = Current_Date + 28 Days
     C/End-Exec
    
    Define CVTDATE in the RPG code as Alptha 10
    It will contain the system date plus 28 days
    
     
    But if it's an input field that must be used you will need to get the
    input field into an 10 character alpha field .. Date10 in the format of 
    'MM/DD/20YY' and then this will do it:
    
    C/EXEC SQL  SET :CvtDate = Date(:DATE10) + days(28)
    C/END-EXEC    
    
    Note: I haven't tested this code 
    
    
    49,590 pointsBadges:
    report
  • TomLiotta
    It's more clear what the problem is. RPGIII doesn't have the more useful features of RPGIV, and the C-specs for adding date values in RPGIII are ugly. Also, for some reason, there is resistance to simply converting the program to RPGIV and fixing it permanently. So, the next best thing is to use a small RPGIV program to do the work and call it.
          * Convert CYYMMDD to mmddyyyy
         H Debug( *yes )
    
         D SDATMDYY        pr                  extpgm( 'SDATMDYY' )
         D  InDate                        7
         D  Mydate                        8
    
         D SDATMDYY        pi
         D  InDate                        7
         D  Mydate                        8
    
          /free
            Mydate = %char( %date(InDate : *CYMD0) + %days( 28 ):*USA0 );
            dsply InDate ;
            dsply Mydate ;
    
            *inlr = *on ;
            return ;
          /end-free
    That can be called from RPGIII with two parameters. The first is 7 characters that contain a CYYMMDD date value, and an 8 character return parameter will be a MMDDYYYY date value. The program name here is SDATMDYY because it converts a "system date" to MMDDYYYY format, but the name can be changed to anything needed. -- Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    The two DSPLY statements can be removed. They were only for some simple testing. -- Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Given the constraints, I liike Tom's answer. and if you wanted the / / in the format change the return field size to 10 and use *USA instead of *USA0 .. the 0 means no seperators.   Phil  
    49,590 pointsBadges:
    report
  • philpl1jb
    No, on second thought, I would pass the number of days as a third parameter to the RPGLE program .. that makes this program able to add any number of days passed.
    49,590 pointsBadges:
    report
  • Larisagas
    Thanks guys. I'll let you know what I got. 
    265 pointsBadges:
    report
  • philpl1jb
    thank Tom too..
    49,590 pointsBadges:
    report
  • TomLiotta
    Phil's right. The program would be more useful to have a third parameter to pass a number of days. If it was signed, the program could choose to add or subtract. Regardless, I'd still simply convert the whole program to RPGIV and remove the problem. -- Tom
    125,585 pointsBadges:
    report
  • Larisagas
    It worked fine. With a little change to Tom's code. Thanks everybody, Tom again for your help.  
    265 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following