Page 1 of 1

DEFINED and BASED query

PostPosted: Wed Sep 08, 2021 8:04 pm
by AusZosGuy
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.

Re: DEFINED and BASED query

PostPosted: Thu Sep 09, 2021 3:59 pm
by prino
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

Re: DEFINED and BASED query

PostPosted: Thu Sep 09, 2021 4:33 pm
by AusZosGuy
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

Re: DEFINED and BASED query

PostPosted: Thu Sep 09, 2021 4:48 pm
by AusZosGuy
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.

Re: DEFINED and BASED query

PostPosted: Thu Sep 09, 2021 6:33 pm
by sergeyken
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.

Re: DEFINED and BASED query

PostPosted: Fri Sep 10, 2021 6:19 am
by AusZosGuy
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.

Re: DEFINED and BASED query

PostPosted: Fri Sep 10, 2021 6:03 pm
by sergeyken
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.

Re: DEFINED and BASED query

PostPosted: Fri Sep 10, 2021 6:40 pm
by AusZosGuy
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!!