2020.02.24 [ABAP] Essay - EXCEL common operating notes 1

EXCEL common operating notes 1

1. Excel template download

TCODE:SMW0

Creating excel template (template can also be other)

We chose the binary data

Select Create a template in which the package inside

 

Click to create:

Note: If the following error occurs (no object assigned to c: MINE type \ a)

 You need to do the following: Save.

 

 

 

 So that you can successfully created.

 

In the report the program code:

TABLES:sscrfields.
SCREEN-SELECTION : FUNCTION KEY 1 . " In the subject line 
SELECTION-SCREEN PUSHBUTTON 02 ( 10 ) TEXT - 001  the USER-the COMMAND pb1. " In the select screen
INITIALIZATION.
  sscrfields-functxt_01 = '下载模板'.

AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
    WHEN 'FC01' OR 'PB1'.
CALL METHOD zcl_document_jxzhu=>download_template_to_frontend
        EXPORTING
          name_of_template = '物料主数据客制表'
*         iv_relid         = 'MI'
          iv_objid         = 'ZMMT001'
*        IMPORTING
*         rv_filepath      =
        EXCEPTIONS
          download_error   = 1
          OTHERS = 2.
      IF sy-subrc <> 0.
*       Implement suitable error handling here
      ENDIF.
    WHEN OTHERS.
  ENDCASE.

其中zcl_document_jxzhu=>download_template_to_frontend的代码为:

同学们可以直接创建SE24类。方便以后可以直接调用。

METHOD download_template_to_frontend.
    DATA: ls_key         TYPE wwwdatatab,
          ls_wwwdata     TYPE wwwdata,
          lv_filename    TYPE string,
          lv_path        TYPE string,
          lv_fullpath    TYPE string,
          lv_extension   TYPE c LENGTH 100,
          lv_user_action TYPE i.
    DATA: lv_offset TYPE i,
          lv_length TYPE i.
    CLEAR rv_filepath.
    IF iv_relid IS INITIAL.
      SELECT SINGLE relid objid srtf2 checkout checknew chname tdate ttime text
        INTO CORRESPONDING FIELDS OF ls_wwwdata
        FROM wwwdata
        WHERE objid = iv_objid.
      iv_relid = ls_wwwdata-relid.
    ELSE.
      SELECT SINGLE relid objid srtf2 checkout checknew chname tdate ttime text
        INTO CORRESPONDING FIELDS OF ls_wwwdata
        FROM wwwdata
        WHERE relid = iv_relid AND objid = iv_objid.
    ENDIF.

*window title
    DATA(iv_window_title) = |Please choose the save filepath !|.
*file extension
    CALL FUNCTION 'WWWPARAMS_READ'
      EXPORTING
        relid            = ls_wwwdata-relid
        objid            = ls_wwwdata-objid
        name             = 'fileextension' "c_extension of include LSHTMTOP
      IMPORTING
        value            = lv_extension
      EXCEPTIONS
        entry_not_exists = 1
        OTHERS           = 2.
    IF sy-subrc <> 0.
    ENDIF.
    DATA iv_default_extension TYPE string.
    iv_default_extension = lv_extension.
*file filter
    DATA(iv_file_filter) = '(*' && iv_default_extension && ')|*' && iv_default_extension.
*file name
    CONCATENATE name_of_template '-' sy-datum+0(8) sy-timlo+0(4)
      INTO DATA(iv_default_file_name).
    IF iv_default_file_name IS INITIAL.
      iv_default_file_name = ls_wwwdata-text.
    ELSE.
      WHILE iv_default_file_name CA './'.
        lv_offset = sy-fdpos.
        lv_length = lv_offset.
        lv_offset = lv_offset + 1.
        iv_default_file_name = iv_default_file_name+0(lv_length) && iv_default_file_name+lv_offset.
      ENDWHILE.
    ENDIF.
    ls_key-relid = iv_relid.
    ls_key-objid = iv_objid.
*File path of selection
    CALL METHOD cl_gui_frontend_services=>file_save_dialog
      EXPORTING
        window_title         = iv_window_title
        default_extension    = iv_default_extension
        default_file_name    = iv_default_file_name
        file_filter          = iv_file_filter
      CHANGING
        filename             = lv_filename
        path                 = lv_path
        fullpath             = lv_fullpath
        user_action          = lv_user_action
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        OTHERS               = 4.
    IF sy-subrc <> 0.
* happen sth wrong
      DATA(ev_rc) = sy-subrc.
    ENDIF.
* user action ( exit or cancal )
    IF lv_user_action <> 0.
      ev_rc = lv_user_action.
    ENDIF.

    IF ev_rc <> 0 .
      RAISE download_error.
    ENDIF.

    rv_filepath = lv_fullpath.

*Download web object
    DATA: lv_destination TYPE rlgrap-filename.
    lv_destination = rv_filepath.
    CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
      EXPORTING
        key         = ls_key
        destination = lv_destination
      IMPORTING
        rc          = ev_rc
      CHANGING
        temp        = lv_destination.
    IF ev_rc <> 0 .
      RAISE download_error.
    ENDIF.
  ENDMETHOD.

 

 效果:

- Tab Zhu 不念过去 不畏将来

 

 

SELECTION-SCREENFUNCTION KEY 1."在标题行
SELECTION-SCREEN PUSHBUTTON 02(10TEXT-001 USER-COMMAND pb1."在select界面

Guess you like

Origin www.cnblogs.com/jxzhu/p/12359692.html