Q
Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

SQL view that SELECTS on functions

This user was having an issue with his SQL view on his iSeries that SELECTS on a few functions. Db2 Expert Kent Milligan explained what was going on.

I have an SQL view on my iSeries that SELECTS on a few functions; i.e.,

SELECT F1(field1,field2),
F2(field1,field2),
F3(field1,field2)
From mylib/myfile

I have a problem with the result of one function (F3) coming up as blanks in Microsoft's SQL Server Query Analyzer. I believe the problem to possibly be that the function references a service program written in SQLRPGLE.

Functions F1 and F2 are written with SQL statements, only. Their results show up fine.

F3 is created with the following SQL statement:

 CREATE FUNCTION F3 (FLD1 DECIMAL(2,0), 
                    FLD2 DECIMAL(8,0)) 

RETURNS CHAR (60)
LANGUAGE RPGLE
NOT DETERMINISTIC
EXTERNAL NAME 'MYLIB/PGM1(PROC1)'
PARAMETER STYLE GENERAL;

We are at V5R2 and at the latest service pack.

My DSN uses the iSeries Access driver, and specifies all possible libraries in the library list section.

The client interface should not matter -- try calling it from iSeries Navigator "Run SQL Scripts" window or STRSQL to see if you get the same result. Most likely, you will get same result on any SQL-based interface.

You need to ensure that your RPG program is returning the output value in the manner dictated by the GENERAL parameter style. Review your code to see if the parameter style specified is correctly implemented in your RPG code. The Redbook titled "Stored Procedures, Triggers and User Defined Functions on DB2 Universal Database for iSeries" is a good resource for UDFs and can be accessed online at here.

You should also determine if the RPG procedure is working correctly and it returning the result that you are expecting. Step through the code using the debugger to validate that it is returning the correct result.

There is an RPG UDF coding example available from the DB2 UDB for iSeries Web site.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

Visit the ITKnowledge Exchange and get answers to your DB2 questions fast.

Check out this Search400.com Featured Topic: Expert advice on DB2

Search400.com's targeted search engine: Get relevant information on DB2/400.

The Best Web Links: Tips, tutorials and more.

This was last published in August 2005

Dig Deeper on DB2 UDB (universal databases)

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close