‎2011 May 12 1:25 AM
The client gets flat files everyday with different names. The name format would be "Vendor number_Invoicenumber" but the vendor number and the Invoice number could be different for every file, but the file location would be the same. The BDC program has to access the files and uploaded into a custom tables. Can the ABAP program be written so dynamic that it can access the flat file with different file names.
Any suggestions on this are welcome.
Thanks in advance
‎2011 May 12 6:04 AM
Hi,
You can read file Application Server file using Open dataset if you don't know file name, It is not issue.
Used any of following function module
RZL_READ_DIR Read directories of an application server
RZL_READ_DIR_GLOBAL Read directories of an application server
RZL_READ_DIR_LOCAL Read local directory
RZL_READ_DIR_REMOTE Read Remote Directory
RZL_READ_DIR_REMOTE_SH Read Directory: Cross Host Boundary via Remote OS Mechanism
you can try any of function module to read file name list in exist in folder.
Afer getting files name, I don't think you any issue to read file.
‎2011 May 12 1:29 AM
Get all files in specified directory using below code:
CALL 'C_DIR_READ_START' ID 'DIR' FIELD DIRNAME
ID 'FILE' FIELD FILENM
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
raise ACCESS_ERROR.
ENDIF.
DO.
CLEAR FILE.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD FILE-TYPE
ID 'NAME' FIELD FILE-NAME
ID 'LEN' FIELD FILE-LEN
ID 'OWNER' FIELD FILE-OWNER
ID 'MTIME' FIELD FILE-MTIME
ID 'MODE' FIELD FILE-FMODE
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
FILE-DIRNAME = DIRNAME.
MOVE SY-SUBRC TO FILE-SUBRC.
CASE SY-SUBRC.
WHEN 0.
CLEAR: FILE-ERRNO, FILE-ERRMSG.
CASE FILE-TYPE(1).
WHEN 'F'. " normal file.
WHEN 'f'. " normal file.
WHEN OTHERS. " directory, device, fifo, socket,...
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
IF FILE-LEN = 0.
MOVE SAP_NO TO FILE-USEABLE.
ENDIF.
WHEN 1.
EXIT.
WHEN OTHERS. " SY-SUBRC >= 2
ADD 1 TO ERRCNT.
IF ERRCNT > 10.
EXIT.
ENDIF.
IF SY-SUBRC = 5.
MOVE: '???' TO FILE-TYPE,
'???' TO FILE-OWNER,
'???' TO FILE-FMODE.
ELSE.
ENDIF.
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
* Does the filename contains the requested pattern?
* Then store it, else forget it.
IF PATTERN = NO_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ELSE.
IF FILE-NAME CP PATTERN.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ENDIF.
ENDIF.
ENDDO.
‎2011 May 12 3:15 AM
Amol- Thanks for the response, but as per your code, it gets all the files stored in the folder. In my requirement, this is not a one time process.The folder gets multiple files every day and once the file is uploaded, the second time it shouldn't be picked. Only the new files have to be uploaded.
‎2011 May 12 8:28 AM
Move the files to a separate SAVE-folder after processing. Please don't ask how, there is plenty of information available.
Thomas
‎2011 May 12 6:04 AM
Hi,
You can read file Application Server file using Open dataset if you don't know file name, It is not issue.
Used any of following function module
RZL_READ_DIR Read directories of an application server
RZL_READ_DIR_GLOBAL Read directories of an application server
RZL_READ_DIR_LOCAL Read local directory
RZL_READ_DIR_REMOTE Read Remote Directory
RZL_READ_DIR_REMOTE_SH Read Directory: Cross Host Boundary via Remote OS Mechanism
you can try any of function module to read file name list in exist in folder.
Afer getting files name, I don't think you any issue to read file.
‎2011 May 27 9:44 PM