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

Code for - 1 Record

adeel_sarwar
Contributor
0 Likes
884

Hi,

How can i achive the following please see example below.

select * from MARA

where MATNR = 'MATERIALB'

Write: MATNR.

So in the above statement i want the record to find Material B and show me the previous record if that makes sense.

Suppose the table MARA has 2 records

Record1: MATERIALA

Record2: MATERIALB

so i want to use the same selection statement and it should bring me MATERIALA in the result not MATERIALB as i want the previous record.

Please note i have created the above scenario to explain.

6 REPLIES 6
Read only

Former Member
0 Likes
863

Hi Adeel,

In the database it may not be stored in the order of what we see.It can be stored in any order other than what we see in T-codes SE11 or SE16. It is practically not possible to fetch the record X by giving keys for record Y.

May i know the exact business reason to bring in the so called previous material number? If that is known then there can be a way

//Kothand

Read only

Former Member
0 Likes
863

Performance will be bad, but so long as you are sure that MATERIALB is in the database, you can use:

DATA: mara_int TYPE TABLE OF mara.

SELECT * FROM mara
  INTO TABLE mara_int
  UP TO 2 ROWS
  WHERE matnr <= 'MATERIALB'
  ORDER BY matnr DESCENDING.

Rob

Read only

Former Member
0 Likes
863

You may want to decrement sy-tabix resulting from select for materialB by 1 and then go to select again from the database with the new index value.

Read only

0 Likes
863

Hi,

I used the above scenario as an example to explain what i am trying to get at. the tables are in the correct order everything else is fine all i want to know is how to get the previous record for what i have searched for as described above.

thanks

Read only

0 Likes
863

Well, I tested my code before posting it. It did what I understood you to want. Did you try it?

Rob

Read only

adeel_sarwar
Contributor
0 Likes
863

Got an ABAPER to do this. thanks