‎2009 Feb 19 6:11 AM
hi,
I want to Copy a file from application server to same application server with different name.
is there any FM available?? Please suggest solution.
Edited by: Nikhil Joshi on Feb 19, 2009 7:11 AM
‎2009 Feb 19 6:18 AM
Hi:
Way - 1
Follow the following procedure like
1. upload the file by using open dataset [open data set|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/content.htm]
2. Read it
3. put it in internal table
4. again download it.
Way -2
Call Basis guy who'll update you how to rename the file.
Regards
Shashi
‎2009 Feb 19 6:12 AM
‎2009 Feb 19 6:28 AM
HI Gautham,
with FM 'WS_FILE_COPY' file is getting created on application server but contents are missing. the newly created file is empty
‎2009 Feb 19 6:13 AM
‎2009 Feb 19 6:13 AM
‎2011 Jan 28 5:22 AM
‎2009 Feb 19 6:18 AM
Hi:
Way - 1
Follow the following procedure like
1. upload the file by using open dataset [open data set|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/content.htm]
2. Read it
3. put it in internal table
4. again download it.
Way -2
Call Basis guy who'll update you how to rename the file.
Regards
Shashi
‎2009 Feb 19 6:28 AM
Hi,
Try the below code for your requirement.
REPORT zcopydata.
*&---------------------------------------------------------------------*
* Data Transfer
*&---------------------------------------------------------------------*
* Parameters to enter the path
PARAMETERS filename(128) DEFAULT '/usr/tmp/tfile.dat'
LOWER CASE.
* Table Declaration
TABLES vbak.
* Data Declaration
DATA d_msg_text(50).
* Get data for file transfer
DATA int_vbak LIKE vbak OCCURS 100
WITH HEADER LINE.
SELECT * FROM vbak INTO TABLE int_vbak.
SORT int_vbak BY vbeln.
LOOP AT int_vbak.
WRITE: / int_vbak-vbeln,
int_vbak-kunnr.
ENDLOOP.
* Open the File
OPEN DATASET filename FOR OUTPUT IN TEXT MODE
MESSAGE d_msg_text ENCODING DEFAULT.
IF sy-subrc NE 0.
WRITE: 'You cannot be open File . Reason:', d_msg_text.
EXIT.
ENDIF.
* Transfer Data
LOOP AT int_vbak.
TRANSFER int_vbak-vbeln TO filename.
ENDLOOP.
* Close the File
CLOSE DATASET filename.Regards,
Syfulla
‎2009 Feb 19 9:07 AM
Hello Nikhil,
Please try the following code-snap, I got it, hope it helps you too.
*&---------------------------------------------------------------------*
*& Report ZAHACK_11
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZAHACK_11.
*---------------------------------------------------------------------*
* Structure for Accounting Information *
*---------------------------------------------------------------------*
TYPES:
BEGIN OF type_s_bkpf,
bukrs TYPE bkpf-bukrs, " Company Code
belnr TYPE bkpf-belnr, " Accounting Document Number
gjahr TYPE bkpf-gjahr, " Fiscal Year
blart TYPE bkpf-blart, " Document Type
bldat TYPE bkpf-bldat, " Document date in document
END OF type_s_bkpf. " BEGIN OF TYPE_S_BKPF
*---------------------------------------------------------------------*
* Field String for Accounting Information *
*---------------------------------------------------------------------*
DATA:
fs_bkpf TYPE type_s_bkpf.
*---------------------------------------------------------------------*
* Internal Table For Accounting Information *
*---------------------------------------------------------------------*
DATA:
t_bkpf LIKE
STANDARD TABLE
OF fs_bkpf.
*---------------------------------------------------------------------*
* Work Variables *
*---------------------------------------------------------------------*
DATA:
w_filename TYPE string, " Selected Filename
w_filename1 TYPE string. " Selected Filename
*---------------------------------------------------------------------*
* INITIALIZATION *
*---------------------------------------------------------------------*
INITIALIZATION.
PARAMETERS:
p_filed1(128) VISIBLE LENGTH 15, " File Name to be open
p_filed2(128) VISIBLE LENGTH 15. " File Name to be saved
*---------------------------------------------------------------------*
* START-OF-SELECTION *
*---------------------------------------------------------------------*
START-OF-SELECTION.
IF ( p_filed1 IS INITIAL ) OR ( p_filed2 IS INITIAL ).
MESSAGE 'No File Name Mentioned' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
PERFORM open_file.
PERFORM save_file.
ENDIF. " IF ( P_FILE IS INITIAL )...
*&---------------------------------------------------------------------*
*& Form save_file
*&---------------------------------------------------------------------*
* This Subroutine facilitates saving on Application Server.
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM save_file .
OPEN DATASET p_filed2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_bkpf INTO fs_bkpf.
TRANSFER fs_bkpf TO p_filed2.
ENDLOOP. " LOOP AT T_BKPF INTO FS_BKPF
CLOSE DATASET p_filed2.
IF sy-subrc NE 0.
MESSAGE 'Saving Failed' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
MESSAGE 'Saving Successfull' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF. " IF SY-SUBRC NE 0
ENDFORM. " FORM SAVE_FILE
*&---------------------------------------------------------------------*
*& Form open_file
*&---------------------------------------------------------------------*
* This Subroutine fetches data from the File saved on Application Server
*----------------------------------------------------------------------*
* This Subroutine has got no Interface Parameters.
*----------------------------------------------------------------------*
FORM open_file .
OPEN DATASET p_filed1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET p_filed1 INTO fs_bkpf.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND fs_bkpf TO t_bkpf.
ENDIF. " IF SY-SUBRC EQ 0
ENDDO. " DO
CLOSE DATASET p_filed1.
ENDFORM. " FORM OPEN_FILEThanks: Zahack
‎2009 Feb 19 9:07 AM
Try this FM to copy a file from application server to same application server,
WS_FILE_COPY
Regards,
Joan
‎2009 Feb 19 9:58 AM
Hi,
Try this FM to copy a file from application server to same application server
CL_GUI_FRONTEND_SERVICES=>FILE_COPY
Hope this helps you.
Regards,
Anki Reddy