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: 

SELECT TOP with parameter by using native SQL

kahyaogluvolkan
Explorer
0 Kudos

Hi Guys,

I'um using native sql to select data from external database. I need use SELECT TOP statement with parameter. I used below code for this purpose.

EXEC SQL PERFORMING do_work.

         SELECT TOP :gs_row INVOICE_DETAIL_ID
           INTO :gs_ids        
           FROM CUSTOMER_PRODUCTS
          WHERE CREATED_AT IS NULL OR CREATED_AT='1900-01-01 00:00:00.000'

ENDEXEC.


But ABAP gives me error and show :gs_row as ? in Query. I can run same query like SELECT TOP 1000.... and it runs with no errors.


isnt it possible with ABAP?

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

In Abap native SQL, you may use OPEN cursor/FETCH/CLOSE cursor to manage the number of records to return.

Hint: Also you won't get into trouble if change of database, as many (most) don't support TOP but use some LIMIT option or ROWNUM virtual field.

Regards,

Raymond

3 REPLIES 3

former_member185414
Active Contributor
0 Kudos

Hello Volkan,

In Open SQL whenever we need a single row we use Select Single / Select ..EndSelect statements. Drawing an analogy here what I suggest is try below two things -

1. Use something like Select Single Top.....

2. Use something like Select Top 1..(This you would have already figured out )

BR.

former_member185587
Participant
0 Kudos

Hi Volkan,

What is the type definition that you've given to "gs_row"?

Regards,

Kiran

raymond_giuseppi
Active Contributor
0 Kudos

In Abap native SQL, you may use OPEN cursor/FETCH/CLOSE cursor to manage the number of records to return.

Hint: Also you won't get into trouble if change of database, as many (most) don't support TOP but use some LIMIT option or ROWNUM virtual field.

Regards,

Raymond