‎2008 Oct 25 8:53 AM
Dear All,
For example :
I have a file in 'C:\file\' folder as JN01.BP01.01:02:87
Except the first 9 chars JN01.BP01 all the other (01:02:87) will vary time by time.
So how can i set that path for the said above file just by comparing first 9 chars .
Note : The file type could be excel or text file.
regards
Siva
‎2008 Oct 25 9:36 AM
think of some different logic....i agree with Reddy....
is the file u want to read, the last file in that directory....or something else.???
this little piece of code may help u...
this program retrieves the filed and folders in a folder(desktop)...
REPORT program_to_to_show_desktop_files_and_execute_them.
DATA: desktop TYPE string, "---->u can pass ur base folder here
count TYPE i,
files TYPE STANDARD TABLE OF file_info WITH HEADER LINE,
path TYPE string.
cl_gui_frontend_services=>get_desktop_directory( CHANGING desktop_directory = desktop ).
cl_gui_cfw=>flush( ).
cl_gui_frontend_services=>directory_list_files( EXPORTING directory = desktop
CHANGING file_table = files[]
count = count ).
LOOP AT files.
WRITE:/ files-filename.
CLEAR files.
ENDLOOP.
AT LINE-SELECTION.
CONCATENATE desktop '\' sy-lisel INTO path.
cl_gui_frontend_services=>execute( EXPORTING application = path ) .
‎2008 Oct 25 8:57 AM
HI Siva,
You are saying that your file will be varying time by time so that case my suggestion is why dont you create a F4 help to read you file and one more requirement you are saying like it may be .xls or .txt so better call F4_FILENAME so that you can call any file.
Check this code.
PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = P_FNAME
.
So in this you can able to call type of file.
Cheers!!
Venkat
‎2008 Oct 25 9:02 AM
Hi,
Thansk for the reply. But here in my case the user is not allowed to select the path. This program has a preassigned path where it fetches the flat file from a predefiled location.'C:\file\'.
Human intervention is now allowed.
So what cani do in this regard ?
Siva
‎2008 Oct 25 9:14 AM
Hi Siva,
I think its pretty tricky requirement as like i am thinking for the logic how could we interpret the file path dynamically my doubt is how to make understand the system that this is my latest file to be uploaded.
According to my thought we have to code such that last 8 charcters i mean time i.e updated time has to be taken into account and put a breakpoint such that once the file is selected it should not select again.
According to idea try to make orelse will try to code.
Cheers!!
Venkat
‎2008 Oct 25 9:23 AM
Dear Reddy,
You are absoultely rite. this is a very tricky requiremnt. If the tme keeps on varying how can we code it ? For date wecan use system date in the requored format. But for time we cannot assume coz even a minue change can affect the tracking of file name. rite ?
Now is thre any way to read an existing file on a location without specifying any name and thenfindisng its name to compare the first 9 chars ??
Regards
sivaprasad
‎2008 Oct 25 9:01 AM
Ok
u can use
CONCATENATE 'C:\file\JN01.BP01.' <VAR> INTO <FOLDER>.
CONDENSE <FOLDER> NO-GAPS.
<VAR> contains the '01:02:87'.
now u have to find a way on how to get 01:02:87.....
‎2008 Oct 25 9:36 AM
think of some different logic....i agree with Reddy....
is the file u want to read, the last file in that directory....or something else.???
this little piece of code may help u...
this program retrieves the filed and folders in a folder(desktop)...
REPORT program_to_to_show_desktop_files_and_execute_them.
DATA: desktop TYPE string, "---->u can pass ur base folder here
count TYPE i,
files TYPE STANDARD TABLE OF file_info WITH HEADER LINE,
path TYPE string.
cl_gui_frontend_services=>get_desktop_directory( CHANGING desktop_directory = desktop ).
cl_gui_cfw=>flush( ).
cl_gui_frontend_services=>directory_list_files( EXPORTING directory = desktop
CHANGING file_table = files[]
count = count ).
LOOP AT files.
WRITE:/ files-filename.
CLEAR files.
ENDLOOP.
AT LINE-SELECTION.
CONCATENATE desktop '\' sy-lisel INTO path.
cl_gui_frontend_services=>execute( EXPORTING application = path ) .
‎2008 Oct 25 12:16 PM
hi Sukriti,
Code looks good but there is one question with me suppose if the last 8 characters are repeating then in that case what file will be accepted.
EXample today there is a file JS.......10:20:20
tomorrow at the same time file is savd then JS....10:20:20
in this case which file is read. Just for interest i have asked this have you thought of this too.?If any solutions then that make your code more valuable.
Cheers!!
Venkat
‎2008 Oct 25 12:41 PM
Dear Reddy,
The file name wont repeat. The ile name is a combination of date and time. So one day only file will be placed at the interface level.
So from the abov code we can get all the files from the given location folder and we can compare the date to sy-date with requored formats and confirm the file.
Thanks any way for all the supports.
best regards
Sivaprasad