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

STRLEN of the variable

Hello,

Am getting string into variable which contains

Ex: (Defects recorded for 301000000454 work item)

this entire text storing into a string variable,Now

i need the number only 301000000454. How to get

number only using STRLEN i wrked but not getting exact number.

Plz let me know.

Regards

Martin

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Posted on Jan 29, 2008 at 06:25 AM

    Hi Martin

    lv_field = 'Defects recorded for 301000000454 work item'.
    
    lv_num = lv_field+21(12).
    
    data: lv_len type i.
    
    lv_len = strlen(lv_num).
    
    write:/ lv_len.

    Check this updated CODE

    Award points if helpful.

    Edited by: Jackandjay on Jan 29, 2008 1:36 AM

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      If you are using Message variable, then MSGV1, MSGV2.... one among them will be having the number.

      if you want logic to get it from the message, then use the below logic:

      str = 'Defects recorded for 301000000987 lotnumber'.

      SPLIT str AT ' ' INTO TABLE itab.

      loop at itab.

      CALL FUNCTION NUMERIC_CHECK.

      importing.

      STRING_IN = itab-text

      exporting

      HTYPE = type.

      if type = 'NUMC'.

      VAL = itab-text.

      EXIT.

      ENDIF.

      endloop.

      WRITE : / VAL. (val will contain the number)

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:32 AM

    Hi,

    If you are sure that always the output will be similar as the text you have given.

    Ex: Defects recorded for 301000000454 work item

    (i mean, except number, rest of the text will remain same?)

    If so, then do as follows:

    data: str type string.

    str = 'Defects recorded for 301000000454 work item'.

    len = strlen( str ).

    str1 = str+21(12).

    Write : / str1.

    If the text in the message varies, then use SPLIT statement using TABLE option separating by space. you will get the desired result.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:39 AM

    hi check this.

    data : s type string value 'Defects recorded for 301000000454 work item'.

    TYPES: BEGIN OF ITAB_TYPE,

    WORD(20),

    END OF ITAB_TYPE.

    DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE with header line.

    translate s to upper case.

    split s at space into table itab.

    loop at itab.

    if itab-word na sy-abcde.

    write itab-word.

    endif.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:44 AM

    DATA: v_lengts TYPE i,

    v_var1 TYPE string,

    v_var2(12) TYPE c.

    v_var1 = 'Defects recorded for 301000000454 work item'.

    v_lengts = STRLEN( v_var1 ).

    v_var2 = v_var1+21(12).

    write:/ v_var2.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:52 AM

    Hey Martin

    Try as below:

    DATA: str TYPE string VALUE
      'Defects recorded for 301000000454 work item'.
    
    DATA: num_c(100) TYPE n.
    
    num_c = str.
    
    SHIFT num_c LEFT  DELETING LEADING '0'.
    
    WRITE:/ num_c.
    

    Regards

    Eswar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:56 AM

    Hello here text varies each and every time but in text number is displayed every time,I need tht number only.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Martin,

      Try executing the code below in a temporary program and check the result. This is just to give an idea on how to handle in your case from the text in string.

      DATA: str TYPE string VALUE
        'Defects recorded for 301000000454 work item'.
      
      DATA: num_c(100) TYPE n.
      
      START-OF-SELECTION.
      
        PERFORM convert_number.
      
        str = 'Defect 289000000567detected for lot number'.
      
        PERFORM convert_number.
      
      *&---------------------------------------------------------------------*
      *&      Form  CONVERT_NUMBER
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM convert_number .
      
        num_c = str.
      
        SHIFT num_c LEFT  DELETING LEADING '0'.
      
        WRITE:/ num_c.
      
      ENDFORM.                    " CONVERT_NUMBER
      

      Consider STR as the variable which holds the string, now use the procedure as above to get the number. Number is available in variable NUM for your further processing.

      Regards

      Eswar

  • Posted on Jan 29, 2008 at 08:30 AM

    hello martin,

    try this code

    REPORT  ZKRIS_GETNUMFROMSTR.
    
    data: stri type string
     value 'Defects recorded for 301000000454 work item'.
    
    data: stri_up type string.
    stri_up = stri.
    data: length type i.
    data: output type string.
    data: charac.
    data: count type i.
    
    length = strlen( stri ).
    
    translate stri_up to upper case.
    do length times.
    
      charac = stri_up+count.
      if not sy-abcde ca charac.
        concatenate output charac into output.
      endif.
      count = count + 1.
    
    enddo.
    
    write:/ output.
    

    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.