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 

Passing pointer to a cobol program
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Fri Dec 10, 2004 12:08 am    Post subject: Passing pointer to a cobol program Reply with quote

Hi,

I tried passing a pointer from a PL1 program to a COBOL program. But when I try passing a pointer from a COBOL program to a PL1 program, its giveing protection exception error. The same error comes when i pass a pointer from a COBOL program to another COBOL program.

Passing pointer from COBOL pgm A to COBOL pgm B
I'm a passing a pointer to character field having value 'ASD' from pgm A to pgm B. I get the value in pgm B and i try to overwrite that with 'SDF' and pass it back to pgm B. But in the statement
Code:
MOVE 'SDF' to TEST-CHAR.
, I'm getting a protection exception error. Please let me know how i can solve this.

Thanks,
Whizkid79.
Back to top
View user's profile Send private message
MikeBaker
Beginner


Joined: 04 May 2004
Posts: 96
Topics: 9

PostPosted: Fri Dec 10, 2004 4:39 am    Post subject: Reply with quote

Whizkid,

Surely "TEST-CHAR" is not your Pointer? Because you don't set pointers like that. Yeah you probably would get a S0C4 if you tried to set a pointer like that. The receiving program will also need to have the Pointer defined as such inside the Linkage section.

Although having never done what you ask, it seems quite feasible.
Back to top
View user's profile Send private message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Fri Dec 10, 2004 10:53 am    Post subject: Reply with quote

This is the code of calling program:
Code:
 
IDENTIFICATION DIVISION.                 
 PROGRAM-ID. TSTCB1.                     
*                                         
 ENVIRONMENT DIVISION.                   
         
 DATA DIVISION.                           
*                                         
 WORKING-STORAGE SECTION.                 
  01 TEST-COB.                           
   05 TEST1-COB  PIC X(10).               
   05 TEST2-COB  PIC X(20).               
  01 TEST1-PTR REDEFINES TEST-COB POINTER.
 LINKAGE SECTION.                         
                                         
                                         
 PROCEDURE DIVISION.                     
                                         
 0000-MAIN.                               
     MOVE 'ABC' TO TEST1-COB             
     MOVE 'CBA' TO TEST2-COB             
     DISPLAY TEST-COB                     
     CALL 'TSTCB2' USING TEST1-PTR         
     DISPLAY TEST-COB                     
     GOBACK                               
      .                                   
 0000-MAIN-EXIT.                         


This is the code of the called program (TSTCB2):
Code:

 IDENTIFICATION DIVISION.               
 PROGRAM-ID. TSTCB2.                     
*                                       
 ENVIRONMENT DIVISION.                   
*                                       
 DATA DIVISION.                         
*                                       
 WORKING-STORAGE SECTION.               
 LINKAGE SECTION.                       
  01 TEST-PTR POINTER.                   
  01 TEST2-COB.                         
   05 TEST1-COB  PIC X(10).             
   05 TEST2-COB  PIC X(20).             
                                         
 PROCEDURE DIVISION USING TEST-PTR.     
                                         
 0000-MAIN.                             
     SET ADDRESS OF TEST2-COB TO TEST-PTR
     MOVE 'ASD' TO TEST1-COB             
     MOVE 'DEF' TO TEST2-COB             
     DISPLAY TEST2-COB                   
     GOBACK                             
      .                                 
 0000-MAIN-EXIT.                         


I did an expeditor testing of the above process. This is what i'm doing:
I'm calling TSTCB2 from TSTCB1 program. Initially, TEST-COB is having the string ABC CBA. Then i pass the pointer to that strucuture to TSTCB2. In TSTCB2 program, in the
Code:
     MOVE 'ASD' TO TEST1-COB             
statement, i'm getting a protection exception error.

Can anyone let me know if i'm doing something wrong.

Thanks,
Whizkid79.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Fri Dec 10, 2004 11:52 am    Post subject: Reply with quote

Change

CALL 'TSTCB2' USING TEST1-PTR

to

CALL 'TSTCB2' USING TEST1-PTR, TEST-COB
Back to top
View user's profile Send private message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Sat Dec 11, 2004 2:59 pm    Post subject: Reply with quote

This didn't work. Moreover if i'm passing the structure also, then there is no use of passing a pointer. The similar code worked well when a pointer is passed from a PL1 program to TSTCB2.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Mon Dec 13, 2004 12:19 pm    Post subject: Reply with quote

I missed the REDEFINES.

What are you trying to achieve in passing the POINTER?
Back to top
View user's profile Send private message
Mike Chantrey
Intermediate


Joined: 10 Sep 2003
Posts: 234
Topics: 1
Location: Wansford

PostPosted: Mon Dec 13, 2004 12:51 pm    Post subject: Reply with quote

The redefines in TSTCB1 has the effect of giving the pointer a value equal to the *contents* of the first 4 bytes of TEST-COB - i.e. "ABC ". This is not a valid address.
You want the pointer to contain the address of this data, not the contents, so the pointer should *not* be a redefines of TEST-COB, it should be a seperate data area.

So remove the REDEFINES in TSTCB1, and then add this code before the CALL:

SET TEST1-PTR TO ADDRESS OF TEST-COB.

Note that if you are using the unsupported COBOL II compiler that this will not work since you can't use SET like this with working storage items, only linkage section items.
Later versions of COBOL will be OK.
Back to top
View user's profile Send private message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Tue Dec 14, 2004 10:41 am    Post subject: Reply with quote

I made the changes. The compile was good. But the run abended because of S0C4 (protection exception).

Is there anything like pointers cannot be passed among cobol programs?
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Tue Dec 14, 2004 11:29 am    Post subject: Reply with quote

Try changing

PROCEDURE DIVISION USING TEST-PTR.

to

PROCEDURE DIVISION USING TEST-COB TEST-PTR.

Change the 01 TEST2-COB variable name in the LINKAGE SECTION of the subroutine to TEST-COB to avoid reference conflicts.
Back to top
View user's profile Send private message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Wed Dec 15, 2004 12:25 am    Post subject: Reply with quote

I've tried out all these options, but its still giving S0C4 abend. Sad
Can anyone give a working cobol program that uses pointer?
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Wed Dec 15, 2004 12:35 pm    Post subject: Reply with quote

I just tested the program and it works for me. Please post your revised code.
Back to top
View user's profile Send private message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Thu Dec 16, 2004 2:47 am    Post subject: Reply with quote

But here, you're passing the structure also. I want to pass only the pointer. If i'm passing the structure then there is no use of a pointer.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Thu Dec 16, 2004 9:06 am    Post subject: Reply with quote

You cannot reference the working storage of the calling program from the subroutine unless you place it in the linkage section and pass a reference to it (CALL ... USING ..) or by using the EXTERNAL clause. Note: the USING statement actually passes the address of the 01 level, not the data itself.

Any attempt to do so will generate a protection exception (S0C4).
Back to top
View user's profile Send private message
whizkid79
Beginner


Joined: 29 Sep 2004
Posts: 53
Topics: 14

PostPosted: Mon Dec 20, 2004 12:51 am    Post subject: Reply with quote

Thanks for the info. So to summerize, there is no use of using pointers among cobol programs.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Mon Dec 20, 2004 12:19 pm    Post subject: Reply with quote

I am sure there are some uses but in this example it should not be used.
Back to top
View user's profile Send private message
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
Goto page 1, 2  Next
Page 1 of 2

 
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