Skip to Content
author's profile photo
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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

10 Answers

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 comment
    10|10000 characters needed characters exceeded

  • 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 comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    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 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