MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Calling a UDF with multiple parameters in

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Thu Sep 26, 2024 9:45 am    Post subject: Calling a UDF with multiple parameters in Reply with quote

Searched and found something similar at https://www.mvsforums.com/helpboards/viewtopic.php?t=13027&highlight=udf but that didn't seem to be quite the same.
Here's my CREATE FUNCTION definition.
Code:

CREATE FUNCTION BINARY_TO_COMP3(VARBINARY(100), CHAR(5))   
RETURNS DECIMAL(18)                                       
EXTERNAL NAME 'MSUDF1'                                     
LANGUAGE COBOL                                             
PARAMETER STYLE DB2SQL                                     
NO SQL                                                     
NO EXTERNAL ACTION                                         
NOT DETERMINISTIC                                         
RETURNS NULL ON NULL INPUT;                               

and here's the call I'm using
Quote:

select
binary_to_ebcdic(substr(dl1_segment1, 13, 5)) as HANDL
, binary_to_comp3(substr(dl1_segment1, 54, 5)) as LAANMAXV
, binary_to_comp3(substr(dl1_segment1, 99, 5)) as LAANBET
, binary_to_comp3(substr(dl1_segment1, 160, 3), 'ABCDE') as RAANTESATS
from TDRT3U0
order by extract_order asc
fetch first row only

I receive the following error message
Quote:

SQL Error [42884]: NO AUTHORIZED FUNCTION NAMED BINARY_TO_COMP3 HAVING COMPATIBLE ARGUMENTS WAS FOUND. SQLCODE=-440, SQLSTATE=42884, DRIVER=4.31.10

Note that if I remove the ", CHAR(5)" from the create function, as well as the ", 'ABCDE'" from the select statement, it all works fine.
Any suggestions?
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Fri Sep 27, 2024 3:03 am    Post subject: Reply with quote

misi01,

A bunch of problems.

misi01 wrote:
RETURNS DECIMAL(18)


This will return ONLY 1 item

misi01 wrote:
EXTERNAL NAME 'MSUDF1'


You need to invoke the function as MSUDF1 instead of binary_to_comp3 . Most people have the function name and external name the SAME.

Check this link for examples

https://www.ibm.com/docs/en/db2-for-zos/13?topic=objects-creation-user-defined-functions
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Mon Sep 30, 2024 6:23 am    Post subject: Reply with quote

Here's an example of a UDF that works.
Quote:

DROP FUNCTION BINARY_TO_EBCDIC ;
CREATE FUNCTION BINARY_TO_EBCDIC(VARBINARY(100))
RETURNS VARCHAR(100)
EXTERNAL NAME 'MSUDF3'
LANGUAGE COBOL
PARAMETER STYLE DB2SQL
NO SQL
NO EXTERNAL ACTION
NOT DETERMINISTIC
RETURNS NULL ON NULL INPUT;

You can see from the above that the actual function name is BINARY_TO_EBCDIC. In this example, MSUDF3 is the name of (in this case) the Cobol program that is called to perform the SQL processing. This can be seen in the first append I included where I wrote , binary_to_ebcdic(substr(dl1_segment1, 13, 5)) as HANDL
so the actual call isn't, in my eyes, incorrect.

Neiher is the
Quote:

CREATE FUNCTION BINARY_TO_COMP3(VARBINARY(100), CHAR(5))
RETURNS DECIMAL(18)

wrong, inasmuch as what I want to do (and maybe THAT'S the problem) that I want to send in two arguments, but only receive one back.
The second argument is intended to be a simple character string that will be analyzed in the COBOL program and result in how the decimal value is formatted and returned. For example, if the content is actually defined a 9V99 comp-3 then I know I need to divide the value (say 123) by 100 and return 1.23 (that in turn possibly opens up a can of worms regarding the definition in the RETURNS argument that's a different matter).

Basically, I'm wondering whether I can define a second argument as a character string that is passed in to the UDF.
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group