【转】
REPORT zbdc_test_by_shir.

* 定义个BDC格式的内表
**************************************************
DATA : BEGIN OF i_bdcdata OCCURS 0,
*BDC的程序名字,比如事物码MM01的程序名字为SAPLMGMM(sap标准程序)
         program LIKE bdcdata-program,
*BDC Dynpro 号码
         dynpro LIKE bdcdata-dynpro,
*BDC BDC Dynpro 開始
         dynbegin LIKE bdcdata-dynbegin,
*BDC 项目名字
         fnam LIKE bdcdata-fnam,
*BDC 项目名字的附加值
         fval LIKE bdcdata-fval,
       END OF i_bdcdata.
*BDC
DATA: t_bdcmsg LIKE bdcmsgcoll  OCCURS 0 WITH HEADER LINE.
*****此方法可以用excel,txt等文件导入
DATA: BEGIN OF itab OCCURS 0,
        maktx  LIKE makt-maktx,
        meins  LIKE mara-meins,
        matkl  LIKE mara-matkl,
      END   OF itab.

DATA: tab LIKE itab OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF t_log OCCURS 0,
         information(289) TYPE c,   "返回信息
      END OF t_log.
DATA:BEGIN OF iexcel OCCURS 0.
        INCLUDE STRUCTURE alsmex_tabline.
DATA:END OF iexcel.
FIELD-SYMBOLS: <fs>.
SELECTION-SCREEN BEGIN OF BLOCK text WITH FRAME TITLE text-001.
PARAMETERS:p_fname LIKE rlgrap-filename .
SELECTION-SCREEN END OF BLOCK text.
*itab-a = 'A0010000000'.
*APPEND itab.
*itab-a = 'A0010000001'.
*APPEND itab.
*itab-maktx = '测试BDC导入数据'.
*itab-meins = 'BAG'.
*itab-matkl = '100106'.
*
*APPEND itab.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
  PERFORM upload USING p_fname .

* START-OF-SELECTION
START-OF-SELECTION.

LOOP AT itab.
    PERFORM append_mm01 USING itab-maktx itab-meins itab-matkl.
    PERFORM run_bdc.
  ENDLOOP.

*---------------------------------------------------------------------*
*       FORM APPEND_DATA_MM01                                         *
*---------------------------------------------------------------------*
*       定义一个子程序里面,用来存放操作的各个步骤                     *
*---------------------------------------------------------------------*
FORM append_mm01 USING fval LIKE itab-maktx
                       fval1 LIKE itab-meins
                       fval2  LIKE itab-matkl.
  CLEAR i_bdcdata.
  CLEAR i_bdcdata[].
*开始新的画面事件
*0173画面
*把程序名字和 BDC DYnpro号码,开始标志 写入内表表头,
  PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
  PERFORM bdc_field  USING 'BDC_CURSOR' 'RMMG1-MATNR'.
  PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
  PERFORM bdc_field  USING 'RMMG1-MATNR' ''.
  PERFORM bdc_field  USING 'RMMG1-MBRSH' 'Z'.
  PERFORM bdc_field  USING 'RMMG1-MTART'  'Z001'.
*开始新的画面事件
  PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
  PERFORM bdc_field  USING  'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)'.
  PERFORM bdc_field  USING  'BDC_OKCODE' '=ENTR'.
  PERFORM bdc_field  USING 'MSICHTAUSW-KZSEL(01)'  'X'.
*开始新的画面事件
  PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
  PERFORM bdc_field  USING 'BDC_OKCODE' '=BU'.
  PERFORM bdc_field  USING 'BDC_CURSOR' 'MAKT-MAKTX'.
  PERFORM bdc_field  USING  'MAKT-MAKTX' itab-maktx.
  PERFORM bdc_field  USING 'MARA-MEINS'  itab-meins.
  PERFORM bdc_field  USING  'MARA-MATKkL' itab-matkl.

ENDFORM.                    "APPEND_MM01

*---------------------------------------------------------------------*
*       FORM RUN_BDC                                *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM run_bdc.
*开始调用事务MM01,把做好的bdc对象传递过去,然后把模式设置为A,
*就是说所有窗口,均可以看见.
* N 表示不看见吧
  REFRESH t_bdcmsg.
  CLEAR t_bdcmsg.

CALL TRANSACTION 'MM01' USING i_bdcdata MODE 'N' MESSAGES INTO t_bdcmsg.

READ TABLE t_bdcmsg WITH KEY msgtyp = 'S'
                               msgid = 'M3'
                               msgnr = '800'.
  IF sy-subrc EQ 0.
    CONCATENATE  '物料号:' t_bdcmsg-msgv1  '创建成功' INTO t_log.
  ELSE.
    LOOP AT t_bdcmsg.
      IF t_bdcmsg-msgtyp = 'E'
          OR t_bdcmsg-msgv1 <> ''
          OR t_bdcmsg-msgv2 <> ''
          OR t_bdcmsg-msgv3 <> ''
          OR t_bdcmsg-msgv4 <> ''.
        MESSAGE ID t_bdcmsg-msgid                   "收集错误信息,并写入自定义的表t_log中。
                        TYPE 'S'
                        NUMBER t_bdcmsg-msgnr
                        WITH t_bdcmsg-msgv1
            t_bdcmsg-msgv2
            t_bdcmsg-msgv3
            t_bdcmsg-msgv4
            INTO t_log-information.

CONCATENATE
                                t_bdcmsg-msgv1
*                               itab-posnr
                               '出错:'
                               t_log-information
          INTO t_log-information.
        APPEND t_log.
        CLEAR t_log.
      ENDIF.
    ENDLOOP.
  ENDIF.

LOOP AT t_log.                          "显示出错信息

WRITE:/ t_log-information.

ENDLOOP.

ENDFORM.                    "RUN_BDC
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0121   text
*      -->P_0122   text
*----------------------------------------------------------------------*
FORM bdc_dynpro  USING    program
                          dynpro.
  i_bdcdata-program = program.
  i_bdcdata-dynpro = dynpro.
  i_bdcdata-dynbegin = 'X'.
  APPEND i_bdcdata.
  CLEAR i_bdcdata.
ENDFORM.                    " BDC_DYNPRO
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0126   text
*      -->P_0127   text
*----------------------------------------------------------------------*
FORM bdc_field  USING  fnam fval.
  i_bdcdata-fnam = fnam .
  i_bdcdata-fval = fval.
  APPEND i_bdcdata.
  CLEAR i_bdcdata.
ENDFORM.                    " BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  UPLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload  USING p_fname.
  DATA:cc TYPE i.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      mask             = ',Excel Files,*.xls,All Files,*.*.'(101)
      title            = '选择文件'(100)
    IMPORTING
      filename         = p_fname
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 4
      OTHERS           = 5.
  IF sy-subrc <> 0 AND sy-subrc <> 3.
    MESSAGE e398(00) WITH '选择文件出错!'(007).
  ENDIF.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_fname
      i_begin_col             = 1
      i_begin_row             = 1
      i_end_col               = 100
      i_end_row               = 1000
    TABLES
      intern                  = iexcel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

IF sy-subrc <> 0.
    WRITE:/'文件读入错误!',p_fname.
  ELSE.
    cc = 1.
    LOOP AT iexcel.
      ASSIGN COMPONENT cc  OF
            STRUCTURE itab TO <fs>.

<fs> = iexcel-value(25).
      cc = cc + 1.
      AT END OF row.
        IF iexcel-row <> '0001'.
          APPEND itab.
        ENDIF.
        CLEAR itab.
        cc = 1.
      ENDAT.

ENDLOOP.
  ENDIF.
ENDFORM.                    " UPLOAD

test_bdc的更多相关文章

随机推荐

  1. 关于web后门权限防删的一个新思路

    见土司有一帖子 具体看下面连接 https://www.t00ls.net/thread-26444-1-2.html 这是php的 其实IIS也有类似的 这是MSF生成的一个ASPX执行shellc ...

  2. Linux非阻塞IO(四)非阻塞IO中connect的实现

    我们为客户端的编写再做一些工作. 这次我们使用非阻塞IO实现connect函数. int connect(int sockfd, const struct sockaddr *addr, sockle ...

  3. 杭电 HDU 2717 Catch That Cow

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  4. git统计代码行数

    查看个人指定时期内代码行数,注意将 --author="user.name" 替换成自己的用户名 git log --since="2018-07-16" -- ...

  5. Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) JAVA日志的前世今生 .NET MVC采用SignalR更新在线用户数 C#多线程编程系列(五)- 使用任务并行库 C#多线程编程系列(三)- 线程同步 C#多线程编程系列(二)- 线程基础 C#多线程编程系列(一)- 简介

    Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) 一.前言 由于本篇文章较长,所以下面给出内容目录方便跳转阅读,当然也可以用博客页面最右侧的文章目录导航栏进行跳转查阅. 一.前言 ...

  6. 无法调试存储过程,无法启动T-SQL调试

    用本机管理员或者具有SYSADMIN角色的帐号登录,不要用.,用实例名来连接

  7. Delphi 泛型(三十篇)

    Delphi 泛型(三十篇)http://www.cnblogs.com/jxgxy/category/216671.html

  8. SQLServer 2017安装时的错误:Polybase要求安装Oracle JRE 7更新51或更高版本

    2016应该也有这个问题 下载JDK7就可以了(我装10是不可以解决的) 重新运行下 安装完后再安装SSMS 附: MS SQL SERVER 2017全套下载地址(含JDK7.SSMS.KEY): ...

  9. 钩子编程(HOOK) 安装进程内键盘钩子 (1)

    摘要:钩子能够监视系统或进程中的各种事件消息.截获发往目标窗体的消息并进行处理.这样,我们就能够在系统中安装自己定义的钩子,监视系统中特定事件的发生.完毕特定的功能,比方截获键盘.鼠标的输入.屏幕取词 ...

  10. linux下apache+php搭建配置记录

    第1章  环境说明1.1 系统说明Centos 6.2 (最小化安装)1.2 软件说明httpd-2.4.2.tar.gzapr-util-1.4.1.tar.gzapr-1.4.6.tar.gzpc ...