Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

XML to SAP table

Former Member
0 Likes
423

Hi,

I would like to upload the informations contained in an XML to a SAP table. My XML is contained string variable.

The SAP table is the following:

TYPES: BEGIN OF outtab1 ,

annullato(1) ,

aoo(8),

dataRegistrazione(24) ,

nomeFileAllegato(50),

numProt(12) ,

oggetto(1024),

progSerie(3),

tipoSerie(15) ,

END OF outtab1 .

DATA: outtab TYPE TABLE OF outtab1,

while the XML is:

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<getInfoProtoResponse xmlns="http://ws.service.test.net/WS_SAP/services/ProtoService">

<ns1:getInfoProtoReturn xmlns:ns1="http://ws.service.it">

<ns1:annullato>0</ns1:annullato>

<ns1:aoo>01-01-00</ns1:aoo>

<ns1:dataRegistrazione>2007-12-03T16:47:09.000Z</ns1:dataRegistrazione>

<ns1:nomeFileAllegato>Determinazione Ammissibilita</ns1:nomeFileAllegato>

<ns1:numProt>0000528-2007</ns1:numProt>

<ns1:oggetto>sd</ns1:oggetto>

<ns1:progSerie>119</ns1:progSerie>

<ns1:tipoSerie>DETERMINA</ns1:tipoSerie>

</ns1:getInfoProtoReturn>

<ns2:getInfoProtoReturn xmlns:ns2="ws.service.it">

<ns2:annullato>0</ns2:annullato>

<ns2:aoo>01-01-00</ns2:aoo>

<ns2:dataRegistrazione>2007-12-03T16:47:09.000Z</ns2:dataRegistrazione>

<ns2:nomeFileAllegato>Allegato A.pdf</ns2:nomeFileAllegato>

<ns2:numProt>0000528-2007</ns2:numProt>

<ns2:oggetto>sd</ns2:oggetto>

<ns2:progSerie>119</ns2:progSerie>

<ns2:tipoSerie>DETERMINA</ns2:tipoSerie>

</ns2:getInfoProtoReturn>

</getInfoProtoResponse>

</soapenv:Body>

</soapenv:Envelope>

How can I insert these XML informations into my SAP table?

Can you help me?

Thanks.

Pacn

Hi,

I would like to upload the informations contained in an XML to a SAP table. My XML is contained string variable.

The SAP table is the following:

TYPES: BEGIN OF outtab1 ,

annullato(1) ,

aoo(8),

dataRegistrazione(24) ,

nomeFileAllegato(50),

numProt(12) ,

oggetto(1024),

progSerie(3),

tipoSerie(15) ,

END OF outtab1 .

DATA: outtab TYPE TABLE OF outtab1,

while the XML is:

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body>

<getInfoProtoResponse xmlns="http://ws.service.test.net/WS_SAP/services/ProtoService">

<ns1:getInfoProtoReturn xmlns:ns1="http://ws.service.it">

<ns1:annullato>0</ns1:annullato>

<ns1:aoo>01-01-00</ns1:aoo>

<ns1:dataRegistrazione>2007-12-03T16:47:09.000Z</ns1:dataRegistrazione>

<ns1:nomeFileAllegato>Determinazione Ammissibilita</ns1:nomeFileAllegato>

<ns1:numProt>0000528-2007</ns1:numProt>

<ns1:oggetto>sd</ns1:oggetto>

<ns1:progSerie>119</ns1:progSerie>

<ns1:tipoSerie>DETERMINA</ns1:tipoSerie>

</ns1:getInfoProtoReturn>

<ns2:getInfoProtoReturn xmlns:ns2="ws.service.it">

<ns2:annullato>0</ns2:annullato>

<ns2:aoo>01-01-00</ns2:aoo>

<ns2:dataRegistrazione>2007-12-03T16:47:09.000Z</ns2:dataRegistrazione>

<ns2:nomeFileAllegato>Allegato A.pdf</ns2:nomeFileAllegato>

<ns2:numProt>0000528-2007</ns2:numProt>

<ns2:oggetto>sd</ns2:oggetto>

<ns2:progSerie>119</ns2:progSerie>

<ns2:tipoSerie>DETERMINA</ns2:tipoSerie>

</ns2:getInfoProtoReturn>

</getInfoProtoResponse>

</soapenv:Body>

</soapenv:Envelope>

How can I insert these XML informations into my SAP table?

Can you help me?

Thanks.

Pacn

2 REPLIES 2
Read only

Former Member
0 Likes
387

Use this statement.

CALL TRANSFORMATION {trans|(name)} 
                    [PARAMETERS {p1 = e1 p2 = e2 ...}|(ptab)] 
                    [OBJECTS    {o1 = e1 o2 = e2 ...}|(otab)] 
                    [OPTIONS    a1 = e1 a2 = e2 ...] 
                    SOURCE {XML sxml} 
                         | {{bn1 = e1 bn2 = e2 ...}|(stab)} 
                    RESULT {XML rxml} 
                         | {{bn1 = f1 bn2 = f2 ...}|(rtab)}.

Look at the following thread for more examples.

Amandeep

Read only

0 Likes
387

Hi Amandeep,

thank you very much for your suggestions! I've applied the transformation schema but it doesn't work.

All my code is:

REPORT ZULH_MM_RP_XMLtest001.

types: begin of outtab1 ,

annullato(1) ,

aoo(10),

dataRegistrazione(50) ,

nomeFileAllegato(50),

numProt(16) ,

oggetto(1024),

progSerie(5),

tipoSerie(50) ,

end of outtab1 .

data: OUTTAB type table of outtab1,

intab type table of outtab1,

outline type outtab1.

*-- variables for xslt parsing error

data : xslt_err type ref to cx_xslt_exception ,

ai_system type ref to cx_ai_system_fault.

data: wf_string type string .

data: wf_string1 type string.

replace all occurrences of

'<' in wf_string1 with '<' .

replace all occurrences of

'>' in wf_string1 with '>' .

replace all occurrences of

'xmlns=' in wf_string1 with 'xmlns:xsl=' .

concatenate

'<?xml version="1.0" encoding="utf-8"?>'

'<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'

'<soapenv:Body><getInfoProtoResponse xmlns="http://ws.sibar.regione.sardegna.net/WS_SAP/services/ProtoService">'

'<getInfoProtoReturn xmlns:ns1="http://ws.a_pecora.it">'

'<ns1:annullato>0</ns1:annullato>'

'<ns1:aoo>01-01-00</ns1:aoo>'

'<ns1:dataRegistrazione>2007-12-03T16:47:09.000Z</ns1:dataRegistrazione>'

'<ns1:nomeFileAllegato>Determinazione Ammissibilita</ns1:nomeFileAllegato>'

'<ns1:numProt>0000528-2007</ns1:numProt>'

'<ns1:oggetto>sd</ns1:oggetto>'

'<ns1:progSerie>119</ns1:progSerie>'

'<ns1:tipoSerie>DETERMINA</ns1:tipoSerie>'

'</ns1:getInfoProtoReturn>'

'<getInfoProtoReturn xmlns:ns2="http://ws.a_pecora.it">'

'<ns2:annullato>1</ns2:annullato>'

'<ns2:aoo>01-01-00</ns2:aoo>'

'<ns2:dataRegistrazione>2007-12-03T16:47:09.000Z</ns2:dataRegistrazione>'

'<ns2:nomeFileAllegato>Determinazione Ammissibilita</ns2:nomeFileAllegato>'

'<ns2:numProt>0000528-2007</ns2:numProt>'

'<ns2:oggetto>sd</ns2:oggetto>'

'<ns2:progSerie>119</ns2:progSerie>'

'<ns2:tipoSerie>DETERMINA</ns2:tipoSerie>'

'</ns2:getInfoProtoReturn>'

'</getInfoProtoResponse>'

'</soapenv:Body>'

'</soapenv:Envelope>'

into wf_string1.

replace all occurrences of

'<' in wf_string1 with '<' .

replace all occurrences of

'>' in wf_string1 with '>' .

*

replace all occurrences of

'xmlns=' in wf_string1 with 'xmlns:xsl=' .

try .

call transformation (`Z1TABELLAXML`)

source xml wf_string1

result OUTTAB = OUTTAB.

catch cx_xslt_exception into xslt_err.

The trasformation schema is:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:strip-space elements="*"/>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="getInfoProtoResponse">

<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">

<asx:values>

<OUTTAB>

<xsl:for-each select="getInfoProtoReturn">

<OUTTAB1>

<ANNULLATO>

<xsl:value-of select="annullato"/>

</ANNULLATO>

<AOO>

<xsl:value-of select="aoo"/>

</AOO>

<DATAREGISTRAZIONE>

<xsl:value-of select="dataRegistrazione"/>

</DATAREGISTRAZIONE>

<NOMEFILEALLEGATO>

<xsl:value-of select="nomeFileAllegato"/>

</NOMEFILEALLEGATO>

<NUMPROT>

<xsl:value-of select="numProt"/>

</NUMPROT>

<OGGETTO>

<xsl:value-of select="oggetto"/>

</OGGETTO>

<PROGSERIE>

<xsl:value-of select="progSerie"/>

</PROGSERIE>

<TIPOSERIE>

<xsl:value-of select="tipoSerie"/>

</TIPOSERIE>

</OUTTAB1>

</xsl:for-each>

</OUTTAB>

</asx:values>

</asx:abap>

</xsl:template>

</xsl:stylesheet>

Can you help me to find where are my errors?

Thanks in advance.

Pacn