Skip to Content
author's profile photo Former Member
Former Member

STRLEN

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 08:03 AM

    Hi,

    Hi use CS operator in the if condition.

    eg if l_file cs '.xls'.

    endif

    regards,

    Santosh Thorat

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 08:04 AM

    Hi,

    if string length = 10.

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

    Regards,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 08:07 AM

    data: l type i.

    l = strlen( l_file ) - 5.

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

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 08: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 08: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.

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 08: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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.