本文介绍: ABAP IDOC 2 XML

有个需求,外围系统希望我们给到一个IDOC 记录的样例,但是我们we02中并无法看到

就找了一个demo去直接展示IDOC内容
 

*&---------------------------------------------------------------------*
*& Report Z_IDOC_TO_XML
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_idoc_to_xml.

*Global tables
DATA: gt_dyfields LIKE dynpread OCCURS 0 WITH HEADER LINE,   "screen fields
      gt_data_tab TYPE TABLE OF string WITH HEADER LINE.     "download data tab

*Global variables
DATA: gv_filename TYPE string VALUE 'idoc',                  "file name
      gv_path     TYPE string,                               "file path
      gv_result   TYPE i,
      gv_xml_str  TYPE string.                                "XML string

DATA: idoc TYPE REF TO cl_idoc_xml1.                         "iDoc class instance

*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
PARAMETERS: p_docnum LIKE edidc-docnum OBLIGATORY.            "iDoc number
SELECTION-SCREEN END OF BLOCK b2.

START-OF-SELECTION.
* Create Object and create IDOC_XML
  CREATE OBJECT idoc
    EXPORTING
      docnum             = p_docnum
    EXCEPTIONS
      error_loading_idoc = 1
      error_building_xml = 2
      OTHERS             = 3.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
               RAISING no_idoc_xml_loaded.
  ENDIF.

* Transformation
  CALL METHOD idoc->get_xmldata_as_string
    IMPORTING
      data_string = gv_xml_str.

*append xml string to data tab
  APPEND gv_xml_str TO gt_data_tab.

  CALL METHOD cl_abap_browser=>show_xml
    EXPORTING
      xml_string = gv_xml_str.

效果如下

原文地址:https://blog.csdn.net/IamRunjiang/article/details/135651687

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_59496.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注