Reputation:
I have come across a DB2 SP code where I see at a place, an End If which does not have a corresponding If
WHILE ( SQLSTATE = '00000' ) DO
IF ( SELECT C5STID FROM OS025F WHERE C5OMID = V_OMID ) = 30 THEN
IF ( SELECT COUNT ( * ) FROM OS085F WHERE J5DLR = P_DLR
AND J5OMID =
V_OMID AND J5DSID > 0 ) = 0 THEN
INSERT INTO OS108F ( L8RGID , L8DLR , L8DESC , L8GOAL , L8TOT )
SELECT V_RGID , P_DLR , C5DESC , E2GOAL , 0
FROM OS025F AS ORDERMASTER
INNER JOIN OS042F AS GOALS ON GOALS . E2OMID = ORDERMASTER . C5OMID
WHERE E2DLR = P_DLR
AND E2OMID = V_OMID
GROUP BY 1 , 2 , C5DESC , E2GOAL ;
ELSE IF P_NET = 'Y' THEN
INSERT INTO OS108F ( L8RGID , L8DLR , L8DESC , L8GOAL , L8TOT )
SELECT V_RGID , P_DLR , C5DESC , E2GOAL , SUM( J5TNDC )
FROM OS025F AS ORDERMASTER
INNER JOIN OS042F AS GOALS ON GOALS.E2OMID = ORDERMASTER.C5OMID
INNER JOIN OS085F AS DEALERORDER ON DEALERORDER.J5OMID =
ORDERMASTER.C5OMID AND DEALERORDER.J5DLR = GOALS.E2DLR
WHERE E2DLR = P_DLR
AND E2OMID = V_OMID
AND J5DSID > 0
GROUP BY 1, 2, C5DESC, E2GOAL;
ELSE
INSERT INTO OS108F ( L8RGID , L8DLR , L8DESC , L8GOAL , L8TOT )
SELECT V_RGID, P_DLR, C5DESC, E2GOAL, SUM( J5TOT )
FROM OS025F AS ORDERMASTER
INNER JOIN OS042F AS GOALS ON GOALS.E2OMID = ORDERMASTER.C5OMID
INNER JOIN OS085F AS DEALERORDER ON DEALERORDER.J5OMID =
ORDERMASTER.C5OMID AND DEALERORDER.J5DLR = GOALS.E2DLR
WHERE E2DLR = P_DLR
AND E2OMID = V_OMID
AND J5DSID > 0
GROUP BY 1, 2, C5DESC, E2GOAL;
END IF ;
END IF ;
ELSE....
I have only pasted the relevant piece of code here. So just before the Else at the very end, there are two End If's out of which 1 seems to be unnecessary thing. The code before the while (first line) is just a few declarations of cursors etc. so doesnt matter. If you run the entire SP code in i navigator, the SP gets created like a gem. I would expect an error to be thrown because of the End if. But the issue here is i am trying to convert this into an equivalent RPG code and the compilation fails..Endyy operation out of place error. Can someone tell me if they are able able to understand why the extra end if is not failing to compile?
Upvotes: 0
Views: 29
Reputation:
Actually I found the answer.. The first Else If in the code should have been actually read as an If inside the else part. That makes everything add up. I have changed my RPG so that the same logic gets applied.
Upvotes: 0