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

File format determination

Former Member
0 Likes
696

Hi friends,

Is there a way to determine the format of the flat file ( eg: Excel, notepad etc ) based on the file path where the file is located.

Thanks in Advance,

Ram.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
669

Hai,

Try like this:

1. Get file using :

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = sy-cprog

dynpro_number = sy-dynnr

field_name = space

IMPORTING

file_name = p_local.

  • where P_local is parameter ( p_local TYPE rlgrap-filename MODIF ID m2.)

2. Check file as following:

DATA: lv_file TYPE string, "File path with name

lv_ext(3) TYPE c.

    • Get file extension

SPLIT p_local AT c_dot INTO lv_file lv_ext.

TRANSLATE lv_ext TO UPPER CASE.

      • IF file is excel get data from excel sheet

IF lv_ext = 'XLS'.

PERFORM get_xls_file USING lv_file.

ELSE.

    • Else get file from gui download

PERFORM get_txt_file USING lv_file.

ENDIF. "lv_ext

4 REPLIES 4
Read only

Former Member
0 Likes
669

i can suggest onse solution.

Get the file path. Get the string after last '.'(dot).

Compare this string with known file extensions.

Award Points if useful

Bhupal

Read only

Former Member
0 Likes
669

Hi Ram,

U can mention the files as

c_doa0001 sy-datum sy-uzeit '-' t_vsart-vsart '.txt'

this file is text file..which is gonna store in application server..under the repectively path..

Like that u can give the .XXX respective extension..to XL or watever u nee...

Regards,

Ari

Read only

Former Member
0 Likes
670

Hai,

Try like this:

1. Get file using :

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = sy-cprog

dynpro_number = sy-dynnr

field_name = space

IMPORTING

file_name = p_local.

  • where P_local is parameter ( p_local TYPE rlgrap-filename MODIF ID m2.)

2. Check file as following:

DATA: lv_file TYPE string, "File path with name

lv_ext(3) TYPE c.

    • Get file extension

SPLIT p_local AT c_dot INTO lv_file lv_ext.

TRANSLATE lv_ext TO UPPER CASE.

      • IF file is excel get data from excel sheet

IF lv_ext = 'XLS'.

PERFORM get_xls_file USING lv_file.

ELSE.

    • Else get file from gui download

PERFORM get_txt_file USING lv_file.

ENDIF. "lv_ext

Read only

0 Likes
669

Thanks allot guys,

You have solved my problem.

Cheers,

Ram.