Search code examples
db2ibm-midrangerpgle

How can I break a long string in an "XMLTABLE" embedded SQL statement in RPGLE across multiple lines?


I have an XML path that exceeds 100 characters (and therefore truncates when the source is saved). My statement is something like this:

Exec SQL
Select Whatever
  Into :Stuff
From Table as X,
  XmlTable(
    XmlNamespaces('http://namespace.url/' as "namespacevalue"),
    '$X/really/long/path' Passing X.C1 as "X"
    Columns
      Field1 Char(3) Path 'example1',
      Field2 Char(8) Path 'example2',
      Field3 Char(32) Path '../example3'
  ) As R; 

I must break $X/really/long/path across multiple lines. Per IBM's documentation,

The plus sign (+) can be used to indicate a continuation of a string constant.

However, this does not even pass precompile ("Token + was not valid"). I suspect this is due to where the string is in the statement.

I have also tried:

  • Putting the path in a host variable; this was not allowed
  • Using SQL CONCAT or ||; not allowed
  • Putting the path in a SQL global variable instead of a host variable; not allowed

I have considered:

  • Preparing the entire statement, but this is not ideal for a multitude of reasons
  • Truncating the path at a higher level in the hierarchy, but this does not return the desired "granularity" of records

Is there any way to span this specific literal in an XmlTable function across multiple lines in my source? Thanks for any and all ideas!


Solution

  • Something like

    Exec SQL
    Select Whatever
      Into :Stuff
    From Table as X,
      XmlTable(
        XmlNamespaces('http://namespace.url/' as "namespacevalue"),
        '$X/really/+
         long/path' Passing X.C1 as "X"
        Columns
          Field1 Char(3) Path 'example1',
          Field2 Char(8) Path 'example2',
          Field3 Char(32) Path '../example3'
      ) As R; 
    

    Should work, is that what you tried ?