Advertisement

08.11.2008 at 01:48PM PDT, ID: 23639340
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

How can I make this Trigger routine to work?

Asked by Enuda in MainFrame Operating Systems, DB2 Database, SQL Query Syntax

Tags: , , , ,

Hi all,
I was handed the code you see here to make a trigger out of it. We started to write a Storproc for the requirement but found out we do not have licennse for the C compiler needed for the storeproc on the Mainframe.
Simply stated, the purpose of the trigger is to determine county and payee of a given transaction item that it receives before allowing insert into the payment table.

Problem is, Triggers doen not allow IF statements and I will very much like to retain the original code if I can but I need to rework the code to eliminate the IF statements....

Can a SQL/Trigger guru "in the house" lend me a hand here?  The code follows and thanks:

--This trigger determines the payee and county for any payment created in the system.
 
CREATE TRIGGER DB2ADMIN.PAYMENT_I NO CASCADE
BEFORE INSERT ON DB2ADMIN.PAYMENT
REFERENCING  NEW AS NEW  
FOR EACH ROW  MODE DB2SQL

BEGIN ATOMIC
DECLARE V_TABLE_ERROR VARCHAR(20) DEFAULT 'UNK';
DECLARE V_FL_FFP CHAR(1);
DECLARE V_FL_OVERRIDE_PRNT CHAR(1);
DECLARE V_FL_OVERRIDE_PRNT_SRVC CHAR(1);
DECLARE V_ID_BSNS INTEGER;
DECLARE V_CD_COUNTY_CNT INTEGER;
DECLARE V_CD_CNTY INTEGER;
SET V_TABLE_ERROR = 'ASSIGNMENT';
SET V_CD_COUNTY_CNT =
( SELECT COUNT(c.CD_COUNTY)
FROM ASSIGNMENT A, ORG_LOCATION_UNIT B,
     ORG_LOCATION c  
WHERE A.ID_GRP_LVL1 = NEW.ID_CASE
      AND A.CD_ASGN_CTGRY = 1  
      AND A.CD_ASGN_ROLE = 1  
      AND  A.FL_OPEN = 'Y'
      AND A.ID_UNIT = B.ID_UNIT
       AND B.ID_LOCATION = C.ID_LOCATION);

IF (V_CD_COUNTY_CNT = 1)
THEN
   SET V_CD_CNTY =
      (SELECT C.CD_COUNTY
      FROM ASSIGNMENT A, ORG_LOCATION_UNIT B, ORG_LOCATION c  
      WHERE A.ID_GRP_LVL1 = NEW.ID_CASE
      AND A.CD_ASGN_CTGRY = 1 AND A.CD_ASGN_ROLE = 1  
      AND  A.FL_OPEN = 'Y'
       AND A.ID_UNIT = B.ID_UNIT AND
      B.ID_LOCATION = C.ID_LOCATION);
ELSE
   SET V_TABLE_ERROR = 'CASE_MASTER';
   SET V_CD_CNTY = (SELECT CD_RGN FROM CASE_MASTER
      WHERE ID_CASE = NEW.ID_CASE);
END IF;

SET NEW.CD_CNTY = V_CD_CNTY;
SET V_TABLE_ERROR = 'PROVIDER_ORG';
SET V_FL_FFP =(SELECT FL_NFP FROM PROVIDER_ORG
WHERE ID_PRVD_ORG = NEW.ID_BSNS);

IF (NEW.ID_EPSD IS NOT NULL)
THEN
   SET V_TABLE_ERROR ='EPISODE';
   SET V_FL_OVERRIDE_PRNT=(SELECT FL_OVERRIDE_PRNT
      FROM EPISODE WHERE ID_EPSD = NEW.ID_EPSD);
   SET V_FL_OVERRIDE_PRNT_SRVC = (SELECT FL_OVERRIDE_PRNT
      FROM SERVICE_TYPE WHERE CD_SRVC = NEW.CD_SRVC);
    IF (NEW.ID_PRVD_ORG <> NEW.ID_BSNS) AND
        (NEW.ID_EPSD IS NOT NULL) AND
        (V_FL_OVERRIDE_PRNT = 'N') AND
        (V_FL_OVERRIDE_PRNT_SRVC = 'N') AND
        ( ( NEW.CD_PMNT_TYPE <> 'C' AND
          (
                        ( V_FL_FFP = 'Y' AND
            ( NEW.AM_ADMIN <> NEW.AM_RQST ) )
                        OR
            ( NEW.AM_ADMIN = NEW.AM_RQST )
          )
        )
        OR
         ( NEW.CD_PMNT_TYPE = 'C' AND
          V_FL_FFP = 'Y' ))
    THEN
            SET NEW.ID_PAYEE = NEW.ID_BSNS;
    ELSE
            SET NEW.ID_PAYEE = NEW.ID_PRVD_ORG;
    END IF;
ELSE
   SET V_TABLE_ERROR ='EPISODE';
   SET NEW.ID_PAYEE = NEW.ID_PRVD_ORG;
END IF;
END

Start Free Trial
[+][-]08.11.2008 at 04:28PM PDT, ID: 22209091

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.11.2008 at 06:40PM PDT, ID: 22209581

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 08:03AM PDT, ID: 22213827

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 09:54AM PDT, ID: 22214931

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 06:46PM PDT, ID: 22218513

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 07:29PM PDT, ID: 22218655

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 07:36PM PDT, ID: 22218679

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MainFrame Operating Systems, DB2 Database, SQL Query Syntax
Tags: IBM, DB2v8 for Z/OS, IBM, MVS, SQL Trigger
Sign Up Now!
Solution Provided By: momi_sabag
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628