DEFINED and BASED query



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

DEFINED and BASED query

Postby AusZosGuy » Wed Sep 08, 2021 8:04 pm

Hi All, Hoping you are doing well.
Just for my understanding on the PL1 concepts of based and defined I was trying to do the below but getting compilation error.
DCL C FIXED DEC(5,0) INIT(10);
DCL C_DEF CHAR(02) DEF C;
I am getting -> IBM1385I E Invalid DEFINED - string overlay defining attempted.
( I have even tried doing the same using BASED but to no avail)
Does it mean that we cannot do this way?
I was just trying to think it in terms of Cobol redefine where we have numeric value of date and can redefine it in char.
Please advise whether it is possible in PL1 as I am new to PL1 arena.
Thanks in advance.
AusZosGuy
 
Posts: 5
Joined: Mon Aug 23, 2021 5:01 pm
Has thanked: 2 times
Been thanked: 0 time

Re: DEFINED and BASED query

Postby prino » Thu Sep 09, 2021 3:59 pm

dcl c_based char(2) based(addr(c));

dcl 1 * union,
      2 c fixed (5),
      2 cc char (3);


And it is PL/I, not PL1
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy

These users thanked the author prino for the post:
AusZosGuy (Thu Sep 09, 2021 4:35 pm)
User avatar
prino
 
Posts: 617
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: DEFINED and BASED query

Postby AusZosGuy » Thu Sep 09, 2021 4:33 pm

Thanks Robert for the reply and indeed for PL1-> PL/I thing :-)

Also, I am trying to test this below but getting Invalid DEFINED - string overlay defining attempted compilation error.
DCL A FIXED DEC(7,1) INIT(0);
DCL AX CHAR(3) DEF A;
PUT SKIP LIST ('A IS:',A);
PUT SKIP LIST ('AX IS:',AX);
is it that I have to set some compiler option to overcome this?
Because I have seen exactly the same code in one of the existing program ( but not able to test that as it belongs to some other system and present in endevor)
If it has been there in prod then why I am getting error while testing using my own compile JCL.
Maybe some compiler option need to be active?
Thanks
AusZosGuy
 
Posts: 5
Joined: Mon Aug 23, 2021 5:01 pm
Has thanked: 2 times
Been thanked: 0 time

Re: DEFINED and BASED query

Postby AusZosGuy » Thu Sep 09, 2021 4:48 pm

Hi Robert, also as you suggested I tested the based thing the union way you suggested but it is not displaying what I was expecting:
I moved 12 to -> c fixed (5) and was expecting that c_based will also display 12 but it is not.
Same way I tried to move 10 to c_based and was expecting C to have the same value but it is causing data exception somehow. (IBM0537S ONCODE=8097 Data exception).
do you have any idea please suggest what I might be doing wrong.
AusZosGuy
 
Posts: 5
Joined: Mon Aug 23, 2021 5:01 pm
Has thanked: 2 times
Been thanked: 0 time

Re: DEFINED and BASED query

Postby sergeyken » Thu Sep 09, 2021 6:33 pm

AusZosGuy wrote:Hi Robert, also as you suggested I tested the based thing the union way you suggested but it is not displaying what I was expecting:
I moved 12 to -> c fixed (5) and was expecting that c_based will also display 12 but it is not.
Same way I tried to move 10 to c_based and was expecting C to have the same value but it is causing data exception somehow. (IBM0537S ONCODE=8097 Data exception).
do you have any idea please suggest what I might be doing wrong.

After the value 12 has been "moved" to a DEC FIXED(5) variable, its value is stored in memory (as hex, 3 bytes) like '00012C'X
When trying to print this value as CHAR(3) it is printed as 3 characters:
#1: code '00'X - non-printable character
#2: code '01'X - non-printable character
#3: code '2C'X - non-printable character

What you are trying to do has no sense, at all, from the very beginning.
I recommend you to start studying the Computer Science from scratch, and then to learn PL/I basics, and syntax.
Before that, do not try to create any real program, except simple and trivial tests.
Javas come and go, but JCL stays forever.

These users thanked the author sergeyken for the post:
AusZosGuy (Fri Sep 10, 2021 6:23 am)
User avatar
sergeyken
 
Posts: 207
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 3 times
Been thanked: 19 times

Re: DEFINED and BASED query

Postby AusZosGuy » Fri Sep 10, 2021 6:19 am

Thanks Sergeyken for your time to reply, agree with you, I will study it.
Guess I got confused with decimal as normal INT in COBOL like 9(5) where as it is equivalent to comp-3 which is packed decimal.
So I have tried using PIC type in PL/I and moving fixed dec to pic and then CHAR defined on this pic and it worked fine.
DCL A FIXED DEC(7,1) INIT(0);
DCL A_PIC PIC '(7)9'
DCL AX CHAR(7) DEF A_PIC;
DCL A_NUMB PIC '(06)9' INIT(0);
DCL A_CHAR CHAR(6) DEF A_NUMB;
A_PIC = A;
PUT SKIP LIST ('A:',A);
PUT SKIP LIST ('A_PIC:',A_PIC);
PUT SKIP LIST ('AX:',AX);
PUT SKIP LIST ('A_NUMB:',A_NUMB);
PUT SKIP LIST ('A_CHAR:',A_CHAR);
Thanks.
AusZosGuy
 
Posts: 5
Joined: Mon Aug 23, 2021 5:01 pm
Has thanked: 2 times
Been thanked: 0 time

Re: DEFINED and BASED query

Postby sergeyken » Fri Sep 10, 2021 6:03 pm

DEC FIXED in PL/I is equivalent to COMP-3 in COBOL.
BIN FIXED in PL/I is equivalent to COMP (or COMP-1) in COBOL.

In both cases it makes absolutely no sense to re-define different data types at the same location of memory, as shown in your post.

You did not explain your final goal, but your intermediate example is absolutely senseless.
Javas come and go, but JCL stays forever.
User avatar
sergeyken
 
Posts: 207
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 3 times
Been thanked: 19 times

Re: DEFINED and BASED query

Postby AusZosGuy » Fri Sep 10, 2021 6:40 pm

Thanks Sergeyken for your feedback!!
I was just fiddling around to see if it was possible to achieve such thing in PL/I, no real requirement as such !!
I am just trying to explore different attributes/variables/features of the language.
Believe PL/1 is far more versatile than Cobol with lots of builtin functions and other stuff.
I am a learner here and appreciate all the feedback.
I am happy that people are active here and replying too :-)
Have a great weekend!!
AusZosGuy
 
Posts: 5
Joined: Mon Aug 23, 2021 5:01 pm
Has thanked: 2 times
Been thanked: 0 time


Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post