Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT ZAPPLSERVER MESSAGE-ID FB.
************************************************************************
* ConstantsCONSTANTS :C_MASK(80) TYPE C VALUE ',.,..', " Mask
C_FILE_TYPE(10) TYPE C VALUE 'ASC', " File type
C_MODE(1) TYPE C VALUE 'L'. " Mode* Internal tables *DATA: BEGIN OF I_FILE OCCURS 0,
FIELD(3000) TYPE C,
END OF I_FILE.
DATA : V_MSG(100),
STRUCT_FILE LIKE I_FILE OCCURS 0.
DATA: P_LOGIN TYPE FILEINTERN.
DATA: P_PHYIN TYPE STRING.
DATA: P_FNAME1 TYPE STRING.* PARAMETERSPARAMETERS: P_FPATH TYPE FILENAME-FILEINTERN OBLIGATORY,
P_LPATH TYPE LOCALFILE,
P_UPLOAD AS CHECKBOX DEFAULT 'X',
P_DLOAD AS CHECKBOX,
P_DELETE AS CHECKBOX.
PARAMETERS: P_FNAME TYPE RLGRAP-FILENAME. "OBLIGATORY.
************************************************************************
* Check selection-screen entries *
************************************************************************
** At selection screen
*
*AT SELECTION-SCREEN. " ON VALUE-REQUEST FOR p_lpath..
*
* PERFORM sub_get_physical_file USING p_fpath p_lpath.
*
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lpath.
*
* PERFORM get_file CHANGING p_lpath.
*
************************************************************************
* AT SELECTION SCREEN
************************************************************************
AT SELECTION-SCREEN.
  PERFORM SUB_GET_PHYSICAL_FILE USING P_FPATH P_LPATH.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_LPATH.
  PERFORM GET_FILE CHANGING P_LPATH.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      STATIC        = 'X'
    CHANGING
      FILE_NAME     = P_FNAME
    EXCEPTIONS
      MASK_TOO_LONG = 1
      OTHERS        = 2.
  IF SY-SUBRC <> 0.
    MESSAGE 'no file' TYPE 'e'.
  ENDIF.
  P_FNAME1 = P_FNAME.
*&---------------------------------------------------------------------*
* At Selection Screen Output
*&---------------------------------------------------------------------*
* Make the physical file name display only
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'p_fpath'.
      SCREEN-INPUT = 0.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
************************************************************************
* Main *
************************************************************************
* Start of selection
START-OF-SELECTION.
  IF P_UPLOAD = 'X'.
* Upload to app server
    PERFORM UPLOAD_TO_APPSERVER.
  ENDIF.
  IF P_DLOAD = 'X'.
* Download to desktop
    PERFORM DOWNLOAD_TO_DESKTOP.
  ENDIF.
  IF P_DELETE = 'X'.
* Delete file on app server
    DELETE DATASET P_FPATH.
    IF SY-SUBRC = 0.
      MESSAGE S000 WITH 'File deleted'.
    ENDIF.
  ENDIF.
************************************************************************
*-------------------------------------------------------------
* Set file path of local machine
*-------------------------------------------------------------
FORM GET_FILE CHANGING FILE_OUT.
  DATA: L_FILENAME TYPE LOCALFILE. "Local file for upload/download
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      MASK             = C_MASK
      MODE             = C_MODE
    IMPORTING
      FILENAME         = L_FILENAME
    EXCEPTIONS
      INV_WINSYS       = 01
      NO_BATCH         = 02
      SELECTION_CANCEL = 03
      SELECTION_ERROR  = 04.
  P_LPATH = L_FILENAME.
ENDFORM. "get_file
*&---------------------------------------------------------------------*
*& Form UPLOAD_TO_APPSERVER
*&---------------------------------------------------------------------*
* Upload local file to app server
*----------------------------------------------------------------------*
FORM UPLOAD_TO_APPSERVER .
* data: l_lpath type string.
*
* l_lpath = p_lpath.
*
* refresh i_file.
*
* clear i_file.
*
* CALL FUNCTION 'GUI_UPLOAD'
*
* EXPORTING
*
* FILENAME = l_lpath
*
* FILETYPE = c_file_type
*
** HAS_FIELD_SEPARATOR = ' '
*
** HEADER_LENGTH = 0
*
** READ_BY_LINE = 'X'
*
** DAT_MODE = 'X'
*
** CODEPAGE = ' '
*
** IGNORE_CERR = ABAP_TRUE
*
** REPLACEMENT = SPACE
*
** CHECK_BOM = '#'
*
** IMPORTING
*
** FILELENGTH =
*
** HEADER =
*
* TABLES
*
* DATA_TAB = i_file
*
* EXCEPTIONS
*
* FILE_OPEN_ERROR = 1
*
* FILE_READ_ERROR = 2
*
* NO_BATCH = 3
*
* GUI_REFUSE_FILETRANSFER = 4
*
* INVALID_TYPE = 5
*
* NO_AUTHORITY = 6
*
* UNKNOWN_ERROR = 7
*
* BAD_DATA_FORMAT = 8
*
* HEADER_NOT_ALLOWED = 9
*
* SEPARATOR_NOT_ALLOWED = 10
*
* HEADER_TOO_LONG = 11
*
* UNKNOWN_DP_ERROR = 12
*
* ACCESS_DENIED = 13
*
* DP_OUT_OF_MEMORY = 14
*
* DISK_FULL = 15
*
* DP_TIMEOUT = 16
*
* OTHERS = 17.
  P_FNAME1 = P_FNAME.
  CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
  FILENAME = P_FNAME1
* FILETYPE = 'ASC'
  HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
  TABLES
  DATA_TAB = I_FILE
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
  .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  OPEN DATASET P_LPATH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
  MESSAGE V_MSG.
  IF SY-SUBRC = 0.
    LOOP AT I_FILE. " into struct_file.
      IF NOT I_FILE IS INITIAL.
        TRANSFER I_FILE TO P_LPATH.
      ENDIF.
    ENDLOOP.
  ELSE.
    MESSAGE E000 WITH 'File cannot be opened for output'.
  ENDIF.
  CLOSE DATASET P_LPATH.
ENDFORM. " UPLOAD_TO_APPSERVER
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_TO_DESKTOP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_TO_DESKTOP .
  OPEN DATASET P_LPATH FOR INPUT IN TEXT MODE
  ENCODING DEFAULT
  MESSAGE V_MSG.
  IF SY-SUBRC = 0.
    REFRESH : I_FILE.
    DO.
      READ DATASET P_LPATH INTO I_FILE.
      IF SY-SUBRC = 0.
        APPEND I_FILE TO I_FILE.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
  ELSE.
    MESSAGE E000 WITH 'File cannot be opened'.
  ENDIF.
  CLOSE DATASET P_LPATH.
  CALL FUNCTION 'DOWNLOAD'
    EXPORTING
      FILENAME = P_LPATH
    TABLES
      DATA_TAB = I_FILE.
ENDFORM. " DOWNLOAD_TO_DESKTOP
*&---------------------------------------------------------------------*
*& Form sub_get_physical_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_LOGIN text
* -->P_P_PHYIN text
*----------------------------------------------------------------------*
FORM SUB_GET_PHYSICAL_FILE USING P_LFILE
P_PFILE.
  CHECK NOT P_LFILE IS INITIAL.
  CALL FUNCTION 'FILE_GET_NAME'
    EXPORTING
      CLIENT           = SY-MANDT
      LOGICAL_FILENAME = P_LFILE
      OPERATING_SYSTEM = SY-OPSYS
    IMPORTING
      FILE_NAME        = P_PFILE
    EXCEPTIONS
      FILE_NOT_FOUND   = 1
      OTHERS           = 2.
  IF SY-SUBRC NE 0.
    P_PFILE = '' .
    MESSAGE E002 WITH P_LFILE.
  ENDIF.
ENDFORM. " sub_get_physical_file
*&---------------------------------------------------------------------*
*Selection texts
*----------------------------------------------------------
* P_DELETE Delete
* P_DLOAD Download
* P_FNAME FileNaME
* P_FPATH Logical FileName
* P_LPATH Logical FilePath
* P_UPLOAD Upload
*Messages
*----------------------------------------------------------
*
* Message class: FB
*000
*002
*
* Message class: Hard coded
* no file
*Selection texts
*----------------------------------------------------------
* P_DELETE Delete
* P_DLOAD Download
* P_FNAME FileNaME
* P_FPATH Logical FileName
* P_LPATH Logical FilePath
* P_UPLOAD Upload
*Messages
*----------------------------------------------------------
*
* Message class: Hard coded
* no file
  • No labels

1 Comment

  1. Standard Classes CL_RSAN_UT_APPSERV_FILE_READER , CL_RSAN_UT_APPSERV_FILE_WRITER, CL_RSAN_UT_FILES can be used to reduce coding.