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: 

Problem with Ws_filename_get

Former Member
0 Kudos

Hi all.

My code:

data: p_file(255).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_FLINP

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

  • def_path = ' '

MASK = ',.txt ,.txt.'

MODE = 'O'

TITLE = 'PC-File-Selection'

IMPORTING

FILENAME = P_FILE

  • RC =

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

IF SY-SUBRC = 0.

PR_FLINP = P_FILE.

ENDIF.

But don't work, I open the windows, select the file, and the program crashed.

something wrong in importing|exporting parameters?

1 ACCEPTED SOLUTION

dani_mn
Active Contributor
0 Kudos

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

mask = ',TXT File,.txt.,All Files,.*.'

mode = '0'

IMPORTING

filename = filenm

  • RC =

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

MOVE filenm TO filename.

ENDIF.

Regards,

Wasim Ahmed

14 REPLIES 14

Former Member
0 Kudos

check this way

Declare PARAMETERS: <b>p_file LIKE rlgrap-filename</b> instead of Char

*Selecting a File, plus inserting default file extension

parameters: p_file like rlgrap-filename default 'c:\hesa.txt' LOWER CASE.

************************************************************************

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR I_FILE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR i_file.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = p_file

mask = ',*.xls.'

mode = 'O'

title = 'Upload File'(078)

IMPORTING

filename = p_file

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

Here is the Link

http://www.sapdevelopment.co.uk/file/file_fmfile.htm

http://www.sapdevelopment.co.uk/file/file_uptabpc.htm

Regards,

Santosh

0 Kudos

<b>DEF_FILENAME = SPACE</b>---> wrong

dani_mn
Active Contributor
0 Kudos

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

mask = ',TXT File,.txt.,All Files,.*.'

mode = '0'

IMPORTING

filename = filenm

  • RC =

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

MOVE filenm TO filename.

ENDIF.

Regards,

Wasim Ahmed

Former Member
0 Kudos

hi

better use F4_FILENAME fm instead of WS_FILENAME_GET

chk this sample

<b>data: p_header type string.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_UNIX'

IMPORTING

FILE_NAME = P_HEADER.</b>

Former Member
0 Kudos

Hi Fabizio,

I think WS_FILENAME_GET is a obsolete FM . Better go for the FILE_OPEN_DIALOG method of CL_GUI_FRONTEND_SERVICES.

here is the code...

data: it_tab type filetable with header line,

gd_subrc type i.

tables: rlgrap.

selection-screen: begin of screen 200.

parameters file_nam type rlgrap-filename .

selection-screen: end of screen 200.

data: user_act type i.

start-of-selection.

call selection-screen 200.

at selection-screen on value-request for file_nam.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

WINDOW_TITLE = 'select a file'

  • DEFAULT_EXTENSION =

DEFAULT_FILENAME = ''

FILE_FILTER = '*.txt'

INITIAL_DIRECTORY = 'D:\SP'

  • MULTISELECTION = 'X'

  • WITH_ENCODING =

CHANGING

file_table = it_tab[]

rc = gd_subrc

USER_ACTION = user_act

  • 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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

if user_act = '0'.

read table it_tab index 1 .

file_nam = it_tab-filename.

endif.

<b>Regarding your program, all u need to do is specify the parameters as follows:

parameters: pr_flinp type rlgrap-filename.</b>

Regards,

SP.

Simha_
Employee
Employee
0 Kudos

Hi check out...

AT SELECTION-SCREEN ON VALUE-REQUEST FOR path.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = 'C:\TEST.txt'

def_path = 'C:\ '

mask = ',.,..'

mode = 'O '

title = 'OPEN '

IMPORTING

filename = path

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE 'File upload path incorrect. Please try again !' TYPE 'I'.

ENDIF.

May be ur file name is wrong...

check out the backward slash and foeward slash giving in the path of the file..

cheers,

Simha.

former_member181962
Active Contributor
0 Kudos

Filename can take only 128 characters.

You have given 255 charaters.

Former Member
0 Kudos

Ihave just aded one line to your code.. so check is you have declared in same way.

data: p_file(255).

PARAMETERS PR_FLINP LIKE FCINTAB-FILENAME1 OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_FLINP.<-added

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

  • def_path = ' '

MASK = ',.txt ,.txt.'

MODE = 'O'

TITLE = 'PC-File-Selection'

IMPORTING

FILENAME = P_FILE

  • RC =

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

IF SY-SUBRC = 0.

PR_FLINP = P_FILE.

ENDIF.

Former Member
0 Kudos

Hi Fabrizio,

Your modified program would look like this:

parameters: pr_flinp type rlgrap-filename.

data: p_file(255).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_FLINP.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

  • def_path = ' '

MASK = ',.txt ,.txt.'

MODE = 'O'

TITLE = 'PC-File-Selection'

IMPORTING

FILENAME = P_FILE

  • RC =

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

IF SY-SUBRC = 0.

PR_FLINP = P_FILE.

ENDIF.

Regards,

SP.

Former Member
0 Kudos

Dont work... I tried also F4_fILENAME, but the same problem... when select the file into the window the the screen is freezed,i don't know...

Former Member
0 Kudos

Hello Fabrizio,

I tried ur code and added the param.

PARAMETERS PR_FLINP LIKE FCINTAB-FILENAME1 OBLIGATORY. have u declared it similarly. Can u show the code is it working fine with me.

Former Member
0 Kudos

<b>parameters : pr_flinp(255).

data : p_file type string.</b>

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_FLINP.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

  • def_path = ' '

MASK = ',.txt ,.txt.'

MODE = 'O'

TITLE = 'PC-File-Selection'

IMPORTING

FILENAME = P_FILE

  • RC =

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

IF SY-SUBRC = 0.

PR_FLINP = P_FILE.

ENDIF.

<b>this works</b>

Former Member
0 Kudos

Hi

You should declare PR_FLINP in the code as " LIKE FCINTAB-FILENAME1" coz in the statement "AT SELECTION-SCREEN ON VALUE-REQUEST FOR PR_FLINP" PR_FLINP should be followed by a parameter or a select-option.

Then it will work fine.

Swathi

Former Member
0 Kudos

Ok thanks all, now work, maybe the problen was the bite difference.

Points for all

Thanks