× 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.



I am trying to avoid redefining things multiple times, but am having no luck with the SQL precompiler. I have my field reference file defined in a common definitions copy book. I also have a separate copy book to hold prototypes for my module, this copy book includes the common definitions copy book. The module contains procedures that define host variables using Like. The definitions are proper for RPG, but not sufficient for SQL. How can I do this a better way? The documentation for embedded SQL says the EXTNAME should work, as long as it doesn't use the third parameter. I am still having trouble with that though. Here are my definitions:

@DTACOM_

// Only define these once
/if defined(@DTACOM)
/eof
/endif

/define @DTACOM

...

// Field Reference File
dcl-ds jcfldr_t ExtName(jcfldr) Qualified Template;
end-ds;


@EMPCOM_

/copy qilesrc,@dtacom_

dcl-pr GetEmployeeName Like(jcfldr_t.ename);
empno Like(jcfldr_t.empno) const;
end-pr;

dcl-pr GetDefaultEmployeeForMachine Like(jcfldr_t.mdempno);
empno Like(jcfldr_t.micno) const;
end-pr;


@EMPCOM

ctl-opt Option(*SrcStmt : *NoDebugIo) DatFmt(*ISO)
NoMain;
*-------------------------------------------------------------------------------------
* Common Employee Procedures
*-------------------------------------------------------------------------------------

/copy qilesrc,@empcom_
/copy qilesrc,@msgcom_

exec sql set option sqlca = *no,
commit = *none,
datfmt = *iso;


// ---------------------------------------------------------------------
// GetEmployeeName
// Returns the employee name for the provided employee number
//
// Parameters
// empno - Input - Employee Number
// ---------------------------------------------------------------------
dcl-proc GetEmployeeName Export;
dcl-pi *n Like(jcfldr_t.ename);
empno Like(jcfldr_t.empno) const;
end-pi;

dcl-s name Like(jcfldr_t.ename) Inz('');
dcl-s message Like(@msgcom_t.SqlDiagnostics) Inz('');

exec sql
select ename
into :name
from jcempf
where empno = :empno;
if %subst(SqlState:1:2) > '02';
exec sql get diagnostics condition 1
:message = message_text;
SndSqlMsg('@EMP01: ' + message);
endif;

return name;
end-proc;


// ---------------------------------------------------------------------
// GetEmployeeName
// Returns the employee name for the provided employee number
//
// Parameters
// empno - Input - Employee Number
// ---------------------------------------------------------------------
dcl-proc GetDefaultEmployeeForMachine Export;
dcl-pi *n Like(jcfldr_t.mdempno);
micno Like(jcfldr_t.micno) const;
end-pi;

dcl-s mdempno Like(jcfldr_t.mdempno) Inz(0);
dcl-s message Like(@msgcom_t.SqlDiagnostics) Inz('');

exec sql
select mdempno
into :mdempno
from jcmcmx
where micno = :micno;
if %subst(SqlState:1:2) > '02';
exec sql get diagnostics condition 1
:message = message_text;
SndSqlMsg('@EMP02: ' + message);
endif;

return mdempno;
end-proc;


So what does the manual mean by: "The precompiler supports EXTNAME, but does not support EXTNAME(filename : fmtname : fieldtype), where fieldtype is *ALL, *INPUT, *OUTPUT, or *KEY."

It sounds pretty clear to me, but I must be missing something since I get errors on :name, :empno, :mdempno, and :micno.
Same error for each field: SQL0312: Position <20 or 29> Variable <fieldname> not defined or not usable.

When I look at the SQL Precompiler listing cross-reference the fields look like this:
CROSS REFERENCE
Data Names Define Reference
EMPNO 430 440
MDEMPNO 463 468
MICNO 460 470
NAME 433 438

The odd thing about this is that id doesn't tell how these fields were defined, just where they are defined, and jcfldr_t is not listed in the cross-reference, though I can see in the source listing that it is being included. In my compile command, RPGPPOPT(*LVL2) is set. I have tried with and without TEMPLATE.

Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.