Skip to Content
avatar image
Former Member

String manipulation

Hello expert,

I have an internal table contains strings. I have to delete the entry that contains some pattern. For example:

   *ABC       delete the entry that starts with ABC
   *ABC*      delete the entry that contains ABC
    ABC*      delete the entry that ends with ABC

Can someone tell me how I can manipulate the string. Are there any methods or functions to find the pattern in a String?

Thanks,

AS

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Jun 22, 2010 at 06:33 PM

    I guess I didn't explain well.

    Assume I have two internal tables as follow: The value in Table 1 is unknown (dynamic)

    >Table 1: Table 2:

    >ABCDE *ABC delete the entry if the string in Table 1 starts with ABC

    >GFABCDE FA delete the entry if the string in Table 1 contains FA

    >FGDEAED ED* delete the entry if the string in Table 1 ends with ED

    I have to find if the string in Table 1 contains * first, I then have to hold pattern such as ABC, FA, and or ED from Table 2,

    Finaly I have to find if the pattern is in the beginning of the string, middle of the string, or end of the string.

    Thanks,

    AS

    Please do not use code tags to format text.

    Edited by: Rob Burbank on Jun 22, 2010 2:35 PM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Neil Woodruff

      Hello, Thanks for all your help.

      I finally created a dynamic range table to solve my problem and it works well. Here is the code.

      *  ALV - Field catalog data
       DATA: l_fc  TYPE lvc_s_fcat,
             ltab_fc TYPE lvc_t_fcat,
             r_fld_desc  TYPE REF TO cl_abap_elemdescr.
      *       dy_range_table TYPE REF TO data.
      
      *   Get the field description
          r_fld_desc ?= cl_abap_typedescr=>describe_by_data( field ).
      
      *   Create a field catalogue of ALV for dynamic ranges table
          REFRESH ltab_fc.
          CLEAR l_fc.
          l_fc-fieldname = 'SIGN'.
          l_fc-datatype  = 'C'.
          l_fc-inttype   = 'C'.
          l_fc-intlen    = '1'.
          APPEND l_fc TO ltab_fc.
      
          CLEAR l_fc.
          l_fc-fieldname = 'OPTION'.
          l_fc-datatype  = 'C'.
          l_fc-inttype   = 'C'.
          l_fc-intlen    = '2'.
          APPEND l_fc TO ltab_fc.
      
          CLEAR l_fc.
          l_fc-fieldname = 'LOW'.
          l_fc-datatype  = r_fld_desc->type_kind.
          l_fc-inttype   = r_fld_desc->type_kind.
          l_fc-intlen    = r_fld_desc->length.
          l_fc-decimals = r_fld_desc->decimals.
          APPEND l_fc TO ltab_fc.
      
          CLEAR l_fc.
          l_fc-fieldname = 'HIGH'.
          l_fc-datatype  = r_fld_desc->type_kind.
          l_fc-inttype   = r_fld_desc->type_kind.
          l_fc-intlen    = r_fld_desc->length.
          l_fc-decimals = r_fld_desc->decimals.
          APPEND l_fc TO ltab_fc.
      
      *   call static method to create the dynamic range table
          CALL METHOD cl_alv_table_create=>create_dynamic_table
            EXPORTING
              it_fieldcatalog = ltab_fc
            IMPORTING
              ep_table        = dy_range_table.
      

      Edited by: Anna Smith on Jun 29, 2010 9:48 PM

  • avatar image
    Former Member
    Jun 22, 2010 at 05:16 PM

    This looks pretty basic to me. Have you pressed F1 on DELETE??

    Rob

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 22, 2010 at 05:28 PM

    you can write like

    delete str WHERE name CP 'ABC*'.

    delete str WHERE name CP 'ABC'.

    delete str WHERE name CP '*ABC'.

    Thanks

    Bala Duvvuri

    Edited by: Bala Duvvuri on Jun 22, 2010 11:29 AM

    Edited by: Bala Duvvuri on Jun 22, 2010 11:30 AM

    Add comment
    10|10000 characters needed characters exceeded