View previous topic :: View next topic |
Author |
Message |
tvssv Beginner
Joined: 11 Mar 2009 Posts: 58 Topics: 25
|
Posted: Mon Jul 29, 2019 11:07 am Post subject: Date Functions in PL/I |
|
|
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 |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Tue Jul 30, 2019 1:15 am Post subject: |
|
|
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 |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Jul 30, 2019 5:56 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Jul 30, 2019 2:56 pm Post subject: |
|
|
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
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
tvssv Beginner
Joined: 11 Mar 2009 Posts: 58 Topics: 25
|
Posted: Tue Aug 13, 2019 10:38 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Aug 13, 2019 10:47 am Post subject: |
|
|
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
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Aug 13, 2019 3:26 pm Post subject: |
|
|
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 |
|
|
tvssv Beginner
Joined: 11 Mar 2009 Posts: 58 Topics: 25
|
Posted: Thu Aug 15, 2019 1:16 pm Post subject: |
|
|
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 |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Thu Aug 15, 2019 2:45 pm Post subject: |
|
|
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 |
|
|
tvssv Beginner
Joined: 11 Mar 2009 Posts: 58 Topics: 25
|
Posted: Thu Aug 22, 2019 2:04 am Post subject: |
|
|
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 |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Thu Aug 22, 2019 4:01 am Post subject: |
|
|
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 |
|
|
|
|