Skip to main content

SAP simple transformer

let say we have s insurance xml data as a response of a web service and we want to expose this data as a complex structure data type to deal with it in SAP   (the same like DOM parser in other programming languages)

the xml data as below


<?xml version="1.0" encoding="utf-8"?>
<RequestResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Response>
    <TreatmentBasis>1</TreatmentBasis>
    <TreatmentClassification>1</TreatmentClassification>
    <MemberDetails>
      <Tag>
        <ID>1</ID>
        <Label>DOB</Label>
        <Value>05-Jun-2011</Value>
        <Type>Date</Type>
      </Tag>
      <Tag>
        <ID>2</ID>
        <Label>Gender</Label>
        <Value>Female</Value>
        <Type>Text</Type>
      </Tag>
    </MemberDetails>
    <CoverageNotes>
      <Tag>
        <ID>1</ID>
        <Label>NetworkTypeName</Label>
        <Value>General Network</Value>
        <Type>Text</Type>
      </Tag>
    </CoverageNotes>
    <ApprovalRequirements>
      <Tag>
        <ID>5</ID>
        <Label>Approval required for:</Label>
        <Value>All in-patient services</Value>
        <Type>Text</Type>
      </Tag>
    </ApprovalRequirements>
    <Attachments>
      <File>
        <ID>1</ID>
        <Filename>IP Approvals - Elective.pdf</Filename>
        <DisplayedName>Applicable procedure</DisplayedName>
        <FileContent />
      </File>
      <File>
        <ID>2</ID>
        <Filename>IP Approvals - Emergency.pdf</Filename>
        <DisplayedName>Emergency Applicable procedure</DisplayedName>
        <FileContent>string based 64</FileContent>
      </File>
      <File>
        <ID>3</ID>
        <Filename>Exclusions - VIP 5.pdf</Filename>
        <DisplayedName>Exclusions</DisplayedName>
        <FileContent>string based 64</FileContent>
      </File>
      <File>
        <ID>4</ID>
        <Filename>Capital Markets Authority - 2016 (1 month ext.)_118223.xls</Filename>
        <DisplayedName>Table of Benefits</DisplayedName>
        <FileContent>string based 64</FileContent>
      </File>
      <File>
        <ID>11</ID>
        <Filename>ConsultationForm.pdf</Filename>
        <DisplayedName>Consultation / Claim Form</DisplayedName>
        <FileContent>string based 64</FileContent>
      </File>
      <File>
        <ID>12</ID>
        <Filename>PrescriptionForm.pdf</Filename>
        <DisplayedName>Prescription Form</DisplayedName>
        <FileContent>string based 64</FileContent>
      </File>
      <File>
        <ID>12</ID>
        <Filename>2817951.png</Filename>
        <DisplayedName>Member Card</DisplayedName>
        <FileContent>ICAgICAgIA==</FileContent>
      </File>
    </Attachments>
    <Messages>
      <Message>
        <Category>Room Type</Category>
        <Text>Private (One Bed)</Text>
        <Severity>2</Severity>
      </Message>
    </Messages>
    <Sender>1070</Sender>
    <Receiver>11</Receiver>
    <ReferenceID>23423434234</ReferenceID>
    <RequestReferenceID>342342343</RequestReferenceID>
    <Result>1</Result>
    <Reason />
    <MemberName>dfgdfgdfgdf</MemberName>
    <CardNumber>fgdfgdfgfg</CardNumber>
    <PayerName>Tazur Takaful Insurance Co. (K.S.C.C.)</PayerName>
    <CoverStartDate>12-Jun-2017</CoverStartDate>
    <CoverEndDate>11-Jul-2017</CoverEndDate>
    <MemberPhoto>string based 64</MemberPhoto>
    <IsVIP>VIP</IsVIP>
    <IsTHIQA>Non THIQA</IsTHIQA>
    <ValidityDate>02-Jul-2018</ValidityDate>
  </Response>
</RequestResponse>



the  structure as below

TYPES:
       BEGIN OF  tag,
                  ID                      TYPE I,
                  Label                   TYPE string,
                  Value                   TYPE string,
                  Type                    TYPE string,
       END OF     tag,

       BEGIN OF   file,
                  ID                      TYPE i,
                  Filename                TYPE STRING,
                  DisplayedName           TYPE STRING,
                  FileContent             TYPE STRING,
       END OF     file,

       BEGIN OF   Message,
                  Category                TYPE STRING,
                  Text                    TYPE STRING,
                  Severity                TYPE I,
       END OF     Message,

       BEGIN OF   Messages,
                  Message                 TYPE Message,
       END OF     Messages.


TYPES:          MemberDetails            TYPE TABLE OF tag  WITH NON-UNIQUE DEFAULT KEY,
                CoverageNotes            TYPE TABLE OF tag  WITH NON-UNIQUE DEFAULT KEY,
                ApprovalRequirements     TYPE TABLE OF tag  WITH NON-UNIQUE DEFAULT KEY,
                Attachments              TYPE TABLE OF file WITH NON-UNIQUE DEFAULT KEY.


TYPES:    BEGIN OF RESPONSE,
                TreatmentBasis          TYPE i,
                TreatmentClassification TYPE i,
                MemberDetails           TYPE MemberDetails,
                CoverageNotes           TYPE CoverageNotes,
                ApprovalRequirements    TYPE ApprovalRequirements,
                Attachments             TYPE Attachments,
                Messages                TYPE Messages,
                Sender                  TYPE i,
                Receiver                TYPE i,
                ReferenceID             TYPE string,
                RequestReferenceID      TYPE STRING,
                Result                  TYPE STRING,
                Reason                  TYPE STRING,
                MemberName              TYPE STRING,
                CardNumber              TYPE STRING,
                PayerName               TYPE STRING,
                CoverStartDate          TYPE STRING,
                CoverEndDate            TYPE STRING,
                MemberPhoto             TYPE STRING,
                IsVIP                   TYPE STRING,
                IsTHIQA                 TYPE STRING,
                ValidityDate            TYPE STRING,

       END OF RESPONSE.









the transformer template will be as below

<?sap.transform simple?>
<!-- tt:transform xmlns:tt="http://www.sap.com/transformation-templates" -->
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates"
xmlns:ddic="http://www.sap.com/abapxml/types/dictionary"
xmlns:def="http://www.sap.com/abapxml/types/defined">



<tt:root name="ROOT"/>
<tt:template>

<RequestResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <tt:loop name="res" ref=".ROOT">
<Response>
    <TreatmentBasis tt:value-ref = "TreatmentBasis" />

    <TreatmentClassification  tt:value-ref = "TreatmentClassification"/>

    <MemberDetails>
        <tt:loop name="md" ref="MemberDetails">
            <Tag>
                <ID tt:value-ref="$md.ID"/>
                <Label tt:value-ref="$md.Label"/>
                <Value tt:value-ref="$md.Value"/>
                <Type tt:value-ref="$md.Type"/>
            </Tag>
        </tt:loop>
    </MemberDetails>
    <CoverageNotes>
        <tt:loop name="cn" ref="CoverageNotes">
            <Tag>
                <ID tt:value-ref="$cn.ID"/>
                <Label tt:value-ref="$cn.Label"/>
                <Value tt:value-ref="$cn.Value"/>
                <Type tt:value-ref="$cn.Type"/>
            </Tag>
        </tt:loop>
    </CoverageNotes>
    <ApprovalRequirements>
        <tt:loop name="ar" ref="ApprovalRequirements">
            <Tag>
                <ID tt:value-ref="$ar.ID"/>
                <Label tt:value-ref="$ar.Label"/>
                <Value tt:value-ref="$ar.Value"/>
                <Type tt:value-ref="$ar.Type"/>
            </Tag>
        </tt:loop>
    </ApprovalRequirements>
    <Attachments>
        <tt:loop ref="Attachments" name="atts">
            <File>
            <ID tt:value-ref="$atts.ID"/>
            <Filename tt:value-ref="$atts.Filename"/>
            <DisplayedName tt:value-ref="$atts.DisplayedName"/>
            <FileContent tt:value-ref="$atts.FileContent"/>
        </File>
        </tt:loop>
    </Attachments>
    <Messages>
        <tt:loop name="msg" ref="Messages">
          <Message>
            <Category tt:value-ref="$msg.Category"/>
            <Text tt:value-ref="$msg.Text"/>
            <Severity tt:value-ref="$msg.Severity"/>
          </Message>
        </tt:loop>
    </Messages>

    <Sender tt:value-ref="Sender" />
    <Receiver tt:value-ref="Receiver" />
    <ReferenceID tt:value-ref="ReferenceID" />
    <RequestReferenceID tt:value-ref="RequestReferenceID" />
    <Result tt:value-ref="Result" />
    <Reason tt:value-ref="Reason" />
    <MemberName tt:value-ref="MemberName" />
    <CardNumber tt:value-ref="CardNumber" />
    <PayerName tt:value-ref="PayerName" />
    <CoverStartDate tt:value-ref="CoverStartDate" />
    <CoverEndDate tt:value-ref="CoverEndDate" />
    <MemberPhoto tt:value-ref="MemberPhoto" />
    <IsVIP tt:value-ref="IsVIP" />
    <IsTHIQA  tt:value-ref="IsTHIQA" />
    <ValidityDate tt:value-ref="ValidityDate" />
 </Response>
 </tt:loop>
</RequestResponse>
</tt:template>


</tt:transform>

Comments

Popular posts from this blog

Installing liferay 6.2 on wildfly 10 app server and oracle 11g database & windows machine

*************************************DATABASE CREATION*********************************************************************************************** DOWNLOAD LIFERAY PORTAL SCRIPTS FROM https://www.liferay.com/downloads/liferay-portal/available-releases Rename the file as liferay.sql put it let say in under c drive , so it will be located like this  c:\liferay.sql from cmd dir c:\ SQLPLUS / AS SYSDBA @liferay.sql lportal lportal it will create the db ..after finishing go to sqlplus again to ggrant the below  to lportal user SQLPLUS / AS SYSDBA grant create session to lportal; grant connect to lportal; grant resource to lportal; *******************************CONFIGURE WILDFLY TO CONNECT TO ORACLE DB *****************************************************************************************************  configure wildfly to connect to oracle db Download the driver: ojdbc[VERSION].jar Create subfolders [WILDFLY_HOME]/modules/system/layers/base/com/o...

itext 2.7.1 writing Arabic and English content in a PDF file

   public void createPdf(String filename) throws IOException, DocumentException {               Document document = new Document();           PdfWriter.getInstance(document, new FileOutputStream(filename));             document.open();             document.add(Chunk.NEWLINE);        FontFactory.register("c:/windows/fonts/tradbdo.ttf", "my_arabic");               Font myArabicFont = FontFactory.getFont("my_arabic" ,BaseFont.IDENTITY_H, BaseFont.EMBEDDED);         PdfPTable table = new PdfPTable(1);         table.getDefaultCell().setNoWrap(false);        // table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);         PdfPCell text = new PdfPCell(new Phrase("محمود السنباطيthis is أبتثجحخدرزسشصضطظعغفقكلمنهوى", myAr...

Liferay Migration form 5.2.3 to 6.2

Liferay Migration form 5.2.3 to 6.2 Liferay Migration from 5.2.3. to 6.2 Step 1. Migration to 6.0.6 1. Create 5.2.3 DB dump (db.sql). 2. Create database for LR 6.0.6 (db606). 3. Load 5.2.3 dump into 6.0.6 database: mysql -uroot -p1 db606 < db.sql; Delete all database views (if any). 4. Unzip clean Liferay 6.0.6. 5. Delete all folders from ' webapps ' (except ' ROOT ' and ' tunnel-web '); delete jre from tomcat folder. 6. Copy 'data' folder from Liferay 5.2.3 to Liferay 6.0.6. 7. Startup Liferay 6.0.6 (with default Hypersonic database settings). 8. Shutdown Liferay 6.0.6. 9. Create  portal-ext.properties  file: jdbc.default.driverClassName=com.mysql.jdbc.Driver jdbc.default.url=jdbc:mysql://localhost:3306/db606?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false jdbc.default.username=root jdbc.default.password=1 permissions.user.check.algorithm=5 image.hook.impl=com....