I had the AI help me with this c code which i tested.
How to use the cobol interface to send in the values for the integers like 5 and 7 integers in the C code PLEASE help.
I think if i could pass the values to int * values, i could use this thing but i don't know the cobol interface for that. Please help with a hint or any tricks.
I can use this to get data values from gixsql and concatenate without first sending to a file and then ummh ... reloading into a textarea.
Then the operation for writing sql to the textarea in cobjapi will be faster and won't be susceptible as much to something going wrong with that process.
It is pretty cool c code ... right?
thanks
#include<stdio.h>#include<cstring>#include<string>extern"C"{__declspec(dllexport)char*accumulate_buffer(char*buffer,int*value,int*size){staticinttotal=0;// Keeps track of the accumulated sumintmax_size=*size;// Convert the integer value to a stringchartemp[12];// Enough to hold a string for a 32-bit intsnprintf(temp,sizeof(temp),"%d",*value);// Check if the buffer can accommodate the new valueintcurrent_length=strlen(buffer);intvalue_length=strlen(temp);if(current_length+value_length+1>=max_size){returnNULL;// Buffer overflow error}// Append the value to the bufferstrcat(buffer,temp);// Return the bufferreturnbuffer;}}extern"C"{__declspec(dllexport)voidinitbuffer(char*buffer,int*values,int*num_values,int*size){// Initialize the buffer to an empty stringbuffer[0]='\0';// Loop through the array of integersfor(inti=0;i<*num_values;i++){if(accumulate_buffer(buffer,&values[i],size)==NULL){// Handle buffer overflowprintf("Buffer overflow occurred!\n");return;}}}}thetestdriverlookslikethis...#include<stdio.h>#include<string.h>// Declare the function prototypes from the DLL__declspec(dllimport)char*accumulate_buffer(char*buffer,int*value,int*size);__declspec(dllimport)voidinitbuffer(char*buffer,int*values,int*num_values,int*size);intmain(){// Define buffer and array for testcharbuffer[100]="";// Ensure buffer is initialized to an empty stringintvalues[]={5,7};// Example integersintnum_values=2;// Number of values in the arrayintbuffer_size=100;// Size of the buffer// Print the buffer before calling the functionprintf("Buffer before call: '%s'\n",buffer);// Call initbuffer to accumulate the values into the bufferinitbuffer(buffer,values,&num_values,&buffer_size);// Print the buffer after calling the functionprintf("Buffer after call: '%s'\n",buffer);return0;}
Last edit: Simon Sobisch 2025-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
WORKINGSTORAGE.01 Arg1PIC X(100)VALUESPACES.*> The buffer 01 Arg2 PIC S9(9) COMP OCCURS 2 TIMES. *> Array of integers01 Arg3PIC S9(9)COMPVALUE2.*> Number of integers in the array01 Arg4PIC S9(9)COMPVALUE100.*> Buffer size01 MY-ARRAY.05 MY-ELEMENTSPIC 9(4)OCCURS2 TIMESINDEXEDBYIDX.ProcedureDivision.MOVE5 TOMY-ELEMENTS(1).*> First integerMOVE7 TOMY-ELEMENTS(2).*> Second integerDISPLAY "Buffer before call: "Arg1.CALL "initbuffer"USINGBYREFERENCEArg1*> The bufferBYREFERENCEMY-ARRAY*> Start of the integer arrayBYREFERENCEArg3*> Number of integersBYREFERENCEArg4*> Buffer sizeDISPLAY "Buffer after call: "Arg1GOBACK.
Last edit: Simon Sobisch 2025-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
so you can see i added a 2 and a 5 and it accumulated them but i got that print out from
c language. I don't see how to get the printout values from c back to cobol.
I might add that I did something a little wrong. I used IDX3 this time instead of a (1) or (2) when I subscripted. I think that helps me with a compiler error.
Like don't do MY-ELEMENTS(1) OR MY-ELEMENTS(2) NEGATORY
SO i will try Ron's guide again with this new fact I learned that I can subscript a different way without a literal 1 constant etc.
I am just wondering though isnt it supposed to be able to send that value back somehow "the buffer after call : '0001
2 5'
when I am finished in c language?
thanks. It would be a tremendous help. Sorry that I am so spacy. jim :-)
#include<stdio.h>#include <cstring>extern"C"{__declspec(dllexport)char*accumulate_buffer(char*buffer,int*value,int*size){chartemp[20];// Enough to hold a string for a 32-bit integer// char t1[15]="goodebyebye\0";snprintf(temp,sizeof(temp),"%d",*value);// Convert integer to stringintcurrent_length=strlen(buffer);intvalue_length=strlen(temp);if(current_length+value_length+1>=*size){returnNULL;// Buffer overflow check}strcat(buffer,temp);// Append the integer string to the bufferstrcat(buffer," ");// Add a space separatorprintf("buffer after call: '%s' \n",buffer);returnbuffer;}__declspec(dllexport)voidinitbuffer(char*buffer,int*values,int*num_values,int*size){// function not used // Initialize the buffer to an empty stringbuffer[0]='\0';// Ensures the buffer starts as an empty string// Loop through the array of integersfor(inti=0;i<*num_values;i++){// Attempt to accumulate the current integer into the bufferif(accumulate_buffer(buffer,&values[i],size)==NULL){// Handle buffer overflowprintf("Buffer overflow occurred!\n");return;// Exit the function if buffer overflow occurs}}}intmain(){//none of this code rancharbuffer[100];// Buffer to accumulate the valuesintvalues[]={5,7};// Example values to accumulateintnum_values=2;// Number of integersintsize=100;// Size of the buffer// Call initbuffer to accumulate values into the bufferinitbuffer(buffer,values,&num_values,&size);// Display the resultprintf("Buffer after call: '%s'\n",buffer);return0;}}
Last edit: Simon Sobisch 2025-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MOVE 1 TO IDX3 MOVE 1 TO MY-ELEMENTS(IDX3) .
Should be SET IDX3 TO 1
MOVE 2 TO IDX3
Should be SET IDX3 TO
Letter of the law zOS, MF, and Fujitsu COBOL wise is the use of SET for INDEXED BY variable.
Perhaps GnuCOBOL does not regard this axiom ?
Using MF or Fujitsu this statement MOVE 2 TO IDX3 results in this compiler diagnostic:
Severe Error: 'IDX3' IN MOVE STATEMENT MUST BE IDENTIFIER. 'IDX3' IGNORED.
Your usage did compile okay with GnuCOBOL
Last edit: Ralph Linkletter 2025-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
GnuCOBOL currently does not imply a hard check here and allows also MOVE and computational statements (while it should only allow SET and PERFORM to adjust indexes).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't see the dialog cbl program. But here is a call I did to a c program and Simon had me to add the SIZE IS parameter . Perhaps you have differing sizes for integers... ?
I do not know, but C and GnuCOBOL and Json may have all different sizes for binary-long on Linux vs Windows vs MinGW vs Msys
Here is what my Ubuntu 64bit says
As you want to pass data between COBOL<->C, use the binary types (BINARY-LONG is your common int), as those have the expected size, non-truncation, and byte-order.
To access a table that has only those in a OCCURS.
It is very cool to receive your help. I have been busy!
I can't wait to make a table viewer for cobjapi but I have to back off of the pace and spend time learning other thing besides just working on 'just that'.
Thanks for all of your cool help.
Have a very nice weekend,
jim
I had the AI help me with this c code which i tested.
How to use the cobol interface to send in the values for the integers like 5 and 7 integers in the C code PLEASE help.
I think if i could pass the values to int * values, i could use this thing but i don't know the cobol interface for that. Please help with a hint or any tricks.
I can use this to get data values from gixsql and concatenate without first sending to a file and then ummh ... reloading into a textarea.
Then the operation for writing sql to the textarea in cobjapi will be faster and won't be susceptible as much to something going wrong with that process.
It is pretty cool c code ... right?
thanks
Last edit: Simon Sobisch 2025-01-03
hI -
i tried this but the email is screwing up my formatting a little.
thanks for any assistance. -jim
Last edit: Simon Sobisch 2025-01-03
Hey Jim, just wondering, which AI are you using? I found Claude to be pretty good at cobol.
Hi Mickey-
I will try out claude.
I use chatgpt - where it does really well is with cobjapi.
Other than that it gets stuck on problems.
thanks
Hi Mickey,
Claude can't solve this problem either.
it is worth a try I like having another AI to fool with though.
thanks
Last edit: Simon Sobisch 2025-01-03
when i run the following scenario it prints out the following after the value clause.:
so you can see i added a 2 and a 5 and it accumulated them but i got that print out from
c language. I don't see how to get the printout values from c back to cobol.
I might add that I did something a little wrong. I used IDX3 this time instead of a (1) or (2) when I subscripted. I think that helps me with a compiler error.
Like don't do
MY-ELEMENTS(1) OR MY-ELEMENTS(2) NEGATORY
SO i will try Ron's guide again with this new fact I learned that I can subscript a different way without a literal 1 constant etc.
I am just wondering though isnt it supposed to be able to send that value back somehow "the buffer after call : '0001
2 5'
when I am finished in c language?
thanks. It would be a tremendous help. Sorry that I am so spacy. jim :-)
Last edit: Simon Sobisch 2025-01-03
Hey all,
I think I got it....
Here is a link which explains more or less what I am trying to do...
https://stackoverflow.com/questions/73160885/getting-a-64-bit-return-value-from-a-c-function-in-gnu-cobol
I will try after midnight it is time to sleep.
Thanks for being patient.
thanks,
jim
Last edit: Simon Sobisch 2025-01-03
MOVE 1 TO IDX3 MOVE 1 TO MY-ELEMENTS(IDX3) .
Should be SET IDX3 TO 1
MOVE 2 TO IDX3
Should be SET IDX3 TO
Letter of the law zOS, MF, and Fujitsu COBOL wise is the use of SET for INDEXED BY variable.
Perhaps GnuCOBOL does not regard this axiom ?
Using MF or Fujitsu this statement MOVE 2 TO IDX3 results in this compiler diagnostic:
Severe Error: 'IDX3' IN MOVE STATEMENT MUST BE IDENTIFIER. 'IDX3' IGNORED.
Your usage did compile okay with GnuCOBOL
Last edit: Ralph Linkletter 2025-01-03
GnuCOBOL currently does not imply a hard check here and allows also MOVE and computational statements (while it should only allow
SET
andPERFORM
to adjust indexes).I don't see the dialog cbl program. But here is a call I did to a c program and Simon had me to add the SIZE IS parameter . Perhaps you have differing sizes for integers... ?
I do not know, but C and GnuCOBOL and Json may have all different sizes for binary-long on Linux vs Windows vs MinGW vs Msys
Here is what my Ubuntu 64bit says
COBOL uses
BY REFERENCE
as standard.As you want to pass data between COBOL<->C, use the binary types (
BINARY-LONG
is your commonint
), as those have the expected size, non-truncation, and byte-order.To access a table that has only those in a OCCURS.
I'd use the following as a first untested try:
COBOL:
C:
Then compile as
cobc -xg prog.cob stuff.c
and see what the results are - rungdb ./prog
to check for strange results.Last edit: Simon Sobisch 2025-01-03
Separating COBOL from C
COMP-5
Just saying those uninitiated to COBOL should probably see COBOL from you :-)
Hi Ralph-
It is very cool to receive your help. I have been busy!
I can't wait to make a table viewer for cobjapi but I have to back off of the pace and spend time learning other thing besides just working on 'just that'.
Thanks for all of your cool help.
Have a very nice weekend,
jim
Sent with Proton Mail secure email.
On Friday, January 3rd, 2025 at 12:33 PM, Ralph Linkletter zosralph@users.sourceforge.net wrote: