View previous topic :: View next topic |
Author |
Message |
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Mon Oct 18, 2010 1:22 pm Post subject: PL1 Data Conversion |
|
|
Variable Cal_year is a four characters digits. I want to add 1 to Cal_Year and return the last 2 digits. In REXX:
Code: |
Cal_Year = '2008'
Next_Year = substr(Cal_Year+1,3,2)
Result: Next_Year = '09'
|
How is it being implemented in PL1? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Oct 18, 2010 3:03 pm Post subject: |
|
|
danm,
Unless I am missing something isn't it a simple redefine? Untested code
Code: |
DCL 1 DATAREC,
3 CHARFLD CHAR(4);
DCL 1 NUMFLD BASED(ADDR(DATAREC)),
3 NUMA,
5 NUMFLD1 PICTURE '99',
5 NUMFLD2 PICTURE '99';
DCL 1 RESULT CHAR(4);
CHARFLD = '2008';
NUMFLD2 = NUMFLD2 + 1;
RESULT = CHARFLD;
|
Kolusu |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Oct 19, 2010 12:04 am Post subject: |
|
|
ccyy = '2008';
ccyy= ccyy + 1;
yy = substr(ccyy,3)
If your characters are integers then integer arithmetic is allowed in PL/1. However, a redefine as follows:
dcl yy pic '99' def ccyy pos(3);
would be preferable. _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Tue Oct 19, 2010 9:57 am Post subject: |
|
|
Thanks. Declaring Cal_Year as PIC '9999' solve the problem. |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Oct 19, 2010 4:15 pm Post subject: |
|
|
Quote: | If your characters are integers then integer arithmetic is allowed in PL/1. |
True in V1 and V2 but not in V3 _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
|
|