Original Message:
Sent: Wed July 31, 2024 02:40 PM
From: Frank Swarbrick
Subject: User Defined Functions in Cobol 6.4
I don't know if there is much advantage of calling BPXWDYN regularly vs calling it as a function. But below is an example of both.
000100 identification division. COBOL6.4000200 function-id. dd-dynamic-alloc as 'BPXWDYN' is prototype000300 entry-interface is dynamic.000400 data division.000500 linkage section.000600 01 parm pic x(254).000700 01 rc pic s9(9) comp-5.000800 procedure division using parm returning rc.000900 end function dd-dynamic-alloc.001000001100 identification division. COBOL6.4001200 program-id. dyndd.001300001400 environment division.001500 configuration section.001600 repository.001700 function dd-dynamic-alloc001800 function all intrinsic.001900002000 data division.002100 working-storage section.002200 01 ddname pic x(8).002300 01 dsname pic x(44).002400 01 wdyn-parm pic x(100) value spaces.002500 01 rc pic s9(8) comp-5.002600 01 redefines rc.002700 05 rcx pic xx occurs 2.002800002900 procedure division.003000 move 'FJS00001' to ddname003100 move 'DATA1.TXT' to dsname003200 string "alloc "003300 "file(" trim(ddname) ")" space003400 "dataset(" trim(dsname) ")" space003500 "shr "003600 "msg(2)"003700 z''003800 delimited by size003900 into wdyn-parm004000 display wdyn-parm004100 perform allocate-via-call004200 perform allocate-via-function004300 goback.004400004500 allocate-via-call.004600 >>callint dynamic004700 call 'BPXWDYN' using wdyn-parm returning rc004800 >>callint004900 display rc space hex-of(rcx(1)) space hex-of(rcx(2))005000 exit.005100005200 allocate-via-function.005300 compute rc = dd-dynamic-alloc(content-of(wdyn-parm))005400 display rc space hex-of(rcx(1)) space hex-of(rcx(2))005500 exit.005600005700 end program dyndd.
Note that this is returning an error (in rc) in both cases (same error), so I must have the input incorrect somehow. Not sure what the issue is, and I've never used dynamic allocation in a program that works.
------------------------------
Frank Swarbrick
------------------------------
Original Message:
Sent: Wed July 31, 2024 08:41 AM
From: Denis FALLAI
Subject: User Defined Functions in Cobol 6.4
Hi,
If I may intervene in this conversation... I can also open a dedicated conversation.
We want to use "user function prototype" to interface routines in C language, in particular to access the file opening/reading/writing/closing functions, to do real dynamic file management in COBOL, (BPXWDYN allows to allocate files, but then we cannot access them in reading or writing except by using a COBOL declaration of the file).
This use case is mentioned in the reference documentation, but no example is provided.
Would it be possible to have an example of a call to a C function via a "user function prototype" declaration?
Thank you.
------------------------------
Denis FALLAI
BPCE SI, BPCE group.
Original Message:
Sent: Tue July 30, 2024 12:25 PM
From: Frank Swarbrick
Subject: User Defined Functions in Cobol 6.4
Just opened https://ibm-z-software-portal.ideas.ibm.com/ideas/COBOLVUE-I-396. Thanks.
------------------------------
Frank Swarbrick
Original Message:
Sent: Tue July 30, 2024 11:16 AM
From: Jeffery Shimoda
Subject: User Defined Functions in Cobol 6.4
Hi Frank,
re: OMITTED, it is not yet in plan and yes! - it would help if you can please open a request in the ideas portal to bring it to attention. Link: https://ideas.ibm.com/
Also note: this is closely related to the OMITTED argument on the CALL statement, which is also not supported yet. We did have a request for this one already (I believe you may have opened it :) ) but it was rejected as not a priority...this was a while ago...but we are keeping track of it internally. https://ibm-z-software-portal.ideas.ibm.com/ideas/COBOLVUE-I-48
------------------------------
Jeffery Shimoda
Original Message:
Sent: Sat July 27, 2024 04:39 PM
From: Frank Swarbrick
Subject: User Defined Functions in Cobol 6.4
By the way, if you use prototypes and then have the function in a separate compile unit from the main program, you shouldn't need an ENTRY statement, because there will no longer be any CSECTs before the main program.
------------------------------
Frank Swarbrick
Original Message:
Sent: Thu July 25, 2024 10:03 PM
From: Hamidali Kottaparamban
Subject: User Defined Functions in Cobol 6.4
Thank you Frank.
I modified my JCL a bit as below to use IGYWCL., and set the entry point as my MAINPROG thru SYSIN as below
//MAINPRGJ JOB ('FUNC'),MSGLEVEL=(1,1),NOTIFY=&SYSUID//***************************************************///COBRUN EXEC IGYWCL//COBOL.SYSIN DD DSN=&SYSUID..CBL(MAINPROG),DISP=SHR//COBOL.SYSLIB DD DSN=&SYSUID..COPY,DISP=SHR//LKED.SYSLMOD DD DSN=&SYSUID..LOAD(MAINPROG),DISP=SHR//LKED.SYSIN DD * ENTRY MAINPROG//***************************************************///***************************************************///RUN EXEC PGM=MAINPROG//STEPLIB DD DSN=&SYSUID..LOAD,DISP=SHR//SYSOUT DD SYSOUT=*//CEEDUMP DD DUMMY//SYSUDUMP DD DUMMY//***************************************************/
BTW, IGYWCLG was my starting point as shared for OpenMainframeProjects JCL as below for their sample program called HELLO.
//HELLOCBL JOB 1,NOTIFY=&SYSUID//COBRUN EXEC IGYWCLG,SRC=HELLO
Next up for me to try the function as PROTOTYPE, and see if I can dynamically call it from any module as we call intrinsic functions. Please let me know if anyone had some luck experimenting the Function Prototypes.
------------------------------
Hamidali Kottaparamban
Original Message:
Sent: Thu July 25, 2024 12:06 PM
From: Frank Swarbrick
Subject: User Defined Functions in Cobol 6.4
I'm not sure how your JCL even worked without error, as SRC is not a parameter for IGYWCLG.
In any case, I did get it to compile/link/go by placing "SYSIN DD *" followed by the source code, in the JCL. I still didn't get any output from the program. This is because by default the entry point is the first source "program" compiled. In this case the entry point is set to DOCALC (the function) rather than MAINPROG (the main program). So, it you have to pass an "EP" parameter to the linkedit step. Try the following:
//HELLOCBL JOB 1,NOTIFY=&SYSUID // JCLLIB ORDER=(IGY.SIGYPROC) //COBRUN EXEC IGYWCLG,LNGPRFX=IGY,GOPGM=MAINPROG, // PARM.LKED='EP=MAINPROG' //SYSIN DD * 000100 Identification division. 000200 Function-id. docalc. 000300 Data division. 000400 Linkage section. 000500 1 kind pic x(3). 000600 1 argA pic 999. 000700 1 argB pic v999. 000800 1 res pic 999v999. 000900 Procedure division 001000 using by reference kind argA argB 001100 returning res. 001200 if kind equal "add" then 001300 compute res = argA + argB 001400 end-if 001500 goback. 001600 End function docalc. 001700 Identification division. 001800 Program-id. 'mainprog'. 001900 Environment division. 002000 Configuration section. 002100 Repository. 002200 function docalc. 002300 Data division. 002400 Working-storage section. 002500 1 result pic 999v999 usage display. 002600 Procedure division. 002700 compute result = docalc("add" 10 0.23) 002800 display "hello from mainprog, result=" result002900 goback. 003000 End program 'mainprog'.//
------------------------------
Frank Swarbrick