SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Проверка расширения файла



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
den
Старший специалист
Старший специалист



Joined: 11 Oct 2007
Posts: 103

PostPosted: Tue Feb 05, 2008 11:57 am    Post subject: Проверка расширения файла Reply with quote

На селекционном экране задается полный пусть к файлу. Он должен быть только txt. Как проверить?
Back to top
View user's profile Send private message
Armann
Модератор
Модератор



Joined: 01 Jan 2008
Posts: 422
Location: Moscow

PostPosted: Tue Feb 05, 2008 12:06 pm    Post subject: Reply with quote

1. Проверяйте расширение введенного файла в секции at selection screen ...
2. Чтобы получить расширение из полного имени - попробуйте ФМ PC_SPLIT_COMPLETE_FILENAME
Back to top
View user's profile Send private message Blog
den
Старший специалист
Старший специалист



Joined: 11 Oct 2007
Posts: 103

PostPosted: Tue Feb 05, 2008 1:26 pm    Post subject: Reply with quote

Armann, спасибо за полезную функцию.

Code:
PARAMETER: p_filename LIKE PCFILE-PATH.

DATA: DRIVE LIKE PCFILE-DRIVE,
          PATH LIKE PCFILE-PATH,
          EXTENSION(3).

AT SELECTION-SCREEN AT p_filename.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
  EXPORTING
    COMPLETE_FILENAME = p_filename
*CHECK_DOS_FORMAT =
  IMPORTING
     DRIVE = DRIVE
     EXTENSION = EXTENSION
*NAME =
*NAME_WITH_EXT =
     PATH = PATH
  EXCEPTIONS
    INVALID_DRIVE = 1
    INVALID_EXTENSION = 2
    INVALID_NAME = 3
    INVALID_PATH = 4
    OTHERS = 5.

IF EXTENSION NE 'TXT' AND EXTENSION NE 'txt'.
  MESSAGE I002 WITH 'The file name is invalid'.
ENDIF.
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 150
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Tue Feb 05, 2008 2:01 pm    Post subject: Reply with quote

Еще вариант, использовать для выбора имени файла ФМ, который не позволит ввести иное расшиерние, кроме заданного

Code:
DATA: file_filter TYPE string VALUE 'TXT files (*.txt*)|*.txt*'.

CLEAR wf_filename .
CALL METHOD cl_gui_frontend_services=>file_open_dialog
  EXPORTING
    window_title = 'Select the File'
    DEFAULT_EXTENSION = cl_gui_frontend_services=>FILETYPE_TEXT
    DEFAULT_FILENAME =
    FILE_FILTER = file_filter
    INITIAL_DIRECTORY =
    MULTISELECTION =
    CHANGING
    file_table = wf_filetab
    rc = wf_filerc
    USER_ACTION =
  EXCEPTIONS
    file_open_dialog_failed = 1
    cntl_error = 2
    error_no_gui = 3
    not_supported_by_gui = 4
    OTHERS = 5.
Back to top
View user's profile Send private message Blog Visit poster's website
Armann
Модератор
Модератор



Joined: 01 Jan 2008
Posts: 422
Location: Moscow

PostPosted: Tue Feb 05, 2008 2:46 pm    Post subject: Reply with quote

den, вместо этого:
Code:
IF EXTENSION NE 'TXT' AND EXTENSION NE 'txt'.
  MESSAGE I002 WITH 'The file name is invalid'.
ENDIF.


Лучше напишите так:
Code:
TRANSLATE EXTENSION TO UPPER CASE.
IF EXTENSION NE 'TXT'.
  MESSAGE I002 WITH 'The file name is invalid'.
ENDIF.

Тогда вы будете абсолютно уверены, что если вдруг ФМ вернет расширение 'Txt' или 'tXt' - все отработает правильно
Back to top
View user's profile Send private message Blog
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.