× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi,

Sometimes even authors of books are wrong!

Tables/Views and Libraries/Schemas cannot be used in static SQL as host
variables, nor can they used as parameter markers.

Parameter markers are a replacement of host variables in dynamic SQL.
Parameter markers can be used to gain performance, because the ODP needs
only to be built a single time and can be reused several times but with
different values.

If a table/view or library/schema must be changed, the ODP must be rebuilt.
That means, an existing ODP must be deleted. Then the string must be
converted into an exeuctable SQL-Statement, i.e. PREPARE must be executed.
After the converted SQL Statement can be executed. When executing a SQL
statement after the PREPARE statement, a full optimization occurs, i.e. an
access plan must be built or at least validated, the necessary temporary
objects (for example Hash tables, Bitmaps, temporary datastructures ...)
must be built and finally filled with data.
Because it makes no sense to use parameter markers in this way, they not
allowed.

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Ellsberry, Steve
Gesendet: Thursday, April 19, 2007 23:09
An: RPG programming on the AS400 / iSeries
Betreff: RE: Dynamic SQL using Parameter Markers


Charles that was my first thought but 83 in Kevin Forsythe's specifically
shows the file name being populated via a parameter marker.

I guess that's what I get for reading the book.

Thanks,

S. Ellsberry

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Wilt, Charles
Sent: Thursday, April 19, 2007 2:57 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Dynamic SQL using Parameter Markers

Steve,

IIRC, you can't use parameter markers for the table name.

Basically, parameter markers can only go into the WHERE clause.

HTH,

Charles

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Ellsberry, Steve
Sent: Thursday, April 19, 2007 2:44 PM
To: RPG List
Subject: Dynamic SQL using Parameter Markers

First of all, sorry for the length of this email but I wanted
to give as much detail as I could so as to head off a million
questions afterwards.



Now to the problem.



Short version

Anybody have any idea what specific release/PTF level I need
to be at (if any) in order to use Parameter Markers with
dynamic SQL? All our boxes are at v5r3m0.



Long version



I've written a simple dynamic SQLRPGLE program that will be
used to insert data from a file within our current release to
the same file in our next release. Both files have the same
name but reside in 2 different libraries. The library names
will differ from market to market.



We've added some additional fields but I couldn't use a
simple CPYF w/ *MAP *DROP because we've changed one of the
fields from numeric (2,0) to alpha 5. We need that field to
be formatted with a leading zero if the current value is
single digit - easily accomplished with casting.



The problem I have is the library names for both files will
differ from market to market. To get around that I figured I
use parameters markers and make it dynamic.



Here's the SQL statement as defined in my D specs

d SQLStatement s 1024 Inz('Insert into ? select
-

d CONBR , SITE ,
ACTNBR, SCRID
,-

d DIRNBR, TSEQNO, 0 ,
ELGTYP,-

d UPGSTS, UPGTYP, TRNDTE,
UPGDTE,-

d USRADD, CCODE , FUTDAT,
NOTSTS,-

d NOTDAT, SMSEML, NEWCHK,
SLCCHN,-

d
cast(substring(digits(QUALVL),1-

d ,2) as char(5)) as qualvl,
-

d QUADSC, QUAWUF, QUACON,
COMINT,-

d COMLEN, LVLCOD, MINMRC,
EQPDSC,-

d DSCAPL, CONLEN, WAIVEF,
ORSELP,-

d ACSELP, OVRRSC, OVRRST,
SOFUID,-

d UPGSEC, '' '' , ''
'' , '' ''
,-

d '' '' , LSMODE, USCODE,
LSTPGM,-

d DTSTMPZ from ?')



The question marks are standard parameters markers for the
from and to library/file names which I build in the program.
Those are defined as:

d FromPath s 21 Inz

d ToPath s 21 Inz



I have a variable called filename that I initialize as
('/custmast') I pull the From/To libraries from a data area.
I build the path names as:

FromPath = %Trim(Fromlibrary) + %Trim(FileName);

ToPath = %Trim(Tolibrary) + %Trim(FileName);



I Prepare the SQL

/End-Free

c/Exec Sql

c+ Prepare @SQLStatement from :SQLStatement

c/End-Exec

/Free



I execute the SQL

/End-Free

c/Exec Sql

c+ Execute @SQLStatement Using :FromPath, :ToPath

c/End-Exec

/Free





The program compiles with no errors. But I run it I get
sqlcode = -104 (syntax error) and sqlerrmrc with a value of ?
<IDENTIFIER>. If I run it in debug and copy the sql
statement and the variables built in the program then run it
interactively the sql runs to completion. That tells me I'm
not missing a comma so something like that. It also tells me
I've formatted the path name correctly.



I've read the DB2 UDB manual. I've read Kevin Forsythe's SQL
for eServer and iSeries. Both say I can do it but.....



Anybody have any suggestions?





Thanks,

S. Ellsberry



--
This is the RPG programming on the AS400 / iSeries (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




This e-mail transmission contains information that is intended to be
confidential and privileged. If you receive this e-mail and you are not a
named addressee you are hereby notified that you are not authorized to read,
print, retain, copy or disseminate this communication without the consent of
the sender and that doing so is prohibited and may be unlawful. Please
reply to the message immediately by informing the sender that the message
was misdirected. After replying, please delete and otherwise erase it and
any attachments from your computer system. Your assistance in correcting
this error is appreciated.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.