我正在尝试编写RPGLE,它将使用SQL生成XML并将其保存到IFS。我遇到的问题是,当使用网络共享从IFS复制XML时,XML不会自动从EBCDIC转换为ASCII。我已经尝试使用正确的CCSID创建文件,但这似乎被忽略了。我能够克服这一点的唯一方法是使用CPY
并在应对时进行翻译。我只是希望有一种更清洁的方式。
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 ;
答案 0 :(得分:2)
要以ASCII格式获取数据,请在XmlSerialize函数中添加CCSID 1208(无法使用819),并确保ifs文件不存在。否则它将保留文件CCSID
XMLSERIALIZE(
XMLDOCUMENT(
XMLELEMENT(NAME "document",
XMLELEMENT(NAME "elements",
XMLAGG(elements.element)
)
)
) AS CLOB CCSID 1208 INCLUDING XMLDECLARATION
) AS Response
并确保您的机器QCCSID设置为65535以外的值(这总是会导致很多转换问题,而不是自动转换)。
答案 1 :(得分:0)
首先,您必须使用Windows代码页
创建文件 // C Language IFS Prototypes
//-----------------------------------------------------------------
// createTempSTMF(): Creates a file name for a temporary stream file
//
// filename = (input) path to file in the IFS
//-----------------------------------------------------------------
DcreateTempSTMF PR * extproc('_C_IFS_tmpnam')
D string 39A options(*omit)
//-----------------------------------------------------------------
// removeSTMF(): Deletes the defined streamed file.
//
// filename = (input) path to file in the IFS
//-----------------------------------------------------------------
DremoveSTMF PR 10I 0 extproc('_C_IFS_remove')
D filename * VALUE OPTIONS( *String)
//-----------------------------------------------------------------
// openSTMF(): Open File for buffered reading/writing
//
// filename = (input) path to file in the IFS
// mode = (input) various open mode flags. (see manual)
//
// returns *NULL upon error, or a pointer to a FILE structure
//-----------------------------------------------------------------
dopenSTMF PR extproc('_C_IFS_fopen')
d like(pFILE)
d filename * value options(*string)
d mode * value options(*string)
//-----------------------------------------------------------------
// closeSTMF(): Close File
// stream = (input) pointer to FILE structure to close
//-----------------------------------------------------------------
dcloseSTMF PR 10i 0 extproc('_C_IFS_fclose')
dparStream like(pFILE) value
dpFile s * based(prototype_only)
d fd s like(openSTMF)
//Unique filename in /tmp
tempFileName = %trim(%str(createTempSTMF(*omit)));
// create new output file
fd = openSTMF(%trim(tempFileName): 'w codepage=1252');
if (fd = *NULL);
*INLR = *ON;
return;
endif;
然后用文本模式重新打开它,以便自动进行翻译
// ------------------------------------------
// close file & reopen in text mode so that
// data will be automatically translated
// ------------------------------------------
closeSTMF(fd);
fd = openSTMF( %trim(tempFileName) : 'a codepage=37');
if (fd = *NULL);
*INLR = *ON;
return;
endif;
然后写一些数据
//Write some data
fputsSTMF('Some data': fd);