Search code examples
hanahana-sql-scriptsap-bwamdp

Using REPLACE_REGEXPR in BW transformation throws syntax error


I'm trying to implement a routine for replacing some invalid characters in a BW transformation. But I keep getting a syntax error. This is my current code:

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.

I keep getting the following error:

 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) ]

Can anyone give me an idea of what I'm doing wrong here?


Solution

  • You might want to enclose the regex expression in a CAST( ... AS NVARCHAR(60)) to ensure that the resulting record structure matches the expected return type.