[ABAP]开发常用组件

﹥>﹥吖頭↗ 提交于 2019-12-03 13:33:48

文件对话框选择文件

DATA:
          L_RC       TYPE I,
          L_FILETABLE  TYPE FILETABLE.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
    EXPORTING
      WINDOW_TITLE      = '选择文件'
      DEFAULT_EXTENSION = 'xls'
      FILE_FILTER       = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
      MULTISELECTION    = ''
    CHANGING
      FILE_TABLE        = L_FILETABLE
      RC                = L_RC.
  IF SY-SUBRC = 0 AND L_RC = 1.
    READ TABLE L_FILETABLE INTO P_FILE INDEX 1."读取一个文件
  ENDIF.

进度 和 将excel数据传输到内表

DATA:   IT_RAW   TYPE TRUXS_T_TEXT_DATA.
  CLEAR   IT_RAW.
  REFRESH IT_RAW[].
  REFRESH IT_EXCEL.


  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' "进度条
     EXPORTING
       PERCENTAGE = 0
       TEXT       = '正在上载Excel文件并检查数据,请等待......'.


  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR    =
      I_LINE_HEADER        = 'X'    "X表示带抬头行的EXCEL的抬头行不传进内表,否则EXCEL不要带抬头
      I_TAB_RAW_DATA       = IT_RAW " WORK TABLE
      I_FILENAME           = P_FILE
    TABLES
      I_TAB_CONVERTED_DATA = IT_EXCEL "EXCEL表格内容上传到IT
    EXCEPTIONS
      CONVERSION_FAILED    = 1 "转化失败1
      OTHERS               = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

重画alv

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
      IS_LAYOUT                = LAYOUT
      IT_FIELDCAT              = FIELDCAT[]
    TABLES
      T_OUTTAB                 = IT_OUT
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

确认对话框

CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          TEXT_QUESTION         = LV_QUESTION
          DISPLAY_CANCEL_BUTTON = ''
          DEFAULT_BUTTON        = '2'
        IMPORTING
          ANSWER                = LV_ANSWER
        EXCEPTIONS
          TEXT_NOT_FOUND        = 1
          OTHERS                = 2.
      CHECK LV_ANSWER = 1.
      PERFORM PROCESS_DATA."处理数据
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!