为类创建事务码,读取EXCEL并显示报表简单版

news2024/11/22 17:30:31

屏幕以及字段定义

DATA: go_container TYPE REF TO cl_gui_custom_container.
DATA: lv_subrc   TYPE i,
      gv_action  TYPE int4,
      lt_filetab TYPE filetable,
      ls_filetab TYPE file_table.

DATA: gv_exit  TYPE flag .
DATA: lt_input              TYPE TABLE OF alsmex_tabline,
      lt_matnr              TYPE zqm_t_aut_check, "需要显示的结构
      lt_output             TYPE zqm_t_aut_check,"需要显示的结构
      ls_matnr              TYPE zqm_aut_check,"需要显示的结构
      lv_filename           TYPE char256,
      lt_ranges             TYPE soi_range_list,
      ls_ranges             TYPE soi_range_item,
      lt_soi                TYPE soi_generic_table,
      ls_soi                LIKE LINE OF lt_soi,
      lv_return             TYPE soi_ret_string,
      lv_runid              TYPE int4 VALUE 1,
      lv_vorname(30)        TYPE c,
      lv_nachname(30)       TYPE c,
      lv_counter            TYPE i,
      lv_cnt                TYPE i,
      gv_file_param_columns TYPE i VALUE 9,
      gv_file_param_rows    TYPE i VALUE 1746,
      gt_fcat1              TYPE lvc_t_fcat,
      gs_fcat               TYPE lvc_s_fcat,
      gs_layout             TYPE lvc_s_layo.
DATA:
  go_error       TYPE REF TO i_oi_error,
  go_control     TYPE REF TO i_oi_container_control,
  go_document    TYPE REF TO i_oi_document_proxy,
  go_spreadsheet TYPE REF TO i_oi_spreadsheet.

**Selection screen with file name input--------------------------屏幕输入----------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-t02.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-t01.
PARAMETERS:
  iv_vkorg TYPE  vkorg,
  iv_vtweg TYPE  vtweg,
  iv_spart TYPE  spart,
  iv_auart TYPE  auart,
  iv_kunnr TYPE  kunnr,
  iv_werks TYPE  werks_d.

SELECTION-SCREEN END OF BLOCK b2.
*----------------------------------------------------------------------*
*                  INITIALIZATION                                       *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM init.

*----------------------------------------------------------------------*
*                  *Open file selection
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM file_open .

*Upload process after selection
START-OF-SELECTION.
 PERFORM upload_excel_file.
 PERFORM get_data.

 IF lt_OUTPUT IS NOT INITIAL.
  PERFORM show_alv.
 ELSE.
    MESSAGE text-t03 TYPE 'S' DISPLAY LIKE 'E'..
*   LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0.
 ENDIF.

END-OF-SELECTION.*----------------------------------------------------------------------*
*                  INITIALIZATION                                       *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM init.

*----------------------------------------------------------------------*
*                  *Open file selection
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM file_open .

*Upload process after selection
START-OF-SELECTION.
 PERFORM upload_excel_file.
 PERFORM get_data.

 IF lt_OUTPUT IS NOT INITIAL.
  PERFORM show_alv.
 ELSE.
    MESSAGE text-t03 TYPE 'S' DISPLAY LIKE 'E'..
*   LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0.
 ENDIF.

END-OF-SELECTION.

PERFORM init.

FORM init .
  CLASS c_oi_errors DEFINITION LOAD.

* Create Instance control for container
  c_oi_container_control_creator=>get_container_control(
    IMPORTING
      control = go_control    " Container-Control
      error   = go_error      " Fehler-Objekt
  ).

  IF go_error->has_failed IS NOT INITIAL.
    go_error->raise_message(
      EXPORTING
        type           = 'E'    " Message-Typ ('A','E','W','I','S')
      EXCEPTIONS
        message_raised = 1
        flush_failed   = 2
        OTHERS         = 3
    ).
    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.

* Create generic container linked to container in screen 100
  CREATE OBJECT go_container
    EXPORTING
      container_name              = 'CONTAINER'
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      OTHERS                      = 6.
  IF sy-subrc <> 0.
    "Error
  ENDIF.

* Establish connection to GUI Control
  go_control->init_control(
    EXPORTING
      r3_application_name = 'Excel Document Container'
      inplace_enabled     = 'X'
      parent              = go_container
    IMPORTING
      error               = go_error
  ).
  IF go_error->has_failed IS NOT INITIAL.
    go_error->raise_message(
      EXPORTING
        type           = 'E'    " Message-Typ ('A','E','W','I','S')
      EXCEPTIONS
        message_raised = 1
        flush_failed   = 2
        OTHERS         = 3
    ).
    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.

* Create Document Proxy
  go_control->get_document_proxy(
    EXPORTING
      document_type  = soi_doctype_excel_sheet
    IMPORTING
      document_proxy = go_document
      error          = go_error
  ).
  IF go_error->has_failed IS NOT INITIAL.
    go_error->raise_message(
      EXPORTING
        type           = 'E'    " Message-Typ ('A','E','W','I','S')
      EXCEPTIONS
        message_raised = 1
        flush_failed   = 2
        OTHERS         = 3
    ).
    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.
ENDFORM.

PERFORM file_open .

* &1 - Windows title
* &2 - Filename chosen

  cl_gui_frontend_services=>file_open_dialog(
    EXPORTING
      window_title      = 'UploadData'
*     default_filename  = 'C:\test.txt'
      initial_directory = 'C:\'
      file_filter       = 'Excel(*.XLS,*.XLSX)|*.XLS;*.XLSX' "'Excel(*.XLS)|*.XLS'
    CHANGING
      file_table        = lt_filetab
      rc                = lv_subrc
      user_action       = gv_action
     EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5
      ).

  IF lv_subrc IS INITIAL.
    FORMAT COLOR COL_BACKGROUND INTENSIFIED.
    WRITE:/ 'Nothing uploaded.'.
    EXIT.
  ENDIF.

  READ TABLE lt_filetab INTO ls_filetab INDEX 1.
  CHECK sy-subrc EQ 0.

  p_file = ls_filetab-filename.

PERFORM upload_excel_file.

FORM upload_excel_file .
  IF p_file IS INITIAL.
    gv_exit = 'X'.
    RETURN.
  ENDIF.
  CONCATENATE 'FILE://' p_file INTO lv_filename.
  CALL METHOD go_document->open_document(
    EXPORTING
*     open_inplace   = 'X'
      document_title = 'Excel'
      document_url   = lv_filename
      no_flush       = ''
    IMPORTING
      error          = go_error
  ).
  IF go_error->has_failed IS NOT INITIAL.
    go_error->raise_message(
      EXPORTING
        type = 'E'
    ).
  ENDIF.
  go_document->get_spreadsheet_interface(
      EXPORTING no_flush        = ''
      IMPORTING sheet_interface = go_spreadsheet
                error           = go_error
 ).
  go_spreadsheet->set_selection(
    EXPORTING
      left     = '1'
      top      = '2'
      rows     = gv_file_param_rows
      columns  = gv_file_param_columns
*      no_flush = ' '
    IMPORTING
      error    = go_error

  ).
  IF go_error->has_failed IS NOT INITIAL.
    go_error->raise_message(
      EXPORTING
        type = 'E'
    ).
  ENDIF.
  go_spreadsheet->insert_range(
      EXPORTING name      = 'Test'
                rows      = gv_file_param_rows
                columns   = gv_file_param_columns
                no_flush  = ''
      IMPORTING error     = go_error
    ).

  ls_ranges-name    = 'Test'.
  ls_ranges-rows    = gv_file_param_rows.
  ls_ranges-columns = gv_file_param_columns.
  APPEND ls_ranges TO lt_ranges.

  go_spreadsheet->get_ranges_data(
    IMPORTING
      contents  = lt_soi      "Contents of the tables
      error     = go_error    "errors
      retcode   = lv_return   "text of the error
    CHANGING
      ranges    = lt_ranges   "Specified ranges
  ).
  IF go_error->has_failed IS NOT INITIAL.
    go_error->raise_message(
      EXPORTING
        type = 'E'
    ).
  ENDIF.

  IF lv_return <> 'OK'.
    RETURN.
  ENDIF.
  CALL METHOD go_document->close_document.
  CALL METHOD go_document->release_document.


  CLEAR: ls_matnr,lv_cnt,lv_counter.
  lv_cnt = 1.
  lv_counter = 1.
  LOOP AT lt_soi INTO ls_soi.
    IF ls_soi-row = lv_cnt AND ls_soi-column = lv_counter.
      IF lv_counter = 1.
        ls_matnr-matnr = ls_soi-value.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            input  = ls_matnr-matnr
          IMPORTING
            output = ls_matnr-matnr.

        lv_counter = 3.
      ELSEIF lv_counter = 3.
        ls_matnr-req_qty = ls_soi-value.
        APPEND ls_matnr TO lt_matnr.
        lv_counter = 1.
        lv_cnt = lv_cnt + 1.
      ENDIF.
      IF ls_matnr-matnr IS INITIAL.
        EXIT.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.

PERFORM get_data.

*----------------------------------------------------------------------*
FORM get_data .
  DATA: lo_qm TYPE REF TO zcl_qm_returnable_verifier.

  TRY.
      CREATE OBJECT lo_qm
        EXPORTING
          it_materials = lt_matnr
          iv_vkorg     = iv_vkorg
          iv_vtweg     = iv_vtweg
          iv_spart     = iv_spart
          iv_auart     = iv_auart
          iv_kunnr     = iv_kunnr
          iv_werks     = iv_werks.
  ENDTRY.

  lo_qm->start_process(
  IMPORTING
    et_materials = lt_output
  ).

ENDFORM.

PERFORM show_alv.

FORM show_alv .
  PERFORM build_fieldcat.
  PERFORM build_layout.
* PERFORM build_events.

  PERFORM build_alv.
ENDFORM.

PERFORM build_fieldcat.

FORM build_fieldcat .
  DEFINE %%append_fieldcat .

    CLEAR gs_fcat .
    gs_fcat-col_pos  = &3."LINE
    gs_fcat-fieldname = &1."DISPLAY FIELD
*    gs_fcat-outputlen = &2." outputlen
    gs_fcat-scrtext_m = &2. "middle key word
*    gs_fcat-key       = &4."SET KEY
APPEND  gs_fcat  TO  gt_fcat1.
  END-OF-DEFINITION.
  %%append_fieldcat:
     'MATNR' 'Material Number' '1',
    'REQ_QTY' 'Quantity' '2',
    'SALES_UNIT' 'Sales Unit' '3',
    'MTART' 'Material Type' '4',
    ..............................
ENDFORM.

PERFORM build_layout.

FORM build_layout .
  gs_layout-cwidth_opt = 'X'.
  gs_layout-zebra = 'X'.
*  gs_layout2-sel_mode = 'A'.
*  gs_layout-box_fname = 'SEL'.
*  gs_layout2-detail_initial_lines = 'X'.
*  gs_layout2-window_titlebar =
*  gs_layout2-confirmation_prompt = 'X'.
  gs_layout-stylefname = 'field_style'.
*   gs_layout2-edit = 'X'.
ENDFORM.

PERFORM build_alv.

FORM build_alv .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'FRM_SET_STATUS'
      i_callback_user_command  = 'FRM_USER_COMMAND'
*     I_GRID_SETTINGS          =
      is_layout_lvc            = gs_layout
*     IT_FIELDCAT_LVC          = gt_fieldcat1
      it_fieldcat_lvc          = gt_fcat1[]
*     it_excluding             = lt_extab
      i_save                   = 'A'
*     IS_VARIANT               =
*     IT_EVENTS                = gt_events
*     IT_EVENT_EXIT            =
    TABLES
      t_outtab                 = lt_output
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.
FORM frm_set_status USING pt_extab TYPE slis_t_extab.
  SET PF-STATUS 'Z_STATUS'.

ENDFORM.

FORM frm_user_command USING r_ucomm LIKE sy-ucomm
      rs_selfield TYPE slis_selfield.

  DATA: gv_grid TYPE REF TO cl_gui_alv_grid.
  DATA: lt_lines TYPE int4.
 " GET BUTTON
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = gv_grid.
  CALL METHOD gv_grid->check_changed_data.
  "REFRSH
  rs_selfield-refresh = 'X'.

ENDFORM. "ALV_USER_COMMAND

在这里插入图片描述
复制标准GUI

2.1.1 输入事物代码SE41;
2.1.2 输入标准的SAPLKKBL程序;

在这里插入图片描述
然后从用户接口->复制->状态进入,填写目标程序复制
在这里插入图片描述
或者从这里进入复制
在这里插入图片描述

最后激活。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/466568.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

人脸识别概述

博主简介 博主是一名大二学生&#xff0c;主攻人工智能研究。感谢让我们在CSDN相遇&#xff0c;博主致力于在这里分享关于人工智能&#xff0c;c&#xff0c;Python&#xff0c;爬虫等方面知识的分享。 如果有需要的小伙伴可以关注博主&#xff0c;博主会继续更新的&#xff0c…

封装 (encapsulation)--计算机程序术语

封装&#xff0c;即隐藏对象的属性和实现细节&#xff0c;仅对外公开接口&#xff0c;控制在程序中属性的读和修改的 访问级别&#xff1b;将抽象得到的数据和行为(或功能)相结合&#xff0c;形成一个有机的整体&#xff0c;也就是将数据与操作数据的 源代码进行有机的结合&…

以轻量级服务器niginx为核心的JavaWeb项目:第一章 项目设计

这里写目录标题 一 需求分析与环境搭建1.需求分析2.环境搭建1.2.1首先配置mysql环境1.2.2 配置maven环境 二 打成War包&#xff0c;发到linux上 一 需求分析与环境搭建 1.需求分析 2.环境搭建 1.2.1首先配置mysql环境 先查找一下mysql环境 [roothadoop122 ~]# mysql --vers…

SpringCloudAlibaba分布式事务——Seata

Seata 本专栏学习内容来自尚硅谷周阳老师的视频 有兴趣的小伙伴可以点击视频地址观看 分布式事务问题 在使用分布式之前&#xff0c;一般都是单机单库或者是单机多库的情况&#xff0c;一个服务对应一个数据库或者多个数据库&#xff0c;这样事务的问题可以通过Transaction解决…

Python学习:Anaconda23.3.1+spyder5.4.3+Python3.10.11环境配置

问题1&#xff1a;Anaconda安装配置教程&#xff08;真的非常详细的安装过程&#xff0c;还带环境配置&#xff09; 【参考文献】本文链接&#xff1a;Windows安装Anaconda使用教程_在奋斗的大道的博客-CSDN博客 问题2&#xff1a;Anaconda半天打不开&#xff0c;就在这转啊转…

MYSQL(六)函数

函数是指一段可以直接被另一端程序调用的代码 字符串函数 update employees set workn lpad(workno,5, 0); 数值函数 根据数据库的函数&#xff0c;生成一个六位数的随机验证码 select rpad(round(rand()*1000000, 0), 6, 0); 日期函数 流程函数

尚融宝24-标的管理

目录 一、需求介绍 &#xff08;一&#xff09;借款人申请借款 &#xff08;二&#xff09;流程 二、生成新标的 三、标的列表 &#xff08;一&#xff09;后端 &#xff08;二&#xff09;前端 四、标的详情 &#xff08;一&#xff09;后端 &#xff08;二&#xf…

FPGA动态配置si5338输出差分时钟,提供工程源码和技术支持

目录 1、前言2、设计框图3、si5338原理图设计4、si5338使用流程5、vivado工程详解6、上板调试验证并演示7、福利&#xff1a;工程代码的获取 1、前言 如今的FPGA板卡随着FPGA本身性能的提高也越来越高端&#xff0c;特别是在高速接口方面表现得越发明显&#xff0c;以Xilinx的…

Redis(10)哨兵

redis哨兵 哨兵配置步骤步骤一 启动redis节点步骤二 配置哨兵节点第三步 设置主从复制第四步 查看状态第五步 验证哨兵配置是否成功第六步 测试 哨兵配置步骤 本文将介绍redis哨兵的配置步骤。Redis哨兵是一种用于监控Redis主从复制和自动故障转移的系统 Redis哨兵是Redis的核…

“探索C++非质变算法:如何更高效地处理数据“

&#x1f4d6;作者介绍&#xff1a;22级树莓人&#xff08;计算机专业&#xff09;&#xff0c;热爱编程&#xff1c;目前在c&#xff0b;&#xff0b;阶段>——目标Windows&#xff0c;MySQL&#xff0c;Qt&#xff0c;数据结构与算法&#xff0c;Linux&#xff0c;多线程&…

无线电设备发射型号核准证(SRRC)

SRRC认证简介 SRRC为国家无线电管理委员会State Radio Regulatory Commission of the People’s Republic of China SRMC认证(又称SRRC认证)自1999年6月1日起&#xff0c;中国信息产业部(Ministry of Information Industry,MII)强制规定&#xff0c;所有在中国境内销售及使用的…

【c语言】static静态变量

创作不易&#xff0c;本篇文章如果帮助到了你&#xff0c;还请点赞支持一下♡>&#x16966;<)!! 主页专栏有更多知识&#xff0c;如有疑问欢迎大家指正讨论&#xff0c;共同进步&#xff01; 给大家跳段街舞感谢支持&#xff01;ጿ ኈ ቼ ዽ ጿ ኈ ቼ ዽ ጿ ኈ ቼ ዽ ጿ…

C++【二叉搜索树】

文章目录 一、二叉搜索树&#xff08;1&#xff09;概念&#xff08;2&#xff09;操作&#xff08;3&#xff09;应用 二、BST模拟实现及函数解析&#xff08;1&#xff09;构建BST结点结构体&#xff08;2&#xff09;BST默认构造及拷贝构造&#xff08;3&#xff09;BST赋值…

2023亚马逊云科技行业峰会,汇聚行业专家分享行业数字化创新之道

从实验室扩展到真实世界&#xff0c;从前沿技术探索到医疗生命科学行业的快速创新实践&#xff0c;亚马逊云科技不断地通过数字化助力医疗和生命科学的行业创新。由上海徐汇区科委指导&#xff0c;上海枫林集团作为支持单位&#xff0c;亚马逊云科技主办的2023亚马逊云科技医疗…

yum仓库及NFS共享服务

部署yum仓库及NFS共享服务 一、yum仓库服务yum概述源种类&#xff1a; 二、安装源安装ftp源安装在线源本地源和在线源同时使用将软件包变成Yum源 三、NFS共享存储服务NFS架构NFS原理 四、NFS实操 一、yum仓库服务 yum概述 基于RPM包构建的软件更新机制可以自动解决依赖关系所…

LVS负载均衡群集部署—NAT

目录 一、群集的概述1、群集的含义2、出现高并发的解决方法3、群集的三种分类3.1负载均衡群集3.2高可用群集3.3高性能运算群集 4、负载均衡的结构 三、LVS调度器用的调度方法四、LVS的工作模式及其工作过程1.NAT模式&#xff08;VS-NAT&#xff09;2.直接路由模式&#xff08;V…

冲实习 or 全力准备秋招?

作者&#xff1a;阿秀 校招八股文学习网站&#xff1a;https://interviewguide.cn 这是阿秀的第「261」篇原创 小伙伴们大家好&#xff0c;我是阿秀。 欢迎今年参加秋招的小伙伴加入阿秀的学习圈&#xff0c;目前已经超过 2300 小伙伴加入&#xff01;去年认真准备和走下来的基…

ADKEY多按键制作阻值选择

参考链接 (10条消息) 【物尽其用】ADKEY多按键制作与经验分享_SimpleJY的博客-CSDN博客https://blog.csdn.net/qq_31247231/article/details/81013459其中的阻值选择经过仿真电路 仿真结果如下表 按键序号ad值键值差0409337113722907228151813263458742047975195028261668657…

数字硬件建模SystemVerilog-通信总线建模 --Interface方法

来到了SV最后一部分&#xff0c;预计三篇文章&#xff0c;两周更完&#xff0c;所有的思维导图如下&#xff1a; 概述 SystemVerilog Interface是modport的一种&#xff0c;但比简单的输入、输出或输入输出端口的功能更多。在其最简单的形式中&#xff0c;Interface端口将相关的…

第5章 数据结构之“链表”

链表简介 1.多个元素组成的列表。 2.元素的存储不连续&#xff0c;用next指针连在一起。 数组 vs 列表 数组&#xff1a;增删非手尾元素时往往需要移动元素。如果要在数组中增加一个元素&#xff0c;数组后面的所有元素需要往后面移动一位。如果在数组中删除一个元素&#x…