关闭

将excel的数据上传到sap系统上,更新到数据库表中

546人阅读 评论(0) 收藏 举报
分类:
*&---------------------------------------------------------------------*
*& Report  Z_INPUT_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_input_test.

DATA:
  it_tab TYPE STANDARD TABLE OF zinfo WITH HEADER LINE,
  it_zin TYPE STANDARD TABLE OF zinfo WITH HEADER LINE,
  it_exc TYPE alsmex_tabline OCCURS WITH HEADER LINE.             "excel中的数据需要先放在参照alsmex_tabline结构体的内表中row col value
FIELD-SYMBOLS: <fs>.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: in_file LIKE rlgrap-filename OBLIGATORY.                      "Local file for upload/download
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR in_file.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      mask             ',Excel Files,*.xls*.'
      mode             'O'
      title            '选择文件'
    IMPORTING
      filename         = in_file
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 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.

START-OF-SELECTION.
  PERFORM excel_upload.
  PERFORM input_data.
*&---------------------------------------------------------------------*
*&      Form  EXCEL_UPLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM excel_upload .
  DATA: l_col TYPE i,
        l_ans(1) type c.
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = in_file
      i_begin_col             = '1'
      i_begin_row             = '2'
      i_end_col               = '50'
      i_end_row               = '5000'
    TABLES
      intern                  = it_exc
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 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.
  ELSE.
    IF it_exc[] IS INITIAL.
      CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
        EXPORTING
*         DEFAULTOPTION        = 'Y'
          diagnosetext1        = 'No data in excel'
*         DIAGNOSETEXT2        = ' '
*         DIAGNOSETEXT3        = ' '
          textline1            = 'Please check data in excel'
*         TEXTLINE2            = ' '
          titel                = 'Confirm'
*         START_COLUMN         = 25
*         START_ROW            = 6
*         CANCEL_DISPLAY       = 'X'
        IMPORTING
          ANSWER               = l_ans
                .
    ELSE.
      SORT it_exc BY row col value.
      LOOP AT it_exc.
        MOVE it_exc-col TO l_col.
        l_col = l_col + 1.
        ASSIGN COMPONENT l_col OF STRUCTURE it_tab TO <fs>.
        MOVE it_exc-value TO <fs>.
        AT END OF row.
          APPEND it_tab.
          CLEAR it_tab.
        ENDAT.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.                    " EXCEL_UPLOAD
*&---------------------------------------------------------------------*
*&      Form  INPUT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form INPUT_DATA .
  select *
    into table it_zin
    from zinfo.
  LOOP AT it_tab.
    LOOP AT it_zin.
      IF it_tab-company = it_zin-company
         and it_tab-customer = it_zin-customer
         and it_tab-valid = it_zin-valid.
        it_tab-discount = it_tab-discount + it_zin-discount.
      ENDIF.
    ENDLOOP.
    modify zinfo from it_tab.
  ENDLOOP.
endform.                    " INPUT_DATA
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16473次
    • 积分:383
    • 等级:
    • 排名:千里之外
    • 原创:20篇
    • 转载:11篇
    • 译文:0篇
    • 评论:0条