【ABAP系列】SAP ABAP DOI展示EXCEL或WORD

公众号:SAP Technical

本文作者:matinal

原文出处:http://www.cnblogs.com/SAPmatinal/

原文链接:【ABAP系列】SAP ABAP DOI展示EXCEL或WORD

前言部分

大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。

正文部分

DOI技术算是比较老的技术了

用来直接调用office展示结果

可以是EXCEL也可以是WORD

?
data: begin of s_fal.
        include structure faglflext.
data: end of s_fal.
data: i_fal like table of s_fal.
data: ok_code like sy-ucomm.
type-pools: soi,sbdst,abap.
class c_oi_errors definition load.

data control type ref to i_oi_container_control.
data retcode  type  soi_ret_string.

data: container type ref to cl_gui_custom_container.

data: document type ref to i_oi_document_proxy.
data: error        type ref to        i_oi_error.
data: errors type ref to i_oi_error occurs 0.

data spreadsheet type ref to i_oi_spreadsheet.
data sheetname(20) type c.
select * from faglflext into corresponding fields of table i_fal where rbukrs = ‘9900‘ and ryear = ‘2008‘ and racct = ‘0020110101‘.

call screen 100.
*&---------------------------------------------------------------------*
*&      Module  status_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status ‘100‘.

  call method c_oi_container_control_creator=>get_container_control
    importing
      control = control
      retcode = retcode.

  create object container
    exporting
      container_name = ‘DOI_PARENT‘."100屏幕上的控件名.

  call method control->init_control
    exporting
      r3_application_name = ‘Demo Document Container‘
      inplace_enabled     = ‘X‘
      parent              = container
    importing
      retcode             = retcode.

  call method control->get_document_proxy
    exporting
      document_type   = ‘Excel.Sheet.8‘
      document_format = ‘OLE‘
    importing
      document_proxy  = document
      retcode         = retcode.

  call method document->create_document
    exporting
      create_view_data = ‘X‘
      open_inplace     = ‘X‘
    importing
      retcode          = retcode.
  call method document->get_spreadsheet_interface
    exporting
      no_flush        = ‘ ‘
    importing
      sheet_interface = spreadsheet
      error           = error.
  call method spreadsheet->get_active_sheet
    exporting
      no_flush  = ‘‘
    importing
      sheetname = sheetname
      error     = error
      retcode   = retcode.
  call method spreadsheet->add_sheet
    exporting
      name     = ‘年度报表‘
      no_flush = ‘‘
    importing
      error    = error
      retcode  = retcode.
  call method spreadsheet->delete_sheet
    exporting
      name     = sheetname
      no_flush = ‘‘
    importing
      error    = error
      retcode  = retcode.
  call method spreadsheet->select_sheet
    exporting
      name     = ‘年度报表‘
      no_flush = ‘‘
    importing
      error    = error
      retcode  = retcode.

  data: rows like sy-tabix.
  data: field_count type i.
  data: rangeitem type soi_range_item.
  data: ranges type soi_range_list.
  data: excel_input type soi_generic_table.
  data: excel_input_wa type soi_generic_item.
  field-symbols: <field> type any,
                 <wa> type any.
  field_count = 1.
  do.
    assign component field_count of structure s_fal to <field>."assign成功subrc = 0.
    if sy-subrc <> 0.
      exit.
    endif.
    add 1 to field_count.
  enddo.
  field_count = field_count - 1.
  describe table i_fal lines rows.
  call method spreadsheet->insert_range_dim
    exporting
      name     = ‘CELL‘
      no_flush = ‘X‘
      top      = 1
      left     = 1
      rows     = rows
      columns  = field_count
    importing
      error    = error.

  clear rangeitem.
  refresh ranges.
  rangeitem-name = ‘CELL‘.
  rangeitem-columns = field_count.
  rangeitem-rows = rows.
  append rangeitem to ranges.
  call method spreadsheet->set_font
    exporting
      rangename = ‘CELL‘
      family    = ‘Times New Roman‘
      size      = 9
      bold      = 0
      italic    = 0
      align     = 0
    importing
      error     = error
      retcode   = retcode.
  call method spreadsheet->set_format
    exporting
      rangename = ‘CELL‘
      typ       = 0
      currency  = ‘RMB‘
    importing
      error     = error
      retcode   = retcode.

  refresh excel_input.

  data: field_value type string.
  loop at i_fal assigning <wa>.
    rows = sy-tabix.
    field_count = 1.
    do.
      assign component field_count of structure <wa> to <field>."assign成功subrc = 0.
      if sy-subrc <> 0.
        exit.
      endif.
      clear excel_input_wa.
      excel_input_wa-column = field_count.
      excel_input_wa-row = rows.
      field_value = <field>.
      excel_input_wa-value = field_value.
      append excel_input_wa to excel_input.
      add 1 to field_count.
    enddo.
  endloop.
* set data
  call method spreadsheet->set_ranges_data
    exporting
      ranges   = ranges
      contents = excel_input
      no_flush = ‘X‘
    importing
      error    = error.
*get desktop directory
  data: desktop_directory type string.
  call method cl_gui_frontend_services=>get_sapgui_workdir
    changing
      sapworkdir            = desktop_directory
    exceptions
      get_sapworkdir_failed = 1
      cntl_error            = 2
      error_no_gui          = 3
      not_supported_by_gui  = 4
      others                = 5.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  if desktop_directory is initial.
    desktop_directory = ‘C:‘.
  endif.
  concatenate desktop_directory ‘\‘ ‘年度报表.xls‘ into desktop_directory.

  data: result type abap_bool.
  call method cl_gui_frontend_services=>file_exist
    exporting
      file                 = desktop_directory
    receiving
      result               = result
    exceptions
      cntl_error           = 1
      error_no_gui         = 2
      wrong_parameter      = 3
      not_supported_by_gui = 4
      others               = 5.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
  data: rc type i.
  if result = ‘X‘.
    call method cl_gui_frontend_services=>file_delete
      exporting
        filename             = desktop_directory
      changing
        rc                   = rc
      exceptions
        file_delete_failed   = 1
        cntl_error           = 2
        error_no_gui         = 3
        file_not_found       = 4
        access_denied        = 5
        unknown_error        = 6
        not_supported_by_gui = 7
        wrong_parameter      = 8
        others               = 9.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endif.
  data:file_name(250) type c.
  file_name = desktop_directory.
  call method document->save_as
    exporting
      file_name   = file_name
      prompt_user = ‘‘
    importing
      error       = error
      retcode     = retcode.
*放到FTP
*.............................
*.............................
*在这里写放到FTP上的语句.
endmodule.                 " status_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  user_command_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.
  case ok_code.
    when ‘EXIT‘ or ‘BACK‘.
      leave to screen 0.
  endcase.
endmodule.                 " user_command_0100  INPUT

?

原文地址:https://www.cnblogs.com/SAPmatinal/p/11183210.html

时间: 2024-08-27 08:17:46

【ABAP系列】SAP ABAP DOI展示EXCEL或WORD的相关文章

【ABAP系列】SAP Web Dynpro 技术简介

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP Web Dynpro 技术简介 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 AP webdynpro是为SAP NetWeaver战略UI编程模型. 它是用于创建平台并独立于语言,基于WEB的用户界面. Web Dynpro可用于SAP NetWeaver Application Serv

【ABAP系列】SAP ABAP 如何控制Dialog中的键盘(回车)功能

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 如何控制Dialog中的键盘(回车)功能 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 MODULE USER_COMMAND_2100 INPUT. CLEAR SAVE_OK. SAVE_OK = OK_CODE. CLEAR OK_CODE. CASE SAVE_OK. WH

【ABAP系列】SAP 的逻辑数据库解析

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 的逻辑数据库解析 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 T-CODE:SE36 逻辑数据库好像是HR模块用的比较多 如果谁有HR350,可以分享一下,非常感谢 当数据量很大,而且很耗时间的时候 用逻辑数据库,可以提高数据读取速度 理解上应该是把数据集放到一块 不用我们平时写OPENS

【ABAP系列】SAP ABAP 工单增强

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 工单增强 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 工单增强:工单——工序——外部BADI:MRO_CONTRACT    实现功能:外部中填入的物料组和维护的物料组是否一致,不一致则报错BADI:WORKORDER_UPDATE  工单的很多判断都在这个里面来实现工单——组件

【ABAP系列】SAP ABAP 物料凭证增强

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 物料凭证增强 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 BADI:MB_DOCUMENT_BADI USER-EXIT:MBCF0002 实现功能1.当参照预留过帐时,检查填入数量是否小于预留数量 2.移动类型是***的时候,查看RSNUM是否为空 3.检查原始单据工厂和库存地

【ABAP系列】SAP ABAP MIR7预制凭证BAPI

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP MIR7预制凭证BAPI 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 做预制凭证有两个BAPI: BAPI_INCOMINGINVOICE_PARK 和 BAPI_INCOMINGINVOICE_CREATE 连个的区别是:第一个只做发票预制,第二个是发票和过账一块做. 下面简单

【ABAP系列】SAP ABAP 开发中的SMARTFORMS 参数

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 开发中的SMARTFORMS 参数 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 &symbol& (括号中,小写字母为变量)&symbol&  屏蔽从第一位开始的N位&symbol (n)&   只显示前N位&symbol (S)&a

【ABAP系列】SAP ABAP smartforms设备类型CNSAPWIN不支持页格式ZXXX

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP smartforms设备类型CNSAPWIN不支持页格式ZXXX 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 昨天有人问我: 马蹄叔在吗,不忙的话帮我看个问题(惊恐表情,什么时候成叔了..我还这么年轻,二十多岁而已) 打印的时候显示:没有输出请求打开.输出不可能. 直接运行SMA

【ABAP系列】SAP ABAP MRKO增强

公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP MRKO增强 前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适. 正文部分 MRKO其实是个报表程序 这个报表程序存在着很多问题 很多时候满足不了使用 1:做增强 2:拷贝重写 我现在暂时做了增强 1:出口RMVKON00 2:隐士增强 出口增强借鉴了网上的例子 寄售记录表:rkwa , "Con