How to pull last record

hi how to pull last record of a db table.
i want to replace this.
Pull out last record of the period
  SELECT mblnr mjahr cpudt cputm
   INTO (gw_act_mkpf-mblnr,gw_act_mkpf-mjahr,
         gw_act_mkpf-cpudt,gw_act_mkpf-cputm)
   FROM mkpf WHERE budat IN s_budat.
  ENDSELECT.
suggest

Hi,
I hope following code will solve your problem.
DATA : it_bseg TYPE TABLE OF bseg,
       x_bseg TYPE bseg,
       v_index TYPE i.
SELECT COUNT(*)
  FROM bseg
  INTO v_index.
SELECT *
  FROM bseg
  INTO TABLE it_bseg.
READ TABLE it_bseg INTO x_bseg INDEX V_INDEX.
First SELECT will give you the number of rows in a table in v_index. Second SELECT will fetch all table data and then READ will give you the last record of the table in a structure x_bseg.
Regads

Similar Messages

  • How to select last record or first record value in a formula?

    Post Author: d111
    CA Forum: General
    I am using a query in a report that in addition to other columns, has a column of month labels like:
    There are no unique identifiers or sequence fields that can be used.   There is only 4 columns: the label and 3 percent columns.
    Jan07Feb07Mar07Apr07etc.
    I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
    I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
    I would like to use a formula to just grab the first and last record.  I can't seem to find any information on this anywhere.
    Please advise and thanks.

    Post Author: bettername
    CA Forum: General
    Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
    If so, try these:
    Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
    //Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
    numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
    //...etc etc you fill in the rest!
    if left({YourTable.YourField},3) = "Dec" then the_month:=12;
    date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
    Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
    totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
    If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
    Stick this in the details section, and call it "HoldRecords" and suppress it:
    whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
    Now create another formula, and put it into the report footer:
    evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
    NOTE:  if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
    Hope this helps...

  • How to get last Record ior Total rows in For Loop Cursor ?

    Hi Friends
    I would like to know , the last record in for loop cursor, i have the code in following format
    cursor c1 is
    select * from emp;
    begin
    for r1 in c1 loop
    v_total_rec := ? ( i would like to know total rows in the cursor , say for example if cursor has 10 rows, i want10 into this variable )
    v_count := v_count +1;
    dbms_output.put_line(r1.emp_name);
    end loop;
    end;
    Hope i am clear
    Any suggestions?
    Thanks
    Ravi

    Even though cursor loops are generally a Bad Idea ^tm^ as Dan says, here's an example of how you can get the information you wanted within the query itself...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    cursor c1 is
      3      select emp.*
      4            ,count(*) over (order by empno) as cnt
      5            ,count(*) over () as total_cnt
      6      from emp
      7      order by empno;
      8  begin
      9    for r1 in c1 loop
    10      dbms_output.put_line(r1.ename||' - row: '||r1.cnt||' of '||r1.total_cnt);
    11    end loop;
    12* end;
    SQL> /
    SMITH - row: 1 of 14
    ALLEN - row: 2 of 14
    WARD - row: 3 of 14
    JONES - row: 4 of 14
    MARTIN - row: 5 of 14
    BLAKE - row: 6 of 14
    CLARK - row: 7 of 14
    SCOTT - row: 8 of 14
    KING - row: 9 of 14
    TURNER - row: 10 of 14
    ADAMS - row: 11 of 14
    JAMES - row: 12 of 14
    FORD - row: 13 of 14
    MILLER - row: 14 of 14
    PL/SQL procedure successfully completed.
    SQL>

  • How to copy last record to a new record ?

    Hello,
    i have a question pls.
    i want to copy last record to every new record
    say,
    multirecord forms has : Tank_no Last_measured Lab_Denisty
    record1 : 1009aw 1532.94 .5796
    what i want to do next record is copying last record (record1 ) as
    record2 : 1009aw 1532.94 .5796
    so the user may change the Last_measured only and not to have to rewrite the Tank_no and the Lab_Denisty cause it doesn't change.
    May i do this ? if yessss, but How..?
    Regards,
    Abdetu..

    Hello poelger
    i check it then found the following code :
    DUPLICATE_RECORD Examples /*
    ** Built-in: DUPLICATE_RECORD;
    ** Example: Make a copy of the current record and increment
    ** the "line_sequence" item by one.
    DECLARE
    n NUMBER;
    BEGIN
    ** Remember the value of the 'line_sequence' from the
    ** current record
    n := :my_block.line_sequence;
    ** Create a new record, and copy all the values from the
    ** previous record into it.
    Create_Record;
    Duplicate_Record;
    ** Set the new record's 'line_sequence' to one more than
    ** the last record's.
    :my_block.line_sequence := n + 1;
    END; but then which trigger best fit the procedure should i use
    w-c-r or w-n-r-i Triggers
    and what is meant by line_sequence pls. ?
    Regards,
    Abdetu..

  • How show the last record by date

    Hi Gurus,
    i got in the cube the next records for example:
    calday                  Material    Quantity
    01.01.2011             A                 10
    15.01.2011             A                  20
    if i present in the query these IO an KF the query will show these 2 records, now i want just show the last record by date
    calday                  Material    Quantity
    15.01.2011             A                  20
    i tried in the query with a calculate KF with exception aggregation , MAX with Reference to calday , but this still show both records... how can i do it? help gurus.

    Hello,
    If there are sales occuring for the material on two different dates and you include date in there will be always two records.
    I dont understand the need to show the last transaction. Anyways if you still need that you need to remodel the backend.
    Put a DSO on the cube with date in the data field, this will always overwrite the value for the key combination you need.
    Then you can return on this DSO.
    Regards
    Shashank

  • 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.

  • How to fetch last record from a flatfile

    I have a flatfile with 5000+ records and last record is the count record , i want to fetch the last record only through sql loader or External table (OS IS Unix)
    Pls any body can give the answer
    Kiran Kumar Thayyuru
    Message was edited by:
    user557500

    you migth want to take a look at the option CONTINUEIF LAST

  • How to retrieve last record entered into database

    Hi all,
    I want to retrieve the last resord entered into a database table.
    I have a MS Access database.
    This code does not return the last record but its my nearest attempt to.
    Can anyone suggest the correct SQL or Solution.
    Help is greatly appriciated.
    Thanks.
    String str = "SELECT * FROM Missions WHERE Mission = (SELECT MAX(Mission) FROM MISSIONS)";
            ResultSet rs = null;
                String f1 = null, f2 = null, f3 = null, f4 = null;
                try{   
                    rs = statement.executeQuery(str);
                    txtMissionInformation.setText("");
                    int row = 0;
                    while(rs.next()){
                        f1 = rs.getString(1);
                        f2 = rs.getString(2);
                        f3 = rs.getString(3);
                        f4 = rs.getString(4);
                        System.out.println(f1 + " " + f2 + " "+f3+" "+f4);
                        txtMissionInformation.append(f1 + ", "+ f2 + ""+","+f3+","+f4);
                    System.out.println("Query Complete !");
                } catch(Exception e){
                    e.printStackTrace();
                }

    I fixed my problem, i aded an autonumber field to my database set it as primary key and called it ID. i then used the syntax from before and it worked.

  • How to pull videos recorded on iPod off device; transfer to computer (if files are too large to email)?

    I've recorded 2 short videos on my iPod with the camcorder function, but they are too long/large to email to myself (I am not interested in cutting them any shorter). What are my options for transferring these files from my iPod to my Macbook Pro?

    iOS: Importing personal photos and videos from iOS devices to your computer

  • 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

  • Getting last record from mseg

    Hi,
    Can any one tell me how to get last record from any db(MSEG) table?
    reward guaranteed
    kaki

    Hello,
    Entries have no "natural order" within a database, apart from the primary key. If you need the "last entry" then you need to know what defines the last entry. If the last entry is the one with the highest year (MJAHR) the you could select it like this:
    data: ls_mseg type mseg.
    select * from mseg into ls_mseg.
        where bwart = 321
          and ebeln = 400000005
          and mjahr = ( select max( mjahr ) from mseg
                          where bwart = 321
                            and ebeln = 400000005 ).
    "process result in ls_mseg
    endselect.
    Note: This is a loop because there might be more than one matching entry.
    best regards
    Roland

  • How to get the last record??

    Hi, I now have to get only the last record from one table
    from MS Access.
    I was looking for the useful method from API, however,
    I cannot get it.
    How to get only the last record from one table ???
    Please help, thanks.

    In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
    Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
    So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
    For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
    select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
    the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
    bRi

  • How do I display last record in database?

    I have a asp guestbook form that I finally have working only
    when the info is sent to me via email, it shows me the first entry
    in the database each time. How do I get it to select/email only the
    last entry?
    Any advice is appreciated!

    "innovationlab" <[email protected]> wrote in
    message
    news:e8u951$1ll$[email protected]..
    > Can't really be sorted, it just has name, email and
    message.
    Then you have no way of knowing which is the last record. You
    need an
    autonumber field or a date/time field in order to be able to
    sort the
    records so you know which one is the last.
    Tom Muck
    co-author Dreamweaver MX 2004: The Complete Reference
    http://www.tom-muck.com/
    Cartweaver Development Team
    http://www.cartweaver.com
    Extending Knowledge Daily
    http://www.communitymx.com/

  • How to restrict the last record and not moving to next reocrd

    1) how to restrict the last record and not moving to next reocrd.
    2) Also for the F6 key(for new record).

    When you are on the last record, next-record will create a new one, so that my question is do you want to forbid new record creation.
    Francois

  • How to come out of loop at last record?

    As I told in my previous posts,Iam transferring data from excel to zgkmaster tabel
    table structure:
    eid
    ename
    First I did SHDB(recording) and then made my BDC program.There are 10 records in table with names gopi,hari,rajesh.... with eid 1 to 10.My task is to updated all these names to 'XXX' for all 10 records (just for simple purpose).In my program I called 'Call transaction 'se11' using ptable mode 'A'.I moved from first screen to last screen (where you will update XXX and save for each record').Here:
    Loop at ptable into otable
    perform screens using <program name> <number> 'X'
    perform fields using zgkmaster-ename , otable-ename
    perform fields using 'BDC_OKCODE' , 'SAVE'
    perform screens using <program name> <number> 'X'
    perform fields using 'BDC_OKCODE' , 'NEXT'
    endloop.
    This code works fine in 'A' mode,but at last record a message comes 'Function code cannot be selected' (i think 'next' cannot be executed as it is last record) but all records are updated.
    When the mode is changed to 'N' and 'E',nothing is saved and the same error 'Function code cannot be selected'.Due the this error whatever data we give before that is not saving into table,may be due to this error.
    Now how shoud i make the loop exit when it reaches last record,i tried even with hardcording
    if sy-index = 10.
    leave prograam'
    endif.
    perform.....'NEXT' statement
    But the program is not exiting,I dont know why?Can anyone help me,I think if i made the loop to exit before next statement for last record that error will not occur.advise me if anything wrong.
    Thanks in advance
    The problem is that
    endloop

    Hi..
    1. To Terminate the LOOP in Last record.
        LOOP AT ITAB.
            << PROCESSING LOGIC>>
             AT LAST.
               EXIT.
             ENDAT.
        ENDLOOP.
    2. It is necessary to Declare the Internal table with same structure as the Excel file
    3. It is not necessary to call the Screen Explicitly before filling the BDCDATA record.
        If you want to process the Screen Twice the Fill the SAME SCREEN twice in BDCDATA Table and set the DYNBEGIN = 'X' in both the cases.
    REWARD IF HELPFUL.

Maybe you are looking for

  • Help with SAP NetWeaver 7.0 SR1

    Hi, I am a university student and ı want to learn ABAP. I try to install netweaver but I get the following error : An error occurred while processing option SAP NetWeaver 7.0 SR1 including Enhancement Package 1 > SAP Application Server ABAP > MaxDB >

  • Exposure Data in iPhoto

    I just returned from vacation after using my new Canon 40D and uploaded my photos to iPhoto (v.6?). I bracketed the exposures and played around with the white balance and picture styles. Now when I am viewing the photos, it would be nice to see the e

  • Another Bean Question.

    I have a Vector of Vectors in request scope that is holding search results. <jsp:useBean id="searchResults" class="java.util.Vector" scope="request" />as I iterate through the Vector, I am pulling each (sub)Vector off and printing out the contents.  

  • Registration key for QTPRO7 ?

    Hi, I've bought two registration keys online, both times I get a receipt for purchase in my inbox, but NO unlock Key ..am I missing something .. or is this just a scam?

  • XML Publisher & Sybase

    How well would XML publisher go with Sybase? Any customer examples who are using such a combination ? Thanks in advance.