I am trying to write RPGLE that would generate an XML using SQL and save it to IFS. The problem I am running into is that when copying XML from IFS using a network share, the XML is not automatically translated from EBCDIC to ASCII. I have tried creating the file first with correct CCSID, but that seemed to get ignored. Only way I was able to overcome this is to use CPY
and translate while coping. I am just hoping there is a cleaner way.
File_Out_FO = SQFOVR;
File_Out_NAME = '/ifs/path/test.xml';
File_Out_NL = %Len(%TrimR(File_Out_NAME));
EXEC SQL
WITH
elements AS (
SELECT
XMLELEMENT(NAME "element",
XMLFOREST(
field1 AS "field1",
field2 AS "field2",
field3 AS "field3"
)
) AS element
FROM table1
)
SELECT
XMLSERIALIZE(
XMLDOCUMENT(
XMLELEMENT(NAME "document",
XMLELEMENT(NAME "elements",
XMLAGG(elements.element)
)
)
) AS CLOB INCLUDING XMLDECLARATION
) AS response
INTO :File_Out
FROM elements ;
To get the data in ASCII add CCSID 1208 (819 is not possible) in the XmlSerialize function and make sure that the ifs-file doesn't exist. Otherwise it would keep the file CCSID
XMLSERIALIZE(
XMLDOCUMENT(
XMLELEMENT(NAME "document",
XMLELEMENT(NAME "elements",
XMLAGG(elements.element)
)
)
) AS CLOB CCSID 1208 INCLUDING XMLDECLARATION
) AS Response
And make sure that your machine QCCSID is set to something other than 65535 (that's always causing lots of Problems with conversion aka not converting automatically).