Application Development 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: 

function module to return file path

Former Member
0 Kudos

Hello,

in my program i have a parameter where the user writes down where he wants the file to be saved when the program is over.

It works well.

My problem is that I need a function module that will allow the user to select in which folder he wants to save his files.

is there a FM that does this

THanks.

parvez

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use FM 'F4_FILENAME'.

Regards,

theja

8 REPLIES 8

Former Member
0 Kudos

Hi,

Use FM 'F4_FILENAME'.

Regards,

theja

Former Member
0 Kudos

Hi

Try using FM

F4_DXFILENAME_TOPRECURSION

Regards

Shiva

Former Member
0 Kudos

For application server file path :

CALL FUNCTION 'F4_DXFILENAME_4_DYNP'

EXPORTING

dynpfield_filename = 'P_OFILE'

dyname = sy-repid

dynumb = sy-dynnr

filetype = 'P'

location = 'A'.

For presentation server file path

FORM help_local_file CHANGING p_path TYPE any .

DATA: lt_file_table TYPE filetable,

la_file_table LIKE LINE OF lt_file_table,

l_rc TYPE i,

l_pcdsn TYPE cffile-filename.

REFRESH lt_file_table.

CLEAR la_file_table.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

CHANGING

file_table = lt_file_table

rc = l_rc.

READ TABLE lt_file_table INTO la_file_table INDEX 1.

l_pcdsn = la_file_table-filename.

MOVE l_pcdsn TO p_path.

ENDFORM.

Former Member
0 Kudos

Hi,

CHeck this prog.

data: begin of itab_string occurs 0,

record type char255,

end of itab_string.

data: L_FILETABLE TYPE FILETABLE,

L_FILETAB_H TYPE FILETABLE WITH HEADER LINE.

data: p_file1 type string.

selection screen .

PARAMETERS: P_FILE TYPE LOCALFILE.

initialization.

at selection-screen on value-request for P_FILE.

IF THE USER SELECT EXTENTION BUTTON IT WILL OPEN THE LOCAL DIRECTORY FOR SELECTING THE FILE LOCATION.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

EXPORTING

WINDOW_TITLE =

DEFAULT_EXTENSION = 'CSV'

DEFAULT_FILENAME = 'C:\Documents and Settings\196093\Desktop\STATUS.csv'

FILE_FILTER =

INITIAL_DIRECTORY = 'C:\Documents and Settings\196093\Desktop\'

MULTISELECTION =

WITH_ENCODING =

CHANGING

FILE_TABLE = L_FILETABLE

RC = RC

USER_ACTION =

FILE_ENCODING =

EXCEPTIONS

FILE_OPEN_DIALOG_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

NOT_SUPPORTED_BY_GUI = 4

others = 5

.

IF SY-SUBRC 0.

ELSE.

LOOP AT l_filetable INTO L_FILETAB_H.

P_FILE = L_FILETAB_H-FILENAME.

move p_file to p_file1.

EXIT.

ENDLOOP.

ENDIF.

passing the selected file name to gui_upload for loading the data

into internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = p_file1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ' '

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

DAT_MODE = ' '

CODEPAGE = ' '

IGNORE_CERR = ABAP_TRUE

REPLACEMENT = '#'

CHECK_BOM = ' '

NO_AUTH_CHECK = ' '

IMPORTING

FILELENGTH =

HEADER =

TABLES

DATA_TAB = itab_string

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC 0.

MESSAGE I000(Z00) WITH 'PLEASE PROVIDE CORRECT FILE NAME'.

ENDIF.

Regards,

Omkar.

Former Member
0 Kudos

Hi Sir ,

Please have a look below .Hope it is suitable and simpler solution for your question.

Please do reward if useful.

Thankx.

simply write this code in your program.

parameter:

p_file type rlgrap-filename.

*AT SELECTION-SCREEN.

at selection-screen on value-request for p_file.

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_FILE'

importing

file_name = p_file

exceptions

mask_too_long = 1

others = 2.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

0 Kudos

Thanks for your useful answers, but nothing has improved.

The FMs mentioned, only works when selecting a file. I need to select a folder and not a file.

Hope this will make my question clearer.

u will be rewarded, don;t worry.

thanks

0 Kudos

Hi,

Please use this call method, that should solve your problem.

Class is CL_GUI_FRONTEND_SERVICES and method is DIRECTORY_BROWSE.

Regards,

Omkar.

0 Kudos

thanks omkar,

but here I have another problem.

When I press F4, nothing happens.

But when I press F8 to execute my program, then the popup appears. The cancel button is ineffective and my files are note created inthe folder I have chosen.

What can be the problem???

thanks