首页 > 代码库 > CALL TRANSFORMATION 的方法生成XML文件

CALL TRANSFORMATION 的方法生成XML文件

*&---------------------------------------------------------------------*
*& Report  Z_BARRY_XML_CALL
*&
*&---------------------------------------------------------------------*
*& CALL TRANSFORMATION的方法生成XML例程
*& 适用ECC5以上系统
*& 普通方法生成XML:http://blog.chinaunix.net/u1/40527/showart_468389.html
*&---------------------------------------------------------------------*

REPORT  z_barry_xml_call.

DATA:  BEGIN OF it_xml OCCURS 0,
         line(100) TYPE c,
       END OF it_xml.
DATA: w_xml TYPE string,
      w_len TYPE i,
      w_fname TYPE string.

DATA: BEGIN OF line  ,
        matnr LIKE mara-matnr ,
        maktx LIKE makt-maktx ,
      END OF line .
DATA: BEGIN OF line2 ,
        class LIKE m_wwgha-class,"部门
        kschl LIKE m_wwgha-kschl,"DESC
      END OF line2 .
DATA: itab_matnr LIKE TABLE OF line ,
      itab_class LIKE TABLE OF line2 .

START-OF-SELECTION.
  PERFORM getdata.
  PERFORM create_xml.

*---------------------------------------------------------------------*
*       FORM getdata                                                  *
*---------------------------------------------------------------------*
FORM getdata.
  SELECT matnr maktx FROM makt
  INTO TABLE itab_matnr
  UP TO 4 ROWS
  WHERE spras = ‘1‘ .
  SELECT class kschl FROM m_wwgha
  INTO TABLE itab_class
  UP TO 4 ROWS
  WHERE spras IN (‘1‘,‘E‘) .
ENDFORM.                    "getdata

*&---------------------------------------------------------------------*
*&      Form  create_xml
*&---------------------------------------------------------------------*
FORM create_xml.
  CALL TRANSFORMATION ztest2
    SOURCE prd = itab_matnr
           class = itab_class
    RESULT XML w_xml.

  CALL FUNCTION ‘SCMS_STRING_TO_FTEXT‘
    EXPORTING
      text      = w_xml
    IMPORTING
      length    = w_len
    TABLES
      ftext_tab = it_xml.

  CALL FUNCTION ‘GUI_DOWNLOAD‘
    EXPORTING
      filename   = ‘c:\xmlcall.xml‘
      filetype   = ‘BIN‘
    IMPORTING
      filelength = w_len
    TABLES
      data_tab   = it_xml.
ENDFORM.                    "create_xml

*Tcode:STRANS,Simple类型

*<?sap.transform simple?>
*<tt:transform xmlns:tt="
http://www.sap.com/transformation-templates">
*  <tt:root name="PRD"/>
*  <tt:root name="CLASS"/>
*  <tt:template>
*    <ROOT>
*      <Products>
*        <tt:loop name="line" ref="PRD">
*          <Product>
*            <matnr>
*              <tt:value ref="$line.matnr"/>
*            </matnr>
*            <maktx>
*              <tt:value ref="$line.maktx"/>
*            </maktx>
*          </Product>
*        </tt:loop>
*      </Products>
*      <Categories>
*        <tt:loop name="line2" ref="CLASS">
*          <Categorie>
*            <CLASS>
*              <tt:value ref="$line2.class"/>
*            </CLASS>
*            <KSCHL>
*              <tt:value ref="$line2.kschl"/>
*            </KSCHL>
*          </Categorie>
*        </tt:loop>
*      </Categories>
*    </ROOT>
*  </tt:template>
*</tt:transform>