下载TR到本地

包含上载和下载

*&---------------------------------------------------------------------*

*& Report ZTRANS_TR
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZTRANS_TR .

TABLES TRDYSE01SN .
TYPES :
   BEGIN  OF TY_TR ,
    SERVER_PATH  TYPE SAEPFAD ,
    LOCAL_PATH   TYPE SAEPFAD ,
    FILENAM      TYPE CHAR20 ,
    TR_CODE      TYPE TRDYSE01SN -TR_TRKORR ,
   END  OF TY_TR .


DATA GT_TR  TYPE  STANDARD  TABLE  OF TY_TR .
DATA GT_FILE_NAMES       TYPE FILETABLE .


SELECT-OPTIONS  S_TR  FOR TRDYSE01SN -TR_TRKORR  NO INTERVALS .
PARAMETERS P_DFNAME  TYPE RLGRAP -FILENAME .
PARAMETERS RB_UP  TYPE CHAR1  RADIOBUTTON  GROUP G1 ,
            RB_DOWN  TYPE CHAR1  RADIOBUTTON  GROUP G1 .

AT  SELECTION-SCREEN  ON  VALUE-REQUEST  FOR S_TR -LOW .
   PERFORM FRM_VALUE_TRKORR .
AT  SELECTION-SCREEN  ON  VALUE-REQUEST  FOR P_DFNAME .
*  PERFORM frm_upload_file.

* call f4-help
   PERFORM FRM_VALREQ_FTFRONT  USING
                             '1000'
                             'Quelldatei auf Frontend' ( 007 ) .

START-OF-SELECTION .

   PERFORM FRM_GET_DATA .
   PERFORM FRM_DOWN_FILE .
*&---------------------------------------------------------------------*
*&      Form  FRM_VALUE_TRKORR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_VALUE_TRKORR  .

   DATA LV_TRFUNCTIONS   LIKE  TRPARI -W_LONGSTAT ,
        LV_TRSTATUS      LIKE  TRPARI -W_LONGSTAT ,
        LV_TRKORR        TYPE  E070 -TRKORR ,
        LS_DYNPFIELD   LIKE DYNPREAD ,
        LT_DYNPFIELDS  LIKE DYNPREAD     OCCURS  0 .

  LV_TRFUNCTIONS  SCTSC_TYPES_ALL .
  LV_TRSTATUS     SCTSC_STATES_CHANGEABLE .

   GET  CURSOR  FIELD LS_DYNPFIELD -FIELDNAME .
   APPEND LS_DYNPFIELD  TO LT_DYNPFIELDS .

   CALL  FUNCTION  'DYNP_VALUES_READ'
        EXPORTING
            DYNAME      'ZTRANS_TR'
            DYNUMB      SY -DYNNR
        TABLES
            DYNPFIELDS  LT_DYNPFIELDS .

   READ  TABLE LT_DYNPFIELDS  INTO LS_DYNPFIELD  INDEX  1 .
  LV_TRKORR  LS_DYNPFIELD -FIELDVALUE .

   CALL  FUNCTION  'TR_F4_REQUESTS'
        EXPORTING
            IV_USERNAME          SPACE
            IV_TRKORR_PATTERN    LV_TRKORR
            IV_TRFUNCTIONS       LV_TRFUNCTIONS
            IV_TRSTATUS          LV_TRSTATUS
        IMPORTING
            EV_SELECTED_REQUEST  LV_TRKORR .

  LS_DYNPFIELD -FIELDVALUE  LV_TRKORR .
   MODIFY LT_DYNPFIELDS  FROM LS_DYNPFIELD
                        INDEX  1
                        TRANSPORTING FIELDVALUE .
   CALL  FUNCTION  'DYNP_VALUES_UPDATE'
        EXPORTING
            DYNAME      'ZTRANS_TR'
            DYNUMB      SY -DYNNR
        TABLES
            DYNPFIELDS  LT_DYNPFIELDS .
ENDFORM .
**&---------------------------------------------------------------------*
**&      Form  FRM_UPLOAD_FILE
**&---------------------------------------------------------------------*
**       从本地打开文件并读取数据到内表
**----------------------------------------------------------------------*
**  -->  p1        text
**  <--  p2        text
**----------------------------------------------------------------------*
*FORM frm_upload_file .
*
*   DATA:
*     lw_file_names TYPE file_table,
*     lv_path       TYPE rlgrap-filename,
*     lv_subrc      TYPE i.
*
*   CALL METHOD cl_gui_frontend_services=>file_open_dialog
*     EXPORTING
**      initial_directory       = 'e:study'
*      default_filename = '*.xls'
**      multiselection          = 'X'
*    CHANGING
*       file_table              = gt_file_names[]
*       rc                      = lv_subrc
*     EXCEPTIONS
*       file_open_dialog_failed = 1
*       cntl_error              = 2
*       error_no_gui            = 3
*       not_supported_by_gui    = 4
*       OTHERS                  = 5.
*
*   READ TABLE gt_file_names INTO lw_file_names INDEX 1.
*   p_dfname = lw_file_names-filename.
*
* ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DOWN_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DOWN_FILE  .
   DATA L_FLG_OPEN_ERROR   TYPE BOOLEAN .
   DATA L_OS_MESSAGE ( 100 TYPE  C .
   DATA L_FTAPPL  TYPE RCGFILETR -FTAPPL .
   DATA LV_TR  TYPE CHAR30 .
   DATA L_OVERWRITE  TYPE RCGFILETR -IEFOW .
   DATA LS_TR  TYPE TY_TR .
   DATA LV_ERR  TYPE CHAR1 .

   DATA LS_TR2  TYPE TY_TR .
   DATA LT_TR  TYPE  STANDARD  TABLE  OF TY_TR .

   IF SY -SYSID+2 ( 1 'Q'  AND RB_UP  'X' .
     MESSAGE  '测试系统中只能下载TR'  TYPE  'E' .
   ENDIF .

   LOOP  AT GT_TR  INTO LS_TR .

     IF RB_DOWN  'X' .
       CALL  FUNCTION  'ARCHIVFILE_SERVER_TO_CLIENT'
        EXPORTING
         PATH                   LS_TR -SERVER_PATH
         TARGETPATH             LS_TR -LOCAL_PATH
        EXCEPTIONS
         ERROR_FILE              1
         NO_AUTHORIZATION        2
          OTHERS                  3 .

       IF SY -SUBRC <>  0 .
        LV_ERR  'X' .
        LS_TR2  LS_TR .
         APPEND LS_TR2  TO LT_TR .
       ENDIF .
     ELSE .
       CALL  FUNCTION  'ARCHIVFILE_CLIENT_TO_SERVER'
         EXPORTING
          PATH                    ls_tr -local_path
          TARGETPATH              ls_tr -server_path
        EXCEPTIONS
         ERROR_FILE              1
         NO_AUTHORIZATION        2
          OTHERS                  3 .

       IF SY -SUBRC <>  0 .
        LV_ERR  'X' .
        LS_TR2  LS_TR .
         APPEND LS_TR2  TO LT_TR .
       ENDIF .

     ENDIF .

   ENDLOOP .

   IF LV_ERR  IS  INITIAL .
     MESSAGE  'DOWNLOAD SUCCESS'  TYPE  'S' .
   ELSE .
     MESSAGE  'DOWNLOAD FAILURE'  TYPE  'E' DISPLAY  LIKE  'E' .
     LOOP  AT LT_TR  INTO LS_TR2 .
       WRITE / LS_TR2 -FILENAM .
     ENDLOOP .
   ENDIF .


*  if sy-subrc = 0.
*    MESSAGE 'DOWNLOAD SUCCESS' TYPE 'S'.
*  ELSE.
*    MESSAGE 'DOWNLOAD FAILURE' TYPE 'E' DISPLAY LIKE 'E'.
*  ENDIF.

ENDFORM .
*&---------------------------------------------------------------------*
*&      Form  FRM_VALREQ_FTFRONT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0036   text
*      -->P_0037   text
*----------------------------------------------------------------------*
FORM FRM_VALREQ_FTFRONT
* Purpose: f4-help for the filename on the front end
   USING
    I_DYNPRO  LIKE D020S -DNUM
    I_TITLE   TYPE STRING .

* Local data ----------------------------------------------------------

   DATA L_STRLEN     TYPE  I .
   DATA L_FTFRONT    LIKE DYNPREAD -FIELDVALUE .
   DATA L_FILENAME   TYPE STRING .
   DATA L_NEW_FILENAME  LIKE RCGFILETR -FTFRONT .
   DATA L_PATH       TYPE STRING .
   DATA L_CHAR       TYPE  C .
   DATA L_FILE_EXTENSION_TAB  TYPE FILETABLE  WITH  HEADER  LINE .

* Function body--------------------------------------------------------

* read value of field from dynpro
   CALL  FUNCTION  'C14Z_DYNP_READ_FIELD'
     EXPORTING
      I_PROGRAM       'ZTRANS_TR'
      I_DYNPRO        I_DYNPRO
      I_FIELDNAME     'P_DFNAME'
      I_FLG_STEPLOOP  SPACE
     CHANGING
      E_VALUE         L_FTFRONT
     EXCEPTIONS
       OTHERS          1 .

   IF SY -SUBRC  0 .

*   split filename into path and filename
    L_STRLEN  STRLEN L_FTFRONT  ) .
     CLEAR L_FILENAME .
    L_PATH  L_FTFRONT .
     WHILE L_STRLEN >  0 .
      L_CHAR  L_FTFRONT+L_STRLEN ( 1 ) .
* Begin Correction 30.03.2010 1454105 **********************************
       IF L_CHAR  '\'  OR L_CHAR  '/' .
* End Correction 30.03.2010 1454105 ************************************
        L_STRLEN  L_STRLEN +  1 .
        L_PATH      L_FTFRONT (L_STRLEN ) .
        L_FILENAME  L_FTFRONT+L_STRLEN .
         EXIT .
       ELSE .
        L_STRLEN  L_STRLEN  1 .
       ENDIF .
     ENDWHILE .

   ENDIF .

* build extension list of file types
   APPEND  'dat'  TO L_FILE_EXTENSION_TAB .
   APPEND  'doc'  TO L_FILE_EXTENSION_TAB .
   APPEND  'key'  TO L_FILE_EXTENSION_TAB .
   APPEND  'txt'  TO L_FILE_EXTENSION_TAB .
   APPEND  '*'    TO L_FILE_EXTENSION_TAB .

  L_FILENAME  'FILENAME' .
* call help
   CALL  FUNCTION  'C13Z_FRONTEND_FILENAME_GET'
     EXPORTING
      I_WINDOW_TITLE        I_TITLE
      I_DEFAULT_FILENAME    L_FILENAME
      I_INITIAL_DIRECTORY   L_PATH
     IMPORTING
      E_FILENAME            L_NEW_FILENAME
     TABLES
      I_FILE_EXTENSION_TAB  L_FILE_EXTENSION_TAB
     EXCEPTIONS
      INTERNAL_ERROR        1
       OTHERS                2 .
   IF  NOT SY -SUBRC  IS  INITIAL .
     " nothing to do

* Begin Correction 30.03.2010 1454105 **********************************
   ELSEIF  NOT L_NEW_FILENAME  IS  INITIAL .
* End Correction 30.03.2010 1454105 ************************************
    P_DFNAME  L_NEW_FILENAME .
   ENDIF .


ENDFORM .
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA  .

   DATA LT_TRANGE  TYPE RANGE  OF TRDYSE01SN -TR_TRKORR .
   DATA LS_TRANGE  LIKE  LINE  OF LT_TRANGE .
   DATA LS_TR  TYPE TY_TR ,
        LV_FILENAME     TYPE CHAR20 ,
        LV_DFNAME       TYPE RLGRAP -FILENAME ,
        LV_SERVER_PATH  TYPE SAEPFAD .


   LOOP  AT S_TR[]  INTO LS_TRANGE .
    LV_DFNAME  P_DFNAME .
    LV_FILENAME  'R' && LS_TRANGE -LOW+4 ( 6 &&  '.E' && SY -SYSID+1 ( 1 &&  'D' .
    LV_SERVER_PATH  '/usr/sap/trans/data/' && LV_FILENAME .
     REPLACE  'FILENAME'  WITH LV_FILENAME  INTO LV_DFNAME .
     CONDENSE  LV_DFNAME   NO -GAPS  .
*    CONCATENATE
    LS_TR -LOCAL_PATH   LV_DFNAME .
    LS_TR -SERVER_PATH  LV_SERVER_PATH .
    LS_TR -FILENAM  LV_FILENAME .
    LS_TR -TR_CODE      LS_TRANGE -LOW .
     APPEND LS_TR  TO GT_TR .
     CLEAR LS_TR .

    LV_DFNAME  P_DFNAME .
    LV_FILENAME  'K' && LS_TRANGE -LOW+4 ( 6 &&  '.E' && SY -SYSID+1 ( 1 &&  'D' .
    LV_SERVER_PATH  '/usr/sap/trans/cofiles/' && LV_FILENAME .
     REPLACE  'FILENAME'  WITH LV_FILENAME  INTO LV_DFNAME .
     CONDENSE  LV_DFNAME   NO -GAPS  .
    LS_TR -LOCAL_PATH   LV_DFNAME .
    LS_TR -SERVER_PATH  LV_SERVER_PATH .
    LS_TR -FILENAM  LV_FILENAME .
    LS_TR -TR_CODE      LS_TRANGE -LOW .
     APPEND LS_TR  TO GT_TR .
     CLEAR LS_TR .

   ENDLOOP .


ENDFORM .

你可能感兴趣的:(ABAP开发)