Operating System - OpenVMS
1752680 Members
5316 Online
108789 Solutions
New Discussion юеВ

Re: Parameter passing in COBOL

 
SOLVED
Go to solution
Stephen Daddona
Frequent Advisor

Parameter passing in COBOL

I would like to do the following:

01 t_accpornam pic x(255) value spaces.

procedure division
giving tt_accpornam.

But, COBOL doesn't allow it:

giving tt_accpornam.
...........^
%COBOL-F-OPDGIVING, Operand must be a COMP data-name with 18 digits or less and
no scaling positions, COMP-1, or COMP-2
at line number 37 in file DISK$DKB100:[GET_TT_ACCPORNAM]GETTTACCPORNAM.COB;65

Is there any way that I pass "back" a pic x(255) data item?


Thanks in advance!
6 REPLIES 6
John Reagan
Respected Contributor

Re: Parameter passing in COBOL

You need an argument to the routine by using a LINKAGE section and a USING clause. The caller will have to pass in the address of a buffer to fill.
Stephen Daddona
Frequent Advisor

Re: Parameter passing in COBOL

Do you have an example of doing that? I'm trying some stuff but not having much luck. I keep getting an access violation.
Richard J Maher
Trusted Contributor
Solution

Re: Parameter passing in COBOL

Hi Graig

This one returns a VARCHAR, but does pretty much what you want (I think?) Somewhere in the procedure calling standard you find the bit about the first parameter being the non-integer return mechanism for functions.

create function ef_get_user_dir (in char(32) by descriptor)
returns varchar(94) by reference
language sql
;
external name ef_get_user_dir
location 'maher$user' with all logical_name translation
language cobol
general parameter style variant
comment is 'Get UAF device and directory info for user'
BIND ON CLIENT SITE
bind scope connect
;


linkage section.
*
01 username_desc pic x(8).
*
01 out_dir.
03 out_dir_len pic 9(4) comp.
03 out_dir_text pic x(94).
*
procedure division
using out_dir,
username_desc.
00.

Cheers Richard Maher
John Gillings
Honored Contributor

Re: Parameter passing in COBOL

Craig,

Something like this:

IDENTIFICATION DIVISION.
PROGRAM-ID GetAccpornam.
...
LINKAGE SECTION.
01 tt_accpornam PIC X(255).
...
PROCEDURE DIVISION USING tt_accpornam.
...

MOVE whatever TO tt_accpornam.
...
EXIT PROGRAM.


(caller)

01 ACCPORNAM PIC X(255).

PROCEDURE DIVISION
...
CALL "GetAccpornam" USING ACCPORNAM.


The reason your example doesn't work is the OpenVMS calling standard only allows scalar objects to be returned as function results. Maximum size is 64 bits. Larger objects can only be returned via arguments.

(note that you could return a pointer to a string, but that's a bit cumbersome in COBOL and it raises issues of ownership and lifetime of the string storage).
A crucible of informative mistakes
Stephen Daddona
Frequent Advisor

Re: Parameter passing in COBOL

That should get me going down the YBR (Yellow Brick Road), since my ultimate goal was to get this COBOL program to pass the process's TT_ACCPORNAM back to an Rdb function.


Thanks!
Stephen Daddona
Frequent Advisor

Re: Parameter passing in COBOL

I'll be trying the suggestions ASAP!