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

Better Selects.

Former Member
0 Likes
1,543

Hi there experts , My Boss always complains coz my selects are not "Efficients" Do you think there is a better way to write the following :

" The key OF TABLE ZOPT10 is :

" MANDT

" PROCESSO

" SEQUENCIA

SELECT  SINGLE processo FROM zopt10
           INTO  wa_oport
             WHERE proc_cli = zbt01-processo.

  IF  sy-subrc = 0.

    SELECT *  FROM zopt10
        INTO ti_zopt10
        WHERE processo = wa_oport.
      APPEND ti_zopt10.
    ENDSELECT.

  ENDIF.

Thanks . I´m trying to improve my abap skills :).

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,504

Hi ,

Try this ,

SELECT SINGLE processo FROM zopt10

INTO wa_oport

WHERE proc_cli = zbt01-processo.

IF sy-subrc = 0.

SELECT * FROM zopt10

INTO table ti_zopt10

WHERE processo = wa_oport.

ENDIF.

Instead of * use the field names what ever you want , You can use into corresponding fields also

Reagrds,

Vijay

Edited by: vijay kumar pamulapati on Jul 29, 2009 11:53 AM

13 REPLIES 13
Read only

Former Member
0 Likes
1,505

Hi ,

Try this ,

SELECT SINGLE processo FROM zopt10

INTO wa_oport

WHERE proc_cli = zbt01-processo.

IF sy-subrc = 0.

SELECT * FROM zopt10

INTO table ti_zopt10

WHERE processo = wa_oport.

ENDIF.

Instead of * use the field names what ever you want , You can use into corresponding fields also

Reagrds,

Vijay

Edited by: vijay kumar pamulapati on Jul 29, 2009 11:53 AM

Read only

Former Member
0 Likes
1,504

Hi,

Instead of using SELECT and ENDSELECT use simple SELECt statement.

Also dont use APPEND statement inside SELECT and ENDSELECT.

Create an internal table (Without Header Line) with a work area and then append the records into the table

Regards,

lakshman.

Read only

0 Likes
1,504

Thank you for your answers , but im a little worried ´cause i made two selects in the same table one after another.

Read only

0 Likes
1,504

Hi ,

Try this ,

SELECT SINGLE processo FROM zopt10

INTO wa_oport

WHERE proc_cli = zbt01-processo.

IF sy-subrc = 0.

SELECT * FROM zopt10

INTO table ti_zopt10

WHERE processo = wa_oport.

ENDIF.

APPEND LINES OF TI_ZOPT10 [] TO TI_ZOPT10_NEW [].

REFRESH TI_ZOPT10.

Reagrds,

Vijay

Edited by: vijay kumar pamulapati on Jul 29, 2009 12:04 PM

Read only

0 Likes
1,504

SELECT processo SEQUENCIA FROM zopt10

INTO table it_zopt10

where proc_cli = zbt01-processo.

.

Read only

Former Member
0 Likes
1,504

The keys which u have mentioned

" The key OF TABLE ZOPT10 is :

" MANDT

" PROCESSO

" SEQUENCIA

But ur select statement looks like


SELECT  SINGLE processo FROM zopt10
           INTO  wa_oport
             WHERE proc_cli = zbt01-processo

Seems that ur using only field processo,Therefor question of single record doesnot come into picture...

There may be multiple records.

Regards,

lakshman.

Read only

0 Likes
1,504

Yes is true i ll get more than one , but processo will be the same for all them only the other two fields change.

Read only

Former Member
0 Likes
1,504

hi,

Please select all the key fieds when doing select single .Also do not use select and endselect .do not append inside it aswell..

also u are writing same select queryy twice in ur code

select all the fields you want in one query into an internal table and then modify the internal table as your requirement

thanks

Read only

Former Member
0 Likes
1,504

Hi Jose,

My first advice to you is to avoid using Select...End Select .

If you loop the select statement the database will be accessed every time which takes time.

I will suggest you to select all the enteries of the database table into an internal table and then use READ

statement to for further computations .

In this way you have reduced the database query time since all enteries are once saved into internal table .

Regards

Aditi Wason

Read only

Former Member
0 Likes
1,504

Hi,


data: v_oport like zopt10-processo.

SELECT  SINGLE processo FROM zopt10
              INTO  v_oport
             WHERE proc_cli = zbt01-processo.

  IF  sy-subrc = 0.
 
    SELECT *  FROM zopt10
        INTO ti_zopt10
        WHERE processo = v_oport.
  ENDIF.

And try to pass as many primary keys as possible in the where conditions of the select query.

Regards,

Vik

Read only

sridhar_meesala
Active Contributor
0 Likes
1,504

Hi,

could you explain what you are trying to do with this SELECT query.

SELECT  SINGLE processo FROM zopt10
INTO  wa_oport
WHERE proc_cli = zbt01-processo.

Here no need to use wa_oport (if it is a work area) as you are going to get a single value only. You can use a local variable.

Thanks,

Sri.

Read only

0 Likes
1,504

Well is not a work area , I didnt know what wa meant i took it from other code .

Read only

Former Member
0 Likes
1,504

Hi Jose,

In your SELECT query there is one thing which will reduce the performance that is using SELECT * . Apart form that using two selct statements will not effect the performance much. If u need to retrieve all the fields as per your requirement then only use SELECT* or else select the required fields.

Regards,

Pavan.