Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic file name for BDC upload program

Former Member
0 Likes
979

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

1 ACCEPTED SOLUTION
Read only

ravi_lanjewar
Contributor
0 Likes
802

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.

5 REPLIES 5
Read only

Former Member
0 Likes
802

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.

Read only

0 Likes
802

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.

Read only

0 Likes
802

Move the files to a separate SAVE-folder after processing. Please don't ask how, there is plenty of information available.

Thomas

Read only

ravi_lanjewar
Contributor
0 Likes
803

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.

Read only

Former Member
0 Likes
802

Thanks Guys!