ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 把本地文件上传到应用服务器

把本地文件上传到应用服务器

原创 Linux操作系统 作者:niuchao 时间:2019-06-17 07:48:06 0 删除 编辑

谢谢FENGLEIHEN兄弟提供的实例

*----------------------------------------------------------------------*
* 功能名
* 作成者   :fengleihen@126.com
* 作成日   :2007/06/05
* 版本     :1.0
*----------------------------------------------------------------------*
* <处理概要>
*
*----------------------------------------------------------------------*
REPORT Y_UPLOAD_TO_SERVER
       NO STANDARD PAGE HEADING
       MESSAGE-ID ZXX001.

SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME.
* File Path
  PARAMETERS: PA_SNAME LIKE RLGRAP-FILENAME OBLIGATORY.
  PARAMETERS PA_LNAME  TYPE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN END OF BLOCK BL1.

DATA: BEGIN OF REC_CHECK,
        LINE  TYPE TEXT1000,
      END   OF REC_CHECK.
DATA: TBL_CHECK LIKE TABLE OF REC_CHECK.
DATA: WK_FNAME,
      FLG_ERROR TYPE C.
*-----  Constants  ----------------------------------------------------*
CONSTANTS:
  CST_X           TYPE C                VALUE 'X',
  CST_MODULE01     TYPE MSGV1            VALUE 'WS_UPLOAD',
  CST_FILETYPE     TYPE RLGRAP-FILETYPE  VALUE 'ASC'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR PA_LNAME.
  PERFORM. PATH_FORM.


START-OF-SELECTION.

  PERFORM. GET_FILE_RTN.
  PERFORM. OUTPUT_FORM.


*&---------------------------------------------------------------------*
*&      Form  PATH_FORM
*&---------------------------------------------------------------------*
FORM. PATH_FORM.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    CHANGING
      FILE_NAME           = PA_LNAME
    EXCEPTIONS
      MASK_TOO_LONG       = 1
      OTHERS              = 2
            .
  IF SY-SUBRC <> 0.
    MESSAGE E042 WITH PA_LNAME.
  ENDIF.
ENDFORM.                    " PATH_FORM


FORM. GET_FILE_RTN.
*
DATA L_FILE LIKE RLGRAP-FILENAME.
*
  L_FILE = PA_LNAME.
*
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
*     CODEPAGE                      = ' '
      FILENAME                      = L_FILE
      FILETYPE                      = CST_FILETYPE
*     HEADLEN                       = ' '
*     LINE_EXIT                     = ' '
*     TRUNCLEN                      = ' '
*     USER_FORM                     = ' '
*     USER_PROG                     = ' '
*     DAT_D_FORMAT                  = ' '
*   IMPORTING
*     FILELENGTH                    =
    TABLES
      DATA_TAB                      = TBL_CHECK
    EXCEPTIONS
     CONVERSION_ERROR              = 1
     FILE_OPEN_ERROR               = 2
     FILE_READ_ERROR               = 3
     INVALID_TYPE                  = 4
     NO_BATCH                      = 5
     UNKNOWN_ERROR                 = 6
     INVALID_TABLE_WIDTH           = 7
     GUI_REFUSE_FILETRANSFER       = 8
     CUSTOMER_ERROR                = 9
     OTHERS                        = 10
            .
  IF SY-SUBRC <> 0.
    MESSAGE E001(ZAPO1) WITH CST_MODULE01 SY-SUBRC L_FILE.
  ENDIF.
*
ENDFORM.                    " GET_FILE_RTN

FORM. OUTPUT_FORM.

  DATA: LO_COUNT      TYPE I,                 "LINES
        LO_NUM(10)    TYPE C,                 "LINES OUTPUT
        LO_NAME       TYPE SDBAH-ACTID,
        LO_EXT        TYPE SDBAD-FUNCT,
        LO_TXT(250)   TYPE C.                 "EXPORT TEXT
*  CALL FUNCTION 'SPLIT_FILENAME'
*    EXPORTING
*      LONG_FILENAME        = PA_LNAME
*    IMPORTING
*      PURE_FILENAME        = LO_NAME
*      PURE_EXTENSION       = LO_EXT
*            .
*
*  CONCATENATE PA_SNAME LO_NAME '.' LO_EXT INTO PA_SNAME.

  OPEN DATASET PA_SNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC <> 0.
* Failed to open file (file name : &1)
    MESSAGE S042 WITH PA_SNAME.
    FLG_ERROR = CST_X.
  ELSE.
* Successfully open file (file name : &1)
    MESSAGE S221 WITH PA_SNAME.
  ENDIF.
  CHECK FLG_ERROR = SPACE.
  DESCRIBE TABLE TBL_CHECK LINES LO_COUNT.
* STOP by 042
  CHECK FLG_ERROR = SPACE.
  LOOP AT TBL_CHECK INTO REC_CHECK.
    TRANSFER REC_CHECK-LINE TO PA_SNAME.
    IF SY-SUBRC <> 0.
* Failed to transfer data to file( file name: &1 )
      MESSAGE S043 WITH PA_SNAME.
      FLG_ERROR = CST_X.
      CLOSE DATASET PA_SNAME.
      EXIT.
    ENDIF.
  ENDLOOP.
  CHECK FLG_ERROR = SPACE.
  CLOSE DATASET PA_SNAME.
  IF SY-SUBRC <> 0.
* Failed to close file( file name: &1 )
    MESSAGE S044 WITH PA_SNAME.
  ELSE.
* Data file is transferred
    MESSAGE S278.
* Output records :&1
    MESSAGE S237 WITH LO_COUNT.
  ENDIF.

ENDFORM.                    " OUTPUT_FORM

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/166523/viewspace-217975/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2004-11-04

  • 博文量
    139
  • 访问量
    107654