Home > Mobile >  Create XML file via Progress 12 using WRITE-XML statement
Create XML file via Progress 12 using WRITE-XML statement

Time:07-01

I am trying to generate an XML file in Progress 12 using temp tables and a WRITE-XML statement. I am almost there. The format should be

<CdtrAgt>
   <FinInstrnId>
      <ClrSysMmbId>
         <MmbId>xxx</MmbId>
      </ClrSysMmbId>
      <Nm>yyy</Nm>
      <PstlAdr>
         <Ctry>US</Ctry>
      </PstlAdr>
      <Othr>
         <Id>zzz</Id>
      </Othr>
   </FinInstrnId>
</CdtrAgt>

I figured out how to move the Nm segment before the PstlAdr using the code:

        PARENT-ID-RELATION FinCR1 FOR FinInstnId-CR, ClrSysMmbId-CR
                PARENT-ID-FIELD FinInstn-Id
                PARENT-FIELDS-AFTER (Nm) 
        PARENT-ID-RELATION FinCR2 FOR FinInstnId-CR, PstlAdr-CR
                PARENT-ID-FIELD FinInstn-Id2

but I'm not able to move the Othr segment after PstlAdr. Here is my code:

/* Temp tables  */
DEFINE TEMP-TABLE CstmrCdtTrfInitn NO-UNDO               
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"      
       INDEX TEMP-ACH-HDR-IDX IS PRIMARY MsgId ASC.
       
DEFINE TEMP-TABLE PmtInf NO-UNDO                      
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR                                                                     
       FIELD PmtMtd AS CHAR         
       FIELD NbOfTxs AS INT                                                      
       FIELD CtrlSum AS DEC DECIMALS 2                                                            
       INDEX TEMP-ACH-HDR-IDX IS PRIMARY MsgId ASC PmtInfId ASC.
       
DEFINE TEMP-TABLE PmtTpInf NO-UNDO              
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD LclInstrm AS CHAR XML-NODE-TYPE "HIDDEN"                                          
       INDEX TEMP-ACH-HDR-IDX IS PRIMARY MsgId ASC PmtInfId ASC.
       
DEFINE TEMP-TABLE CdtTrfTxInf NO-UNDO                  
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"                                 
       INDEX TEMP-ACH-CRED-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.  
       
DEFINE TEMP-TABLE PmtId NO-UNDO         
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"                                
       FIELD EndToEndId AS CHAR    /* Receiver Id Number */                      
       INDEX TEMP-ACH-CRED-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.         
       
DEFINE TEMP-TABLE Amt NO-UNDO              
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"
       INDEX TEMP-ACH-CRED-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.         
       
DEFINE TEMP-TABLE CdtrAgt NO-UNDO        
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"
       INDEX TEMP-ACH-CRED-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.         
       
DEFINE TEMP-TABLE FinInstnId-CR NO-UNDO XML-NODE-NAME "FinInstnId"                
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"        
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"
       FIELD Nm AS CHAR                                               
       INDEX TEMP-ACH-CRED-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.         
       
DEFINE TEMP-TABLE ClrSysMmbId-CR NO-UNDO XML-NODE-NAME "ClrSysMmbId"           
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"        
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"
       FIELD FinInstn-Id AS RECID  XML-NODE-TYPE "HIDDEN"
       FIELD MmbId AS CHAR    
       INDEX TEMP-ACH-HDR-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.
       
DEFINE TEMP-TABLE PstlAdr-CR NO-UNDO XML-NODE-NAME "PstlAdr"                          
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"
       FIELD FinInstn-Id2 AS RECID  XML-NODE-TYPE "HIDDEN"
       FIELD Ctry AS CHAR   /* Remit To Postal Country */
       INDEX TEMP-ACH-HDR-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.
       
DEFINE TEMP-TABLE Othr-CI NO-UNDO XML-NODE-NAME "Othr"                                        
       FIELD MsgId AS CHAR XML-NODE-TYPE "HIDDEN"        
       FIELD PmtInfId AS CHAR XML-NODE-TYPE "HIDDEN"
       FIELD SeqNum AS INT XML-NODE-TYPE "HIDDEN"
       FIELD FinInstn-Id3 AS RECID  XML-NODE-TYPE "HIDDEN"
       FIELD Id AS CHAR    /* DFI Account Number */
       FIELD IBAN AS CHAR     /* Remit To N1 ID Code ID - if populated */
       INDEX TEMP-ACH-CRED-IDX IS PRIMARY MsgId ASC PmtInfId ASC SeqNum ASC.         
/* ***************************  Define Pro Dataset for XML Reading *************************** */
/* NAMESPACE-URI is used to set the dataset attribute - will appear as follows:
   <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   */
 DEFINE DATASET Document NAMESPACE-URI "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" FOR CstmrCdtTrfInitn, CdtTrfTxInf, PmtInf, PmtTpInf, 
                               CdtrAgt, FinInstnId-CR, ClrSysMmbId-CR, PstlAdr-CR, Othr-CI

        DATA-RELATION Pymt-1 FOR CstmrCdtTrfInitn, PmtInf
                                 RELATION-FIELDS(MsgId, MsgId)
                                 NESTED

        DATA-RELATION Cred-1 FOR PmtInf, CdtTrfTxInf
                                 RELATION-FIELDS(MsgId, MsgId,
                                                 PmtInfId, PmtInfId)
                                 NESTED
        DATA-RELATION Cred-5 FOR CdtTrfTxInf, CdtrAgt
                                 RELATION-FIELDS(MsgId, MsgId,
                                                 PmtInfId, PmtInfId,
                                                 SeqNum, SeqNum)
                                 NESTED

        DATA-RELATION Cred-6 FOR CdtrAgt, FinInstnId-CR
                                 RELATION-FIELDS(MsgId, MsgId,
                                                 PmtInfId, PmtInfId,
                                                 SeqNum, SeqNum)
                                 NESTED
        DATA-RELATION Cred-10 FOR FinInstnId-CR, Othr-CI
                                 RELATION-FIELDS(MsgId, MsgId,
                                                 PmtInfId, PmtInfId,
                                                 SeqNum, SeqNum)
                                 NESTED

        PARENT-ID-RELATION FinCR1 FOR FinInstnId-CR, ClrSysMmbId-CR
                PARENT-ID-FIELD FinInstn-Id
                PARENT-FIELDS-AFTER (Nm) 

        PARENT-ID-RELATION FinCR2 FOR FinInstnId-CR, PstlAdr-CR
                PARENT-ID-FIELD FinInstn-Id2.

Any assistance would be appreciated.

Julie

CodePudding user response:

Change the order of your data-relations so that the relations appear in the order in the dataset that they should appear in the XML.

DEFINE  TEMP-TABLE tt NO-UNDO 
    FIELD id AS INTEGER SERIALIZE-HIDDEN 
    FIELD val AS CHARACTER .

DEFINE  TEMP-TABLE tt2 NO-UNDO 
    FIELD id AS INTEGER SERIALIZE-HIDDEN 
    FIELD parentId AS RECID SERIALIZE-HIDDEN
    FIELD customField AS CHARACTER 
    FIELD val AS CHARACTER .

DEFINE  TEMP-TABLE tt3 NO-UNDO 
    FIELD id AS INTEGER SERIALIZE-HIDDEN 
    FIELD parentId AS RECID SERIALIZE-HIDDEN
    FIELD val AS CHARACTER .

DEFINE  TEMP-TABLE tt4 NO-UNDO 
    FIELD id AS INTEGER SERIALIZE-HIDDEN 
    FIELD parentId AS RECID SERIALIZE-HIDDEN
    FIELD val AS CHARACTER .

CREATE tt.
ASSIGN  
    tt.id  = 1
    tt.val = "AAA".

CREATE tt2.
ASSIGN 
    tt2.id = 2
    tt2.parentId = tt.id
    tt2.val = "BBB"
    tt2.customField = "inbetween".
    
CREATE tt3.
ASSIGN 
    tt3.parentId = RECID(tt2)
    tt3.val = "CCC".

CREATE tt4.
ASSIGN 
    tt4.parentId = RECID(tt2)
    tt4.val = "DDD".

DEFINE DATASET ds FOR tt, tt2, tt3, tt4
        DATA-RELATION dr1 FOR tt,  tt2 RELATION-FIELDS(tt.id,tt2.parentId)  NESTED 
        PARENT-ID-RELATION pi1 FOR tt2, tt4 PARENT-ID-FIELD tt4.parentId 
            PARENT-FIELDS-BEFORE(customField) PARENT-FIELDS-AFTER(val)
        PARENT-ID-RELATION pi2 FOR tt2, tt3 PARENT-ID-FIELD tt3.parentId.

DATASET ds:WRITE-XML("file", "c:/temp/file.xml", TRUE).

This reflects in the xml:

<ds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tt>
<val>AAA</val>
<tt2>
<customField>inbetween</customField>
<tt4>
<val>DDD</val>
</tt4>
<val>BBB</val>
<tt3>
<val>CCC</val>
</tt3>
</tt2>
</tt>
</ds>

Edit: changed the dataset so it handles field before/after

  • Related