调用DB2存储过程时出错

时间:2016-06-20 21:33:28

标签: db2-400

我使用输入和输出参数定义了一个存储过程,当我尝试调用存储过程时出现以下错误。

[SQL0312]变量KUNNR未定义或不可用。

这是电话:

CALL R3QA6DATA.SP_ADDRESS_CHANGES('1999-12-31 23:59:59','2016-06-01 23:59:59',:KUNNR,:KUNN2,:NAME1,:NAME2,:STRAS,: ORT01,:REGIO,:PSTLZ,:LAND1,:TELF1,:TELFX,:DEFPA) GO

以下是存储过程:

CREATE PROCEDURE R3QA6DATA.SP_ADDRESS_CHANGES 
(IN STARTDATE TIMESTAMP, IN ENDDATE TIMESTAMP, 
 OUT KUNNR GRAPHIC(10), OUT KUNN2 GRAPHIC(10), OUT NAME1 GRAPHIC(35), OUT NAME2 GRAPHIC(35), OUT STRAS GRAPHIC(35), OUT ORT01 GRAPHIC(35),
 OUT REGIO GRAPHIC(3), OUT PSTLZ GRAPHIC(10), OUT LAND1 GRAPHIC(3), OUT TELF1 GRAPHIC(16), OUT TELFX GRAPHIC(31), OUT DEFPA GRAPHIC(1) )

LANGUAGE SQL

BEGIN 
    SELECT DISTINCT 
         knvp.kunnr 
        , knvp.kunn2 
        , kna1.name1 
        , kna1.name2 
        , kna1.stras 
        , kna1.ort01 
        , kna1.regio 
        , kna1.pstlz  
        , kna1.land1 
        , kna1.telf1 
        , kna1.telfx 
        , knvp.defpa 
        INTO KUNNR, KUNN2, NAME1, NAME2, STRAS, ORT01, REGIO, PSTLZ, LAND1, TELF1, TELFX, DEFPA
    FROM 
        R3QA6DATA.KNA1 AS kna1 
        INNER JOIN  
        R3QA6DATA.ZMBCM AS zmbcm 
        ON  
        kna1.KUNNR = zmbcm.KUNAG 
        INNER JOIN 
        R3QA6DATA.KNVV AS knvv 
        ON 
        ( kna1.KUNNR = knvv.KUNNR ) 
        INNER JOIN 
        R3QA6DATA.KNVP AS knvp  
        ON 
        (  
            knvv.KUNNR = knvp.KUNNR  
            AND 
            knvv.VKORG = knvp.VKORG 
            AND 
            knvv.VTWEG = knvp.VTWEG 
            AND 
            knvv.SPART = knvp.SPART 
        ) 
    WHERE 
        kna1.MANDT = '010' 
        AND 
        knvp.PARVW IN ('WE', 'AG') 
        AND 
        ( 
            knvv.VKORG = zmbcm.VKORG 
            AND 
            knvv.VTWEG = zmbcm.VTWEG 
            AND 
            knvv.SPART = zmbcm.SPART 
        ) 
        AND 
        kna1.loevm = ' ' 
        AND 
        knvv.loevm = ' ' 
        AND 
        knvp.KUNN2 IN 
        ( 
            SELECT  
                SUBSTRING(bdcp2.tabkey, 4, 10) 
            FROM 
                R3QA6DATA.BDCP2 AS bdcp2 
            WHERE 
                bdcp2.mestype = 'DEBMAS' 
                AND 
                ( 
                    (  bdcp2.tabname = 'KNA1' 
                    AND 
                    bdcp2.fldname IN  
                    ('NAME1' 
                    , 'NAME2' 
                    , 'STRAS' 
                    , 'ORT01' 
                    , 'REGIO' 
                    , 'LAND1' 
                    , 'PSTLZ' 
                    , 'TELF1' 
                    , 'TELFX') ) 
                    OR 
                    (  bdcp2.tabname = 'KNVP' ) 
                ) 
                AND 
                (  
                    bdcp2.cretime > STARTDATE 
                    AND  
                    bdcp2.cretime < ENDDATE
                ) 
        ) 
        AND 
        zmbcm.STOREID = 4 ;
END 
Go

1 个答案:

答案 0 :(得分:0)

在RPGLE或COBOL中,如果您在外部源中定义了变量并通过COPY语句访问,则通常会发生此问题。如果问题出现这种情况,请尝试通过INCLUDE使用源代码。