I'm trying to create a trigger in a SQL interpreter, and I'm having some head-scratching problems with it. 

```
CREATE TRIGGER log_permission_role_rel_update AFTER UPDATE ON permission_role_rel
REFERENCING NEW ROW as newrow OLD ROW as oldrow 
FOR EACH ROW
BEGIN ATOMIC

    /* delete old row */
    FOR SELECT * FROM TABLE(MYSCHEMA.simulate_by_permission_role_rel(oldrow.id_role, oldrow.id_permission)) simulationA
    DO
    CALL MYSCHEMA.log_proc('DELETE', 'SECVAL', 'test', '{}');
    END FOR;

    /* insert new row */
    FOR SELECT * FROM TABLE(MYSCHEMA.simulate_by_permission_role_rel(newrow.id_role, newrow.id_permission)) simulationB
    DO
    CALL MYSCHEMA.log_proc('INSERT', 'SECVAL', '{}', 'test');
    END FOR;
END;

```

The statement above results in an error claiming the end-of-instruction isn't valid, and highlighting the end of the second CALL as the culprit.

```
SQL State: 42601
Vendor Code: -104
Message: [SQL0104] Token <END-OF-INSTRUCTION> was not valid. Valid tokens: ;.

```

Both FOR loops work independently, just not when they are both together under the same trigger. I don't really know what more to try. What am I doing wrong here? And why would a single FOR loop work, but not two?

Thank you.

**EDIT**
(edited for more info) 

I'm running under DB2 on iSeries, i5/OS 7.1. I'm also running all SQL statements through iNavigator. 

**EDIT #2**

All the triggers seem to be created with these properties:

```
...
FOR EACH ROW 
MODE DB2SQL 

SET OPTION  ALWBLK = *ALLREAD , 
ALWCPYDTA = *OPTIMIZE , 
COMMIT = *NONE , 
DECRESULT = (31, 31, 00) , 
DFTRDBCOL = MYSCHEMA, 
DYNDFTCOL = *NO , 
DYNUSRPRF = *USER , 
SRTSEQ = *HEX   
BEGIN
...

```

Procedure:

```
CREATE PROCEDURE MYSCHEMA.LOG_PROC ( 
    IN OP VARCHAR(6) , 
    IN TABLENAME VARCHAR(128) , 
    IN OLDVAL VARCHAR(255) , 
    IN NEWVAL VARCHAR(255) ) 
    LANGUAGE SQL 
    SPECIFIC MYSCHEMA.LOG_PROC 
    NOT DETERMINISTIC 
    MODIFIES SQL DATA 
    CALLED ON NULL INPUT 
    SET OPTION  ALWBLK = *ALLREAD , 
    ALWCPYDTA = *OPTIMIZE , 
    COMMIT = *NONE , 
    DECRESULT = (31, 31, 00) , 
    DFTRDBCOL = MYSCHEMA , 
    DYNDFTCOL = *NO , 
    DYNUSRPRF = *USER , 
    SRTSEQ = *HEX   
    BEGIN 
    INSERT INTO AA_LEGACYLOG ( OPERATION , TABLENAME , OLDVALUE , NEWVALUE ) VALUES ( OP , TABLENAME , OLDVAL , NEWVAL ) ; 
END  ; 

```

Function:

```
CREATE FUNCTION MYSCHEMA.SIMULATE_BY_PERMISSION_ROLE_REL ( 
    ARG_ID_ROLE INTEGER , 
    ARG_ID_PERMISSION INTEGER ) 
    RETURNS TABLE ( 
    USRCODE VARCHAR(10) , 
    SECURABLE VARCHAR(12) , 
    LG_INDX VARCHAR(1) , 
    LG_VALO VARCHAR(10) , 
    LG_ATRB VARCHAR(6) )   
    LANGUAGE SQL 
    SPECIFIC MYSCHEMA.SIMULATE_BY_PERMISSION_ROLE_REL 
    NOT DETERMINISTIC 
    READS SQL DATA 
    CALLED ON NULL INPUT 
    SET OPTION  ALWBLK = *ALLREAD , 
    ALWCPYDTA = *OPTIMIZE , 
    COMMIT = *NONE , 
    DECRESULT = (31, 31, 00) , 
    DFTRDBCOL = MYSCHEMA , 
    DYNDFTCOL = *NO , 
    DYNUSRPRF = *USER , 
    SRTSEQ = *HEX   
    RETURN ( 
        SELECT DISTINCT A . USER_REF , P . SECURABLE , P . LG_INDX , P . LG_VALO , P . LG_ATRB 
        FROM ROLE R , PERMISSION P , ACTOR A , ACTOR_ROLE_REL 

        WHERE R . ID = ARG_ID_ROLE 
        AND P . ID = ARG_ID_PERMISSION   

        AND ACTOR_ROLE_REL . ID_ACTOR = ACTOR . ID 
        AND ACTOR_ROLE_REL . ID_ROLE = R . ID 

        GROUP BY A . USER_REF , P . SECURABLE , P . LG_INDX , P . LG_VALO , P . LG_ATRB  
    )  ; 

```