Read the last record of an internal table
Hello All,
I need to read the last entry of the internal table? Is it possible to achieve this without using loop - endloop?
In the following example, I need to get the Batch '110776' and store it in a variable.
ITAB:
MATNR|CHARG
010780|110770
010780|110772
010780|110773
010780|110774
010780|110775
010780|110776
Thanks.
Use DESCRIBE to get the number of entires in variable last_entry
and then use read table ....index last_entry
Similar Messages
-
How to get the last record of an internall table ....
Hi All..
i want to get the last record of an internal table itab, and i want the the value of the last record.Hi,
Use describe statment.
data: lv_line type i.
Describe table itab lines lv_line.
read table itab into wa_itab index lv_line.
regards,
Santosh Thorat -
How can I search the last line in an internal table?
How can I search the last line in an internal table?
With a describe?? If it is , how can I do that?
Thanks!!Hi shilpa,
it seems to be you are NEW to SDN. welcome. if you want to get solutions to your Questions, you have to post a NEW thread.dont use the existing thread to post your question.
any way i am giving you the solution for your question
LOOP AT ITAB WHERE F1 = <SOME VALUE>
F2 = <SOME VALUE>.
ENDLOOP.
IF SY-SUBRC = 0.
ITAB WILL HAVE THE LAST RECORD which satisfying the given criteria in WHERE clause of LOOP.
write itab <--this ITAB will have the last record.
ENDIF.
regards,
Srikanth.
Message was edited by: Srikanth Kidambi -
Read the last record in the database table..
Hi..
I am new to ABAP. So i have one condition to read the address number field in the last record from database table by using the person number where clause field.
But the person number is same for some the records.
So can any tell me the logic for to read the addressnumber field in the last record of selected records from database where personnumber is equal to some thing.
Please help me..
Thanks
venkiHi Venkat ,
u mean to say
person number addressnumber
aa1 0000000000001
aa1 0000000000002
aa1 0000000000003
aa1 0000000000004
aa2 0000000000021
aa3 0000000000110
if i have to read the addressnumber 00000000000004
of the person number aa1
u can go like
data v_address number like addressnumber.
sort itab by personnumber addressnumber
loop at itab .
at end of personnumber.
move addressnumber to v_addressnumber ..
endat.
endloop.
so using control break statements i can fetch the last record of my person number if at all the same person number is having more than one address number ..
hope this helps,
Regards,
Vijay
Message was edited by: Vijay -
Selecting the last record from a database table
In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key. In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first. I know I can use an internal table to sort the records first and then retrieve the right value. But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step? Thanks!
hi,
tables:mara.
data: begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
end of it_mara.
select-options:s_matnr for mara-matnr.
select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr.
if not it_mara[] is initial.
sort it_mara by matnr descending.
read table it_mara index 1.
endif.
then you get the last record of the select statement.
reward points if useful,
venkat. -
Need to fetch the last record/row from a table
Hi,
I have a requirement like fetching the closing balance of the last record of the table and inserting the same into the opening balance of the immediatetly created next record.
In simple words, I need to fetch a value from the last row of the record.
For example, I use the below query,
select rownum, empno, ename from emp
where rownum = (select count(rownum) from emp);
But, the above query does not return any of the record.
Hence, need help on this.
Regards,
Shivakumar A
Edited by: shiva on Mar 27, 2011 10:14 PMRows in a table are inherently unordered. In order to introduce the concept of "first" and "last", you would need to specify how to order the rows which would require that there was one or more columns in the table that you could order by in order to determine the "last" record.
In your closing balance example, if we assume that there is something like a BALANCE_DATE column,
SELECT account_number, balance_amount, balance_date
FROM (
SELECT account_number,
balance_amount,
balance_date,
rank() over (partition by account_number order by balance_date desc) rnk
FROM table_of_balances )
WHERE rnk = 1Justin -
Pickup only the newest record in an Internal Table.
Hi all:
I have and internal table that i am accesing in a transformation.
Which is the best approach to read from the internal table only the
record with the newest date. Data look like this:
Date_________MAT___ Qty
12.08.2009___4050___70
10.05.2009___4050___30
18.11.2009___4050___42
20.07.2009___4050___28
In this case, for Material 4050 i need only the third record (18.11.2009),
any code example or guideline..?
Regards,Hi,
You can sort the internal table by date and material in descending order and then perform read on the internal table with key as material. this would bring the latest date for that material.
Regards,
Rk. -
How to delete the matching records from two internal tables
Hi ,
I have two internal tables say A and B of the same type. If A has 10 records and B has 4 records , I want to delete the 4 records in B from A .
loop at B into wa .
delete A where key = wa - key .
endloop.
takes a long time if the table B is huge. how can I improve the performance.
Thanks.
GayathriHi Gayathri,
You could try field-symbols. It reduces the data transfer from the internal table B to the work area.
field-symbols <fs_itab_b> like line of B.
loop at B assigning <fs_itab_b>.
delete A where key = <fs_itab_b>?-key.
endloop.
Regards,
<a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=zwcc%2fwm4ups%3d">anand Mandalika</a>. -
Reading the data from field symbol internal table //
Hi,
There are 2 internal tables defined as Fieldsymbols (type any) and I need to retrive data from second internal table based on a field value in first internal table.
Let's assue the name internal table 1 is <it_itab1>, 2nd internal table name is <it_itab2> and the work areas are <wa_itab1> and <wa_itab2>.
The existing logic :
LOOP at <it_itab1> ASSIGNING <wa_itab1>.
ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab1> TO l_field6.
LOOP AT <it_itab2> ASSIGNING <wa_itab2>.
ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab2> TO <p_field7>.
IF <p_field7> = l_field6.
do the required business.
ELSE.
* do the required business.
ENDIF.
ENDLOOP.
ENDLOOP.
The requirement of reading second internal table was achieved by putting loop on the internal table but its giving considerable effect on performance !!
Is there any way to use READ statement in my case OR any way of putting WHERE condition on loop statement of second internal table ??
Thank you !!Use the below Logic.
Loop at Itab1 into wa_itab1.
Loop at itab2 into wa_itab2 where p_field7 = wa_itab1-xyz or I_field6.
do the required business.
endloop.
Loop at itab2 into wa_itab2 where p_field7 <> wa_itab1-xyz or I_field6.
do the required business.
endloop.
endloop.
Hope it is useful... -
To read the column names of an internal table
Hi ,
I want to read the column/field names of an internal table into another internal table.
How can this be done?
Kind Regards,
hgarsht RungtaHi ,
you can get the attributes of any internal table into another ..
check the following code ..
DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
DATA : it_detail TYPE abap_compdescr_tab,
wa_comp TYPE abap_compdescr.
DATA : ref_descr TYPE REF TO cl_abap_structdescr.
ref_descr ?= cl_abap_typedescr=>describe_by_data( it_mara ).
it_detail[] = ref_descr->components .
loop at it_detail into wa_comp.
write:/ wa_comp-name .
endloop.
Regards,
Rajesh Kumar -
HI All Capturing the error records in an internal table
Hi All,
I am retrieving the data from application server .
My requirement is to :
Check if the Measurement Point Id provided in the file is a valid one or not. Query the table EUITRANS by passing the Measurement point Id in the EXT_UI field. If the query is successful, then proceed to next step. If not, log it in the error log with error message DM-001 and proceed with the next Measurement point id.
so i nee the code for capturing the error log with error message.
pls provide me ASAP.
Thanks&Regards,
BharatHi,
if you like do display all messages online have a look at FM:
'MESSAGES_INITIALIZE'
'MESSAGE_STORE'
'MESSAGES_SHOW'
If you want to write application log look at function group SBAL modules BAL_LOG*. There is also a good documentation in SAPDOCU..
Kind regards,
HP -
Accessing the very last record in a transparent table.
Hi!
There's any way to read the last record of a transparent table?
My problem is:
I have to access the very las record of a Z table because I need the maximun value of a numeric field (that is the first field of the primary key).
I used a SELECT MAX, with no condition , but I was asked to find a more performance solution.
There is any way to access the last record of a table? Something like we have for the internal tables with the READ TABLE INDEX N, but with a select statement?
Thanks a lot for your help!Yes, that was my first thought, but I made a comparising between both options with SE30.
Check this numbers:
TIME: 11,377,702
select * from t100 into table t_t100.
sort t_t100 descending.
read table t_t100 index 1.
TIME: 954,218
DATA: MAX_MSGNR type t100-msgnr.
SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr.
Select MAX is better...
I don't think there is a better solucion... Maybe a big brain here has an idea...
Vasanth, thanks for your quick reply! -
Getting the last record from the internal table
When we use a READ statement it always picks up the first record which fulfill its condition but in my case I want to pick up the last record that fulfills it condition
I have a internal table like
id type
N1 A
N1 T
N1 A
N1 6 ----> LAST RECORD
my code is
read table itab wIth key id = netobjid.
for eg if netobjid = N1 , then I want to read the last record that corresponds to N1 ie ID N1 TYPE - 6...
How to do that?HI
actually i have done same requirement like this ...
Take one count variable into your internal table ..you pass the number of records into cont variable for every time u enter the loop .
Sort the internal table with count variable descending . ( AS we cant sort the internal table with sy-tabix)
Then use read statement with sy-index = 1 .
USe below logic ,............
data : count type i value '0'.
LOOP at int .
count = count + 1 .
endloop.
sort int count descending .
read int with index = 1 . -
How to get the last row of a database table.
HI ,
I want to get record exactly from the last row of a database table.
How is that possible?Hi,
To fetch last record from an internal table, just do find the number of records in it and read using index.
DESCRIBE TABLE ITAB LINES L_LINES.
READ TABLE ITAB INDEX L_LINES.
You can also use LOOP .. ENDLOOP but the above method is better (performance wise).
using LOOP .. ENDLOOP.
LOOP AT ITAB.
**do nothing
ENDLOOP.
**process ITAB (Header record of ITAB).
**after ENLOOP, ITAB will have the last record of the internal table.
[here ITAB is internal table as well as header record.]
But what is the requirement?
If you are looking for the current record of an employee then you can use ENDDA = HIGH_DATE.
My advice is to review your requirement again and try to fetch only that record which you need.
Mubeen -
Maximum record length in internal table?
Is there a maximum record length in an internal table? Please note: My question is NOT related to table space. I'm referring only to the length of an individual record (A.K.A. row length).
I am using a work area to insert data into an internal table. Both the work area and internal table are defined by the same structure.
The structure has a total length of 672 bytes. For the sake of this discussion I'll point out that at the end of the structure, bytes 669, 670, 671, and 672 are four separate fields of 1 character each.
When viewing the work area record in the debugger I'm seeing all the fields and all the values. When viewing the internal table in the debugger after a record is inserted, the internal table ends with the field defined at Byte 670. The internal table does not include the two fields defined at Bytes 671 and 672.
Am I to assume from the above explanation that the length of a record ( A.K.A. row) in an internal table cannot exceed 670 bytes?
Thank you.Manish,
False alarm! While, technically, you didn't answer my question, your request for code ended up helping me answer my own question.
To provide you with some code I wrote a simple test program using the record layout referred to above, with a DO loop to put some records into the internal table, followed by a LOOP AT, with accompanying WRITE statements to display the contents of the internal table and demonstrate that the last two fields weren't being stored.
However, when I ran the test program, the last two fields were being displayed.
It was at that point, when stepping through the debugger that I noticed the scroll arrows above the last column of my internal table that allowed me to scroll to the right and see my final two fields.
Apparently, because of the large number of fields in my internal table I had reached the default display length of the debugger. While I was obviously aware of the scroll bar found at the bottom of the display, I had never worked with an internal table of that width in the past and hadn't even noticed the scroll arrows above the last column before.
Thanks for taking the time to respond helping me get to the solution.
Maybe you are looking for
-
1. Create a Crystal Report. 2. Add a Text box. 3. Type a big sentence so that reaches near 20th inches. 4. User the following Page Setup options. a) Check the box "Dissociate Formatting" b) Select "User Defined" and Unit=Inches c) Horizontal=25 d) Ve
-
VERY unstable iPod Nano (crashes every time in iTunes) plz help!
Hi Folks, As I wrote earlier in this thread, the iPod nano I bought for my GF (and the one before that) suffered from the 'updater bug'. At least I know now how to revive it, thanks to the great tips of a few users here, but it's a nuisance that the
-
Hi,I am having difficulty with opening up PDFs attachments in my email or on my computer. Every time I tried to open up an attachment, it asks me to renew my subscription when I already have a valid subscription. Please abvise
-
Can't drag and drop music to iphone5
I updated to the latest Itunes, plugged my new Iphone5 in and "restore from previous Iphone back up" It did it fine, then i went to manage music manually and checked the boxes for all the artists I wanted on my new phone. Sync it to my phone and al
-
Payload type of wav files encoded with gms codec
Hello everybody, I have an application which receives and plays alaw formated wav files using JMF(with the help of some additional libraries) . I want to use lower bandwidth for my application. A quick google search indicated that i can do this by us