‎2008 Jul 17 6:03 PM
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.
‎2008 Jul 17 6:11 PM
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
‎2008 Jul 17 6:19 PM
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
‎2008 Jul 17 6:20 PM
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.
‎2008 Jul 17 9:19 PM
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
‎2008 Jul 17 9:22 PM
Well, I tested my code before posting it. It did what I understood you to want. Did you try it?
Rob
‎2008 Aug 27 11:20 PM