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 

Date Functions in PL/I

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


Joined: 11 Mar 2009
Posts: 58
Topics: 25

PostPosted: Mon Jul 29, 2019 11:07 am    Post subject: Date Functions in PL/I Reply with quote

Hi,

I am new to PL/I programming. This is first Program. Please Help.

I have written the program and getting the desired result 95%. The only thing pending is to generate Heading for the columns.

My Report generated from PL/I program is as below.
Code:

XXXXXX                    8JUL19   9JUL19  10JUL19  11JUL19  12JUL19  13JUL19  14JUL19

XXXXXXXXX AIRLINES         20.18    20.10    20.11    20.14    20.10    19.53    19.47
XXX SYSTEMS                20.18    20.09    20.10    20.13    20.09    19.53    19.47
XXXXXXXXXX                 20.18    20.09    20.10    20.13    20.09    19.53    19.47
XXXXXXX                    20.18    20.09    20.10    20.13    20.10    19.53    19.47


I Have to generate this report weekly. I have generated this using PL/I program. My problem here is the first row is dates of previous week starting from monday. The program written is working fine now. But if any job did not run on particular day it is comming wrongly. For example if the job did not run on 8JUL19 that job will have only 6 days data and the program will wrtie it starting from 8JUL19 instead of 9JUL19.

I searched and did not find propler help on date functions in PL/I. Could you please refer any website for date funtions.

My idea is to take the system date in pli program and subtract 7 from it and starting from (systam date - 7 ) value I want to add 1 to each date and place the dates in header as they are fixed. If I can acheive this I can tune my existing code for remaining result.

Please help me out with date functions in PL/I. Example Code for this will be more helpful.

Thanks
_________________
Thanks
TVSSV
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 621
Topics: 173
Location: Stockholm, Sweden

PostPosted: Tue Jul 30, 2019 1:15 am    Post subject: Reply with quote

Not sure EXACTLY what you want. I haven't written any PL/1 for about 20-30 years, but since you already have the code (basically) working, couldn't you simply populate the missing date column values with something like --.-- to indicate they are missing?
So, instead of 20.18 in the first line above, you'd have --.--
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Jul 30, 2019 5:56 am    Post subject: Reply with quote

The DATE builtin function is properly documented in the PL/I Language Reference Guide accessible via the Manuals link above, or by Google search on the internet.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Jul 30, 2019 2:56 pm    Post subject: Reply with quote

tvssv,

Download the PDF manual for "Enterprise PL/I Language Reference" from here

https://www-01.ibm.com/support/docview.wss?uid=swg27036735

Read Chapter 18. Built-in functions, pseudovariables, and subroutines.

Look for the built-in function "Days" and you will find an example.

something like this
Code:

 TESTPGM: PROCEDURE OPTIONS(MAIN);                         
 DCL DATE_FORMAT VALUE ('YYYYMMDD') CHAR;                 
 DCL TODAYS_DATE CHAR(LENGTH(DATE_FORMAT));               
 DCL LAST_WEEK_DATE CHAR(LENGTH(DATE_FORMAT)) INIT(' ');   
                                                           
 TODAYS_DATE    = DATETIME(DATE_FORMAT);                   
 LAST_WEEK_DATE = DAYSTODATE(DAYS() - 07, DATE_FORMAT);   
                                                           
 DISPLAY (' THE CURRENT DATE IS    : '  ||                 
          SUBSTR(TODAYS_DATE, 1, 4)     ||'-' ||           
          SUBSTR(TODAYS_DATE, 5, 2)     ||'-' ||           
          SUBSTR(TODAYS_DATE, 7, 2));                     
                                                           
 DISPLAY (' THE LAST WEEK DATE IS  : '  ||                 
          SUBSTR(LAST_WEEK_DATE, 1, 4)  ||'-' ||           
          SUBSTR(LAST_WEEK_DATE, 5, 2)  ||'-' ||           
          SUBSTR(LAST_WEEK_DATE, 7, 2));                   
                                                           
 END TESTPGM;                                             


The output is
Code:

+ THE CURRENT DATE IS    : 2019-07-30     
+ THE LAST WEEK DATE IS  : 2019-07-23     

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

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


Joined: 11 Mar 2009
Posts: 58
Topics: 25

PostPosted: Tue Aug 13, 2019 10:38 am    Post subject: Reply with quote

I have coded the PLI code as below.
Code:

SIDTST2: PROC OPTIONS(MAIN);                                     
                                                                 
DCL DATE_FORMAT VALUE ('DDMMMYY') CHAR;                         
DCL TODAYS_DATE CHAR(LENGTH(DATE_FORMAT));                       
DCL LAST_WEEK_DATE CHAR(LENGTH(DATE_FORMAT)) INIT(' ');         
                                                                 
                                                                 
TODAYS_DATE    = DATETIME(DATE_FORMAT);                         
LAST_WEEK_DATE = DAYSTODATE(DAYS() - 07, DATE_FORMAT);           
DISPLAY (" THE CURRENT DATE IS    : " || TODAYS_DATE);           
DISPLAY (" THE LAST WEEK DATE IS  : " || LAST_WEEK_DATE);       
END SIDTST2;                                                     


JCL as below.

Code:


//JOBLIB  DD   DSN=LOADLIB,DISP=SHR         
//        DD   DSN=PROD.LOADLIB,DISP=SHR         
//SID26505 EXEC PGM=SIDTST2,REGION=2M                       
//*                                                         
//PLIDUMP  DD   SYSOUT=*                                   
//SYSOUT   DD   SYSOUT=*                                   
//SYSPRINT DD   SYSOUT=*                                   
//SYSUDUMP DD   SYSOUT=*                                   
//*                                                         


Job is running fine but I am not able to see the output Display statements. Please correct me.

Thanks
_________________
Thanks
TVSSV
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Aug 13, 2019 10:47 am    Post subject: Reply with quote

tvssv wrote:

Job is running fine but I am not able to see the output Display statements. Please correct me.

Thanks


tvssv,

The Display statements are writing to the operator(WTO), so you can find them in the JESMSGLG of your job output.

Put a ? next to the job output in SDSF and it will expand the job log into individual segments. Check the JESMSGLG and you will find your Display statement outputs.

or you can look at the job from the beginning.
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Aug 13, 2019 3:26 pm    Post subject: Reply with quote

You should not be sending messages to the console. Use PUT to send them to SYSPRINT.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
tvssv
Beginner


Joined: 11 Mar 2009
Posts: 58
Topics: 25

PostPosted: Thu Aug 15, 2019 1:16 pm    Post subject: Reply with quote

Hi,

I am facing a problem. My Input file is having dates as below.
Code:

 8AUG19
 9AUG19
10AUG19
11AUG19
12AUG19
13AUG19
14AUG19


But the dates generated using the PLI program are as below.

Code:

08AUG19
09AUG19
10AUG19
11AUG19
12AUG19
13AUG19
14AUG19


How to remove leading zero in PLI program, because when I am comparing the dates 08AUG19 & 8AUG19 are not matching and my program is not executing correctly, I mean I am not getting desired report because of leading zero.

I am getting the dates correctly by below code but only problem is I need to supress the leading zero in date.
Code:

DCL DATE_FORMAT       VALUE ('DDMMMYY') CHAR;

DCL TODAYS_DATE       CHAR(LENGTH(DATE_FORMAT)) INIT(' ');
DCL LAST_WEEK_DATE    CHAR(LENGTH(DATE_FORMAT)) INIT(' ');
DCL 1 H_REC2,                                                           
      2 SYSTEM          CHAR(08),                                       
      2 FILL1           CHAR(17) INIT(' '),                             
      2 DATA(7),                                                       
        3 DATE          CHAR(07) INIT((*) (' ')),                       
        3 FILL2         CHAR(02) INIT((*) (' ')),                       
      2 FILL3           CHAR(2) INIT(' ');                             

I       = 1;   
DATE_CTR = 7; 

DO WHILE (I<=7);                                                           
   H_REC2.DATE(I) = DAYSTODATE(DAYS() - date_ctr, DATE_FORMAT);
   H_REC2.DATE(I) = FDATE;                                         
   I = I + 1;                                                     
   DATE_CTR = DATE_CTR - 1;                                       
END;                         


Please help me out with solution to supress the leading zero in date.

Thanks
_________________
Thanks
TVSSV
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu Aug 15, 2019 2:45 pm    Post subject: Reply with quote

According to your code snippet the dates are in CHAR format therefore you can SUBSTR a blank into the first position if it is 0 but better would be to define an array over the date and set element 1 to blank if it is 0.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
tvssv
Beginner


Joined: 11 Mar 2009
Posts: 58
Topics: 25

PostPosted: Thu Aug 22, 2019 2:04 am    Post subject: Reply with quote

Hi,

Thank you so much. I have coded as below and I am getting the desired result.
Code:

H_REC1.DATE1 = DAYSTODATE(DAYS() - 07, DATE_FORMAT);                   
H_REC1.DATE2 = DAYSTODATE(DAYS() - 01, DATE_FORMAT);                   
                                                                       
WRITE FILE(OUTFILE) FROM (H_REC1);                                     
WRITE FILE(OUTFILE) FROM (OUTREC2);                                   
                                                                       
DO WHILE (I<=7);                                                       
   H_REC2.DATE(I) = DAYSTODATE(DAYS() - DATE_CTR, DATE_FORMAT);       
   IF SUBSTR(H_REC2.DATE(I),1,1) = '0' THEN                           
      SUBSTR(H_REC2.DATE(I),1,1) = ' ';                               
   I = I + 1;                                                         
   DATE_CTR = DATE_CTR - 1;                                           
END;                                                                   


I have one question. I referred in PL/1 manual, but not able to find.

Is it required to declare the below builtin functions in program
Code:

DCL DATETIME          BUILTIN;
DCL SUBSTR            BUILTIN;
DCL DAYS              BUILTIN;
DCL DAYSTODATE        BUILTIN;
DCL LENGTH            BUILTIN;


Without declaring also it is working. Is there any advantage by declaring in program. Please advise.

Thanks
_________________
Thanks
TVSSV
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu Aug 22, 2019 4:01 am    Post subject: Reply with quote

If you look at your compiler messages you will see the difference between declaring them and not declaring them - possibly the return code as well. You should aim to have as few messages as possible. It makes no difference - as long as the compiler is correct in think that you want the builtin functions. Actually, the keyword BUILTIN should have answered your question. It is not there for fun.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
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