SAP ABAP/4学习---上传和下载(1)


*&---------------------------------------------------------------------*
*& Report  ZTEST_LIUGANG_913                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZTEST_LIUGANG_913 .

DATA:BEGIN OF ITAB OCCURS 0,
         A(6),
         B(6),
     END   OF ITAB.

DATA:FILENAME(160),
     FILEPATH(128),
     TEST LIKE RLGRAP-FILENAME.

DATA:BEGIN OF ITAB2 OCCURS 0,
        A(60),
     END   OF ITAB2.

ITAB-A = '123'.
ITAB-B = '456'.
APPEND ITAB.
ITAB-A = 'ABC'.
ITAB-B = 'DEF'.
APPEND ITAB.

LOOP AT ITAB.
  WRITE: / ITAB-A,ITAB-B.
ENDLOOP.

PARAMETERS: AA LIKE ITAB-A.

INITIALIZATION.

START-OF-SELECTION.
SET PF-STATUS '1000'.
 AT USER-COMMAND.
   CASE SY-UCOMM.
     WHEN 'DOWN'.
          PERFORM DOWNLOAD_SAVE USING 'S' '保存文件'.
          IF STRLEN( FILEPATH ) > 0.
            PERFORM START_SAVE.
          ENDIF.
     WHEN 'UPLO'.
          PERFORM DOWNLOAD_SAVE USING 'O' '上传文件'.
          IF STRLEN( FILEPATH ) > 0.
            PERFORM START_UPLOAD.
          ENDIF.
     WHEN 'BACK'.
       LEAVE TO SCREEN 0.
     WHEN 'RW'.
       LEAVE PROGRAM.
   ENDCASE.
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_SAVE
*&---------------------------------------------------------------------*
*       保存文件到本地
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DOWNLOAD_SAVE USING OPEN_TYPE OPEN_TXT.
 CALL FUNCTION 'WS_FILENAME_GET'
   EXPORTING
     DEF_FILENAME           = FILEPATH
     MASK                   = ',*.CSV.'
     MODE                   = OPEN_TYPE
     TITLE                  = OPEN_TXT
   IMPORTING
     FILENAME               = FILEPATH
   EXCEPTIONS
    INV_WINSYS             = 1
    NO_BATCH               = 2
    SELECTION_CANCEL       = 3
    SELECTION_ERROR        = 4
    OTHERS                 = 5
           .
 IF SY-SUBRC <> 0.
   MESSAGE E001(ZTEST_LIUGANG).
 ENDIF.

ENDFORM.                    " DOWNLOAD_SAVE
*&---------------------------------------------------------------------*
*&      Form  START_SAVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM START_SAVE .
  DATA:TEMP(30).
  LOOP AT ITAB.
   CONCATENATE ITAB-A  ITAB-B INTO ITAB2-A SEPARATED BY ','.
   APPEND ITAB2.
  ENDLOOP.

 CALL FUNCTION 'WS_DOWNLOAD'
  EXPORTING
    FILENAME                      = FILEPATH
    FILETYPE                      = 'ASC'
   TABLES
     DATA_TAB                     = ITAB2.
ENDFORM.                    " START_SAVE
*&---------------------------------------------------------------------*
*&      Form  START_UPLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM START_UPLOAD .

  CLEAR ITAB2.
  CLEAR ITAB2[].
  CLEAR ITAB.
  CLEAR ITAB[].

CALL FUNCTION 'WS_UPLOAD'
  EXPORTING
   FILENAME                      = FILEPATH
   FILETYPE                      = 'ASC'
  TABLES
    DATA_TAB                      = ITAB2 .

  LOOP AT ITAB2.
    SPLIT ITAB2-A AT ',' INTO ITAB-A ITAB-B.
    APPEND ITAB.
  ENDLOOP.

 LOOP AT ITAB.
   WRITE:/ ITAB-A  ,ITAB-B.

 ENDLOOP.

ENDFORM.                    " START_UPLOAD


 

 

你可能感兴趣的:(function,upload,report,SAP,Parameters,download)