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

How to write Select statement for this codition

I need to check whether SGTXT contains BELNR value.

SGTXT is a text field and It should be matched with BELNR

How to write select statement for this.

Select AUGBL AUGDT into t_BSAD

from BSAD

where SGTXT should have the given BELNR Value.

Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 10:41 AM

    You should be able to use CS (Contains operator). If you know that BELNR is going to be the starting or ending of the field SGTXT, then you can use a wild card like %BELNR, BELNR%.

    Regards,

    Ravi

    Note : Please reward points if you think this was helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 10:43 AM

    Hi Sumi,

    You can pass the value of Belnr to a variable of same length of SGTXT using <b>MOVE</b>.

    For Example,

    Data: W_BELNR like BSAD-SGTXT.

    MOVE BELNR to W_BELNR.

    Select AUGBL AUGDT into t_BSAD

    from BSAD

    where SGTXT = W_BELNR.

    Regards,

    Baburaj

    Please Give the Reward points.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 10:45 AM

    DATA WA_SGTXT LIKE BSAD-SGTXT.

    MOVE BELNR TO WA_SGTXT.

    Select AUGBL AUGDT into t_BSAD

    from BSAD

    where SGTXT eq WA_SGTXT

    ...

    Cheers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 10:49 AM

    Hi,

    Try this.

    data t_bsad type bsad.

    select AUGBL AUGDT into (t_BSAD-AUGBL, t_BSAD-AUGDT)

    from BSAD where SGTXT = BSAD~BELNR.

    endselect.

    Svetlin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 10:50 AM

    data w_belnr like bsad-sgtxt.

    concatenate 'belnr' '%' into w_belnr.

    Select * from bsad where sgtxt like w_belnr.

    Note: This SQL will be expensive

    Ravi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 10:53 AM

    u can't do a comparison in a select statement where both the fields on the left as well as on the right are from the database table. U probably have to go for one of these options...

    1) compare with sgtxt that is previously determined in the program...this could be like retrieving in a separate internal table and then using 'FOR ALL ENTRIES' on it...like ....

    select augbl augdt from bsad into table t_bsad

    for all entries in t_bsad1

    where belnr eq t_bsad1-sgtxt+0(10)...(followed by other conditions)

    2) not recommended but u can try and go for a nested select.

    rgds,

    PJ

    2)

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 11:51 AM

    hi,

    try with this code,i am not sure about this but i think it could be helpful to you,

    Data: duplicate_BELNR like BSAD-SGTXT.

    WRITE BELNR to duplicate_BELNR.

    Select AUGBL AUGDT into t_BSAD

    from BSAD

    where SGTXT = duplicate_BELNR.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 11:58 AM

    Hi Sumi,

    U can also create the another data type with type 'C' and length 50. Move belnr value into that.

    Then in select use that field in where clause.

    Reg,

    Arpit

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 03, 2005 at 12:17 PM

    Hi,

    data temp(12).

    concatenate '%' belnr '%' into temp.

    Select AUGBL AUGDT into t_BSAD

    from BSAD

    where SGTXT like temp.

    If belnr is having multiple values,just create a internal table as follows.

    types : begin of ty,

    belnr....

    temp(12),

    end of ty.

    data itab_ type standard table of ty.

    data wa type ty.

    loop at itab into wa.

    concatenate '%' wa-belnr '%' into wa-temp.

    modify itab from wa index sy-tabix transporting temp.

    endloop.

    Change your select statement accordingly.

    Kindly reward poits if it helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2005 at 12:33 PM

    1. Like is not working

    2. I cannot use EQ. Coz SGTXT will have chars other than BELNR.

    IF

    BELNR = 123

    SGTXT can be like this

    TEST123TEST.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi

      You should create a string with tha value you want to check:

      DATA SGTXT TYPE BSAD-SGTXT.

      WRITE: '%' TO SGTXT(1),

      BELNR TO SGTXT+1.

      LEN = STRLEN( SGTXT ).

      WRITE: '%' TO SGTXT+LEN(1).

      SELECT * FROM BSAD WHERE SGTXT LIKE SGTXT

      .....

      Anyway I hope this isn't only condition you'd check, because it can take many time, it should be better you use the compnay code and vendor code.

      Max

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.