TO CREATE A BUTTON ON THE TOP OF AN ABAP PROGRAM WITHOUT USING gui STATUS

REPORT  ZTEST_DOWNLOAD_TEMP.
*----------------------------------------------------------------------*
*  TABLES AND VARIABLES
*----------------------------------------------------------------------*
TABLESsscrfields"+ch001

TYPES:BEGIN OF T_DATATAB,
      WERKS(8TYPE C,
      MATNR(50TYPE C,"material no
      CHARG(50TYPE C,"batch
      VALUE(50TYPE C,"batch grade value
      END OF T_DATATAB.


*----------------------------------------------------------------------*
*  SELECTION-SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK RAD1 WITH FRAME TITLE TEXT-T01.

PARAMETERSP_FILE TYPE  RLGRAP-FILENAME.

SELECTION-SCREEN END OF BLOCK RAD1.
SELECTION-SCREEN BEGIN OF LINE.
* Add buttons to application toolbar
SELECTION-SCREEN FUNCTION KEY 1.  "Will have a function code of 'FC01'
SELECTION-SCREEN END OF LINE.
PARAMETERp_ucomm LIKE sy-ucomm NO-DISPLAY.


*----------------------------------------------------------------------*
*  INITIALIZATION
*----------------------------------------------------------------------*

*+ch001 additional button to download template start
INITIALIZATION.

* Add displayed text string to buttons
  MOVE 'Download Template' TO sscrfields-functxt_01.


*----------------------------------------------------------------------*
*  AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Check if button have been selected or not
  IF sscrfields-ucomm EQ 'FC01'.
    p_ucomm 'BUTN1'.
  ELSE.
    CLEAR p_ucomm.
  ENDIF.

AT SELECTION-SCREEN OUTPUT.

  IF p_ucomm 'BUTN1'.
    PERFORM download_template1.
  ENDIF.
*+ch001 additional button to download template end

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





*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_TEMPLATE1 ++ch001
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM download_template1 .

*TYPES:BEGIN OF T_DATATAB,
*      WERKS(8) TYPE C,
*      MATNR(50) TYPE C,"material no
*      CHARG(50) TYPE C,"batch
*      VALUE(50) TYPE C,"batch grade value
*      END OF T_DATATAB.

  DATAt_templt type T_DATATAB OCCURS WITH HEADER LINE.

  REFRESH t_templt.
  t_templt-werks =  'Plant'.
  t_templt-matnr  'Material no'.
  t_templt-charg  =  'Batch'.
  t_templt-value 'batch grade value'.

  APPEND t_templt.
  CLEAR t_templt.

  DATAlv_rc         TYPE i,
        lt_filetable  TYPE filetable.

  DATAv_path              TYPE string.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title      'Please Select File'
      default_extension 'XLS'
    CHANGING
      file_table        lt_filetable
      rc                lv_rc.
  IF sy-subrc <> 0.
    MESSAGE 'Can not get file path' TYPE 'E'.
  ELSEIF lv_rc 1.
    READ TABLE lt_filetable INTO v_path INDEX 1.
  ENDIF.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
*     BIN_FILESIZE            =
      filename                v_path
      filetype                'DAT'
      codepage                '8400'
    TABLES
      data_tab                t_templt
*     FIELDNAMES              =
    EXCEPTIONS
      file_write_error        1
      no_batch                2
      gui_refuse_filetransfer 3
      invalid_type            4
      no_authority            5
      unknown_error           6
      header_not_allowed      7
      separator_not_allowed   8
      filesize_not_allowed    9
      header_too_long         10
      dp_error_create         11
      dp_error_send           12
      dp_error_write          13
      unknown_dp_error        14
      access_denied           15
      dp_out_of_memory        16
      disk_full               17
      dp_timeout              18
      file_not_found          19
      dataprovider_exception  20
      control_flush_error     21
      OTHERS                  22.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDFORM.                    " DOWNLOAD_TEMPLATE1
0 comments:

Post a Comment

message

Labels

NuffNang

Search google

Blog Archive

My Blog List

Twitter

Message

Followers