Chinaunix首页 | 论坛 | 博客
  • 博客访问: 706286
  • 博文数量: 145
  • 博客积分: 3446
  • 博客等级: 中校
  • 技术积分: 1567
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-30 13:58
文章分类

全部博文(145)

文章存档

2021年(1)

2020年(1)

2019年(1)

2018年(6)

2017年(1)

2016年(10)

2015年(12)

2014年(10)

2013年(15)

2012年(33)

2011年(21)

2010年(9)

2009年(18)

2008年(2)

2006年(5)

我的朋友

分类:

2009-09-27 14:12:26

将订单信息从SAP中以XML格式导出上载到FTP服务器上,客户从FTP下载到本地ERP系统,读取相应的信息生成自己报表。以此实现了EDI功能,是个不错的方法。
*&---------------------------------------------------------------------*
*& Report  Z1766_TEST_XML
*&
*&---------------------------------------------------------------------*
REPORT  z1766_test_xml.
*DATA:itab_item TYPE TABLE OF z1crm_sales_item.
DATA: BEGIN OF s_head,
        order_id LIKE z1crm_sales_head-order_id,
        status_h  LIKE z1crm_sales_head-status_h,
        creat_date_h LIKE z1crm_sales_head-creat_date_h,
        creat_time_h LIKE z1crm_sales_head-creat_time_h,
        sold_to LIKE z1crm_sales_head-sold_to,
        ship_to LIKE z1crm_sales_head-ship_to,
        cont_total LIKE z1crm_sales_head-cont_total,
        zzroute LIKE z1crm_sales_head-zzroute,
        ship_cond LIKE z1crm_sales_head-ship_cond,
        pmnttrms LIKE z1crm_sales_head-pmnttrms,
       END OF s_head,
      itab_head   LIKE STANDARD TABLE OF s_head.
DATA: BEGIN OF s_item,
        itemcode LIKE z1crm_sales_item-number_int,
        pn_group  LIKE z1crm_sales_item-pn_group,
        matnr LIKE z1crm_sales_item-matnr,
        charg  LIKE z1crm_sales_item-charg,
        status_i LIKE z1crm_sales_item-status_i,
       END OF s_item,
      itab_item   LIKE STANDARD TABLE OF s_item.
DATA: BEGIN OF adminfo,
        object TYPE string,
        version TYPE string,
       END OF adminfo,
       adminfo_itab  LIKE STANDARD TABLE OF adminfo.
PARAMETERS:order_id LIKE z1crm_sales_head-order_id DEFAULT '8895100207'.
PARAMETERS: p_show AS CHECKBOX DEFAULT 'X'.
CONSTANTS:
  c_xml_root TYPE string VALUE 'BOM',
  c_xml_adminfo TYPE string VALUE 'AdmInfo',
  c_xml_documents TYPE string VALUE 'Documents',
  c_xml_document_lines TYPE string VALUE 'Document_Lines',
  c_xml_bo TYPE string VALUE 'BO'.
DATA:
  g_xml TYPE REF TO cl_xml_document.",
START-OF-SELECTION.
  REFRESH:itab_head,itab_item.
  SELECT * INTO CORRESPONDING FIELDS OF TABLE itab_head
  FROM z1crm_sales_head
    WHERE order_id = order_id.
  READ TABLE itab_head INTO s_head INDEX 1.
 
  SELECT number_int AS itemcode pn_group matnr charg status_i
  INTO CORRESPONDING FIELDS OF TABLE itab_item
   FROM z1crm_sales_item
    WHERE order_id = order_id.
  adminfo-object  = '17'.
  adminfo-version = '2'.
END-OF-SELECTION.
  DATA:
  mtd_name TYPE string,
  class_root TYPE REF TO if_ixml_node,
  class_bo TYPE REF TO if_ixml_node.
  CREATE OBJECT g_xml
    EXPORTING
      description = 'test'
      object_type = cl_xml_document=>c_bor_classtype.
*      object_name = s_head-mill.
* Simply generate sections of XML document
* First create root section
  g_xml->set_data( name       = c_xml_root
                  dataobject = '' ).
  class_root = g_xml->find_node( name   = c_xml_root ).
  g_xml->set_data( name       = c_xml_bo
                parent_node = class_root
                  dataobject = '' ).
  class_bo =  g_xml->find_node( name   = c_xml_bo ).
* All other sections will be under the root (see parent_node)
  DEFINE set_section_data.
    g_xml->set_data( name = &1
                     parent_node = class_bo
                     dataobject  = &2 ).
  END-OF-DEFINITION.
  set_section_data:
    'AdmInfo' '',
    'Object' adminfo-object ,
    'Version'  adminfo-version ,
    'Documents'  s_head    ,
    'Document_Lines' itab_item .
*  LOOP AT itab_item INTO s_item.
*    set_section_data:
*    'row' s_item.
*  ENDLOOP.
 

* Now display resulting XML-file or export it into workstation file
  mtd_name = order_id.
  IF p_show = 'X'.
    g_xml->display( ).
    EXIT.
  ENDIF.
  DATA:
    user_action TYPE i,
    path TYPE string,
    full_path TYPE string,
    file_name TYPE string.
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      default_extension    = 'xml'
      default_file_name    = mtd_name
      file_filter          = cl_gui_frontend_services=>filetype_xml
    CHANGING
      filename             = file_name
      path                 = path
      fullpath             = full_path
      user_action          = user_action
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  CHECK user_action = cl_gui_frontend_services=>action_ok.
  DATA:
    localfile TYPE localfile.
  localfile = full_path.
  g_xml->export_to_file( filename = localfile ).
 
执行结果:
  xml version="1.0" ?>
- <BOM>
- <BO>
  <AdmInfo />
  <Object>17Object>
  <Version>2Version>
- <Documents>
  <ORDER_ID>8895100207ORDER_ID>
  <STATUS_H>ASTATUS_H>
  <CREAT_DATE_H>2009-07-09CREAT_DATE_H>
  <CREAT_TIME_H>16:00:24CREAT_TIME_H>
  <SOLD_TO>0006000056SOLD_TO>
  <SHIP_TO>0006000056SHIP_TO>
  <CONT_TOTAL>1*20GP*22.00CONT_TOTAL>
  <ZZROUTE>B3US79ZZROUTE>
  <SHIP_COND>11SHIP_COND>
  <PMNTTRMS>N030PMNTTRMS>
  Documents>
- <Document_Lines>
- <item>
  <ITEMCODE>0000000010ITEMCODE>
  <PN_GROUP>GZ0300PN_GROUP>
  <MATNR>43250003MATNR>
  <CHARG>0000000003CHARG>
  <STATUS_I>A010STATUS_I>
  item>
- <item>
  <ITEMCODE>0000000020ITEMCODE>
  <PN_GROUP>GZ0300PN_GROUP>
  <MATNR>43250003MATNR>
  <CHARG>0000000003CHARG>
  <STATUS_I>A010STATUS_I>
  item>
- <item>
  <ITEMCODE>0000000030ITEMCODE>
  <PN_GROUP>GZ0300PN_GROUP>
  <MATNR>43255002MATNR>
  <CHARG>0000000093CHARG>
  <STATUS_I>A010STATUS_I>
  item>
- <item>
  <ITEMCODE>0000000040ITEMCODE>
  <PN_GROUP>GZ0300PN_GROUP>
  <MATNR>43255002MATNR>
  <CHARG>0000000093CHARG>
  <STATUS_I>A010STATUS_I>
  item>
  Document_Lines>
  BO>
  BOM>
阅读(2642) | 评论(0) | 转发(0) |
0

上一篇:SAP ABAP 实现多线程

下一篇:SAP CRM Tables 1

给主人留下些什么吧!~~