Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to write Select statement for this codition

Former Member
0 Kudos

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.

14 REPLIES 14

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

0 Kudos

Hi,

Just try this.

<b>concatenate '' belnr '' into temp.</b>

Select AUGBL AUGDT into t_BSAD

from BSAD

where SGTXT like temp.

Former Member
0 Kudos

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.

0 Kudos

hi,

retieve all the records into interal table like

Select AUGBL AUGDT SGTXT into table t_xxxxx

from BSAD.

loop at t_xxxx

if t_xxx sgtxt ca belnr

else

delete t_xxxx

endif.

endloop

cheers,

sasi

0 Kudos

Then use

CS (Contains String)

'ABCDE' CS 'CD' is true; SY-FDPOS = 2.

'ABCDE' CS 'XY' is false; SY-FDPOS = 5.

'ABC DEF' CS ' ' is true; but: SY-FDPOS = 0,

since ' ' is interpreted as a trailing blank and is thus

ignored.

0 Kudos

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