DO UNTIL (H_REC2.DATE(I) = H_REC1.DATE2);
I = I + 1;
H_REC2.DATE(I) = DAYSTODATE(DAYS(H_REC1.DATE1,DATE_FORMAT) +
DT_CTR,DATE_FORMAT);
IF SUBSTR(H_REC2.DATE(I),1,1) = '0' THEN
SUBSTR(H_REC2.DATE(I),1,1) = ' ';
DT_CTR=DT_CTR + 1;
END;
H_REC1.DATE2 will have the value of last month end date, i.e., 30 or 31 or 28 or 29 based on the current month.
H_REC1.DATE1 will have for any month 1MMMYY i.e., for ex 1OCT19. so I have coded as below.
Code:
H_REC1.DATE1 = ' 1' || SUBSTR(H_REC1.DATE2,3,5);
IF SUBSTR(H_REC1.DATE1,1,1) = '0' THEN
SUBSTR(H_REC1.DATE1,1,1) = ' ';
H_REC2.DATE(1)=H_REC1.DATE1;
to supress any leading zero i have replaced '0' with ' ' in first char of date field.
I need to generate column heading starting from 1OCT19 02OCT19 03OCT19...upto end of the month 31OCT19 for a report.
For this I have coded the below.
Code:
DO UNTIL (H_REC2.DATE(I) = H_REC1.DATE2);
I = I + 1;
H_REC2.DATE(I) = DAYSTODATE(DAYS(H_REC1.DATE1,DATE_FORMAT) +
DT_CTR,DATE_FORMAT);
IF SUBSTR(H_REC2.DATE(I),1,1) = '0' THEN
SUBSTR(H_REC2.DATE(I),1,1) = ' ';
DT_CTR=DT_CTR + 1;
END;
The code is working fine.
But I have got the below comments asking to change the code.
Code:
Though the code happens to work in this case, because the last day of the month has a double digit number, it is still problematic, since it compares dates with leading blanks to dates with leading zeros. I would suggest using a FOR loop instead of the DO UNTIL, and using the number of days in the month to determine the number of column headers required. This will be more reliable and also simpler. If you wish, you can even set the day using the subscript variable, instead of doing a calculation to determine it.
Please suggest the code for this comment using FOR loop. I am new to PL/I this is my second program. Please help me with declarations and code for this part.
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
Posted: Wed Nov 27, 2019 4:35 pm Post subject:
Convert J to PIC before assigning that intermediate to CHAR otherwise you will (used to) get a message saying "conversion will be done by sub-routine call". Do this for all conversions. _________________ Utility and Program control cards are NOT, repeat NOT, JCL.
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Thu Nov 28, 2019 8:32 am Post subject:
tvssv,
You have been a member on this site for more than a decade and yet you cannot simply follow the rules. I warned you even 3 months ago on August 22nd 2019 about using descriptive titles to your problems, but you still ignore and chose the topic title as PL/I help
Keep this charade up once more, you will never be able to post questions on this forum. _________________ Kolusu
www.linkedin.com/in/kolusu
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