I would like to convert the following Firebird stored procedure to
iSeries / DB2 / SQL one. My problem is that i don't know how to
handle "suspend", which is the keyword statment for returning a set of output results to the calling program.
Is it a good idea to use a temp file writing all the output there
and select it with a result cursor in the end?
The application is using Delphi with Firebird localy and accessing
data remotely on the iSeries.
CREATE OR ALTER PROCEDURE AR_AR100_TRA(
ICUST CHAR(6),
IMONF CHAR(2),
IMONT CHAR(2),
IYEAR CHAR(4),
IORIS CHAR(1),
IYPOL SMALLINT)
RETURNS (
OLOGD VARCHAR(10),
OSRAR CHAR(2),
OARAR CHAR(6),
OKKIN CHAR(3),
OAITI VARCHAR(60),
ONOOP CHAR(10),
OXREO NUMERIC(13,2),
OPIST NUMERIC(13,2),
OYPOL NUMERIC(13,2),
ORIST CHAR(1),
OPAYD VARCHAR(10),
OCOPA CHAR(3))
AS
declare variable tlogd date;
declare variable tpayd date;
declare variable ttrva numeric(13,2);
declare variable tfil3 char(3);
declare variable hlogd char(10);
declare variable ppe smallint;
declare variable xresyn numeric(13,2);
declare variable xreper numeric(13,2);
declare variable xretre numeric(13,2);
declare variable pissyn numeric(13,2);
declare variable pisper numeric(13,2);
declare variable pistre numeric(13,2);
declare variable ypoxre numeric(13,2);
declare variable ypopis numeric(13,2);
declare variable ypoloi numeric(13,2);
declare variable treypo numeric(13,2);
declare variable synypo numeric(13,2);
declare variable wrkypo numeric(13,2);
begin
if ((icust <> '') and (ioris = '1')) then
begin
oypol = 0;
oxreo = 0;
opist = 0;
ypoxre = 0;
ypopis = 0;
treypo = 0;
xreper = 0;
pisper = 0;
xresyn = 0;
pissyn = 0;
synypo = 0;
for select atkkin, attrva, atfil3
from artra
where atcust = :icust
and f_year(atlogd) = :iyear
and f_month(atlogd) < :imonf
and atoris = '1'
and atrrnt = 0
order by atlogd,atsrar,atarar,atrrne,atrrnt
into
kkin, :ttrva, :tfil3
do
begin
execute procedure ar_arpar_ppe(
kkin,:tfil3,:iypol) returning_values
pe;
if (ppe <> 0) then
begin
if (ppe = 1) then
begin
ypoxre = ypoxre + :ttrva;
xresyn = xresyn + :ttrva;
end
else if (ppe = -1) then
begin
ypopis = ypopis + :ttrva;
pissyn = pissyn + :ttrva;
end
end
end
ypoloi = ypoxre - ypopis;
synypo = synypo + ypoloi;
oxreo = xresyn;
opist = pissyn;
oypol = ypoloi;
ologd = '';
osrar = '';
oarar = '';
okkin = '';
orist = '';
ocopa = '';
opayd = '';
onoop = '';
oaiti = '';
suspend;
for select atlogd, atsrar, lpad(f_lrtrim(cast(atarar as char(6))),6,'0'),
atkkin, ataiti, attrva,
atoris, atfil3, atcopa, atnoop, aopayd
from artra
left join arope
on aocode = atcoop
and aonoet = atnoop
where atcust = :icust
and attran = '1'
and atoris = '1'
and atrrnt = 0
and f_year(atlogd) = :iyear
and f_month(atlogd) between :imonf and :imont
order by atlogd,atsrar,atarar,atrrne,atrrnt
into :tlogd,
srar,
arar,
kkin,
aiti, :ttrva,
rist, :tfil3,
copa,
noop, :tpayd
do
begin
execute procedure ar_arpar_ppe(
kkin,:tfil3,:iypol) returning_values
pe;
if (ppe <> 0) then
begin
if (ppe = 1) then
begin
pistre = 0;
xretre = :ttrva;
xresyn = xresyn + :ttrva;
xreper = xreper + :ttrva;
end
else if (ppe = -1) then
begin
xretre = 0;
pistre = :ttrva;
pissyn = pissyn + :ttrva;
pisper = pisper + :ttrva;
end
wrkypo = :ttrva *
pe;
treypo = treypo + wrkypo;
synypo = synypo + wrkypo;
oxreo = xretre;
opist = pistre;
oypol = treypo;
hlogd = cast(:tlogd as char(10));
ologd = substring(:hlogd from 9 for 2) || '/' ||
substring(:hlogd from 6 for 2) || '/' ||
substring(:hlogd from 1 for 4);
if (tpayd is null) then
opayd = '';
else
begin
hlogd = cast(:tpayd as char(10));
opayd = substring(:hlogd from 9 for 2) || '/' ||
substring(:hlogd from 6 for 2) || '/' ||
substring(:hlogd from 1 for 4);
end
suspend;
end
end
oxreo = xreper;
opist = pisper;
oypol = treypo;
ologd = '';
osrar = '';
oarar = '';
okkin = '';
orist = '';
ocopa = '';
opayd = '';
onoop = '';
oaiti = '';
suspend;
oxreo = xresyn;
opist = pissyn;
oypol = synypo;
ologd = '';
osrar = '';
oarar = '';
okkin = '';
orist = '';
ocopa = '';
opayd = '';
onoop = '';
oaiti = '';
suspend;
end
exit;
end
Thank a lot for your attention.
G.Bakas
iSeries / DB2 / SQL one. My problem is that i don't know how to
handle "suspend", which is the keyword statment for returning a set of output results to the calling program.
Is it a good idea to use a temp file writing all the output there
and select it with a result cursor in the end?
The application is using Delphi with Firebird localy and accessing
data remotely on the iSeries.
CREATE OR ALTER PROCEDURE AR_AR100_TRA(
ICUST CHAR(6),
IMONF CHAR(2),
IMONT CHAR(2),
IYEAR CHAR(4),
IORIS CHAR(1),
IYPOL SMALLINT)
RETURNS (
OLOGD VARCHAR(10),
OSRAR CHAR(2),
OARAR CHAR(6),
OKKIN CHAR(3),
OAITI VARCHAR(60),
ONOOP CHAR(10),
OXREO NUMERIC(13,2),
OPIST NUMERIC(13,2),
OYPOL NUMERIC(13,2),
ORIST CHAR(1),
OPAYD VARCHAR(10),
OCOPA CHAR(3))
AS
declare variable tlogd date;
declare variable tpayd date;
declare variable ttrva numeric(13,2);
declare variable tfil3 char(3);
declare variable hlogd char(10);
declare variable ppe smallint;
declare variable xresyn numeric(13,2);
declare variable xreper numeric(13,2);
declare variable xretre numeric(13,2);
declare variable pissyn numeric(13,2);
declare variable pisper numeric(13,2);
declare variable pistre numeric(13,2);
declare variable ypoxre numeric(13,2);
declare variable ypopis numeric(13,2);
declare variable ypoloi numeric(13,2);
declare variable treypo numeric(13,2);
declare variable synypo numeric(13,2);
declare variable wrkypo numeric(13,2);
begin
if ((icust <> '') and (ioris = '1')) then
begin
oypol = 0;
oxreo = 0;
opist = 0;
ypoxre = 0;
ypopis = 0;
treypo = 0;
xreper = 0;
pisper = 0;
xresyn = 0;
pissyn = 0;
synypo = 0;
for select atkkin, attrva, atfil3
from artra
where atcust = :icust
and f_year(atlogd) = :iyear
and f_month(atlogd) < :imonf
and atoris = '1'
and atrrnt = 0
order by atlogd,atsrar,atarar,atrrne,atrrnt
into
kkin, :ttrva, :tfil3do
begin
execute procedure ar_arpar_ppe(
kkin,:tfil3,:iypol) returning_values
pe;if (ppe <> 0) then
begin
if (ppe = 1) then
begin
ypoxre = ypoxre + :ttrva;
xresyn = xresyn + :ttrva;
end
else if (ppe = -1) then
begin
ypopis = ypopis + :ttrva;
pissyn = pissyn + :ttrva;
end
end
end
ypoloi = ypoxre - ypopis;
synypo = synypo + ypoloi;
oxreo = xresyn;
opist = pissyn;
oypol = ypoloi;
ologd = '';
osrar = '';
oarar = '';
okkin = '';
orist = '';
ocopa = '';
opayd = '';
onoop = '';
oaiti = '';
suspend;
for select atlogd, atsrar, lpad(f_lrtrim(cast(atarar as char(6))),6,'0'),
atkkin, ataiti, attrva,
atoris, atfil3, atcopa, atnoop, aopayd
from artra
left join arope
on aocode = atcoop
and aonoet = atnoop
where atcust = :icust
and attran = '1'
and atoris = '1'
and atrrnt = 0
and f_year(atlogd) = :iyear
and f_month(atlogd) between :imonf and :imont
order by atlogd,atsrar,atarar,atrrne,atrrnt
into :tlogd,
srar,
arar,
kkin,
aiti, :ttrva,
rist, :tfil3,
copa,
noop, :tpayddo
begin
execute procedure ar_arpar_ppe(
kkin,:tfil3,:iypol) returning_values
pe;if (ppe <> 0) then
begin
if (ppe = 1) then
begin
pistre = 0;
xretre = :ttrva;
xresyn = xresyn + :ttrva;
xreper = xreper + :ttrva;
end
else if (ppe = -1) then
begin
xretre = 0;
pistre = :ttrva;
pissyn = pissyn + :ttrva;
pisper = pisper + :ttrva;
end
wrkypo = :ttrva *
pe;treypo = treypo + wrkypo;
synypo = synypo + wrkypo;
oxreo = xretre;
opist = pistre;
oypol = treypo;
hlogd = cast(:tlogd as char(10));
ologd = substring(:hlogd from 9 for 2) || '/' ||
substring(:hlogd from 6 for 2) || '/' ||
substring(:hlogd from 1 for 4);
if (tpayd is null) then
opayd = '';
else
begin
hlogd = cast(:tpayd as char(10));
opayd = substring(:hlogd from 9 for 2) || '/' ||
substring(:hlogd from 6 for 2) || '/' ||
substring(:hlogd from 1 for 4);
end
suspend;
end
end
oxreo = xreper;
opist = pisper;
oypol = treypo;
ologd = '';
osrar = '';
oarar = '';
okkin = '';
orist = '';
ocopa = '';
opayd = '';
onoop = '';
oaiti = '';
suspend;
oxreo = xresyn;
opist = pissyn;
oypol = synypo;
ologd = '';
osrar = '';
oarar = '';
okkin = '';
orist = '';
ocopa = '';
opayd = '';
onoop = '';
oaiti = '';
suspend;
end
exit;
end
Thank a lot for your attention.
G.Bakas
