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

One question about Selection screen

Former Member
0 Likes
1,467

Hi experts,

I am writing a report, on the selection screen, I need to input the file path and then do the file upload.

My question is about how to check the file path I put is correct or not? If it is incorrect, I want to get a message and the cursor still in the field and don't jump to the next page.

How can I do like that?

Any one has any suggestion, please help me.

Thanks in advance.

Regards,

Chris Gu

1 ACCEPTED SOLUTION
Read only

shishupalreddy
Active Contributor
0 Likes
1,412

Hello ,

Write the related code in AT SELECTION-SCREEN event

as below

If p_file Contains the reuired fiel type

for ex : .CSV , .TXT or .xls or .DAT

if u r condtion fails provide a Error messaage saying that File type is wrong ...

Regarding File path : If u have laredy the defined file path the u can use that

Regards

14 REPLIES 14
Read only

shishupalreddy
Active Contributor
0 Likes
1,413

Hello ,

Write the related code in AT SELECTION-SCREEN event

as below

If p_file Contains the reuired fiel type

for ex : .CSV , .TXT or .xls or .DAT

if u r condtion fails provide a Error messaage saying that File type is wrong ...

Regarding File path : If u have laredy the defined file path the u can use that

Regards

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
1,412

hi,

See the below pseudo code.


PARAMETERS : p_upload TYPE rlgrap-filename.
AT SELECTION-SCREEN.
****validations on p_upload.
  PERFORM f_validationson_upload.
*&---------------------------------------------------------------------*
*&      f_validationson_upload
*&---------------------------------------------------------------------*
FORM f_validationson_upload .
  DATA: lv_len       TYPE i.
  lv_len = STRLEN( p_upload ).
  lv_len = lv_len - 4.
  TRANSLATE p_dnload+lv_len TO UPPER CASE.
  IF p_dnload+lv_len NE '.XLS'. "--> if file is not of type .'XLS' ,it will throw an error message
    MESSAGE text-020 TYPE 'S'.
    LEAVE TO SCREEN 1000.
  ENDIF.

Thanks & REgards

Read only

Former Member
0 Likes
1,412

Hi,

use the FM

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

and method

CALL METHOD cl_gui_frontend_services=>directory_exist

CALL METHOD cl_gui_frontend_services=>file_exist

Pass related file in the above FM and methods and try to validate.

Regards,

jaya

Read only

Former Member
0 Likes
1,412

Hi,

The FM whichyou are using for uploading the file will through the error message, then you can write the code set cursor on field and next populate the error message.

Read only

Former Member
0 Likes
1,412

You can use FM: 'GUI_UPLOAD' to read the file into an internal table 'AT SELECTION-SCREEN' event. If filepath is wrong, SY-SUBRC at end of FM will not be 0. Check for that.

Read only

Former Member
0 Likes
1,412
PARAMETERS :
  p_path  TYPE rlgrap-filename.

AT SELECTION-SCREEN ON p_path.

  IF sscrfields-ucomm = 'ONLI'.
    PERFORM validate_file_path USING p_path.
  ENDIF.                               " IF SSCRFIELDS-UCOMM = 'ONLI'..


FORM validate_file_path USING pv_path LIKE p_path.

  DATA: lw_path TYPE string,
        lw_return TYPE abap_bool.

  lw_path = pv_path.
  IF sy-ucomm = 'ONLI' AND p_path IS INITIAL.
    CLEAR sscrfields-ucomm.
    MESSAGE e010(ad) WITH 'Fill in All the required fields'.
  ELSE.
    CALL METHOD cl_gui_frontend_services=>directory_exist
      EXPORTING
        directory            = lw_path
      RECEIVING
        result               = lw_return
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 4
        OTHERS               = 5.
    IF sy-subrc <> 0 OR lw_return IS INITIAL.
      CLEAR sscrfields-ucomm.
      MESSAGE e010(ad) WITH 'Invalid Path'.
    ENDIF.                             " IF SY-SUBRC <> 0 OR LW_RETURN.

  ENDIF.                               " IF SY-UCOMM = 'ONLI' AND P_PA.

ENDFORM.                               " FORM VALIDATE_FILE_PATH USING.

OR use: CALL METHOD cl_gui_frontend_services=>File_EXISTS

Regards,

Gurpreet

Read only

dev_parbutteea
Active Contributor
0 Likes
1,412

Hi,

You can use call method cl_gui_frontend_services=>file_exist to check if a file exists.

call method cl_gui_frontend_services=>file_exist

exporting

file = source_file_path

receiving

result = rc

exceptions

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

others = 4.

if sy-subrc <> 0.

raise cntl_error.

endif.

Regards.

Read only

Former Member
0 Likes
1,412

Hi Chris,

do it this way: check my code after calling gui_upload what condition i am using.

parameters:
  p_file type rlgrap-filename.          " File name

*"--------------------------------------------------------------------*
*           AT SELECTION-SCREEN ON VALUE-REQUEST EVENT                
*"--------------------------------------------------------------------*
at selection-screen on value-request for p_file.

  perform get_file_name.

*"--------------------------------------------------------------------*
*                       AT SELECTION-SCREEN EVENT                     
*"--------------------------------------------------------------------*
at selection-screen on p_file.

  perform validate_upload_file.

*---------------------------------------------------------------------*
*  Form  GET_FILE_NAME                                                
*---------------------------------------------------------------------*
form get_file_name.

  call function 'F4_FILENAME'
   exporting
     program_name        = syst-cprog
     dynpro_number       = syst-dynnr
     field_name          = ' '
   importing
     file_name           = p_file.

endform.                               " GET_FILE_NAME

*---------------------------------------------------------------------*
*  Form  VALIDATE_UPLOAD_FILE                                         
*---------------------------------------------------------------------*
form validate_upload_file.

  data:
    lw_file  type string.              " File Path

  lw_file = p_file.

  call function 'GUI_UPLOAD'
    exporting
      filename                    = lw_file
      filetype                    = 'ASC'
      has_field_separator         = 'X'
      dat_mode                    = 'X'
    tables
      data_tab                    = t_final_data.
 

  IF sy-subrc ne 0 and t_final_data is initial. " here message if file path is wrong
    Message 'File not found' type 'E'.
  ELSEIF sy-subrc eq 0 and t_final_data is initial.
    Message 'File empty' type 'E'.
  ENDIF.                               

endform.                               " VALIDATE_UPLOAD_FILE

With luck,

Pritam.

Edited by: Pritam Ghosh on May 8, 2009 8:57 AM

Read only

Former Member
0 Likes
1,412

May be this will help ful

Data : P_file(50) type c,

P_pathname(4) type c,

k(1024) type c.

constant : filepath(4) type c value '.txt'.

P_file = 'C:\Vendor.txt'.

k = strlen( p_file ).

k = k - 4.

p_pathname = p_file+k(4).

if filepath <> P_pathname.

Message 'Invalid path' TYPE 'E'.

Endif.

Read only

sarbajitm
Contributor
0 Likes
1,412

use FM F4_FILENAME in AT SELECTION-SCREEN ON VALUE-REQUEST event.

Regards.

Sarbajit.

Read only

Former Member
0 Likes
1,412

Hi,

Use this method CL_GUI_FRONTEND_SERVICES->FILE_EXIST ti check the existence of file.

PARAMETERS: p_file TYPE char100.
DATA : g_file TYPE string.
DATA p_result TYPE c.

AT SELECTION-SCREEN ON p_file.
  g_file = p_file.
  CALL METHOD cl_gui_frontend_services=>file_exist
    EXPORTING
      file                 = g_file
    RECEIVING
      result               = p_result
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      wrong_parameter      = 3
      not_supported_by_gui = 4
      OTHERS               = 5.
  IF p_result EQ ' '.
    MESSAGE e016(pn) WITH 'File Does not exist/Check the File path'.
  ENDIF.

Read only

Former Member
0 Likes
1,412

Hi,

You can use file_exist method of class cl_gui_frontend_services .

In the bellow code all your requirements are fulfilled .

TYPE-POOLS : abap.
DATA : w_result TYPE abap_bool,
       w_file TYPE string.

PARAMETERS : p_file(30) TYPE c.
w_file = p_file.
CONDENSE w_file   NO-GAPS.

CALL METHOD cl_gui_frontend_services=>file_exist
  EXPORTING
    file                 = w_file
  RECEIVING
    result               = w_result  " Imports the results 
  EXCEPTIONS
    cntl_error           = 1
    error_no_gui         = 2
    wrong_parameter      = 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 w_result NE 'X'.
  MESSAGE 'File path is not valid ! Enter a Valid path' TYPE 'I'.
  EXIT.   "  To retan the selection-screen If the file path is not correct
ENDIF.
WRITE : 'Test'.

Here if the w_result's value is 'X' then the file exists else does not exist.

So accordingly Message and Exit are used.

Regards

Pinaki

Read only

Former Member
0 Likes
1,412

Hi,

I have one doubt, I have input a correct file path and the file exists in the local server,

when I use the directory_exist method, result is still empty. Why?

Regards,

Chris Gu

Edited by: Gu Chris on May 8, 2009 10:28 AM

Read only

Former Member
0 Likes
1,412

Solved.

Used the file_exist method, I can get the result = 'X' if I enter the existed file path.

Thanks all.

Regards,

Chris Gu