0

我正在尝试实现一个例程来替换 BW 转换中的一些无效字符。但我不断收到语法错误。这是我当前的代码:

METHOD S0001_G01_R40 BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT 
OPTIONS READ-ONLY.
-- target field: 0POSTXT
-- Note the _M class are not considered for DTP execution.
-- AMDP Breakpoints must be set in the _A class instead.

outTab = SELECT REPLACE_REGEXPR('([^[:print:]|^[\x{00C0}-\x{017F}]|[#])' 
IN "SGTXT" WITH '' OCCURRENCE ALL ) AS "/BI0/OIPOSTXT"
FROM :inTab;

errorTab = SELECT '' AS ERROR_TEXT,
          '' AS SQL__PROCEDURE__SOURCE__RECORD FROM DUMMY
          WHERE DUMMY <> 'X';
ENDMETHOD.

我不断收到以下错误:

 SQLSCRIPT message: return type mismatch: Procedure 
 /BIC/QCW72C4IJDC8JAFRICAU_M=>S0001_G01_R40: OUTTAB[ /BI0/OIPOSTXT:NVARCHAR(5000) ]
 != expected result [ POSTXT:NVARCHAR(60) RECORD:NVARCHAR(56)
 SQL__PROCEDURE__SOURCE__RECORD:NVARCHAR(56) ]

谁能告诉我我在这里做错了什么?

4

2 回答 2

3

对于那些想知道如何纠正这个问题的人,这里是解决方案。一切都在错误消息中:

OUTTAB[ /BI0/OIPOSTXT:NVARCHAR(5000) ]
 != expected result [ POSTXT:NVARCHAR(60) RECORD:NVARCHAR(56)
 SQL__PROCEDURE__SOURCE__RECORD:NVARCHAR(56) ]

这意味着结果表 OutTab 仅包含一个字段 (/BI0/OIPOSTXT),因此与预期的 OutTab 不同,它应包含 3 个字段 POSTXT、RECORD 和 SQL__PROCEDURE__SOURCE__RECORD。

通常可以在公共部分的顶部看到预期的结构:

  types:
    begin of TN_S_IN_S0001_G01_R1_1,
       POSTXT type C length 60,
       RECORD type C length 56,
       SQL__PROCEDURE__SOURCE__RECORD type C length 56,
    end of TN_S_IN_S0001_G01_R1_1 .

所以正确的语法是:

outTab =
  SELECT CAST(REPLACE_REGEXPR('([^[:print:]|^[\x{00C0}-\x{017F}]|[#])' IN "SGTXT" WITH '' OCCURRENCE ALL) AS NVARCHAR(60)) AS "POSTXT"
    ,"RECORD" AS "RECORD"
    ,SQL__PROCEDURE__SOURCE__RECORD AS "SQL__PROCEDURE__SOURCE__RECORD"
    FROM :inTab;

问候,让-纪尧姆

于 2020-03-12T08:59:22.390 回答
1

您可能希望将正则表达式包含在 aCAST( ... AS NVARCHAR(60))中,以确保生成的记录结构与预期的返回类型匹配。

于 2019-09-05T00:45:23.423 回答