Hello Stack community,
I have been stuck for the past couple of days with what I initially thought was a relatively simple SQR update.
In a nutshell, procedure Process-Main selects all the employees where COMPANY = 'ABC' and then I need to insert a record into TableA & TableB associated with each employeeID
TableB is empty, so I am simply running an INSERT statement for every empID and the records are being added without any problems.
However, some empIDs might have existing records in TableA and I need to check for that before dong the INSERT into TableA.
Oddly, when i execute this SQR, i'm getting the following error
(SQR 3721) Bad param found on 'BEGIN-SELECT' line;
(SQR 3704) Missing procedure name.
A.EMPLID
I'm fairly certain this is a syntax issue or i'm just having a brain fart... Does anyone have any advice/suggestions?
Here's my pseudo code
!***************************
begin-procedure Process-Main
!***************************
begin-select distinct
J.DEPTID
J.EMPLID
J.EFFDT
do Insert-TableA-Record
do Insert-TableB-Record
FROM PS_JOB J
WHERE J.COMPANY = 'ABC'
end-select
end-procedure
!****************************
begin-procedure Insert-TableA-Record
!****************************
let $found = 'N'
begin-select
A.EMPLID
let $found = 'Y'
FROM TableA A
WHERE A.EMPLID=&J.EMPLID
AND A.PLAN_TYPE='P1234'
end-select
if $found = 'N'
begin-sql ON-ERROR = Abort-Update
INSERT INTO TableA (
EMPLID,
PLAN_TYPE
)
VALUES (
&J.EMPLID,
'P1234'
);
end-sql
end-if
end-procedure
!****************************
begin-procedure Insert-TableB-Record
!****************************
begin-sql ON-ERROR = Abort-Update
!INSERT INTO TableB STMT HERE...
!everything runs fine in this procedure
end-sql
end-procedure