IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Pl/1 program issue


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
hemanthj642

New User


Joined: 14 Sep 2005
Posts: 21

PostPosted: Mon Jan 02, 2012 9:20 am
Reply with quote

Hi Friends,

I have tried simple PL/1 program to test the parameter passing in PL/1.
I have tested it BYADDR and got the expected results.
When I try with BYVALUE I got the unexpected results.
Below is my code.

Main program:

- MUPLI: PROC OPTIONS(MAIN);
DCL X FIXED BIN(31,0);
DCL Y FIXED BIN(31,0);
DCL SYSPRINT FILE OUTPUT;
PUT SKIP LIST('ENTER IN TO MAIN PGM');
DCL MUSUB ENTRY OPTIONS(BYVALUE);
PUT SKIP LIST('ENTER AFTER MUSUB DCL');
X=2;
Y=3;
CALL MUSUB( (X), (Y) );
PUT SKIP LIST('VALUES OF X Y:',X,Y);
- END MUPLI;

Sub Program:
MUSUB:PROC(A,B) REORDER;
PUT SKIP LIST('BEFORE DCL');
DCL A FIXED BIN(31,0);
DCL B FIXED BIN(31,0);
PUT SKIP LIST('VALUE OF A =:',A);
PUT SKIP LIST('VALUE OF B =:',B);
PUT SKIP LIST('VALUE OF C =:',A+B);
END MUSUB;

My test results:

ENTER IN TO MAIN PGM
ENTER AFTER MUSUB DCL
BEFORE DCL
VALUE OF A =: 1
VALUE OF B =: 304
VALUE OF C =: 305
VALUES OF X Y: 2 3

Here I am expecting values 2 and 3 to be substituted to parameters A and B but value 1 and 304 substituted.

Can anyone have a look in to the prblem and let me know how 1 and 304 substituted to parameters A and B ?

Thanks in advance ...
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jan 02, 2012 10:11 am
Reply with quote

Your expectations were clashed by Your wrong coding ...
the OPTIONS(BYVALUE) is in the wrong place....
or ... at least the two declarations should be the same


when the two declarations are different
the address is considered as data,
or
the data is considered an address

if You play a bit around with the two combinations You might find out which is which icon_cool.gif

for PROCs in the same source, no need for the DCL ENTRY stuff

here is a complete TESTED and WORKING snippet of the whole shebang

Code:
 ****** ***************************** Top of Data ******************************
 000001  zmf03:                                                                 
 000002      Proc Options(Main);                                               
 000003      dcl x1      fixed bin(31) init(101);                               
 000004      dcl y1      fixed bin(31) init(102);                               
 000005      dcl x2      fixed bin(31) init(201);                               
 000006      dcl y2      fixed bin(31) init(202);                               
 000007                                                                         
 000008      put  skip list('Main Starting');                                   
 000009      put  skip list('declared ');                                       
 000010      put  skip list('x1   =',x1 );                                     
 000011      put  skip list('y1   =',y1 );                                     
 000012      put  skip list('x2   =',x2 );                                     
 000013      put  skip list('y2   =',y2 );                                     
 000014                                                                         
 000015      x1=1101;y1=1102;                                                   
 000016      x2=1201;y2=1202;                                                   
 000017                                                                         
 000018      put  skip list('assigned ');                                       
 000019      put  skip list('x1   =',x1 );                                     
 000020      put  skip list('y1   =',y1 );                                     
 000021      put  skip list('x2   =',x2 );                                     
 000022      put  skip list('y2   =',y2 );                                     
 000023                                                                         
 000024      call sub1(x1, y1);                                                 
 000025      put  skip list('after sub1');                                     
 000026      put  skip list('x1   =',x1 );                                     
 000027      put  skip list('y1   =',y1 );                                     
 000028                                                                         
 000029      call sub2(x2, y2);                                                 
 000030      put  skip list('after sub2');                                     
 000031      put  skip list('x2   =',x2 );                                     
 000032      put  skip list('y2   =',y2 );                                     
 000033                                                                         
 000034      put  skip list('Main Ending');                                     
 000035      End  zmf03 ;                                                       
 000036                                                                         
 000037  sub1:proc(a1,b1);                                                     
 000038      dcl a1      fixed bin(31) ;                                       
 000039      dcl b1      fixed bin(31) ;                                       
 000040      put  skip list('sub1 Entered');                                   
 000041      put  skip list('at entry');                                       
 000042      put  skip list('a1   =',a1 );                                     
 000043      put  skip list('b1   =',b1 );                                     
 000044      a1 = 2101; b1=2102;                                               
 000045      put  skip list('aft     ');                                       
 000046      put  skip list('a1   =',a1 );                                     
 000047      put  skip list('b1   =',b1 );                                     
 000048      put  skip list('sub1 Leaving');                                   
 000049      return;                                                           
 000050      end sub1;                                                         
 000051  sub2:proc(a2,b2) options(byvalue);                                     
 000052      dcl a2      fixed bin(31) ;                                       
 000053      dcl b2      fixed bin(31) ;                                       
 000054      put  skip list('sub2 Entered');                                   
 000055      put  skip list('at entry');                                       
 000056      put  skip list('a2   =',a2 );                                     
 000057      put  skip list('b2   =',b2 );                                     
 000058      a2 = 2101; b2=2102;                                               
 000059      put  skip list('after   ');                                       
 000060      put  skip list('a2   =',a2 );                                     
 000061      put  skip list('b2   =',b2 );                                     
 000062      put  skip list('sub2 Leaving');                                   
 000063      return;                                                           
 000064      end sub2;                                                         
 ****** **************************** Bottom of Data ****************************


and here is the result

Code:
********************************* TOP OF DATA **********************************
Main Starting                                                                   
declared                                                                       
x1   =                             101                                         
y1   =                             102                                         
x2   =                             201                                         
y2   =                             202                                         
assigned                                                                       
x1   =                            1101                                         
y1   =                            1102                                         
x2   =                            1201                                         
y2   =                            1202                                         
sub1 Entered                                                                   
at entry                                                                       
a1   =                            1101                                         
b1   =                            1102                                         
aft                                                                             
a1   =                            2101                                         
b1   =                            2102                                         
sub1 Leaving                                                                   
after sub1                                                                     
x1   =                            2101                                         
y1   =                            2102                                         
sub2 Entered                                                                   
at entry                                                                       
a2   =                            1201                                         
b2   =                            1202                                         
after                                                                           
a2   =                            2101                                         
b2   =                            2102                                         
sub2 Leaving                                                                   
after sub2                                                                     
x2   =                            1201                                         
y2   =                            1202                                         
Main Ending                                                                     
******************************** BOTTOM OF DATA ********************************
Back to top
View user's profile Send private message
hemanthj642

New User


Joined: 14 Sep 2005
Posts: 21

PostPosted: Mon Jan 02, 2012 11:05 am
Reply with quote

Hi enrico-sorichetti,

Thanks for quick responce.

Now I got the clear picture of BYADDR and BYVALUE.

Thanks for the help.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts DB2 Event passed to the Application P... DB2 1
No new posts How to pass the PARM value to my targ... COBOL Programming 8
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
Search our Forums:

Back to Top