SAP xml 的解析

*&---------------------------------------------------------------------*
*& Report  ZEXPOT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZEXPOT.

TYPE-POOLSIXML,ABAP.

typesbegin of XML_LINE,
        DATA(256type X,
       end of XML_LINE.

DATAL_XML_TABLE       TYPE TABLE OF XML_LINE,
      L_XML_SIZE        TYPE I,
      L_RC              TYPE I.

DATA XMLDATA TYPE XSTRING .
DATARESULT_XML TYPE STANDARD TABLE OF SMUM_XMLTB .
DATARETURN TYPE STANDARD TABLE OF BAPIRET2 .
DATAWA_XML TYPE SMUM_XMLTB.

*如果需要上載XML可以用一下方法
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME   'C:\sou.xml'
    FILETYPE   'BIN'
  IMPORTING
    FILELENGTH L_XML_SIZE
  TABLES
    DATA_TAB   L_XML_TABLE.

*--將XML數據導入到內表
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    INPUT_LENGTH L_XML_SIZE
  IMPORTING
    BUFFER       XMLDATA
  TABLES
    BINARY_TAB   L_XML_TABLE
  EXCEPTIONS
    FAILED       1
    OTHERS       2.

CALL FUNCTION 'SMUM_XML_PARSE'
  EXPORTING
    XML_INPUT XMLDATA
  TABLES
    XML_TABLE RESULT_XML
    RETURN    RETURN.

LOOP AT RESULT_XML INTO WA_XML .

ENDLOOP.

============================

對應的XML文件,內表中的數據和XML文件要請仔細作比對

才知道需要取什麼數據

============================

<?xml version="1.0"?>
<flights>


 <airline code="AA" name="American Airlines">
  <flight number="0017">
   <from airport="JFK">NEW YORK,US</from>
   <to airport="SFO">SAN FRANCISCO,US</to>
   <departure>110000</departure>
   <arrival>140100</arrival>
   <type>Scheduled</type>
  </flight>

  <flight number="0064">
   <from airport="SFO">SAN FRANCISCO,US</from>
   <to airport="JFK">NEW YORK,US</to>
   <departure>090000</departure>
   <arrival>172100</arrival>
   <type>Scheduled</type>
  </flight>
 </airline>



 <airline code="AZ" name="Alitalia">
  <flight number="0555">
   <from airport="FCO">ROME,IT</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>190000</departure>
   <arrival>210500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0788">
   <from airport="FCO">ROME,IT</from>
   <to airport="TYO">TOKYO,JP</to>
   <departure>120000</departure>
   <arrival>085500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0789">
   <from airport="TYO">TOKYO,JP</from>
   <to airport="FCO">ROME,IT</to>
   <departure>114500</departure>
   <arrival>192500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0790">
   <from airport="FCO">ROME,IT</from>
   <to airport="KIX">OSAKA,JP</to>
   <departure>103500</departure>
   <arrival>081000</arrival>
   <type>Charter</type>
  </flight>
 </airline>



 <airline code="DL" name="Delta Airlines">
  <flight number="1984">
   <from airport="SFO">SAN FRANCISCO,US</from>
   <to airport="JFK">NEW YORK,US</to>
   <departure>100000</departure>
   <arrival>182500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="1699">
   <from airport="JFK">NEW YORK,US</from>
   <to airport="SFO">SAN FRANCISCO,US</to>
   <departure>171500</departure>
   <arrival>203700</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0106">
   <from airport="JFK">NEW YORK,US</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>193500</departure>
   <arrival>093000</arrival>
   <type>Scheduled</type>
  </flight>
 </airline>


 <airline code="JL" name="Japan Airlines">
  <flight number="0407">
   <from airport="NRT">TOKYO,JP</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>133000</departure>
   <arrival>173500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0408">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="NRT">TOKYO,JP</to>
   <departure>202500</departure>
   <arrival>154000</arrival>
   <type>Charter</type>
  </flight>
 </airline>


 <airline code="LH" name="Lufthansa">
  <flight number="2407">
   <from airport="TXL">BERLIN,DE</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>071000</departure>
   <arrival>081500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="2402">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="SXF">BERLIN,DE</to>
   <departure>103000</departure>
   <arrival>113500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0402">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="JFK">NEW YORK,US</to>
   <departure>133000</departure>
   <arrival>150500</arrival>
   <type>Charter</type>
  </flight>
  <flight number="0401">
   <from airport="JFK">NEW YORK,US</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>183000</departure>
   <arrival>074500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0400">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="JFK">NEW YORK,US</to>
   <departure>101000</departure>
   <arrival>113400</arrival>
   <type>Scheduled</type>
  </flight>
 </airline>



 <airline code="QF" name="Qantas Airways">
  <flight number="0005">
   <from airport="SIN">SINGAPORE,SG</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>225000</departure>
   <arrival>053500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0006">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="SIN">SINGAPORE,SG</to>
   <departure>205500</departure>
   <arrival>150500</arrival>
   <type>Scheduled</type>
  </flight>
 </airline>



 <airline code="SQ" name="Singapore Airlines">
  <flight number="0988">
   <from airport="SIN">SINGAPORE,SG</from>
   <to airport="TYO">TOKYO,JP</to>
   <departure>163500</departure>
   <arrival>001500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0158">
   <from airport="SIN">SINGAPORE,SG</from>
   <to airport="JKT">JAKARTA,ID</to>
   <departure>152500</departure>
   <arrival>160000</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0015">
   <from airport="SFO">SAN FRANCISCO,US</from>
   <to airport="SIN">SINGAPORE,SG</to>
   <departure>160000</departure>
   <arrival>024500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="0002">
   <from airport="SIN">SINGAPORE,SG</from>
   <to airport="SFO">SAN FRANCISCO,US</to>
   <departure>170000</departure>
   <arrival>192500</arrival>
   <type>Scheduled</type>
  </flight>
 </airline>



 <airline code="UA" name="United Airlines">
  <flight number="0941">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="SFO">SAN FRANCISCO,US</to>
   <departure>143000</departure>
   <arrival>170600</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="3504">
   <from airport="SFO">SAN FRANCISCO,US</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>150000</departure>
   <arrival>103000</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="3516">
   <from airport="JFK">NEW YORK,US</from>
   <to airport="FRA">FRANKFURT,DE</to>
   <departure>162000</departure>
   <arrival>054500</arrival>
   <type>Scheduled</type>
  </flight>
  <flight number="3517">
   <from airport="FRA">FRANKFURT,DE</from>
   <to airport="JFK">NEW YORK,US</to>
   <departure>104000</departure>
   <arrival>125500</arrival>
   <type>Scheduled</type>
  </flight>
 </airline>
</flights>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章