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

Improve multiple SELECT

Hi all,

in a FORM i've a multiple sequential SELECT like this :

  • Case 1

SELECT * FROM myTABLE INTO myZone WHERE XX = 'X4'.

  • Case 2

SELECT * FROM myTABLE INTO myZone WHERE XX = 'X3'.

  • Case 3

SELECT * FROM myTABLE INTO myZone WHERE XX = 'X2'.

  • Case 4

SELECT * FROM myTABLE INTO myZone WHERE XX = 'X1'.

It's just an sample 😉 So, how can i do to improve this code ; i must use internal table or ?

Thanks so much

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 04, 2005 at 10:06 AM

    Select all the lines of your table myTABLE into an internale table (itab)

    then read this itab with read table itab with key xx = p_name binary search. Where p_name is a passing parameter in the form

    don't forget to sort table itab by xx.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 04, 2005 at 10:12 AM

    Hi,

    Check this Hint.

    *--> store the records from MyTable into the internal table myZone.

    SELECT * FROM myTABLE INTO TABLE myZone WHERE XX IN ('X1', 'X2', 'X3', 'X4').

    SORT myZone BY XX.

    *-->Now use the Read table statement with Binary Search addition.

    *Case 1

    READ TABLE myZone with key XX eq 'X4' BINARY SEARCH.

    *Case 2

    READ TABLE myZone with key XX eq 'X3' BINARY SEARCH.

    *Case 3

    READ TABLE myZone with key XX eq 'X2' BINARY SEARCH.

    *Case 4

    READ TABLE myZone with key XX eq 'X1' BINARY SEARCH.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 04, 2005 at 10:17 AM

    Hi, use select-options / ranges

    for your selection

    regards Andreas

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 04, 2005 at 10:18 AM

    Hi,

    Try this.

    select * from myTable into table myzone where XX in ('X1','X2','X3','X4').

    or

    select * from mytable into table myzone where xx = 'X1'

    or XX = 'X2' or XX = 'X3' or XX = 'X4'.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 04, 2005 at 10:28 AM

    Hi,

    You can also use something like this -

    SELECT * 
      FROM myTABLE 
      INTO myZone 
     WHERE XX BETWEEN 'X1' and 'X4'.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 04, 2005 at 10:39 AM

    hi, in my opinion, select in a (X1 or X2 or ..) way do no improvement on your business. Because redundant data has been selected out.

    Here is my suggestion, also no improvement on perfermance, but make the code looks nice, maybe.

    TYPES: BEGIN OF ITAB_RECORD,

    TEXT(72),

    END OF ITAB_RECORD.

    DATA: WHERE_ITAB TYPE STANDARD TABLE OF ITAB_RECORD INITIAL SIZE 3

    WITH HEADER LINE.

    case XX.

    when 'X1'.

    WHERE_ITAB-TEXT = 'XX = 'X1''.

    when 'X2'.

    WHERE_ITAB-TEXT = 'XX = 'X2''.

    when 'X3'.

    WHERE_ITAB-TEXT = 'XX = 'X3''.

    when 'X4'.

    WHERE_ITAB-TEXT = 'XX = 'X4''.

    endcase.

    APPEND WHERE_ITAB.

    SELECT * FROM myTABLE INTO myZone WHERE (WHERE_ITAB).

    Hope it will be helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 04, 2005 at 10:52 AM

    All depends XX is a primary key or not of the table myTABLE.

    If, yes then you should use one Itab

    SELECT * FROM myTABLE INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE XX BETWEEN 'X1' and 'X4'.

    ENDSELECT.

    use

    itab LIKE SORTED TABLE OF myTABLE

    WITH UNIQUE KEY XX.

    Then on case you use

    read table Itab

    Reg,

    Arpit

    I feel it'll improve the performance considerable.

    Add a comment
    10|10000 characters needed characters exceeded

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.