2006 Dec 23 4:11 PM
Hi friends,
I m supposed to convert data in XML format in a SAP table into ABAP dat in another internal table.One of these entries is as follows-
<?xml version="1.0" ?>
<!DOCTYPE xs:schema (View Source for full doctype...)>
- <xs:schema targetNamespace="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml" finalDefault="" blockDefault="" elementFormDefault="unqualified" attributeFormDefault="unqualified">
- <xs:annotation>
- <xs:documentation>
<h1>XML Schema instance namespace</h1>
- <p>
See
<a href="http://www.w3.org/TR/xmlschema-1/">the XML Schema Recommendation</a>
for an introduction
</p>
<hr />
$Date: 2001/03/16 20:25:57 $
<br />
$Id: XMLSchema-instance.xsd,v 1.4 2001/03/16 20:25:57 ht Exp $
</xs:documentation>
</xs:annotation>
- <xs:annotation>
- <xs:documentation>
- <p>
This schema should never be used as such:
<a href="http://www.w3.org/TR/xmlschema-1/#no-xsi">the XML Schema Recommendation</a>
forbids the declaration of attributes in this namespace
</p>
</xs:documentation>
</xs:annotation>
<xs:attribute name="nil" />
<xs:attribute name="type" />
<xs:attribute name="schemaLocation" />
<xs:attribute name="noNamespaceSchemaLocation" />
</xs:schema>
I will be extreamly thankful if anybody can help.
Thank you.
2006 Dec 23 9:01 PM
Welcome to SDN...
Check this links..
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
YOu can do it through XLST. it is supported in ABAP from 4.7. you can create a XSLT, and read you XML, then CALL TRANSFORMATION to convert a XML into ABAP data structure.
reference link:
http://help.sap.com/saphelp_nw04/helpdata/en/fd/9d7348389211d596a200a0c94260a5/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/bb/576670dca511d4990b00508b6b8b11/content.htm
<i>* Reward each helpful answer.</i>
Raja T
Message was edited by:
Raja Thangamani
Welcome to SDN...
Check this links..
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
YOu can do it through XLST. it is supported in ABAP from 4.7. you can create a XSLT, and read you XML, then CALL TRANSFORMATION to convert a XML into ABAP data structure.
reference link:
http://help.sap.com/saphelp_nw04/helpdata/en/fd/9d7348389211d596a200a0c94260a5/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/bb/576670dca511d4990b00508b6b8b11/content.htm
<i>* Reward each helpful answer.</i>
Raja T
Message was edited by:
Raja Thangamani
2006 Dec 23 9:01 PM
Welcome to SDN...
Check this links..
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
YOu can do it through XLST. it is supported in ABAP from 4.7. you can create a XSLT, and read you XML, then CALL TRANSFORMATION to convert a XML into ABAP data structure.
reference link:
http://help.sap.com/saphelp_nw04/helpdata/en/fd/9d7348389211d596a200a0c94260a5/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/bb/576670dca511d4990b00508b6b8b11/content.htm
<i>* Reward each helpful answer.</i>
Raja T
Message was edited by:
Raja Thangamani
2006 Dec 23 10:43 PM
Hi Sanjay,
Conversion of XML data into ABAP data is file dependent. So the program for this is dependet on the XML file. I am sending yo one program for the particular file and is also giveing the xml file. So Try to modify this program and get the work done.
In this program you have one case endcase. Give the field names required there and you will get them back.
Try to debug the program and you can modify accordingly.
File
<?xml version="1.0" encoding="utf-8" ?>
- <SO>
<VBELN>0000000057</VBELN>
<SLSTYPE>TA</SLSTYPE>
<VKORG>1000</VKORG>
<VTWEG>10</VTWEG>
<SPART>10</SPART>
<SOLDTO>0000100000</SOLDTO>
<BILLTO>0000100000</BILLTO>
<SHIPTO>0000100000</SHIPTO>
<BSTKD>sample chg 1000</BSTKD>
<BSTDK>2006-10-26</BSTDK>
<PRSDT>2006-11-10</PRSDT>
<AUDAT>2006-11-10</AUDAT>
<KETDAT>2006-10-30</KETDAT>
<ZTERM>0001</ZTERM>
<INCO1>FOB</INCO1>
- <ITEM>
- <item>
<VBELN>0000000057</VBELN>
<POSNR>000010</POSNR>
<PRODUCT>CEMENT2</PRODUCT>
<PRODES>cement type 2</PRODES>
<ORDQTY>3.000</ORDQTY>
<WERKS>370A</WERKS>
<UNITPRC>225.00</UNITPRC>
- <TEXT>
- <item>
<VBELN>0000000057</VBELN>
<POSNR>000010</POSNR>
<SEQNO>0021</SEQNO>
<TEXTID>0001</TEXTID>
<TDLINE>ssam1</TDLINE>
</item>
- <item>
<VBELN>0000000057</VBELN>
<POSNR>000010</POSNR>
<SEQNO>0021</SEQNO>
<TEXTID>0001</TEXTID>
<TDLINE>ssam2</TDLINE>
</item>
</TEXT>
</item>
- <item>
<VBELN>0000000057</VBELN>
<POSNR>000020</POSNR>
<PRODUCT>CEMENT2</PRODUCT>
<PRODES>cement type 2</PRODES>
<ORDQTY>5.000</ORDQTY>
<WERKS>370A</WERKS>
<UNITPRC>225.00</UNITPRC>
- <TEXT>
- <item>
<VBELN>0000000057</VBELN>
<POSNR>000020</POSNR>
<SEQNO>0021</SEQNO>
<TEXTID>0001</TEXTID>
<TDLINE>Test Cement Product</TDLINE>
</item>
</TEXT>
</item>
</ITEM>
</SO>
Program
*&----
*& Report ZXML_TO_DATA
*&
&----
*&
*&
&----
REPORT ztest_xml_to_data_sp04.
Load iXML Lib.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA: g_ixml TYPE REF TO if_ixml.
DATA: streamfactory TYPE REF TO if_ixml_stream_factory.
DATA: istream TYPE REF TO if_ixml_istream.
DATA: document TYPE REF TO if_ixml_document.
DATA: parser TYPE REF TO if_ixml_parser.
DATA: lv_file_url TYPE rlgrap-filename.
You should provide the parameter for file name
lv_file_url = 'C:\urls\urls.XML'.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA: BEGIN OF ty_text,
vbeln TYPE vbeln,
posnr TYPE posnr,
seqno TYPE seqno,
textid TYPE tdid,
tdline TYPE tdline,
END OF ty_text.
DATA: BEGIN OF ty_item,
vbeln TYPE vbeln,
posnr TYPE posnr,
product TYPE matnr,
prodes TYPE arktx,
ordqty TYPE kwmeng,
werks TYPE werks_d,
unitprc TYPE netpr,
dispct1(16),
dispct2(16),
dispct3(16),
text LIKE ty_text,
END OF ty_item.
DATA: BEGIN OF ty_header,
vbeln TYPE vbeln,
slstype TYPE auart,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
soldto TYPE kunnr,
billto TYPE kunnr,
shipto TYPE kunnr,
bstkd TYPE bstkd,
bstdk(10) TYPE c,
prsdt(10) TYPE c,
audat(10) TYPE c,
ketdat(10) TYPE c,
zterm TYPE dzterm,
inco1 TYPE inco1,
item LIKE TABLE OF ty_item,
END OF ty_header.
DATA: it_header LIKE ty_header .
DATA: it_item LIKE TABLE OF ty_item WITH HEADER LINE.
DATA: it_text LIKE TABLE OF ty_text WITH HEADER LINE.
DATA: xml_table TYPE TABLE OF xml_line,
xml_table_size TYPE i,
v_flag TYPE c VALUE ' '.
The next step is creating the main factory for the iXML library:
g_ixml = cl_ixml=>create( ).
Now Create Stream Factory
streamfactory = g_ixml->create_stream_factory( ).
upload a file from the client's workstation
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = lv_file_url
filetype = 'BIN'
IMPORTING
filelength = xml_table_size
TABLES
data_tab = xml_table
EXCEPTIONS
OTHERS = 11.
wrap the table containing the file into a stream
istream = streamfactory->create_istream_itable( table = xml_table
size = xml_table_size )
.
Get the file data as Stream
*istream = streamfactory->create_istream_uri( public_id = lv_file_url
system_id = lv_file_url ).
Create XML Document instance
document = g_ixml->create_document( ).
Create parser Object
parser = g_ixml->create_parser( stream_factory = streamfactory
istream = istream
document = document ).
Parse an XML document into a DOM tree
*parser->parse( ).
Parsing Error Processing
IF parser->parse( ) NE 0.
IF parser->num_errors( ) NE 0.
DATA: parseerror TYPE REF TO if_ixml_parse_error,
str TYPE string,
i TYPE i,
count TYPE i,
index TYPE i.
count = parser->num_errors( ).
WRITE: count, ' parse errors have occured:'.
index = 0.
WHILE index < count.
parseerror = parser->get_error( index = index ).
i = parseerror->get_line( ).
WRITE: 'line: ', i.
i = parseerror->get_column( ).
WRITE: 'column: ', i.
str = parseerror->get_reason( ).
WRITE: str.
index = index + 1.
ENDWHILE.
ENDIF.
ENDIF.
Close the stream since it ?s not needed anymore
CALL METHOD istream->close( ).
CLEAR istream.
DATA : gv_node TYPE REF TO if_ixml_node.
DATA : gv_nodetext TYPE string.
DATA: gv_first_time.
gv_first_time = 'X'.
gv_node = document.
*gt_item-item_no = 1.
PERFORM get_data TABLES it_item
USING gv_node
CHANGING it_header.
CLEAR v_flag.
Last item is still not added.
APPEND it_item.
APPEND it_text.
Format Color 5.
Write: / 'Header Data'.
Format color off.
WRITE: /5 it_header-vbeln, SPACE,
it_header-slstype,SPACE,
it_header-vkorg, SPACE,
it_header-vtweg, SPACE,
it_header-spart, SPACE,
it_header-soldto, SPACE,
it_header-billto, SPACE,
it_header-shipto, SPACE,
it_header-bstkd, SPACE,
it_header-bstdk, SPACE,/,
5 it_header-prsdt, SPACE,
it_header-audat, SPACE,
it_header-ketdat, SPACE,
it_header-zterm, SPACE,
it_header-inco1.
Format Color 4.
Write: / 'Item Data'.
Format color off.
LOOP AT it_item.
WRITE: /5
it_item-posnr,
it_item-product,
it_item-prodes,
it_item-ordqty,
it_item-werks,
it_item-unitprc,
it_item-dispct1,
it_item-dispct2,
it_item-dispct3.
ENDLOOP.
Format Color 3.
Write: / 'Text Data'.
Format color off.
LOOP AT it_text.
WRITE: /5
it_text-vbeln,
it_text-posnr,
it_text-seqno,
it_text-textid,
it_text-tdline.
ENDLOOP.
----
FORM Get_data *
----
FORM get_data TABLES yt_item STRUCTURE it_item
USING value(x_node) TYPE REF TO if_ixml_node
CHANGING y_header LIKE it_header.
DATA: indent TYPE i.
DATA: ptext TYPE REF TO if_ixml_text.
DATA: string TYPE string.
DATA: temp_string(100).
CASE x_node->get_type( ).
WHEN if_ixml_node=>co_node_element.
string = x_node->get_name( ).
gv_nodetext = string.
WHEN if_ixml_node=>co_node_text.
ptext ?= x_node->query_interface( ixml_iid_text ).
IF ptext->ws_only( ) IS INITIAL.
string = x_node->get_value( ).
CASE gv_nodetext.
WHEN 'SO'.
CLEAR it_header.
WHEN 'VBELN'.
MOVE string TO it_header-vbeln.
WHEN 'SLSTYPE'.
MOVE string TO it_header-slstype.
WHEN 'VKORG'.
MOVE string TO it_header-vkorg.
WHEN 'VTWEG'.
MOVE string TO it_header-vtweg.
WHEN 'SPART'.
MOVE string TO it_header-spart.
WHEN 'SOLDTO'.
MOVE string TO it_header-soldto.
WHEN 'BILLTO'.
MOVE string TO it_header-billto.
WHEN 'SHIPTO'.
MOVE string TO it_header-shipto.
WHEN 'BSTKD'.
MOVE string TO it_header-bstkd.
WHEN 'BSTDK'.
MOVE string TO it_header-bstdk.
WHEN 'PRSDT'.
MOVE string TO it_header-prsdt.
WHEN 'AUDAT'.
MOVE string TO it_header-audat.
WHEN 'KETDAT'.
MOVE string TO it_header-ketdat.
WHEN 'ZTERM'.
MOVE string TO it_header-zterm.
WHEN 'INCO1'.
MOVE string TO it_header-inco1.
Iteam details
WHEN 'ITEM'.
MOVE string TO it_item-vbeln.
WHEN 'VBELN'.
MOVE string TO it_item-vbeln.
WHEN 'POSNR'.
MOVE string TO it_item-posnr.
WHEN 'PRODUCT'.
MOVE string TO it_item-product.
WHEN 'PRODES'.
MOVE string TO it_item-prodes.
WHEN 'ORDQTY'.
MOVE string TO it_item-ordqty.
WHEN 'WERKS'.
MOVE string TO it_item-werks.
WHEN 'UNITPRC'.
MOVE string TO it_item-unitprc.
WHEN 'DISPCT1'.
MOVE string TO it_item-dispct1.
WHEN 'DISPCT2'.
MOVE string TO it_item-dispct2.
WHEN 'DISPCT3'.
MOVE string TO it_item-dispct3.
*------Text Details
WHEN 'VBELN'.
MOVE string TO it_text-vbeln.
WHEN 'TPOSNR'.
MOVE string TO it_text-posnr.
WHEN 'SEQNO'.
MOVE string TO it_text-seqno.
WHEN 'TEXTID'.
MOVE string TO it_text-textid.
WHEN 'TDLINE'.
MOVE string TO it_text-tdline.
ENDCASE.
ENDIF.
ENDCASE.
IF gv_nodetext = 'SO'.
CLEAR it_header.
ELSEIF gv_nodetext = 'item'.
APPEND it_item.
IF gv_first_time NE 'X'.
APPEND it_item.
v_flag = 'X'.
ENDIF.
gv_first_time = ' '.
ELSEIF gv_nodetext = 'TEXT'.
IF gv_first_time NE 'X' AND v_flag = 'X'.
APPEND it_text.
ENDIF.
gv_first_time = ' '.
ENDIF.
Get the next child
x_node = x_node->get_first_child( ).
Recurse
WHILE NOT x_node IS INITIAL.
PERFORM get_data TABLES it_item
USING x_node
CHANGING it_header.
x_node = x_node->get_next( ).
ENDWHILE.
ENDFORM. "get_data
Its easy - so don't worry, Good luck.
Smiles from miles,
Regards,
Amandeep kumar
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |