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

Get file attributes

Former Member
0 Likes
1,727

Hi all,

My requirement is to upload flat file from presentation server, if in case if end user changes xyz.pdf to xyz.txt,

i have to check the file type, if it is a text file, then i have to do further processing.

Thanks in advance.

13 REPLIES 13
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,406

In the method: CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG pass '*.txt' to FILE_FILTER.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title     = 'Select Source File'
      default_filename = '*.txt'
      multiselection   = ' '
      file_filter      = '*.txt'
    CHANGING
      file_table       = l_itab
      rc               = l_subrc.

Edited by: Suhas Saha on Aug 16, 2010 4:38 PM

Read only

Former Member
0 Likes
1,406

Hi,

The end user can rename the pdf file as text file @ presentation server and if this file is uploaded using fm gui_upload, system gives to dump..

Read only

Former Member
0 Likes
1,406

Hi,

The end user can rename the pdf file as text file @ presentation server and if this file is uploaded using fm gui_upload, system gives dump..

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,406

Check this:


PARAMETERS: p_file TYPE string.

AT SELECTION-SCREEN.
  DATA: l_file TYPE pc_path,
        l_extn TYPE char3.

  IF sy-ucomm = 'ONLI'. "Execute Button(F8)
    l_file = p_file. "Assign seln-scr param 
    CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
      EXPORTING
        complete_filename = l_file
      IMPORTING
        extension         = l_extn
      EXCEPTIONS
        invalid_drive     = 1
        invalid_extension = 2
        invalid_name      = 3
        invalid_path      = 4
        OTHERS            = 5.
    IF sy-subrc = 0.
      IF l_extn NE 'TXT'.
        MESSAGE 'Please use .TXT file only' TYPE 'E'.
      ENDIF.
    ENDIF.

  ENDIF.

BR,

Suhas

Read only

0 Likes
1,406

Hi Suhas,

I dont think the problem is with the matter of extension, if so your earlier solution will work fine.

The end user can rename the pdf file as text file @ presentation server and if this file is uploaded using fm gui_upload, system gives to dump..

Does that do anything with the content ?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,406

Hello Keshav,

OP's requirement:

i have to check the file type, if it is a text file, then i have to do further processing.

In the earlier post, we can restrict the user to select .TXT files only. But he can jolly well change the extension to .DOC, .XLS, .PDF in the selection-screen.

The OP wants to check that while executing the report only .TXT file needs to be processed.

BR,

Suhas

Read only

0 Likes
1,406

Stupid me ... i was thinking that the user will change the extension at system level and then upload

Read only

Former Member
0 Likes
1,406

Hi Vemkatesh,

try this way.



  PARAMETERS : p_infile   TYPE rlgrap-filename.  "Input

AT SELECTION-SCREEN.
           
  IF p_pcfile CP '*.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'         "Excel file upload Function module
  ELSEIF p_pcfile CP '*.csv' OR p_pcfile CP '*.txt'.
    CALL FUNCTION 'GUI_UPLOAD'.                                     "* Text File and CSV file Open Upload Function Module
 ENDIF.


Prabhudas

Read only

0 Likes
1,406
  • CALL FUNCTION 'UPLOAD'

  • EXPORTING

  • filename = pa_fich

  • filetype = 'ASC'

  • TABLES

  • data_tab = ti

  • EXCEPTIONS

  • conversion_error = 1

  • invalid_table_width = 2

  • invalid_type = 3

  • YES_batch = 4

  • unkYESwn_error = 5

  • gui_refuse_filetransfer = 6

  • OTHERS = 7.

DATA: lfs_file TYPE file_table,

l_fname_tab LIKE table of lfs_file,

l_rc TYPE i,

l_p_def_file TYPE string,

l_p_file TYPE string,

l_user_act TYPE i.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

EXPORTING

DEFAULT_FILENAME = l_p_def_file

CHANGING

FILE_TABLE = l_fname_tab

RC = l_rc

USER_ACTION = l_user_act

EXCEPTIONS

FILE_OPEN_DIALOG_FAILED = 1

CNTL_ERROR = 2

ERROR_YES_GUI = 3

YEST_SUPPORTED_BY_GUI = 4

others = 5 .

IF sy-subrc = 0

AND l_user_act <> CL_GUI_FRONTEND_SERVICES=>ACTION_CANCEL.

LOOP AT l_fname_tab INTO lfs_file.

l_p_file = lfs_file.

EXIT.

ENDLOOP.

Elseif l_user_act EQ cl_gui_frontend_services=>action_cancel.

l_p_file = l_p_def_file.

ENDIF.

l_p_def_file = pa_fich.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = l_p_file

FILETYPE = 'ASC'

TABLES

DATA_TAB = ti

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

YES_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

YES_AUTHORITY = 6

UNKYESWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_YEST_ALLOWED = 9

SEPARATOR_YEST_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKYESWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

I think it will helps u when the user dynamically entered file type pass that variable to file type.just try it.

Read only

former_member201275
Active Contributor
0 Likes
1,406

Do 2 gui uploads, one for the pdf file and one for the txt file.

Fit each one of these between TRY, and, 'ENDTRY'.... then you shouldn't get dump and one of the uploads will work?

Read only

Former Member
0 Likes
1,406

Hi,

try this FM GUI_GET_FILE_INFO inorder to get tthe attributes of a file..

I hope this answer will help you.

Regards,

Kiran

Read only

Former Member
0 Likes
1,406

Hi,

Anyone provide solution to this issue, or any other way to solve this issue...

Thanks.

Read only

0 Likes
1,406

Hi,

Upload the files in Binary mode. Filetype = BIN. Read first line of data tab and try to identify if it is pdf.

Kind Regards

Michael