Skip to end of metadata
Go to start of metadata

Author: Steffen Fröhlich
Submitted: 24.05.2007
Related Links:

Report to read out the whole sample XML file provided by Airplus.

REPORT  ZFI_AIRPLUS.

TYPE-POOLS: abap, ixml.

TYPES: BEGIN OF t_xml_line,
        	data(256) TYPE x,
           END OF t_xml_line.

*Typdefinition für Airplus
*READ THE DOCUMENTATION "LASG_XML_INVOICE_BTM"!!!
*VARs beginning with "a_*" are ATTRIBUTES
  TYPES: BEGIN OF t_inv_number,
          number(30),
          extension(3),
          sequence(1),
         END OF t_inv_number.

      TYPES: BEGIN OF t_inv_part_address,
              addressline(50),
              post_code(6),
              city(12),
              state_code(6),
              country_code(6),
              country(12),
             END OF t_inv_part_address.

    TYPES: BEGIN OF t_inv_part_payee,
            partycode(10),
            address TYPE t_inv_part_address,
           END OF t_inv_part_payee.

    TYPES: BEGIN OF t_inv_part_invoicee,
            billing_level(50),
            partycode(10),
            address TYPE t_inv_part_address,
           END OF t_inv_part_invoicee.

  TYPES: BEGIN OF t_inv_parties,
          payee    TYPE t_inv_part_payee,
          invoicee TYPE t_inv_part_invoicee,
         END OF t_inv_parties.

TYPES: BEGIN OF t_ap_head,
        a_language(5),
        a_direct_debit_qual(3),
        inv_date(8),
        inv_number TYPE t_inv_number,
        credit_debit_qualifier(1),
        credit_debit_label(10),
        billing_currency(3),
        base_currency(3),
        due_date(8),
        inv_parties TYPE t_inv_parties,
        inv_qualifier(4),
       END OF t_ap_head.

*---------------------------------------->

TYPES: BEGIN OF t_det_customer,
        cardnumber(50),
        name(50),
       END OF t_det_customer.
TYPES: BEGIN OF t_det_serv_prov,
        code(15),
        companyname(50),
        street(50),
        place(50),
        tax_code(50),
       END OF t_det_serv_prov.
TYPES: BEGIN OF t_det_cust_dat,
        personal_id(50),
        dep_code(30),
        cost_center(30),
        acc_unit(30),
        acc_number(30),
        file_date(8),
        proj_number(30),
        order_number(30),
        action_code(15),
        destination(30),
        txn_ref(15),
        cust_ref(30),
        dom_tag(5),
       END OF t_det_cust_dat.

      TYPES: BEGIN OF t_det_values_sum,
              a_rate(5),
              vat_value(15),
              net_value(15),
             END OF t_det_values_sum.
    TYPES: BEGIN OF t_det_values,
            a_sale_to_base_rate,
            currency(3),
            net_value(15),
            vat_value(15),
            gross_value(15),
            add_ins_val(15),
            line_gross_val(15),
            vat_sum TYPE t_det_values_sum,
           END OF t_det_values.


  TYPES: BEGIN OF t_desc_sal_prov,
          agency(30),
          branch(15),
         END OF t_desc_sal_prov.
  TYPES: BEGIN OF t_desc_db_travel,
          start_stat(50),
          dest_stat(50),
          db_class(15),
          adults(2),
          children(2),
         END OF t_desc_db_travel.
  TYPES: BEGIN OF t_desc_ht_book,
          start_date(8),
          end_date(8),
          amount(2),
         END OF t_desc_ht_book.
  TYPES: BEGIN OF t_desc_serv_desc,
          date(8),
          doc_number(30),
          voucher_number(30),
          cc_code(15),
          class(10),
          txn_type_detail(3),
          etix_qual(1),
          flight_tax(15),
          a_add_info_line(5),
          add_info(50),
          db_travel_data TYPE t_desc_db_travel,
          ht_book_data   TYPE t_desc_ht_book,
         END OF t_desc_serv_desc.


  TYPES: BEGIN OF t_det_det_desc_line,
          sales_prov TYPE t_desc_sal_prov,
          sale_val   TYPE t_det_values,
          bill_val   TYPE t_det_values,
          serv_desc  TYPE t_desc_serv_desc,
         END OF t_det_det_desc_line.


  TYPES: BEGIN OF t_det_det_desc,
          detail_desc TYPE t_det_det_desc_line,
         END OF t_det_det_desc.

TYPES: BEGIN OF t_ap_detail,
        a_line(5),
        a_typ(30),
        customer     TYPE t_det_customer,
        service_prov TYPE t_det_serv_prov,
        customer_dat TYPE t_det_cust_dat,
        sales_date(8),
        proce_date(8),
        onl_ord_ref(50),
        sale_values  TYPE t_det_values,
        bill_values  TYPE t_det_values,
        det_descrip  TYPE t_det_det_desc,
       END OF t_ap_detail.

TYPES: BEGIN OF t_ap_details,
        inv_detail TYPE t_ap_detail,
       END OF t_ap_details.

*-------------------------------------------------->

  TYPES: BEGIN OF t_sum_vat_sum,
          a_rate(5),
          net_value(15),
          vat_value(15),
         END OF t_sum_vat_sum.
TYPES: BEGIN OF t_sum_total_sale,
        a_currency(3),
        net_total(15),
        vat_total(15),
        vat_sum TYPE t_sum_vat_sum,
       END OF t_sum_total_sale.
TYPES: BEGIN OF t_sum_total_bill,
        net_total(15),
        vat_total(15),
        vat_sum TYPE t_sum_vat_sum,
        add_ins_val(15),
        total_bill_amount(15),
       END OF t_sum_total_bill.



TYPES: BEGIN OF t_ap_summary,
        a_num_inv_det(5),
        total_sale_values TYPE t_sum_total_sale,
        total_bill_values TYPE t_sum_total_bill,
       END OF t_ap_summary.
*-------------------------------------------------->
TYPES: BEGIN OF t_ap,
        head    TYPE t_ap_head,
        details TYPE t_ap_details,
        summary TYPE t_ap_summary,
       END OF t_ap.

DATA: l_ixml            TYPE REF TO if_ixml,
      l_streamfactory   TYPE REF TO if_ixml_stream_factory,
      l_parser          TYPE REF TO if_ixml_parser,
      l_istream         TYPE REF TO if_ixml_istream,
      l_document        TYPE REF TO if_ixml_document,
      l_node            TYPE REF TO if_ixml_node,
      l_xmldata         TYPE string.

DATA: l_xml_table       TYPE TABLE OF t_xml_line,
         l_xml_line        TYPE t_xml_line,
         l_xml_table_size  TYPE i.
DATA: l_filename        TYPE string.

DATA: l_xml_x1   TYPE xstring.

*airplus tables
DATA: it_airplus    TYPE STANDARD TABLE OF t_ap,
      wa_airplus    TYPE t_ap
      .

*Errorvariables
DATA: xslt_err   TYPE REF TO cx_xslt_exception,
      err_string TYPE string
      .

PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:\HOTEL_TEST.XML'.

START-OF-SELECTION.

*   Creating the main iXML factory
    l_ixml = cl_ixml=>create( ).

*   Creating a stream factory
    l_streamfactory = l_ixml->create_stream_factory( ).

    PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.

*   wrap the table containing the file into a stream
    l_istream = l_streamfactory->create_istream_itable( table = l_xml_table
                                                    size  = l_xml_table_size ).

*   Creating a document
    l_document = l_ixml->create_document( ).

*   Create a Parser
    l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
                                      istream        = l_istream
                                      document       = l_document ).

*   Validate a document
    IF pa_val EQ 'X'.
      l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
    ENDIF.

*   Process the document
    IF l_parser->is_dom_generating( ) EQ 'X'.


* here we use the CALL TRANSFORMATION method which calls
* the XSLT program "ZFI_AIRPLUS_XSLT"
TRY.
    CALL TRANSFORMATION ZFI_AIRPLUS_XSLT
      SOURCE xml l_xml_x1
      RESULT xml_output = it_airplus
      .
* catch any error, very helpful if the XSLT isn't correct
    CATCH cx_xslt_exception INTO xslt_err.

    err_string = xslt_err->get_text( ).
    WRITE: / 'Transformation error: ', err_string.
    EXIT.
  ENDTRY.* setting a breakpoint to watch the workarea
* by the internal table "it_airplus"
  	break-point.

  LOOP AT it_airplus INTO wa_airplus.
  ENDLOOP.

1 Comment

  1. Unknown User (vjfhy0b)

    I  was trying out these sample programs, and noticed that there is a missing subroutine.

    The routine GET_XML_TABLE is not included in the source.

     Any chance of getting this routine added?