So I'm trying to develop a function in AS400 RPG that receives 4 String parameters, uses DB2 XMLSERIALIZE to build an XML Header using said parameters and returns that header in a string. The return string shows different characters in the tag values when I use an RPG variable. I think maybe the problem is the character coding, but I've tried many solutions and none works.
Here's the code of the RPG function:
The problem is specifically in the variables: bicFrom, bicTo, BizMsgIdr, MsgDefIdr.
The expected XML Header is the following:
And the (incorrect) output that is returned is the following (notice the tags BicFi, BizMsgIdr, MsgDefIdr, BizSvc) :
Any ideas are welcome. Thanks in advance!!!
Here's the code of the RPG function:
Code:
dcl-proc SWFS02801_generaHeaderMX export;[INDENT]dcl-pi *n Ind;[/INDENT][INDENT=2]bicFrom Char(12);[/INDENT][INDENT=2]bicTo Char(12);[/INDENT][INDENT=2]BizMsgIdr Char(20);[/INDENT][INDENT=2]MsgDefIdr Char(20);[/INDENT][INDENT=2]AppHeaderData Char(2000);[/INDENT][INDENT]end-pi; dcl-s AppHeader SQLTYPE(CLOB:2000); dcl-s bicFromClob SQLTYPE(CLOB:12); dcl-c BizSvc 'swift.cbprplus.01'; bicFromClob_DATA = bicFrom; Exec Sql SELECT XMLSERIALIZE([/INDENT][INDENT=2]XMLELEMENT(NAME "AppHdr", XMLNAMESPACES(DEFAULT 'urn:iso:std:iso:20022:tech:xsd:head.001.001.02'), XMLFOREST( XMLELEMENT(NAME "FiId", XMLELEMENT(NAME "FinInstId", XMLFOREST( :bicFrom as "BicFi") ) ) as "Fr", XMLELEMENT(NAME "FiId", XMLELEMENT(NAME "FinInstId", XMLFOREST( :bicTo as "BicFi") )) as "To", :BizMsgIdr as "BizMsgIdr", :MsgDefIdr as "MsgDefIdr", :BizSvc as "BizSvc", CubDDat.UbdFGenFec(Current date) as "CredDt"[/INDENT][INDENT=2])[/INDENT][INDENT]) as CLOB(2000) ) AS RESULTADO INTO :AppHeader FROM SYSIBM.SYSDUMMY1; If SQLCODE = 0;[/INDENT][INDENT=2]AppHeaderData = AppHeader_DATA; return *on;[/INDENT][INDENT]Else;[/INDENT][INDENT=2]return *off;[/INDENT][INDENT]ENDIF;[/INDENT] END-PROC;
The problem is specifically in the variables: bicFrom, bicTo, BizMsgIdr, MsgDefIdr.
The expected XML Header is the following:
Code:
<AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001 .02">[INDENT]<Fr>[/INDENT][INDENT=2]<FiId>[/INDENT][INDENT=3]<FinInstId>[/INDENT][INDENT=4]<BicFi>BICFROM1</BicFi>[/INDENT][INDENT=3]</FinInstId>[/INDENT][INDENT=2]</FiId>[/INDENT][INDENT]</Fr> <To>[/INDENT][INDENT=2]<FiId>[/INDENT][INDENT=3]<FinInstId>[/INDENT][INDENT=4]<BicFi>BICTO1</BicFi>[/INDENT][INDENT=3]</FinInstId>[/INDENT][INDENT=2]</FiId>[/INDENT][INDENT]</To> <BizMsgIdr>tstBizMsgIdr</BizMsgIdr> <MsgDefIdr>tstMsgDefIdr</MsgDefIdr> <BizSvc>swift.cbprplus.01</BizSvc> <CredDt>2021-12-28T06:00:00.0Z</CredDt>[/INDENT] </AppHdr>
Code:
<AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001 .02">[INDENT]<Fr>[/INDENT][INDENT=2]<FiId>[/INDENT][INDENT=3]<FinInstId>[/INDENT][INDENT=4]<BicFi>wsnDxtnW1PFAQEBA</BicFi>[/INDENT][INDENT=3]</FinInstId>[/INDENT][INDENT=2]</FiId>[/INDENT][INDENT]</Fr> <To>[/INDENT][INDENT=2]<FiId>[/INDENT][INDENT=3]<FinInstId>[/INDENT][INDENT=4]<BicFi>wsnDxuPW8UBAQEBA</BicFi>[/INDENT][INDENT=3]</FinInstId>[/INDENT][INDENT=2]</FiId>[/INDENT][INDENT]</To> <BizMsgIdr>oqPCianUoofJhJlAQEBAQEBAQEA=</BizMsgIdr> <MsgDefIdr>oqPUoofEhYbJhJlAQEBAQEBAQEA=</MsgDefIdr> <BizSvc>oqaJhqNLg4KXmZeTpKJL8PE=</BizSvc> <CredDt>2021-12-28T06:00:00.0Z</CredDt>[/INDENT] </AppHdr>