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: 

STRLEN

Former Member
0 Kudos

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 ). ???

9 REPLIES 9

Former Member
0 Kudos

Hi,

Hi use CS operator in the if condition.

eg if l_file cs '.xls'.

endif

regards,

Santosh Thorat

Former Member
0 Kudos

Hi,

if string length = 10.

data pos type i.
pos = strlen - 4.
last_four = i_file+pos(4).

Regards,

Satish

Former Member
0 Kudos

data: l type i.

l = strlen( l_file ) - 5.

if l_file+l(3) = '.xls'.

endif.

former_member386202
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

matt
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

matt
Active Contributor
0 Kudos

> 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

0 Kudos

its working fine.i checked it.

still gives sy -subrc = 0.

and sy-fdpos = 4.