View previous topic :: View next topic
|
Author |
Message |
sedireswarapu
New User
Joined: 18 Jun 2008 Posts: 28 Location: India
|
|
|
|
Hi..
Am new to this pointer concept in Cobol programming and
in my project trying to send a Character pointer from C program to Cobol.
LINKAGE SECTION.
01 MYPOINTER USAGE IS POINTER.
01 MYCHAR-POINTER.
05 MYCHARS PIC X(20).
PROCEDURE DIVISION USING MYPOINTER,MYCHAR-POINTER.
SET ADDRESS OF MYCHAR-POINTER TO MYPOINTER
also tried
SET ADDRESS OF MYPOINTER TO MYCHAR-POINTER .. but no luck
As per above code, Cobol module will get Pointer in Linkage section and tries to assign it to a group Item. And i also tried to display the pointer as such but i see only some random numbers.
Am getting SOC4 abend while trying to Set the address.
Could you pls throw some light on this pointer handling in cobol. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Quote: |
PROCEDURE DIVISION USING MYPOINTER,MYCHAR-POINTER. |
I don't understand, if you are recieving both fields, why are you trying to set one to the other? |
|
Back to top |
|
|
sedireswarapu
New User
Joined: 18 Jun 2008 Posts: 28 Location: India
|
|
|
|
Sorry for the confusion.
Actually am doing :
PROCEDURE DIVISION USING MYPOINTER
and the MYCHAR-POINTER group item is declared in Workstorage division.
What am trying to do is :
1. printing the pointer content - its not working ( shows me some random number)
2. Trying to assign the MYPOINTER (usually COBOL gets pointer like VOID pointer) to a String of Chars variable.
Is it possible to assign a pointer ( in future i will be sending a structure pointer from C to COBOL and have to assign it to a group item to get the fields out of it ..) to a data item of similar type ?
Thanks. |
|
Back to top |
|
|
hchinnam
New User
Joined: 18 Oct 2006 Posts: 73
|
|
|
|
Can you try changing it as follows.
Code: |
LINKAGE SECTION.
01 MYCHAR-POINTER.
05 MYCHARS PIC X(20).
01 MYPOINTER USAGE IS POINTER.
PROCEDURE DIVISION USING MYPOINTER.
SET ADDRESS OF MYCHAR-POINTER TO MYPOINTER
|
|
|
Back to top |
|
|
sedireswarapu
New User
Joined: 18 Jun 2008 Posts: 28 Location: India
|
|
|
|
Thanks for your reply.
But it abends with SOC4 during the SET statement.
LINKAGE SECTION.
01 MYCHAR-POINTER.
05 MYCHARS PIC X(20).
01 MYPOINTER USAGE IS POINTER.
PROCEDURE DIVISION USING MYPOINTER.
DISPLAY "TESTING COBOL WITH POINTERS".
SET ADDRESS OF MYCHAR-POINTER TO MYPOINTER
DISPLAY "MYCHARS = " MYCHAR-POINTER.
GOBACK.
This cobol module is invoked from a C module
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma linkage (TESTCOB,COBOL)
void TESTCOB (char*);
void main()
{
char *pName = "BALAJI";
printf ("Testing pointers with cobol\n");
printf ("Name : %s\n", pName);
TESTCOB(pName);
printf ("Exit\n");
}
At this point all am trying is to set the pointer that i get in the COBOL to another variable.. Since bcoz in future i will be sending STRUCTURE POINTER from C program and have to map that pointer in COBOL to a GROUP ITEM.
Not sure whether this is possible but this is my idea of doing things with COBOL on this design. Please help as this sounds very new to me but yet challenging ..
Thanks. |
|
Back to top |
|
|
hchinnam
New User
Joined: 18 Oct 2006 Posts: 73
|
|
|
|
Looks like MYPOINTER is not set.
Are you sure about the SYNTAX/OPTIONs of call from C to COBOL.
Because back when we tried doing similar thing between PL/I and COBOL, we used to mention some specific option, which signifies it is a call between different languages. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Your program is violating COBOL standards:
Code: |
LINKAGE SECTION.
01 MYCHAR-POINTER.
05 MYCHARS PIC X(20).
01 MYPOINTER USAGE IS POINTER.
PROCEDURE DIVISION USING MYPOINTER. |
whereas the manual says
Quote: |
4.2.2 Coding the LINKAGE SECTION
Code the same number of data-names in the identifier list of the calling program as the number of data-names in the identifier list of the called program. Synchronize them by position, because the compiler passes the first identifier of the calling program to the first identifier of the called program, and so on.
You will introduce errors if the number of data-names in the identifier list of a called program is greater than the number of data-names in the identifier list of the calling program. The compiler does not try to match arguments and parameters. |
The PROCEDURE DIVISION USING variables need to be in the same order as in the LINKAGE SECTION. Do anything else and an S0C4 is certainly a possibility. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Robert Sample wrote: |
Your program is violating COBOL standards...
.
.
.
The PROCEDURE DIVISION USING variables need to be in the same order as in the LINKAGE SECTION. Do anything else and an S0C4 is certainly a possibility. |
That is wrong, it is the order in the USING of the PROCEDURE and the CALL that must be in sync.
The passed parameter list consists of individual addresses for each parm. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Actually, in this case it does not matter what the CALL has. Sriram's program has 2 01 levels in the LINKAGE SECTION. The PROCEDURE DIVISION is USING the second 01 level but not the first; trying to reference both LINKAGE SECTION 01 fields will cause the S0C4 because COBOL isn't setting up addressability for two fields.
Sriram: why do you think you need a pointer variable in COBOL? If your C program does a CALL to a COBOL routine and the CALL includes a struct, just define the LINKAGE SECTION in the COBOL program to include each item in the structure, then reference the items in your COBOL program. The PROCEDURE DIVISION USING <linkage section 01> establishes the addressability of the variables. I have tested this and passed data both ways successfully. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Robert Sample wrote: |
trying to reference both LINKAGE SECTION 01 fields will cause the S0C4 because COBOL isn't setting up addressability for two fields. |
That's what the SET should be doing....
Sriram:
A S0C4 at the SET would indicate that tha passed address of MYPOINTER is (probably) low-values......
Before the SET, do a SET ANOTHER-POINTER (in ws) TO ADDRESS OF MYPOINTER and then display ANOTHER-POINTER and view with hex on.... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
From the manual, LINKAGE SECTION description:
Quote: |
Record description entries and data item description entries in the linkage section provide names and descriptions, but storage within the program or method is not reserved because the data area exists elsewhere. |
If the calling program calls the COBOL program with a single parameter, and the COBOL program has PROCEDURE DIVISION USING <one variable>, exactly where does the data area referenced in the second variable in the LINKAGE SECTION exist? It's not in the calling program -- that only passed one argument. It's not in the COBOL program -- LINKAGE SECTION fields are not allocated any storage. When Sriram does his SET there's going to be 4 bytes set to an address -- but which 4 bytes? I suspect the 4 bytes are memory locations 0000 through 0003 which cause the S0C4. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
You can set the address of a linkage area to a working storage address, a record (FD) address or an address passed by a called/calling program and those ws & fd addresses do not need to be 01 levels.
That one passed argument is (if done correctly) an address. Setting the other linkage area to that address establishes addressability to it.
Picture the linkage section 01s as assembler DSECTs (just as the 01s in the FD are) and the 01s in working storage as CSECTs...... |
|
Back to top |
|
|
sedireswarapu
New User
Joined: 18 Jun 2008 Posts: 28 Location: India
|
|
|
|
Thanks for all your suggestions.
Things i tried earlier:
1. Passed only one pointer arg from C and had two data items in Linkage
Now i have changed the linkage section to accept the pointer arg from C and now am trying to set it to a POINTER in WS section.
But my compilation keeps failing saying
Quote: |
IGYPS2161-S "ADDRESS OF" operand "MYANOTHERPTR" was found as the receiving operand of a "SET" statement,but was not alevel-01 or level-77 "LINKAGE SECTION" item. |
but i have mentioned MYANOTHERPTR as 01 level.
If this compilation gets successful. will i be able to set it correctly and display pointer content ?
Why I tried with Structure Pointer because this is a generic structure which will have fields containing int, Void Pointer. Based upon the int filed i will be typecasting the Void Pointer to a specific Structure, this i did in C program.
I want same kind of design to implement in COBOL mapping structure to copybook, I dont know if i can ( since its very early at this point).
So as a starting point am trying to see if i can receive a pointer at first in Cobol successfully and print it.
WORKING-STORAGE SECTION.
01 MYANOTHERPTR USAGE IS POINTER.
LINKAGE SECTION.
01 MYPOINTER USAGE IS POINTER.
PROCEDURE DIVISION USING MYPOINTER.
DISPLAY "TESTING COBOL WITH POINTERS".
SET ADDRESS OF MYANOTHERPTR TO MYPOINTER.
DISPLAY "MYANOTHER PTR : " MYANOTHERPTR
Let me know if any further info is needed. Pls correct me if am wrong anywhere.
Appreciate your help. |
|
Back to top |
|
|
|