Want last record in internal table

Hi All,
I have two internal table. in one internal table all data are available. now i want last record on first internal table and store in second internal table.... so give me some logic or sample code......
Thanks
zeni

get the latest record from an internal table.
if you are using function module RH_READ_INFTY_1001 then <itab
 > will always contain all the records betweebn specified period (taken from selection screen), but to retrieve the latest, sort the records by ENDDA and you will get it on top, then use INDEX 1 for that record only, and store the record in a <work_area>, finally get that record from <work_area> to <itab> it self. thats way your <itab> will hold only latest record.  
(you can store <work_area> in <work_area_2> and then pass the record in to <itab>
or, you can store the <work_area> to a different <itab_2>).
   call function RH_READ_INFTY_1001
   tables
      i1001         = it_hrp1001
  sort  it_hrp1001 by endda descending.
  read table it_hrp1001 into wa_hrp1001 INDEX 1.
  refresh it_hrp1001.
  append wa_hrp1001 to it_hrp1001.

Similar Messages

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • Inserting records from internal table to database table

    Hi all,
    i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
    1) insert one by one record from internal table
    loop at itab.
    insert ztable from wa.
    endloop.
    2) insert total records at a time
    INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or let me know if any other statement is there with high performance.
    i internal table contains nearly 40000 records.
    thanks.

    Hi,
    Insert the entire table at atime rather than a record so as to increase the performance.
    you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or
    MODIFY ZPRODUCT FROM TABLE GI_AFPO.
    Regards,
    Raj.

  • How to fetch last record from the table to display in screen painter?

    Hi Gurus,
                  I have a requirement where i have to fetch the last record value in the table.
    I have a screen where the TEXT name is REQUEST and I/P field name is REQ and SAVE push button.
    In this I/P field automatically 1 should display when i excecute the program and when i save this, the request number should turn to 2 that is dynamically..once agin save then 3 and so on....and this 1, 2, 3 will be storeing in table.
    I have succeeded till generating the values dynamically and saving in the table like 1 is displayed and when i click save it is changeing to 2..but the problem is when i am coming out of program and logon again the request number is again displaying as 1 rather it has to start with 4 because already 3 request are there in the table.
    My code is...
    Table zsave.
    data declarations....
    data req type i.
    req = 0.
    req = zsave-req.
    PROCESS BEFORE OUTPUT
    req = 0.
    select req into table fun_st from zsave.
    req = zsave-req.
    zsave-req = req.
    req = zsave-req + 1.
    PAI
    req = zsave-req + 1.
    zsave-req = req.
    when 'save'.
    wa_funst-req = zsave-req.
    Please can you provide me with the solution....answer will be rewared.
    THKS

    Can you tell me, when updaing the ZSAVE table with the counter value are you modifying the exisiting value or inserting the value as new record?
    From the code in your first post, i see that you are extracting records into internal table but when you are moving to variable REQ, you are moving from table work area which is blank, so everytime when you execute it may be starting as 0.
    Hope below code can help you understand on handling your requirement
    Global Declaration:
    >DATA: l_req TYPE i. 
    PBO:
      SELECT MAX( req ) INTO l_req FROM zsave.
      l_req = l_req + 1.
    PAI:
      DATA: wa TYPE zsave.
      CASE ucomm.
      WHEN 'SAVE'.
        wa-req = l_req.
        INSERT zsave FROM wa.
      ENDCASE.

  • To delete duplicate records from internal table

    hi friends,
    i have to delete records from internal table based on following criterion.
    total fields are 7.
    out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
    in case all five fields are same,the program should do nothing.
    for example.
    if there are 3 records as follows
    a1 b1 c1 d1 e1 f g
    a1 b1 c1 d1 e2 w r
    a1 b1 c1 d1 e1 j l
    then first two records should be deleted as four fields are same but fifth(e) field differs.
    but third record should remain as it is evenif first five fields are same for first and third record.
    values of last two fields need not to be consider for deleting the records.

    LOOP AT ITAB.
      V_FILED5 = ITAB-F5. "to compare later
      V_TABIX = SY-TABIX. "used to delete if condition not matches
      READ TABLE ITAB WITH KEY F1 = ITAB-F1
                               F2 = ITAB-F2
                               F3 = ITAB-F3
                               F4 = ITAB-F4.
      IF SY-SUBRC = 0.
        IF ITAB-F5 <> V_FIELD5.
    *--both the records to be deleted,as Field5 is different.
          DELETE ITAB INDEX SY-TABIX. "deletes that record
          DELETE ITAB INDEX V_TABIX. "deletes the current record
        ENDIF.
      ENDIF.
    ENDLOOP.
    Message was edited by: Srikanth Kidambi
    added comments
    Message was edited by: Srikanth Kidambi

  • How to find the last records of the table in adventure work db

    hi all,
    i want to find out " how to receive a last records of the table (eg:  person.emailaddress ) in sql 2008 and 2005"
    Thanks

    If you are looking for the latest record( the one which got inserted/modified last) then use this query
    select top 1 * from person.emailaddress
    Order by ModifiedDate desc
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Fetch last record from database table

    hi,
    how to fetch last record from database table.
    plz reply earliest.
    Regards,
    Jyotsna
    Moderator message - Please search before asking - post locked
    Edited by: Rob Burbank on Dec 11, 2009 9:44 AM

    abhi,
    just imagine the table to be BSEG or FAGLFLEXA... then what would be performance of the code ?
    any ways,
    jyotsna, first check if you have a pattern to follow like if the primary key field have a increasing number range or it would be great if you find a date field which stores the inserted date or some thing..
    you can select max or that field or order by descending using select single.
    or get all data.. sort in descending order.(again you need some criteria like date).
    read the first entry. using read itab index 1

  • Question reg. modifying latest record in internal table

    Can you tell me if it is possible to modify the last appended record to the internal table?
    I just want to modify the record in the internal table which is appended at the latest. Please tell me the logic for this.
    Thanks a lot,
    Krishen

    Hi try with this:
    DATA line TYPE I.
    DATA wa_itab TYPE LINE OF it_itab.
    DESCRIBE TABLE IT_TABLE LINE line.
    READ TABLE IT_TABLE INTO wa_itab INDEX line.
    WA_TABLE-FIELD = 'new value'.
    MODIFY TABLE IT_TABLE FROM wa_itab
           TRANSPORTING field.
    Best regards.

  • How to get multiple records from internal table through BDC

    PERFORM DYNPRO USING:
      'X'  'SAPMM61L'  '0500',
      ' '  'BDC_OKCODE'  '=NEWC',
      'X'  'SAPMM61L'  '0500',
      ' '  'BDC_CURSOR'  'PLPTU-PLWRK(01)',
      ' '  'BDC_OKCODE'  '=TAKE',
      ' '  'PLPTU-PLWRK(01)' '2531'. (2531 is a plant)
    This is the recording used to get plant via BDC of MS31.
    Using this code i can get only single plant...
    If i want to get multiple plants from an internal table,how i can change this code?
    Since it is a recording i cant put this code in LOOP..ENDLOOP.
    Suggest any method for doing this....
    Awaiting for ur reply...

    Hi,
    While recording also record the scroll down button.
    The you can place different plant in the BDC using loop and endloop
    Regards
    Arun

  • How to fetch previous record from internal table?

    Hi,
    My final internal table (it_final) has all the data month wise year wise.(opening and closing qty)
    but if
    Material   Batch    Month   Year        opening_qty         closing_qty
    FC5431   abc        08        2008        100                       50
    FC5431   ABC       09        2009         0                          100
    Suppose I want to take PREVIOUS record(closing_qty = 50  in my 09/2009  openin_qty = 50)  how will Ido this?
    Any solution????????? BTW i m using S033 for opening an closing qt monthwise.
    Plz reply soon if anyone knows.
    Thanks and Regards,
    Archana

    Hi,
    Test the following Sample code hope will solve out your problem,
    TYPES:  BEGIN OF ty_test,
            m(3),
            open_qty TYPE i,
            close_qty TYPE i,
            END OF ty_test.
    DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE,
          wa_test LIKE LINE OF it_test,
          ctabix LIKE sy-tabix,
          ptabix LIKE sy-tabix.
    it_test-m = 'AAA'. it_test-open_qty = 100. it_test-close_qty = 50. append it_test.
    it_test-m = 'AAA'. it_test-open_qty =  0. it_test-close_qty = 100. append it_test.
    LOOP AT it_test.
      ctabix = sy-tabix.
      IF sy-tabix > 1.
        ptabix = sy-tabix - 1.
        READ TABLE it_test into wa_test INDEX ptabix.
        IF sy-subrc = 0.
          it_test-open_qty = wa_test-close_qty.
        ENDIF.
        MODIFY it_test INDEX ctabix.
      ENDIF.
    ENDLOOP.
    LOOP AT it_test.
      WRITE: it_test-m, it_test-open_qty, it_test-close_qty, /.
    ENDLOOP.
    Regards,
    Faisal

  • Delete records from internal table

    hi all,
    i want to delete records from intenal table which are starting with a particular starting number .
    eg internal table
    10000
    20000
    90000
    91000
    92000
    88880
    i want delete the records starting with 9 i.e. 90000 91000 92000.
    Thanks in Adv
            RAJ

    You can test this piece of code.
    DATA:
    i_tab TYPE STANDARD TABLE OF mara,
    wa_tab TYPE mara.
    wa_tab-matnr = '1000'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1002'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1003'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '2001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '3001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '4010'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM

  • Calling record in internal table

    Hi,
    I have an internal table itab of this type:
    types: begin of tdat
      fld1(10) type c,
      fld2(10) type c,
      fld3(10) type c,
      end of tdat.
    All I want to do is assign the second field of the second record of the internal table to a variable.  How do I do so?
    thanks!

    Not sure what you requirement is......but you can do this too.
    report zrich_0001.
    data: begin of itab occurs 0,
          fld1(10)  type c,
          fld2(10)  type c,
          fld3(10)  type c,
          end of itab.
    field-symbols: <fs>.
    data: some_variable(10).
    itab-fld1 = '1'.
    itab-fld2 = '2'.
    itab-fld3 = '3'.
    append itab.
    itab-fld1 = '4'.
    itab-fld2 = '5'.
    itab-fld3 = '6'.
    append itab.
    itab-fld1 = '7'.
    itab-fld2 = '8'.
    itab-fld3 = '9'.
    append itab.
    assign itab-fld2 to <fs>.
    read table itab index 2.
    check sy-subrc = 0.
    some_variable = <fs>.
    Regards,
    Rich Heilman

  • Duplicate records in Internal table

    Hi All,
    I want to find out the duplicate entry in the internal table. I have used,
    Delete Adjacent duplicates from itab.
    It is straight away deleting the record.
    I want the user to correct that duplicate record.
    May be some error message.
    I have tried, with read,
    Read table itab with key bzirk = itab-bzirk vkorg = itab-vkorg kunnr = itab-kunnr
    matnr = itab-matnr comparing bzirk vkorg kunnr matnr.
    But it's giving sy-subrc = 0 for the first record also.
    Even, I have tried like, but it's giving syntax error.
    Loop at itab where bzirk = itab-bzirk vkorg = itab-vkorg kunnr = itab-kunnr
    matnr = itab-matnr.
    Endloop.
    Any method in case on Table control entries.
    Thanks & Regards,
    Kalyan Chandramouli
    SAP Consultant

    Hi,
    Create a new internal table and assign the all the records of itab1 to itab2.
    1.Sort Itab2.
    2.delete adjacent duplicates.
    3. loop at itab2.
         loop at itab1 where <conditon you want....>
         count = count + 1.
         endloop.
          if count GT 1.
            append the iatb2 records for user correction....
          endif.
       endloop.
    If the hint is useful… Say thanks by reward….
    Regards,
    Prabhu Rajesh

  • How to know no of records(in Internal Table) modified after using Modify statement

    Hi Experts ,
    I am using statement Modify internal table transporting XYZ FIELD.
    I just wanted to know how many Records/Count (assuming more then 1 ) get updated just after successful execution of this command.
    Is there any system field exist?
    if yes please let me know?
    Warm Regards,
    Santosh

    Hello Santosh,
    Try like below and it works for me.
    Count will have the number rows changed.
    DATA: itab_mara TYPE STANDARD TABLE OF mara,
          itab_mara1 TYPE STANDARD TABLE OF mara,
          str_mara TYPE mara,
          str_mara1 TYPE mara,
          diff LIKE IREF-IIND,
          count TYPE int2.
    SELECT * FROM mara INTO TABLE itab_mara UP TO 10 ROWS.
      itab_mara1[] = itab_mara[].
      str_mara-lvorm = 'X'.
    MODIFY itab_mara FROM str_mara TRANSPORTING lvorm WHERE VPSTA = 'KVB'.
    LOOP AT itab_mara INTO str_mara.
      READ TABLE itab_mara1 INTO str_mara1 WITH KEY matnr = str_mara-matnr.
    CALL FUNCTION 'COMPARE_STRUCTURE_DATA'
      EXPORTING
        i_ddic_name       = 'MARA'
        i_rec_old         = str_mara
        i_rec_new         = str_mara1
       I_CHECK_MODE      = 'Y'
    IMPORTING
       E_IS_DIFF         = diff.
    IF diff = 'X'.
      count = count + 1.
    ENDIF.
    ENDLOOP.
    WRITE:/ count.
    Regards,
    Thanga

  • Deleting records from internal table.

    Hello Friends,
    I have done F1 on delete and also went through the forum . I want to do a delete effectively as it involves huge amount of data ..
    Lets cosider I have two internal tables ITAB 1 and ITAB 2 .
    ITAB 1 has 10000 records  having two key fields
    ITAB2 has 1000 records having the same two key fields in it .
    THe other fields are different .
    Now I want to perform an operation where for corresponding  1000 records in ITAB2 I must delete the records in ITAB1 and result in ITAB 1 must be 10000 - 1000 = 9000 records.
    Which could be the most effecient way to do this.?
    Comradely,
    K.Sibi

    Are you sure that the keys are all unique? That is non trivial with internal tables.
    If yes, then you should define itab1 as a hashed table or copy into a hashed table.
    LOOP AT itab2
        READ TABLE itab1 WITH TABLE KEY ...
        IF ( sy-subrc = 0 ).
          DELETE itab1 WITH TABLE KEY ...
        ENDIF
    ENDLOOP.
    You can also use sorted tables and delete with index, will be somewhat slower. Or standard table with REAB BINARY SEARCH and DELETE with index.
    If the uniqueness is unclear, then you must change the order and LOOP itab1first and comletely, because the same key can appear several times.
    A READ without BINARY SEARCH will kill you, i.e. the above recommendation is incorrect.
    Siegfried

Maybe you are looking for

  • CS6 temp file blunder - can you repeat this problem?

    There is a serious root problem with Adobe's implemented permissionless-temp-file creation methods (pun intended.) The problem is that during startup, both Bridge and Photoshop CS6 try to make temp files on the root folder of the OS drive. Its affect

  • Best Option to learn Java: Search the Web, Books or Real Training

    Good Evening People, I came to the following conclusion during my 4 weaks of trying to just connect and read a MySql Database, to read a CVS file. It seems that you get some leads, but never the full answer. So I am asking what will be my best Option

  • House episode wont work??

    i bought an house episode and i got it with HD and i downloaded HD cause the original got deleted and when i try to download it says episode cannot be played on this ipod and its the ipod touch 2nd gen software 4.0 8gb so why wont it work? also all t

  • What are the reporting changes in BI 7.0 and sap 3.5

    Hi, what are the reporting changes in BI 7.0 and sap 3.5. can anybody know the other name of BI 7.0. what are the min,max no of load times. what is the load timings if the onsite office is at USA. Thanks & Regards, cheta.

  • Mozilla Firefox Start Page Scam Attachment

    On my Firefox Start Page I have been getting the following message under the map of the World- " Mozilla as maker of Firefox is non profit and we rely on donations and grants. If everyone reading this gave $3, we would only have to fundrais 1 day a y