CALL TRANSFORMATION的方法生成XML例程

    技术2022-05-14  1

    注:以下内容为转载,ECC6.0之上版本要注意字段的大小写对应关系。

    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>


    最新回复(0)