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 

PL/I programming Help

 
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: Tue Nov 26, 2019 1:04 pm    Post subject: PL/I programming Help Reply with quote

I have written the below code.


Code:

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

DCL CTR               FIXED BIN(31) INIT(0);                     
DCL CTR2              FIXED BIN(31) INIT(0);                     
DCL I                 FIXED BIN(31) INIT(0);                     
DCL DT_CTR            FIXED BIN(31) INIT(0);                     
DCL H_DATE2_CTR       FIXED BIN(31) INIT(0);                     
DCL OR4_CTR           FIXED BIN(31) INIT(0);                     
DCL O4_CTR            FIXED BIN(31) INIT(0);                     
DCL D_NUM             FIXED BIN(31) INIT(0);                     
DCL @PTR              POINTER;                                   
DCL EOF1              BIT(1)   INIT('0'B);                       
DCL OUT4              CHAR(1)  INIT('N');                         
                                                                 
DCL DATE_FORMAT       VALUE ('DDMMMYY') CHAR;                     
DCL TODAYS_DATE       CHAR(LENGTH(DATE_FORMAT)) INIT(' ');       

DCL 1 H_REC1,                                                       
      2 FILL1           CHAR(50)  INIT(' '),                         
      2 TEXT            CHAR(39)  INIT                               
                        ('THE SABRE & ABACUS MIDT FTP TIMES FROM '),
      2 DATE1           CHAR(07)  INIT(' '),                         
      2 FILL2           CHAR(01)  INIT(' '),                         
      2 FILL3           CHAR(03)  INIT('TO '),                       
      2 DATE2           CHAR(07)  INIT(' '),                         
      2 FILL4           CHAR(199) INIT(' ');                         
                                                                     
DCL 1 H_REC2,                                                       
      2 SYSTEM          CHAR(08),                                   
      2 FILL1           CHAR(17) INIT(' '),                         
      2 DATA(31),                                                   
        3 DATE          CHAR(07) INIT((*) (' ')),                   
        3 FILL2         CHAR(02) INIT((*) (' ')),                   
      2 FILL3           CHAR(2)  INIT(' ');           

OUTREC2  = ' ';                             
H_REC2   = ' ';                             
OUTREC1  = ' ';                             
OUTREC4  = ' ';                             
CTR      = 1;                               
I        = 1;                               
OR4_CTR  = 1;                               
O4_CTR   = 0;                               
DT_CTR   = 1;                               

TODAYS_DATE    = DATETIME(DATE_FORMAT);                             
H_REC1.DATE2 = DAYSTODATE((DAYS(TODAYS_DATE,DATE_FORMAT) -         
                          SUBSTR(TODAYS_DATE,1,2)),DATE_FORMAT);   
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;                                       

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.

Thanks
_________________
Thanks
TVSSV
Back to top
View user's profile Send private message
tvssv
Beginner


Joined: 11 Mar 2009
Posts: 58
Topics: 25

PostPosted: Tue Nov 26, 2019 1:12 pm    Post subject: Reply with quote

My sample report looks like below.

Code:

                                     THE SABRE & ABACUS MIDT FTP TIMES FROM  1OCT19 TO 31OCT19

ABACUS                    1OCT19   2OCT19   3OCT19   4OCT19   5OCT19   6OCT19   7OCT19   8OCT19   9OCT19  10OCT19  11OCT19  12OCT19  13OCT19  14OCT19  ....  30OCT19  31OCT19


[/code]
_________________
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: Tue Nov 26, 2019 3:48 pm    Post subject: Reply with quote

There is no FOR loop structure in PL/I. Does this person mean:
Code:

DO counter_variable = inital_value TO end_value

?
_________________
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: Tue Nov 26, 2019 9:37 pm    Post subject: Reply with quote

Nic Clouston wrote:
There is no FOR loop structure in PL/I. Does this person mean:
Code:

DO counter_variable = inital_value TO end_value

?


Yes, it should be.
_________________
Thanks
TVSSV
Back to top
View user's profile Send private message
tvssv
Beginner


Joined: 11 Mar 2009
Posts: 58
Topics: 25

PostPosted: Wed Nov 27, 2019 6:11 am    Post subject: Reply with quote

tvssv wrote:
Nic Clouston wrote:
There is no FOR loop structure in PL/I. Does this person mean:
Code:

DO counter_variable = inital_value TO end_value

?[/code]


Yes, it should be.


I have coded as below.
Code:

DCL j                 fixed dec(2) INIT(0);   
DCL EDATE_CTR         FIXED dec(2) INIT(0);
DCL DT_CTR            FIXED BIN(31) INIT(0);
DCL wdd               char(8);


edate_ctr = substr(H_REC1.DATE2,1,2);                               
do j = 2 to edate_ctr by 1;                                         
     wdd = j;                                                       
     H_REC2.DATE(j) = substr(wdd,4,2) || substr(h_rec1.date2,3,5);   
     DT_CTR=DT_CTR + 1;                                             
end;                                                                 


I am getting desired result. But not sure whether assigning value J to WDD and declaring WDD as char(8) are correct. 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: Wed Nov 27, 2019 4:35 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Nov 28, 2019 8:32 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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