Application Development and Automation 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: 
Read only

Is this select statement okay?

former_member195355
Participant
0 Likes
909

Hi,

COuld you just check this:

This is the current code:

SELECT SINGLE * FROM v_anlhz

WHERE bukrs = '3166'

AND anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

Sometimes the value for anlkl can be XXX, so is the following code okay?

SELECT SINGLE * FROM v_anlhz

WHERE bukrs = '3166'

AND anlkl = 'GB060'

OR anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

Many Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
859

hi,

both the select statments into statement are missing

you change like that

data temp like v_anlhz

SELECT SINGLE * FROM v_anlhz into temp

WHERE bukrs = '3166'

AND anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

Sometimes the value for anlkl can be XXX, so is the following code okay?

SELECT SINGLE * FROM v_anlhz into temp

WHERE bukrs = '3166'

AND anlkl = 'GB060'

OR anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

so the result will be available in temp.

cheers,

sasi

6 REPLIES 6
Read only

Former Member
0 Likes
860

hi,

both the select statments into statement are missing

you change like that

data temp like v_anlhz

SELECT SINGLE * FROM v_anlhz into temp

WHERE bukrs = '3166'

AND anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

Sometimes the value for anlkl can be XXX, so is the following code okay?

SELECT SINGLE * FROM v_anlhz into temp

WHERE bukrs = '3166'

AND anlkl = 'GB060'

OR anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

so the result will be available in temp.

cheers,

sasi

Read only

Former Member
0 Likes
859

this is just the addition of '(' ')' in sasi's solution -

SELECT SINGLE * FROM v_anlhz into temp

WHERE bukrs = '3166'

AND anlkl = 'GB060'

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

Sometimes the value for anlkl can be XXX, so is the following code okay?

SELECT SINGLE * FROM v_anlhz into temp

WHERE bukrs = '3166'

AND ( anlkl = 'GB060'

OR anlkl = 'GB060' ) "<<< change

AND aktiv = sy-datum

AND erdat = sy-datum

AND txt50 = bdc_inrec-txt50

AND kostl = v_kostl.

Read only

0 Likes
859

Hai!

try to mention what are the fields name u want, thats give good performances.

Alex

Read only

0 Likes
859

Hi,

I think into clause is not mandatory in case you are selecting all the fields. If you are selection particular no of fields then you need to specify the into clause. also when you have two/more possible values for one field in the data base table then put the brackets before and last of the values.

Best way is you can assign that value to any variable and use that variable to that select condition.

Hope this will solve your problem.

Regards,

Amit

Read only

former_member221770
Contributor
0 Likes
859

Robert,

If you have a list of Asset Classes, you can also use a RANGE.

eg.


RANGES: ra_anlkl for anla-anlkl.

perform add_anlkl using 'GB060'.
perform add_anlkl using 'GB070'.

form add_anlkl using pa_anlkl.
  clear ra_anlkl.
  ra_anlkl-sign   = 'EQ'.
  ra_anlkl-option = 'I'.
  ra_anlkl-low    = pa_anlkl.
  append ra_anlkl.
endform.

SELECT SINGLE * FROM v_anlhz
       WHERE bukrs = '3166'          AND
             anlkl IN ra_anlkl       AND
             aktiv = sy-datum        AND
             erdat = sy-datum        AND
             txt50 = bdc_inrec-txt50 AND
             kostl = v_kostl.

This makes your SELECT statement neater and easier to read if you want to select for multiple Asset Classes.

Hope this helps.

Cheers,

Pat.

Read only

Former Member
0 Likes
859

Robert,

Insert INTO or INTO CORRESPONDING FIELDS in the select statement.

If you have multiplea entries for ANLKL, then it is always better to build a range will all the possible values and use that in the WHERE condition of the SELECT statement using IN operator like

anlkl IN r_anlkl

Thanks,