08-01-2013 12:24 PM
Hi I have to generate XML from ABAP Code, the challenge is here to add custom routs depends on the requirement let me know is there any way to achieve this.
Regards
Sas
08-20-2013 10:36 AM
Can any one please provide sample way to achieve the same, I have to achieve this soon or elsei I will be having difficult time
08-01-2013 12:46 PM
What do you mean by custom routs?
Post can be updated with a sample of desired xml and available data in program.
08-01-2013 1:04 PM
Below is the sample:
<?xml version="1.0" encoding="utf-8" ?>
- <!--
Created with Liquid XML Studio - Designer Edition 7.1.4.1284
-->
- <tns:HrImportRequest xmlns:tns="http://cmsg2.com/CMSG2Schema/HRImport/V6" xmlns:xsi="http://www.w5.org/2001/XMLSchema-instance">
- <tns:Customer Id="1486">
<tns:CustomerName>XYZ</tns:CustomerName>
</tns:Customer>
- <tns:HrImports>
- <tns:HrImport ImportId="1" ActionType="2" IndividualId="12121212">
- <tns:Individual>
<tns:LastName>Test</tns:LastName>
<tns:FirstName>Marie</tns:FirstName>
<tns:BirthDate>1950-01-01</tns:BirthDate>
<tns:MiddleName>Q</tns:MiddleName>
<tns:NameSuffix>Jr</tns:NameSuffix>
<tns:TitleCode>6</tns:TitleCode>
<tns:BillingCode>XY123</tns:BillingCode>
<tns:FirstResidentStateCode>CA</tns:FirstResidentStateCode>
- <tns:FormerEntry>
<tns:FormerEntryTypeCode>AKA</tns:FormerEntryTypeCode>
<tns:FormerEntryPurposeCode>3</tns:FormerEntryPurposeCode>
</tns:FormerEntry>
</tns:Individual>
</tns:HrImport>
- <tns:HrImport ImportId="2" ActionType="3" IndividualId="12121212">
- <tns:IndividualStatus>
<tns:StatusCode>1</tns:StatusCode>
<tns:StatusDate>1900-01-01</tns:StatusDate>
</tns:IndividualStatus>
</tns:HrImport>
- <tns:HrImport ImportId="3" ActionType="1" IndividualId="12121212">
- <tns:IndividualAddress>
<tns:AddressTypeCode>1</tns:AddressTypeCode>
<tns:AddressPurposeCode>1</tns:AddressPurposeCode>
<tns:LineOneAddress>5678 Purple Road</tns:LineOneAddress>
<tns:CityName>Los Angeles</tns:CityName>
<tns:StateCode>CA</tns:StateCode>
<tns:PostalCode>12345</tns:PostalCode>
<tns:CountryCode>224</tns:CountryCode>
<tns:FromDate>2000-01-02</tns:FromDate>
<tns:PrivateResidenceIndicator>N</tns:PrivateResidenceIndicator>
</tns:IndividualAddress>
</tns:HrImport>
- <tns:HrImport ImportId="4" ActionType="1" IndividualId="12121212">
- <tns:IndividualAddress>
<tns:AddressTypeCode>2</tns:AddressTypeCode>
<tns:AddressPurposeCode>1</tns:AddressPurposeCode>
<tns:LineOneAddress>345 Orange Street</tns:LineOneAddress>
<tns:CityName>Anaheim</tns:CityName>
<tns:StateCode>CA</tns:StateCode>
<tns:PostalCode>12345</tns:PostalCode>
<tns:CountryCode>224</tns:CountryCode>
<tns:FromDate>2000-01-02</tns:FromDate>
<tns:PrivateResidenceIndicator>Y</tns:PrivateResidenceIndicator>
</tns:IndividualAddress>
</tns:HrImport>
- <tns:HrImport ImportId="5" ActionType="1" IndividualId="12121212">
- <tns:IndividualEmailAddress>
<tns:EmailAddress>mary.q.test@email.com</tns:EmailAddress>
</tns:IndividualEmailAddress>
</tns:HrImport>
- <tns:HrImport ImportId="6" ActionType="1" IndividualId="12121212">
- <tns:IndividualPhone>
<tns:PhoneNumber>5551234567</tns:PhoneNumber>
<tns:TypeCode>1</tns:TypeCode>
</tns:IndividualPhone>
</tns:HrImport>
- <tns:HrImport ImportId="7" ActionType="1" IndividualId="12121212">
- <tns:IndividualExternalSystemID>
<tns:ExternalSystemIDTypeCode>EMPLOYEEID</tns:ExternalSystemIDTypeCode>
<tns:ExternalSystemID>98989</tns:ExternalSystemID>
<tns:StartDate>2000-01-02</tns:StartDate>
</tns:IndividualExternalSystemID>
</tns:HrImport>
- <tns:HrImport ImportId="8" ActionType="1" IndividualId="12121212">
- <tns:IndividualAdministrativeSupervisor>
<tns:AssociatedIndividualId>22859683</tns:AssociatedIndividualId>
<tns:StartDate>2000-01-02</tns:StartDate>
<tns:StatusCode>1</tns:StatusCode>
</tns:IndividualAdministrativeSupervisor>
</tns:HrImport>
</tns:HrImports>
</tns:HrImportRequest>
08-01-2013 1:34 PM
After generating xml string the usual way, all occurrences of < and </ can be replaced by <tns and </tns respectively.
Is that what you meant?
08-05-2013 7:18 AM
Yes that's also one more issue, can you please let me know how can we do that in ABAP???
08-02-2013 5:06 AM
Could you give more details?
What do you mean with "handle custom roots"?
08-05-2013 7:27 AM
********No progress can any one please through some light**********
Custom means:
this will be standard
xml version="1.0" encoding="utf-8" ?>
- <!--
Created with Liquid XML Studio - Designer Edition 7.1.4.1284
-->
- <tns:HrImportRequestxmlns:tns="http://cmsg2.com/CMSG2Schema/HRImport/V6"xmlns:xsi="http://www.w5.org/2001/XMLSchema-instance">
- <tns:Customer Id="1486">
<tns:CustomerName>XYZ</tns:CustomerName>
</tns:Customer>
- <tns:HrImports>
but action type nodes will be added more and more saying that we need to add '1' OR '2' depends on the requirement
08-05-2013 7:45 AM
Hi,
May be try designing yours in XSLT_TOOL T-code they give a repository of nodes. Check it once.
Cheers,
Arindam
08-20-2013 10:36 AM
Can any one please provide sample way to achieve the same, I have to achieve this soon or elsei I will be having difficult time
08-20-2013 5:23 PM
Refer to the following texts.
http://help.sap.com/saphelp_nw04/helpdata/en/86/8280ba12d511d5991b00508b6b8b11/frameset.htm
http://wiki.sdn.sap.com/wiki/display/ABAP/Parse+an+xml+file+and+insert+values+in+ABAP
There is no way to do this without doing some effort to read the available docs. Besides, I can barely understand what you intend to do.
Good luck.
08-21-2013 7:26 AM
ok I will try to explain what it is.... Let me know if my explanation is clear
1) I have to generate XML from ABAP ...
so as per the attached XML.
I have understood Call Transformation using XLST_TOOL will help in generating the desired XML.
Issues with achieving the same is :
1) The tags like <tns:lastname>sas</tns:Lastname>
when I am working with XLST_TOOL in the source code I am unable to place ":" this symbol in between.,
2) certain tags shouldn't display based on the requirement..if employee has SSN ssn tag should display or else CRD should display..How can we achieve customization.
ONE MORE HEADACHE using CALL TRANSFORMATION I am able to generate the display mode of the XML IN SAP how to download that??
below is the sample code: GUI_DOWNLOAD services not accepting the XSTRING Value or STRING Value...
Please find the attached code with this message.
Regards
Sass
Message was edited by: saslove sap
08-21-2013 1:28 PM
check the interface/class IF_IXML and do some searches. This is not so hard to find out, but you have to put some effort in.
e.g:
http://wiki.sdn.sap.com/wiki/display/ABAP/iXML+-+Create+XML+file
That was just one of the results when I searched scn for "create xml".
It is that easy.
08-21-2013 11:59 PM
Ok, my friend,
After a significant invest of time doing some research, reading, coding, testing, recoding, here's an approach to do (I hope so) what you are expecting based on the source code sent.
Based on the demo program SXSLTDEMO_FLIGHTS, I designed a very simple XSLT named ZPRUEBA
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/sapxsl" version = "1.0"
xmlns:tns="http://cmsg2.com/CMSG2Schema/HRImport/V6">
<xsl:output indent="yes"/>
<xsl:template match="T_PA0002">
<data>
<xsl:for-each select="*">
<tns:Customer Id="{PERNR}">
<tns:CustomerName>
<xsl:value-of select="NACHN"/>
</tns:CustomerName>
<xsl:if test="GESCH = 1">
<tns:Sex>
<xsl:value-of select="GESCH"/>
</tns:Sex>
</xsl:if>
</tns:Customer>
</xsl:for-each>
</data>
</xsl:template>
</xsl:transform>
To be able to use the prefix tns, you must declare it before in the corresponding namespace (xmlns).
As shown, using xsl is quite a programming languaje, so you can use conditional operations, for your request, use the IF statement.
So... retrieving data in a Z program.
REPORT zprueba_ovn24.
TYPES: line_t(line_length) TYPE x,
table_t TYPE STANDARD TABLE OF line_t.
CONSTANTS: line_length TYPE i VALUE 4096,
encoding TYPE string VALUE 'utf-8'.
DATA: t_pa0002 TYPE STANDARD TABLE OF pa0002.
DATA: resstream TYPE REF TO if_ixml_ostream,
ressize TYPE i VALUE 0,
restab TYPE table_t,
g_ixml TYPE REF TO if_ixml,
g_stream_factory TYPE REF TO if_ixml_stream_factory,
g_encoding TYPE REF TO if_ixml_encoding.
g_ixml = cl_ixml=>create( ).
g_stream_factory = g_ixml->create_stream_factory( ).
g_encoding = g_ixml->create_encoding( character_set = encoding
byte_order = 0 ).
SELECT * INTO TABLE t_pa0002
FROM pa0002
WHERE
endda = '99991231'.
REFRESH restab.
resstream = g_stream_factory->create_ostream_itable( table = restab ).
resstream->set_encoding( encoding = g_encoding ).
CALL TRANSFORMATION zprueba
SOURCE t_pa0002 = t_pa0002
RESULT XML resstream.
ressize = resstream->get_num_written_raw( ).
PERFORM store_file USING 'c:\temp\teste.xml' ressize restab.
*&---------------------------------------------------------------------*
*& Form store_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PATH text
* -->BIN_FILESIZE text
* -->TAB text
*----------------------------------------------------------------------*
FORM store_file
USING path TYPE localfile
bin_filesize TYPE i
tab TYPE table.
DATA: s TYPE string.
s = path.
IF bin_filesize > 0.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = bin_filesize
filename = s
filetype = 'BIN'
TABLES
data_tab = tab
EXCEPTIONS
OTHERS = 1.
ELSE.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = s
filetype = 'ASC'
TABLES
data_tab = tab
EXCEPTIONS
OTHERS = 1.
ENDIF.
ENDFORM. "store_file
The resulting xml string returned by transformation, as you notice, is a xstring. You must do first a transfer to an internal table.
The program will extract valid data from pa0002 and call transformation.
The transformation creates a xml filtering by IF operator displaying ONLY male gender records.
The final teste.xml file will be on c:\temp folder.
I'd explain some details on this approach, but considering the time spent, I'd guess that you can figure it out by reading the code and doing some research (I really hope this to happen).
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_ostream TYPE REF TO if_ixml_ostream,
l_renderer TYPE REF TO if_ixml_renderer,
l_document TYPE REF TO if_ixml_document.
DATA:
l_element_root TYPE REF TO if_ixml_element,
l_emisor TYPE REF TO if_ixml_element,
l_domfiscal TYPE REF TO if_ixml_element.
l_ixml = cl_ixml=>create( ).
l_document = l_ixml->create_document( ).
l_element_root = l_document->create_simple_element(
name = 'Comprobante'
parent = l_document ).
l_element_root->set_attribute( name = 'version' value = '2.0' ).
l_element_root->set_attribute( name = 'serie' value = 'dato' ).
l_emisor = l_document->create_simple_element( name = 'Emisor' parent = l_element_root ).
l_domfiscal = l_document->create_simple_element( name = 'DomicilioFiscal' parent = l_emisor ).
l_domfiscal->set_attribute( name = 'pais' value = 'MEXICO' ).
l_streamfactory = l_ixml->create_stream_factory( ).
l_ostream = l_streamfactory->create_ostream_itable( table = t_xml ).
Good luck
08-22-2013 7:03 AM
Thank you so much for your valuable time Oscar...I will defintely try to work around your valuable and suggestions and get back on this asap. Please stay tuned..Already spend plenty time on this but if no output thats going to be very bad for me.
just reply are we able to place " :" in the codes is my question? can you attach your output screen shot for reference pls.
Ex: <TNS:LASTNAME> SAS</TNS:LASTNAME>
I got the symbol is displaying
I am able to get the sybol but issue is :
<TNS:LASTNAE XMLNS:TNS = '"http://cmsg2.com/CMSG2Schema/HRImport/V6">SAS<TNS:LASTNAME> is getting edditions
that link is also displaying....
Regards
sas
08-22-2013 4:48 PM
Did you replicate the sample code that I've already sent to you?
the results of that code are as follows.
<data xmlns:tns="http://cmsg2.com/CMSG2Schema/HRImport/V6">
<tns:Customer Id="00000001">
<tns:CustomerName>
Rodríguez
</tns:CustomerName>
<tns:Gender>
1
</tns:Gender>
</tns:Customer>
</data>
all magic comes from xslt, there's no need to do something special in ABAP code to insert : symbol on xml tags.
check the attachment
08-29-2013 7:05 AM