Binary Upload / Download from/to SAP Server
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Hi.
Here 2 Function Modules for Up/Download binary file from / to the Application Server.
br Jens
Here 2 Function Modules for Up/Download binary file from / to the Application Server.
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- FUNCTION YBC_FILE_DOWNLOAD_BINARY.
- *"----------------------------------------------------------------------
- *"*"Lokale Schnittstelle:
- *" IMPORTING
- *" VALUE(I_FILE_FRONT_END) LIKE RCGFILETR-FTFRONT
- *" VALUE(I_FILE_APPL) LIKE RCGFILETR-FTAPPL
- *" VALUE(I_FILE_OVERWRITE) TYPE ESP1_BOOLEAN
- *" DEFAULT ESP1_FALSE
- *" EXPORTING
- *" VALUE(E_FLG_OPEN_ERROR) TYPE ESP1_BOOLEAN
- *" VALUE(E_OS_MESSAGE) TYPE C
- *" EXCEPTIONS
- *" FE_FILE_OPEN_ERROR
- *" FE_FILE_EXISTS
- *" FE_FILE_WRITE_ERROR
- *" AP_NO_AUTHORITY
- *" AP_FILE_OPEN_ERROR
- *" AP_FILE_EMPTY
- *"----------------------------------------------------------------------
- * Local data ----------------------------------------------------------
- * Function body -------------------------------------------------------
- * init
- E_FLG_OPEN_ERROR = FALSE.
- CLEAR E_OS_MESSAGE.
- * check the authority to read the file from the application server
- L_AUTH_FILENAME = I_FILE_APPL.
- CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
- EXPORTING
- * PROGRAM =
- ACTIVITY = SABC_ACT_READ
- FILENAME = L_AUTH_FILENAME
- EXCEPTIONS
- NO_AUTHORITY = 1
- ACTIVITY_UNKNOWN = 2
- OTHERS = 3.
- * no auhtority
- RAISE AP_NO_AUTHORITY.
- RAISE AP_FILE_OPEN_ERROR.
- * check if the file on the front-end exists
- CALL FUNCTION 'C13Z_UPLOAD'
- EXPORTING
- * CODEPAGE = ' '
- FILENAME = I_FILE_FRONT_END
- FILETYPE = 'BIN'
- * HEADLEN = ' '
- * LINE_EXIT = ' '
- * TRUNCLEN = ' '
- * USER_FORM = ' '
- * USER_PROG = ' '
- * DAT_D_FORMAT = ' '
- * IMPORTING
- * FILELENGTH =
- DATA_TAB = L_DATA_TAB
- 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
- NO_AUTHORITY = 10
- BAD_DATA_FORMAT = 11
- HEADER_NOT_ALLOWED = 12
- SEPARATOR_NOT_ALLOWED = 13
- HEADER_TOO_LONG = 14
- UNKNOWN_DP_ERROR = 15
- ACCESS_DENIED = 16
- DP_OUT_OF_MEMORY = 17
- DISK_FULL = 18
- DP_TIMEOUT = 19
- NOT_SUPPORTED_BY_GUI = 20
- ERROR_NO_GUI = 21
- OTHERS = 22.
- .
- * if file exists continue only if parameter is specified
- RAISE FE_FILE_EXISTS.
- RAISE FE_FILE_OPEN_ERROR.
- * open the file on the application server
- IN BINARY MODE.
- E_FLG_OPEN_ERROR = TRUE.
- EXIT.
- CLOSE DATASET I_FILE_APPL.
- * read data from application server
- CALL FUNCTION 'C13Z_RAWDATA_READ'
- EXPORTING
- I_FILE = I_FILE_APPL
- IMPORTING
- E_FILE_SIZE = L_ORLN
- E_LINES = L_LINES
- E_RCGREPFILE_TAB = L_DATA_TAB
- EXCEPTIONS
- NO_PERMISSION = 1
- OPEN_FAILED = 2
- * Begin Correction 21.03.2005 816266 *******************
- READ_ERROR = 3
- * End Correction 21.03.2005 816266 *********************
- OTHERS = 4.
- * no auhtority
- RAISE AP_NO_AUTHORITY.
- RAISE AP_FILE_OPEN_ERROR.
- * check if data table is empty
- READ TABLE L_DATA_TAB INDEX 1.
- L_FILENAME = I_FILE_FRONT_END.
- L_FILELENGTH = L_ORLN.
- CALL FUNCTION 'C13Z_DOWNLOAD'
- EXPORTING
- BIN_FILESIZE = L_FILELENGTH
- * CODEPAGE = ' '
- FILENAME = L_FILENAME
- FILETYPE = LC_FILEFORMAT_BINARY
- * mode = ' '
- * WK1_N_FORMAT = ' '
- * WK1_N_SIZE = ' '
- * WK1_T_FORMAT = ' '
- * WK1_T_SIZE = ' '
- * COL_SELECT = ' '
- * COL_SELECTMASK = ' '
- IMPORTING
- FILELENGTH = L_FILELENGTH
- DATA_TAB = L_DATA_TAB
- * FIELDNAMES =
- EXCEPTIONS
- FILE_OPEN_ERROR = 1
- FILE_WRITE_ERROR = 2
- INVALID_FILESIZE = 3
- INVALID_TABLE_WIDTH = 4
- INVALID_TYPE = 5
- NO_BATCH = 6
- UNKNOWN_ERROR = 7
- OTHERS = 8.
- RAISE FE_FILE_OPEN_ERROR.
- RAISE FE_FILE_WRITE_ERROR.
- ELSE.
- * file on application server has no contents
- RAISE AP_FILE_EMPTY.
- GeSHi ©
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- FUNCTION YBC_FILE_UPLOAD_BINARY.
- *"----------------------------------------------------------------------
- *"*"Lokale Schnittstelle:
- *" IMPORTING
- *" VALUE(I_FILE_FRONT_END) LIKE RCGFILETR-FTFRONT
- *" VALUE(I_FILE_APPL) LIKE RCGFILETR-FTAPPL
- *" VALUE(I_FILE_OVERWRITE) TYPE ESP1_BOOLEAN
- *" DEFAULT ESP1_FALSE
- *" EXPORTING
- *" VALUE(E_FLG_OPEN_ERROR) TYPE ESP1_BOOLEAN
- *" VALUE(E_OS_MESSAGE) TYPE C
- *" EXCEPTIONS
- *" FE_FILE_NOT_EXISTS
- *" FE_FILE_READ_ERROR
- *" AP_NO_AUTHORITY
- *" AP_FILE_OPEN_ERROR
- *" AP_FILE_EXISTS
- *"----------------------------------------------------------------------
- * Local data ----------------------------------------------------------
- * Function body -------------------------------------------------------
- * init
- E_FLG_OPEN_ERROR = FALSE.
- CLEAR E_OS_MESSAGE.
- * check the authority to write the file to the application server
- L_AUTH_FILENAME = I_FILE_APPL.
- CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
- EXPORTING
- * PROGRAM =
- ACTIVITY = SABC_ACT_WRITE
- FILENAME = L_AUTH_FILENAME
- EXCEPTIONS
- NO_AUTHORITY = 1
- ACTIVITY_UNKNOWN = 2
- OTHERS = 3.
- * no auhtority
- RAISE AP_NO_AUTHORITY.
- RAISE AP_FILE_OPEN_ERROR.
- * open the file on the application server for reading to check if the
- * file exists on the application server
- IN BINARY MODE.
- * nothing to do
- CLOSE DATASET I_FILE_APPL.
- RAISE AP_FILE_EXISTS.
- CLOSE DATASET I_FILE_APPL.
- * upload the file
- L_FILENAME = I_FILE_FRONT_END.
- CALL FUNCTION 'C13Z_UPLOAD'
- EXPORTING
- * CODEPAGE = ' '
- FILENAME = L_FILENAME
- FILETYPE = LC_FILEFORMAT_BINARY
- * HEADLEN = ' '
- * LINE_EXIT = ' '
- * TRUNCLEN = ' '
- * USER_FORM = ' '
- * USER_PROG = ' '
- IMPORTING
- FILELENGTH = L_FILELENGTH
- DATA_TAB = L_DATA_TAB
- EXCEPTIONS
- CONVERSION_ERROR = 1
- FILE_OPEN_ERROR = 2
- FILE_READ_ERROR = 3
- INVALID_TABLE_WIDTH = 4
- INVALID_TYPE = 5
- NO_BATCH = 6
- UNKNOWN_ERROR = 7
- OTHERS = 8.
- RAISE FE_FILE_NOT_EXISTS.
- RAISE FE_FILE_READ_ERROR.
- * count lines in rawdata table
- DESCRIBE TABLE L_DATA_TAB LINES L_LINES.
- * write file to frontend
- CALL FUNCTION 'C13Z_RAWDATA_WRITE'
- EXPORTING
- I_FILE = I_FILE_APPL
- I_FILE_SIZE = L_FILELENGTH
- I_LINES = L_LINES
- I_RCGREPFILE_TAB = L_DATA_TAB
- EXCEPTIONS
- NO_PERMISSION = 1
- OPEN_FAILED = 2
- OTHERS = 3.
- * no auhtority
- RAISE AP_NO_AUTHORITY.
- RAISE AP_FILE_OPEN_ERROR.
- GeSHi ©
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- FUNCTION YBC_RAWDATA_WRITE.
- *"----------------------------------------------------------------------
- *"*"Lokale Schnittstelle:
- *" IMPORTING
- *" VALUE(I_FILE) LIKE RCGIEDIAL-IEFILE
- *" VALUE(I_FILE_SIZE) TYPE I OPTIONAL
- *" VALUE(I_LINES) TYPE I DEFAULT 0
- *" VALUE(I_FILE_OVERWRITE) TYPE ESP1_BOOLEAN DEFAULT ESP1_TRUE
- *" TABLES
- *" I_RCGREPFILE_TAB STRUCTURE RCGREPFILE
- *" EXCEPTIONS
- *" NO_PERMISSION
- *" OPEN_FAILED
- *" AP_FILE_EXISTS
- *" CLOSE_FAILED
- *" WRITE_FAILED
- *"----------------------------------------------------------------------
- * lokal data -----------------------------------------------------------
- * Begin Correction 20.11.2005 899632 *******************
- * End Correction 20.11.2005 899632 *********************
- * function body --------------------------------------------------------
- * check the authority for file
- CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
- EXPORTING
- * PROGRAM =
- ACTIVITY = SABC_ACT_WRITE
- FILENAME = I_FILE
- EXCEPTIONS
- NO_AUTHORITY = 1
- ACTIVITY_UNKNOWN = 2
- OTHERS = 3.
- RAISE NO_PERMISSION.
- * Begin Correction 0202B0300F01 05.10.1998 BS **************************
- * check if file exists if we arn't allowed to overwrite file
- * Begin Correction 20.11.2005 899632 *******************
- CLEAR L_SUBRC.
- DATASET_TOO_MANY_FILES = 2
- OTHERS = 4.
- OPEN DATASET I_FILE FOR INPUT IN BINARY MODE.
- L_SUBRC = SY-SUBRC.
- * nothing
- ELSE.
- CLOSE DATASET I_FILE.
- RAISE AP_FILE_EXISTS.
- CLOSE DATASET I_FILE.
- * End Correction 20.11.2005 899632 *********************
- * End Correction 0202B0300F01 05.10.1998 MS ****************************
- * open dataset for writing
- OPEN DATASET I_FILE FOR OUTPUT IN BINARY MODE.
- RAISE OPEN_FAILED.
- ELSE.
- L_LEN = LG_MAX_LEN.
- LOOP AT I_RCGREPFILE_TAB.
- * last line is shorter perhaps
- L_ALL_LINES_LEN = LG_MAX_LEN * ( I_LINES - 1 ).
- L_DIFF_LEN = I_FILE_SIZE - L_ALL_LINES_LEN.
- L_LEN = L_DIFF_LEN.
- * write data in file
- * Begin Correction 20.11.2005 899632 *******************
- OTHERS = 4.
- * End Correction 20.11.2005 899632 *********************
- * Begin Correction 0682669 20.11.2003 **********************************
- RAISE WRITE_FAILED.
- * End Correction 0682669 20.11.2003 ************************************
- * close the dataset
- * Begin Correction 20.11.2005 899632 *******************
- OTHERS = 4.
- CLOSE DATASET I_FILE.
- * End Correction 20.11.2005 899632 *********************
- * Begin Correction 0682669 20.11.2003 **********************************
- RAISE CLOSE_FAILED.
- * End Correction 0682669 20.11.2003 ************************************
- GeSHi ©
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- FUNCTION YBC_RAWDATA_READ.
- *"----------------------------------------------------------------------
- *"*"Lokale Schnittstelle:
- *" IMPORTING
- *" VALUE(I_FILE) LIKE RCGIEDIAL-IEFILE
- *" EXPORTING
- *" VALUE(E_FILE_SIZE) LIKE DRAO-ORLN
- *" VALUE(E_LINES) TYPE I
- *" TABLES
- *" E_RCGREPFILE_TAB STRUCTURE RCGREPFILE
- *" EXCEPTIONS
- *" NO_PERMISSION
- *" OPEN_FAILED
- *" READ_ERROR
- *"----------------------------------------------------------------------
- * lokal data -----------------------------------------------------------
- * Begin Correction 20.11.2005 899632 *******************
- * End Correction 20.11.2005 899632 *********************
- * function body --------------------------------------------------------
- * Begin Correction 14.03.2006 931560 **********************************
- REFRESH E_RCGREPFILE_TAB.
- * End Correction 14.03.2006 931560 ************************************
- * check the authority for file
- CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
- EXPORTING
- * PROGRAM =
- ACTIVITY = SABC_ACT_READ
- FILENAME = I_FILE
- EXCEPTIONS
- NO_AUTHORITY = 1
- ACTIVITY_UNKNOWN = 2
- OTHERS = 3.
- RAISE NO_PERMISSION.
- * read the raw-file from the appl.server
- * Begin Correction 20.11.2005 899632 *******************
- CLEAR L_SUBRC.
- DATASET_TOO_MANY_FILES = 2
- OTHERS = 4.
- OPEN DATASET I_FILE FOR INPUT IN BINARY MODE.
- L_SUBRC = SY-SUBRC.
- L_SUBRC <> 0.
- RAISE OPEN_FAILED.
- * End Correction 20.11.2005 899632 *********************
- * Begin Correction 21.03.2005 816266 *******************
- OTHERS = 12.
- DO.
- CLEAR L_LEN.
- CLEAR E_RCGREPFILE_TAB.
- READ DATASET I_FILE INTO E_RCGREPFILE_TAB-ORBLK LENGTH L_LEN.
- * Begin Correction 20.11.2005 899632 *******************
- * End Correction 20.11.2005 899632 *********************
- E_FILE_SIZE = E_FILE_SIZE + L_LEN.
- APPEND E_RCGREPFILE_TAB.
- EXIT.
- E_FILE_SIZE = E_FILE_SIZE + L_LEN.
- APPEND E_RCGREPFILE_TAB.
- RAISE READ_ERROR.
- * End Correction 31.03.2005 816266 *********************
- DESCRIBE TABLE E_RCGREPFILE_TAB LINES E_LINES.
- * Begin Correction 20.11.2005 899632 *******************
- OTHERS = 4.
- CLOSE DATASET I_FILE.
- * but there wasn't any error at the reading of the data
- * End Correction 20.11.2005 899632 *********************
- GeSHi ©
br Jens