12-04-2007 8:00 AM
Hi,
Cosider the following scenario:
I have filename stored in <b>l_file</b> (type string)
I want to determine if the last four chararcters are <b>.xls</b>
How do i proceed after i determine the length with strlen( l_file ). ???
12-04-2007 8:03 AM
Hi,
Hi use CS operator in the if condition.
eg if l_file cs '.xls'.
endif
regards,
Santosh Thorat
12-04-2007 8:04 AM
Hi,
if string length = 10.
data pos type i.
pos = strlen - 4.
last_four = i_file+pos(4).
Regards,
Satish
12-04-2007 8:07 AM
data: l type i.
l = strlen( l_file ) - 5.
if l_file+l(3) = '.xls'.
endif.
12-04-2007 8:07 AM
Hi,
Split into 2 strings at '.' using split statement then copmare second string if it .xls or not
SPLIT f AT g INTO h1 ... hn.
Regards,
Prashant
12-04-2007 8:08 AM
Hi,
You can try the below logic instead of STRLEN.
SPLIT filename AT '.' INTO file1 extension.
if extension = 'xls'.
Proceed further.
endif.
If you want to use STRLEN.
flen = STRLEN(filename).
flen = flen - 5.
exten = filename + flen(4).
if exten = '.xls'.
xxxxxxxxx
endif.
12-04-2007 8:32 AM
SPLIT and CS are nice ideas, but won't work with all strings. E.g.
mymalformedfilename1.xlsxyz - will pass with CS, but shouldn't.
mymalformedfilename2.xls.xls - will fail with SPLIT, but shouldn't.
Also, strlen with STRING types includes any following spaces, so they need to be removed first using condense.
How about this?
PERFORM check_xls USING: `x.xls`,
`mymalformedfilename1.xlsxyz`,
`mymalformedfilename2.xls.xls`.
*&---------------------------------------------------------------------*
*& Form check_xls
*&---------------------------------------------------------------------*
FORM check_xls USING i_fn TYPE string.
DATA: l_fn TYPE string,
l_len TYPE i.
WRITE: / i_fn.
l_fn = i_fn.
CONDENSE l_fn.
TRANSLATE l_fn TO UPPER CASE.
l_len = STRLEN( l_fn ).
SUBTRACT 4 FROM l_len.
IF l_fn+l_len(4) EQ '.XLS'.
WRITE: / 'Is valid'.
ELSE.
WRITE: / 'Is not valid'.
ENDIF.
ENDFORM.
matt
12-04-2007 8:56 AM
DATA F(20) VALUE 'file.xls'.
SEARCH F FOR '.xls' .
sy-subrc will be zero as <b>.xls</b> is found.
also sy-fdpos contains the offset.
12-04-2007 9:03 AM
> DATA F(20) VALUE 'file.xls'.
> SEARCH F FOR '.xls' .
>
> sy-subrc will be zero as <b>.xls</b> is found.
> also sy-fdpos contains the offset.
Fails on file.xlsxyz
matt
12-04-2007 9:24 AM
its working fine.i checked it.
still gives sy -subrc = 0.
and sy-fdpos = 4.