SUBSTRING

In the select query how to search for a particular part of data. (in ABAP code)
Table         : ABC
Field name    : Category
Field content : Enterprise.
Query : Select * from ABC where substr(category,1,3) ='Ent'.
[The query should check the complete table ABC and list all the category where the first three characters are = 'Ent']

Hi,
Query : Select * from ABC where category like '%Ent%'.
More info about LIKE in the SAP documentation:
f [NOT] LIKE g
Addition:
... ESCAPE h
Effect
The condition is met for a table entry if the statement "f (does not) equal the pattern in g" is true for the values of f and g. f must always be a field descriptor, and g an ABAP field or an ABAP string. If f has the value NULL, then the result of the check for the statement is unknown. Within a pattern, there are two special characters:
'_' (underscore) stands for any single character.
'%' (percentage sign) stands for any sequence of characters, including an empty string.
Examples
Example to select all customers whose name begins with 'M':
DATA SCUSTOM_WA TYPE SCUSTOM.
SELECT ID NAME FROM SCUSTOM
       INTO CORRESPONDING FIELDS OF SCUSTOM_WA
       WHERE NAME LIKE 'M%'.
  WRITE: / SCUSTOM_WA-ID, SCUSTOM_WA-NAME.
ENDSELECT.
Example to select all customers whose name contains 'huber':
DATA SCUSTOM_WA TYPE SCUSTOM.
SELECT ID NAME FROM SCUSTOM
       INTO CORRESPONDING FIELDS OF SCUSTOM_WA
       WHERE NAME LIKE '%huber%'.
  WRITE: / SCUSTOM_WA-ID, SCUSTOM_WA-NAME.
ENDSELECT.
Example to select all customers whose name does not contain 'n' as the second character:
DATA SCUSTOM_WA TYPE SCUSTOM.
SELECT ID NAME FROM SCUSTOM
       INTO CORRESPONDING FIELDS OF SCUSTOM_WA
       WHERE NAME NOT LIKE '_n%'.
  WRITE: / SCUSTOM_WA-ID, SCUSTOM_WA-NAME.
ENDSELECT.
Notes
LIKE can only be used for alphanumeric database fields. In other words, table field f must have Dictionary type ACCP, CHAR, CLNT, CUKY, LCHR, NUMC, UNIT, VARC, TIMS or DATS. The comparison field g must always have type C.
The maximum length of the pattern is 2n - 1 characters, where n is the length of field f.
Trailing spaces are ignored in comparison field g. If a pattern contains trailing spaces, you must enclose it in single inverted commas ('). If your pattern is enclosed in inverted commas and you also want to include inverted commas as part of the pattern, the inverted commas in the pattern must be doubled.
You cannot use this variant in the ON addition to the FROM clause.
Thanks,
Ramakrishna

Similar Messages

  • IF and SUBSTR in XML Publisher

    Hi
    I am developing a XML RTF template for a report.
    All I am trying to do is, if first 4 letters of the data of xml tag ITEM = 'Summ'
    then print a constant word 'Notes'
    <?if: xdofx:substr(ITEM,1,4)=’Summ’?> Notes<?end if?>
    I have been trying hard. IF and SUBSTR is not at all going along. Always throwing some error. Can some one please help me to resolve this issue
    Thanks

    Hi,
    I have a similar requirement, however instead of static text in the example i.e ITEM I am trying to get a substring from a tag value directly. Ex - Tag Value <eod>23-10-2009<eod>. I am trying to pick up the value 10 in the particular example and trying to compare with 1, which would be false and hence I need to print as false. I cannot use a hardcoded value since the value between the tags <eod> is dynamic and I need to use that itself.
    Can you please provide me with the sytax which can achieve this?
    Regards,
    Praseed

  • Can we use Trunc,Substr in Excel templates

    Hi All,
    I have a date xml tag with value like "2012/04/01 00:00:00" i need to show this in excel output as "01-APR-2012".
    I am using Excel template, need your help to achieve the same.
    I tired to use Trunc,Substr,Format date but nothing is working.
    Please give me your valuable inputs to solve this issue.
    Thanks
    Rajehs

    Varma,
    Thanks for the reply, i have already checked the link but it doesn't have syntax to use Trunc,substr etc. functions.
    Also date in example is - "1996-02-03T00:00:00.000-07:00" , but in my case date format is different "2012/01/01 00:00:00".
    Thanks
    Rajesh

  • How to find a substring in XML-lookslike string?

    Hi,
    I have a question and wondering if anyone can help me with it.
    We have Java tool that does a string replacement inside another string (that is actually an XML request). It works fine when searching for a simple substring (that exists within 1 line of the XML string).
    But when I'm trying to find and replace a substring that covers more then 1 line of XML request - it does not work. And I'm not sure what is wrong or (more importantly) how to make it work.
    There is no return or new-line chars seen in the XML request.
    To make it more clear - here is what I have and trying to do:
    <a>
    <a>
    <b>
    <c>
    <d> </d>
    <c>
    <c>
    </c>
    </c>
    </c>
    </b>
    </a>
    </a>
    If I'll seach for either <c> OR </c> OR <d> </d> it all works fine ... BUT if Itry to find
    </c>
    </b>
    which will be copied directly from the XML request and past into field - thus it will look like this (horisontal line instead of vertical) </c> </b> - it does not work

    qavlad wrote:
    But when I'm trying to find and replace a substring that covers more then 1 line of XML request - it does not work. First statement - "more than 1 line"
    There is no return or new-line chars seen in the XML request.Second statement.
    There is no way that I can understand what you meant in your first statement in terms of your second.
    If there are no end of line characters at all then there is only one line. Period.
    If there are end of line characters, of any kind, then that would really suggest the source of the problem.

  • Get the values using substr

    Hi All,
    i am a comma seperated values into a variable. below are the values.
    "1234567,3,124567,3,14"
    the length of the values can vary. eg the output can also be
    "123,3,124567,443,1224"
    I need to get each value and store it a separate variable. is it possible using substr..?
    Please help me out...

    Hi,
    Here's how you can split a delimited list into parts in Oracle 9:
    WITH     got_part_cnt     AS
         SELECT     pk
         ,     csv
         ,     1 + LENGTH (csv)
                - LENGTH (REPLACE (csv, ','))     AS part_cnt
         FROM     table_x
    ,     cntr     AS
         SELECT     LEVEL     AS n
         FROM     ( SELECT  MAX (part_cnt)     AS max_part_cnt
                FROM       got_part_cnt
         CONNECT BY     LEVEL <= max_part_cnt
    ,     got_pos          AS
         SELECT     p.pk
         ,     p.csv
         ,     c.n
         ,     INSTR ( ',' || p.csv
                    , 1
                    , c.n
                    )          AS start_pos
         ,     INSTR ( p.csv || ','
                    , 1
                    , c.n
                    )      AS end_pos
         FROM    got_part_cnt     p
         JOIN     cntr          c     ON     c.n     <= p.part_cnt
    SELECT       pk
    ,       csv
    ,       n
    ,       SUBSTR ( csv
                 , start_pos
               , end_pos - start_pos
               )               AS item
    FROM       got_pos
    ORDER BY  pk
    ,            n
    ;Pk is the primary key of table_x. If you don't need it, you can omit it.
    Of course, this will work in versions later than 9, but you wouldn't want to if you could use REGEXP_SUBSTR.

  • How we get all string from substring,.,.

    Hi,
    I am doing one application . In that i have to enter substrubg in search user inputfield and then i click on search . Not i want to show all user which contain that substring . So please guide in that.
    Example...
    Like i am writing "ab*" then all users comes which contain ab substring.
    Regards,
    Gurprit Bhatia

    Hi,
    Try this logic.
    String searchString="ab*";
    searchString=searchString.subString(0,searchString.length-2);
    String[] matchedArray=new matchedArray(100);
    int j=0;
    //Let your compare strings be in an array strArray
    for(int i=0;i<strArray.length;i++){
    String temp=strArray<i>.subString(0,searchString.length-2);
    if(temp.equals(searchString)){
      matchedArray[j]=strArray<i>;
      j++;
    Then display the matched String array.
    Hope it helps.
    Regards,
    Srinivasan Subbiah

  • Need help in using SUBSTR

    Hi,
    I have a table tablea where a column stores values like ABC LTD,BCD LTD,CEF LTD,DEFEF LTD.
    I want the output as
    ABC,BCD,CEF,DEF
    i have used substr but could not frame the result as the last value stores DEFEF so culd not do substr(1,3) from the table
    Any help will be needful for me
    Edited by: user13443042 on Jan 26, 2011 2:31 AM

    You mean like this?
    SQL> ed
    Wrote file afiedt.buf
      1  select trim('.' from replace('ABC LTD,BCD LTD,CEF LTD,DEF LTD.',' LTD'))
      2* from dual
    SQL> /
    TRIM('.'FROMREP
    ABC,BCD,CEF,DEF
    SQL>However, it looks like your data structure is wrong. You shouldn't store multiple values in a single string in a colulmn. These should be multiple records or multiple columns as appropriate.

  • How to use substr in external table defnition.

    Hi All,
    Im using oracle 11g. I have an external table which is reading data from a file. For one of the column, i need to get only the first 250 characters. My external table defnition looks like this
    create table tbl_substr
    ( col1 varchar2(20),
    col2 varchar2(250)
    organization external
    ( type oracle_loader
    default directory XXXX
    access parameters (
    records delimited by newline
    FIELDS TERMINATED BY '|'
    missing field values are null
    ( col1 ,
    col2 "substr(:col2,1,250)"
    ) ) location ('file.txt') )
    reject limit unlimited
    But this defnition gives an error when i do select * from tbl_substr
    I want to use substr in external table defnition its self and not in SELECT. Also i dont want to crete a view to solve this. If anyone has done this please help.

    You need to play with COLUMN_TRANSFORMS
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/et_params.htm#sthref1792
    BTW, i too got it from Google. I was not aware about this :)
    Amardeep Sidhu

  • How to select a substring in oracle up to a more than one specific character

    How to select a substring in oracle up to a more than one specific character
    for ex : 121.051^NP: FAMILY PRACTICE  ( trim the values before ^ )
                121.051^*NP: FAMILY PRACTICE (trim the value before *).
    with below function I can only get rid of ^ , I want both the specific characters ^ and ^* to be removed at the same time.   
    SUBSTR(p.phys_sub_grp_2_desc,INSTR(p.phys_sub_grp_2_desc, '^') +1)

    Another option is to boldly replace 'em:
    SQL> with t as (
      2  select '121.051^NP: FAMILY PRACTICE' str from dual union
      3  select '121.051^*NP: FAMILY PRACTICE' from dual
      4  )
      5  --
      6  -- actuel query:
      7  --
      8  select substr( replace(str, '*')
      9               , instr(replace(str, '*'), '^')+1
    10               ) str
    11  from   t;
    STR
    NP: FAMILY PRACTICE
    NP: FAMILY PRACTICE
    2 rows selected.

  • How to use a parameter field value as a substring in a "like" statement?

    Hi all,
    I'm trying to use a parameter field in a Record selection formula where the parameter field value would be a substring of the data stored in the field.
    My parameter field (SlctResearcher) is constructed as follows:
    Type: string
    List of Values: static
    Value Field: (Reports) RptAuthors
    (in Value Options) Allow custom values?: True
    {Reports.PubDate} in DateTime (2009, 04, 01, 00, 00, 00) to DateTime (2010, 03, 31, 23, 59, 59) and
    {Reports.RptAuthors} like "*{?SlctResearcher}*"
    When I hit F5 to generate the data, I get no results (and the parameter prompt field does not even come up...)
    If I modify the formula to put a hard-coded string, like
    "*Jones*"
    after the 'like', I get results (all the reports where "Jones" is a substring in the RptAuthors string.) If I modify the formula to just use the parameter field without the quotes/stars like:
    {Reports.PubDate} in DateTime (2009, 04, 01, 00, 00, 00) to DateTime (2010, 03, 31, 23, 59, 59) and
    {Reports.RptAuthors} like {?SlctResearcher}
    I do get the parameter prompt field, but still no results even if I put in a valid substring value (since it is not searching for a substring anymore...)
    How can I do this?
    Thanks,
    Will

    1st thing... Make a copy of your report before doing anything!!!
    To use a SQL Command, you'll want to open the Database Expert and look at the Current Connections. Expand the data source and the 1st option you see is the Add Command option.
    To find the SQL That CR is currently using, choose Database from the menu bar and select Show SQL Query...
    You can copy this and paste it directly into the command window. (If you you can write your own SQL you don't need copy CR's, it's just an option.)
    You'll also want to take not of any parameters that you have, you'll need to add them the the Parameter List of the command as well... be sure to spell them EXACTLY as they are in the design pane.
    Anyway, once the SQL statement is in the Command window you'll be able to alter the WHERE clause to use the wild cards.
    For future reference... What type of database are you reporting against???
    Jason

  • How do I update the substring of a string value?

    UPDATE table1
    SET  SUBSTR  (TO_CHAR(field_value),3,2) = ' 50'  and SUBSTR (TO_CHAR(field_value),5,2)  =  '50'
    where  ( SUBSTR(TO_CHAR(field_value), 3, 2) =  '100' ) or ( SUBSTR(TO_CHAR(field_value), 5, 2) =  '100' )tried the above in TOAD and I got "ORA-00927: missing equal sign." Please help!
    data type for field_value is number. oracle version is 10g
    thank you

    Here's an example of how you can do it:
    SQL> CREATE TABLE x
      2  AS
      3  SELECT 'SOME50HERE' AS field_x
      4  FROM dual;
    Table created.
    SQL> SELECT * FROM x;
    FIELD_X
    SOME50HERE
    1 row selected.
    SQL> UPDATE x
      2  SET    field_x =  SUBSTR(field_x,1,4)
      3                 || '75'
      4                 || SUBSTR(field_x,7)
      5  ;
    1 row updated.
    SQL> SELECT * FROM x;
    FIELD_X
    SOME75HEREBasically you need to break your string into three parts:
    1. The part before the text you want to change.
    2. The text you want to change.
    3. The part after the text you want to change.
    Then you concatenate them all together.
    If #1 is not a known fixed number of characters, you can still use SUBSTR, by looking for the string you want to change like the following:
    UPDATE x
    SET    field_x =  SUBSTR(field_x,1,INSTR(field_x,'50') - 1)
                   || '75'
                   || SUBSTR(field_x,7)
    ;

  • Error while converting CLOB to varchar using DBMS_LOB.SUBSTR() in Oracle11g

    Hi
    Whenever I am using DBMS_LOB.SUBSTR(columnname,4000,1) package for a clob column in a simple Select Query, the following error is thrown for Oracle 11g version.
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1.
    Please find the installation details of the database and the character set
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    PARAMETER VALUE
    NLS_LANGUAGE AMERICAN
    NLS_TERRITORY AMERICA
    NLS_CURRENCY $
    NLS_ISO_CURRENCY AMERICA
    NLS_NUMERIC_CHARACTERS .,
    NLS_CHARACTERSET AL32UTF8
    NLS_CALENDAR GREGORIAN
    NLS_DATE_FORMAT DD-MON-RR
    NLS_DATE_LANGUAGE AMERICAN
    NLS_SORT BINARY
    NLS_TIME_FORMAT HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY $
    NLS_COMP BINARY
    NLS_LENGTH_SEMANTICS BYTE
    NLS_NCHAR_CONV_EXCP FALSE
    NLS_NCHAR_CHARACTERSET AL16UTF16
    NLS_RDBMS_VERSION 11.2.0.1.0
    It is working fine if I reduce from 4000 to 3500 . But I want to use 4000.
    Please let me know if any solution

    you are using a multibyte character set:
    NLS_CHARACTERSET AL32UTF8
    so each character takes between 1 and 4 bytes of storage.
    a varchar2(4000) column can only hold 4000 BYTES. Regardless of the character set - varchar2 is limited to 4000 bytes.
    In a single byte character set, that is 4000 characters as a character = a byte
    In your character set, a varchar2(4000) can hold somewhere between 1000 and 4000 characters - depending on what the characters are.
    So, you must have some CLOB whose first 4000 characters include at least one "more than one byte" character. That won't fit into a varchar2(4000)
    Your approach of backing off the substr size is reasonable (and you'll need to remember that in your application - end users can type in as little as 1000 characters and get an error about the column being too small!) as it reduces the number of BYTES to be belong 4000.

  • Receiver determination using substring in filename in file adapter

    Hi
    In PI 7.11 I would like to determine the receiver based on a substring in the filename in a file receiver adapter. I am planning on using a context object but am having trouble entering the correct code in the "Right Operand" field.
    I have tried selecting Context Object = Filename http://sap.com/xi/XI/System/File and entering this code in the Right Operand: "contains(substring('_4000_'))"   and an "=" in the as I am looking for a filename, that contains the substring "_4000_".
    I would like to avoid using an extra map and using Dynamic Configuration, as I thing this would be the most elegant way of fixing it
    Is there a way of referencing the context object if I chose xpath in stead of context object?
    MIkael

    Hi Mikael,
    I have the same scenario like you , could you please tell me about the condition how to you use XPath for Context Object
    I need to check the file name and according to that I have to put the file in the different directory.
    Source File: XXXX_IN_xxxx
                       XXXX_PH_xxxx
    I have to check the 7th and 8th Char of the file and according to that I have to place the file in the folder
    Target: DGE008\IN\Inbound
                DGE008PH\Inbound
    I don't know how to used the XPATH for file and specially how to use the substring in that.
    Could you please help.
    Thanks,

  • Get substring of file name up to the last underscore

    I have filenames and I want to get a substring of the file name up to the last underscore if it exists and if not up to the last period.
    Create table FileNames (fileName varchar(40))
    insert into FileNames values ('this_is_a_long_filename.ext')
    insert into FileNames values ('this_is_an_even_longer_filename.ext')
    insert into FileNames values ('short_filename.ext')
    insert into FileNames values ('supershort.ext')
    What I want returned is:
    this_is_a_long
    this_is_an_even_longer
    short
    supershort
    Any help would be appreciated.
    lg

    This will work too... 
    IF OBJECT_ID('tempdb..#FileNames') IS NOT NULL
    DROP TABLE #FileNames
    GO
    CREATE TABLE #FileNames (
    fileName varchar(40)
    insert into #FileNames values ('this_is_a_long_filename.ext')
    insert into #FileNames values ('this_is_an_even_longer_filename.ext')
    insert into #FileNames values ('short_filename.ext')
    insert into #FileNames values ('supershort.ext')
    SELECT
    fn.fileName,
    LEFT(fn.fileName, LEN(fn.fileName) - COALESCE(NULLIF(PATINDEX('%[_]%', REVERSE(fn.fileName)), 0), PATINDEX('%.%', REVERSE(fn.fileName))))
    FROM
    #FileNames fn
    Jason Long

  • XSLT substring issue

    Hi All,
    I've got XSLT issue.
    Suppose in XML I have string like that :
    world.country.town.Moskow.SomeOtherValue
    Capitalized word/s/ is/are/ always at the end.
    Using XSLT how to get substring returning capitalized words only i.e Moskow.SomeOtherValue
    Thanks

    Hi,
    Here are two possible solutions :
    1) If you can run XSLT 2.0, then you may use a regular expression :
    Sample XML :
    <test>world.country.town.Moskow.SomeOtherValue</test>
    <?xml version="1.0"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="/">
    <xsl:analyze-string select="test" regex="\.([A-Z].*)$">
      <xsl:matching-substring>
        <result><xsl:value-of select="regex-group(1)"/></result>
      </xsl:matching-substring>
    </xsl:analyze-string>
    </xsl:template>
    </xsl:stylesheet>
    output :
    <result>Moskow.SomeOtherValue</result>2) With XSLT 1.0, you can use a recursive template to analyze the string :
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="/">
      <result>     
        <xsl:call-template name="find_cap_words">
          <xsl:with-param name="in" select="test"/>
        </xsl:call-template>
      </result>
    </xsl:template>
    <xsl:template name="find_cap_words">
      <xsl:param name="in"/>
      <xsl:variable name="rem" select="substring-after($in,'.')"/>
      <xsl:choose>
        <xsl:when test="translate(substring($rem,1,1),'_ABCDEFGHIJKLMNOPQRSTUVWXYZ','_')=''">
              <xsl:value-of select="$rem"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="find_cap_words">
            <xsl:with-param name="in" select="$rem"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>
    output :
    <result>Moskow.SomeOtherValue</result>Hope that helps.

  • Problem with substring in xsl file?

    Hallo,
    i have a xsl file, when using
    <xsl:value-of select="StsEdat"/> i've got 2007-05-21, that's o.k.
    when using <xsl:value-of select="substring(StsEdat,9,2)"/> the answer is blank.
    also 0,5 or so on. substring at this position delivers blank. why?
    what can it be? i'am helpless.
    any help is appreciated.

    Hi,
    I used <xsl:value-of select="substring(StartDate,9,2)"/> the answer was 21 and to 0,5 the answer was 2007. It seems that's ok!
    Try to do it and see if you have problem with substring.
    <xsl:variable name="StsEdat">2007-05-21</xsl:variable>
    <xsl:value-of select="substring($StsEdat,9,2)"/>
    or this weird way, :)
    <xsl:variable name="StsEdat">2007-05-21</xsl:variable>
    <xsl:value-of select='substring-after(substring-after($StsEdat, "-"), "-")' />
    Regards,
    Cleiton

Maybe you are looking for

  • How to delay creation of VideoDisplay

    My Flex' app reads an xml with different video-source-url's. On the same time the VideoDisplay is created. But it does not have the url for the VideoDisplay source property because parsing is taking to long. How can I delay the creation of the VideoD

  • What is the BAPI name for FB01

    Hi all,         Currently i got requirement on Transactional data uploding to FB01 transaction thru BAPI. I found the BAPI ' BAPI_ACC_GL_POSTING_POST'. But in this iam unable to find the Posting key(BSCHL) at line item level. If it is the exact BAPI

  • Unable connect to SQLServer

    I using JDBC driver (Microsoft SQL Server 2000 Driver for JDBC) to access Database (SQLServer 2000). I using NonXA-Datasource driver: com.microsoft.jdbc.sqlserver.SQLServerDriver INDI name : jdbc/SqlServer url : jdbc.microsoft.sqlserver://local:1433;

  • Wanted:  BV/Crystal report writer

    Post Author: Heather CA Forum: General Hi, We're looking for a Crystal Report writer that is familiar with Sage BusinessVision. We would like to have an existing BV report customized. If you are familiar with BV, it would be great to hear from you! T

  • IE7 visibility Issue

    On my personal website ( www.davidbstubbs.com) I seem to have an ongoing issued with Spry + IE7. I have a couple display:none elements that come into view through a spry fadeAppear + Slider. They work fine in IE6/Opera/FF/Safari, except in IE7 they t