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: 

How to validate string ending with only .xls or .xlsx.

Former Member
0 Kudos

Hello gurus,

I'm using FM  F4_FILENAME, but I need filter for excel only, I want validate string like this:

P_FileName = 'C:\Documents and Settings\lfranco\Mis documentos\Mis imágenes\INDICADORES POOL\Prueba_Layout.xlsx'

I wnat validate this string finish in .xls or .xlsx

Could any one help me? I

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Luis,

   SEARCH gv_string for '.xls'.

   IF sy-subrc eq 0.

   ..........

Regards,

Archer

6 REPLIES 6

former_member235395
Contributor
0 Kudos

Hi Luis,

You can to use SPLIT sentence.... Like this

DATAp_filename TYPE string,

           data1   TYPE string,

           data2   TYPE string.

p_filename = 'C:\Documents and Settings\lfranco\Mis documentos\Mis imágenes\INDICADORES POOL\Prueba_Layout.xlsx'.

SPLIT p_filename AT '.' INTO data1 data2.


Work validating data2 variable   ----> XLS or XLSX.


Regards,

kashif_bashir
Explorer
0 Kudos


There are several options.

1- Use the cl_gui_fronend_services=>FILE_OPEN_DIALOG( . . .)

     You can set the  parameter FILE_FILTER = "X.XLS"

this will let user open only XLS type of files.

2-. Incase you want to check the file name after callinf f4 (What ever logic you are following) You can use string functions.

I can think of s simple one like.

data:   filename type string VALUE 'C:/abc/XYZ/me.xls',
           xls
type boolean VALUE abap_false.

(Assuming you want to check for .xls i.e 4 chars).

if '.xls' = substring( VAL = filename off = strlen( filename ) - 4 len = 4 ).

  xls
= abap_true.

endif.

I hope this is what you were after.

Regards,

Former Member
0 Kudos

Hi Luis,

   SEARCH gv_string for '.xls'.

   IF sy-subrc eq 0.

   ..........

Regards,

Archer

Former Member
0 Kudos

Hi,

You may use the below code.

  SPLIT LS_PATH AT LS_DELI INTO LS_PATH LS_EXTENSION.

  TRANSLATE LS_EXTENSION TO UPPER CASE.

  IF P_UP EQ 'X'.

    IF LS_EXTENSION NE TEXT-012 AND LS_EXTENSION NE TEXT-023 AND LS_EXTENSION NE TEXT-024. "XLS/XLSX/CSV

      MESSAGE E023(ZXXX). "Incorrect file extension(valid only XLS/XLSX/CSV)

    ENDIF.

  ELSE.

    IF LS_EXTENSION NE TEXT-012  AND LS_EXTENSION NE TEXT-024. "XLS/CSV

      MESSAGE E024(ZXXX). "Incorrect file extension(valid only XLS/CSV)

    ENDIF.

  ENDIF.

Regards,

Vadamalai A

Former Member
0 Kudos

Hi,

You may use the below code.

  SPLIT LS_PATH AT LS_DELI INTO LS_PATH LS_EXTENSION.

  TRANSLATE LS_EXTENSION TO UPPER CASE.

  IF P_UP EQ 'X'.

    IF LS_EXTENSION NE TEXT-012 AND LS_EXTENSION NE TEXT-023 AND LS_EXTENSION NE TEXT-024. "XLS/XLSX/CSV

      MESSAGE E023(ZXXX). "Incorrect file extension(valid only XLS/XLSX/CSV)

    ENDIF.

  ELSE.

    IF LS_EXTENSION NE TEXT-012  AND LS_EXTENSION NE TEXT-024. "XLS/CSV

      MESSAGE E024(ZXXX). "Incorrect file extension(valid only XLS/CSV)

    ENDIF.

  ENDIF.

Regards,

Vadamalai A

Former Member
0 Kudos

Easiest way is to get the file name and validate based on the code below...

FIND FIRST OCCURRENCE OF '.XLS' IN <filename> IGNORING CASE.


if syst-subrc eq 0.

* send an error message
endif.