View previous topic :: View next topic |
Author |
Message |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Fri Dec 10, 2004 12:08 am Post subject: Passing pointer to a cobol program |
|
|
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 |
|
 |
MikeBaker Beginner
Joined: 04 May 2004 Posts: 96 Topics: 9
|
Posted: Fri Dec 10, 2004 4:39 am Post subject: |
|
|
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 |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Fri Dec 10, 2004 10:53 am Post subject: |
|
|
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 |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Fri Dec 10, 2004 11:52 am Post subject: |
|
|
Change
CALL 'TSTCB2' USING TEST1-PTR
to
CALL 'TSTCB2' USING TEST1-PTR, TEST-COB |
|
Back to top |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Sat Dec 11, 2004 2:59 pm Post subject: |
|
|
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 |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Mon Dec 13, 2004 12:19 pm Post subject: |
|
|
I missed the REDEFINES.
What are you trying to achieve in passing the POINTER? |
|
Back to top |
|
 |
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
Posted: Mon Dec 13, 2004 12:51 pm Post subject: |
|
|
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 |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Tue Dec 14, 2004 10:41 am Post subject: |
|
|
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 |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Tue Dec 14, 2004 11:29 am Post subject: |
|
|
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 |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Wed Dec 15, 2004 12:25 am Post subject: |
|
|
I've tried out all these options, but its still giving S0C4 abend.
Can anyone give a working cobol program that uses pointer? |
|
Back to top |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Wed Dec 15, 2004 12:35 pm Post subject: |
|
|
I just tested the program and it works for me. Please post your revised code. |
|
Back to top |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Thu Dec 16, 2004 2:47 am Post subject: |
|
|
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 |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Thu Dec 16, 2004 9:06 am Post subject: |
|
|
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 |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Mon Dec 20, 2004 12:51 am Post subject: |
|
|
Thanks for the info. So to summerize, there is no use of using pointers among cobol programs. |
|
Back to top |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Mon Dec 20, 2004 12:19 pm Post subject: |
|
|
I am sure there are some uses but in this example it should not be used. |
|
Back to top |
|
 |
|
|