11-06-2007 9:03 AM
we have files arriving on usr/sap/tmp directory . We need to copy the last of these files arriving each evening on the usr/SAP/files directory with a standard naming convention to load them into BW. The name of the file arriving on usr/sap/tmp is every day different eg. G30981 - G30982- G30990. How can we do it with an abap program ?
Thanks
Points assured!
11-06-2007 9:14 AM
You can do that by scheduling your report in background daily evening...
in your report you have to use OPEN DATASET, READ DATASET amd TRANSFER DATASET.. CLOSE DATASET..
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/open_dat.htm
11-06-2007 9:25 AM
Hi this FM will give you all the files in a Application server directory.. after that in internal table you will all the fils and you can delete the unnecessary files depending on name..date...etc
Retrieving the list of files in the given directory
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
EXPORTING
NAME = PA_AFILE " App Server Direcotory
TABLES
FILE_TBL = T_AFILES
EXCEPTIONS
ARGUMENT_ERROR = 1
NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
If it is run in background
IF SY-BATCH EQ C_TRUE.
WRITE: /5 'Directory cannot be opened'(039).
FL_FALSE = C_TRUE.
ELSE.
MESSAGE S000(ZZ_PA) WITH 'Directory cannot be opened'(039).
FL_FALSE = C_TRUE.
ENDIF. " IF sy-batch EQ c_true
ELSE.
LOOP AT T_AFILES INTO FS_AFILE.
IF FS_AFILE-NAME+0(2) EQ 'AD'.
IF FS_AFILE-NAME CS 'UNPAIRED'.
ELSE.
DELETE T_AFILES.
ENDIF. " IF FS_AFILE-NAME CP 'UNPAIRED'
ELSE.
DELETE T_AFILES.
ENDIF. " IF FS_AFILE-NAME+0(2) EQ 'AD'
ENDLOOP. " LOOP AT T_AFILES INTO FS_AFILE
IF T_AFILES[] IS INITIAL.
If it is run in background
IF SY-BATCH EQ C_TRUE.
WRITE: /5 'No Valid files found in the Directory'(040).
FL_FALSE = C_TRUE.
ELSE.
MESSAGE S000(ZZ_PA) WITH
'No Valid files found in the Directory'(040).
FL_FALSE = C_TRUE.
ENDIF. " IF sy-batch EQ c_true
ENDIF. " IF T_AFILES[] IS INITIAL
ENDIF. " IF SY-SUBRC <> 0
W_AFILE = PA_AFILE.
ENDIF.