How to fetch first 4 records from database.

hi experts.i am inexperience in this field.
please tell me suppose i want to extract only 4 records from the database ,
what is the select statement for this .
best regards.
subhasis.

Hi
use this program as example.
u wil get solution.
REPORT  ZSEN_ABAP_TABLE                         .
Tables : mara.
data : wa_mara type mara,
       it_mara type table of mara.
SELECT * UP TO 4 ROWS FROM MARA INTO TABLE it_mara.
loop at it_mara into wa_mara.
Write : / wa_mara-MATNR,
         wa_mara-MTART,
         wa_mara-BISMT.
endloop.
Thanks
Senthil

Similar Messages

  • 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

  • How to fetch latest data from database instead of clicking on Generate report in RSRT?

    Hi all,
    We are not able to get latest data of BEx query.Everytime we have to click on Generate Report  button in RSRT for getting latest value.
    Is there any way to get latest value automatically? We are not doing any changes in query.
    When we click on Generate Report it is fetching data from Database instead of cache,so if it is possible to disable cache or any other workaround?
    We have used time(0TIME) characteristic in query as a formula variable. We have applied a condition on that variable to fetch the first record (latest value). When we click on generate report, it fetches correct value with latest time but when we run the query without generate report, it is not fetching latest value. The cube on which this query is developed, is a realtime cube.
    Regards,
    Zalak

    Once its in the request attributes it would be far better to use JSP Expression Language as well as the JSTL that Malcolm suggested So if the servlet code said:
         request.setAttribute("myList", al);Then using EL and the JSTL tags from <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> the JSP would look something like:
    <c:forEach items="${myList}" var="user">
    <TR>
       <TD><c:out value="${user.name}" /></TD>
       <TD><c:out value="${user.fname}" /></TD>
       <TD><c:out value="${user.city}" /></TD>
       <TD><c:out value="${user.cont}" /></TD>
       <TD><c:out value="${user.age}" /></TD>
    </TR>
    </c:forEach>

  • How to fetch corresponding records from 2 tables using ADF Toplink & EJB

    Hi,
    I am unable to fetch records from 2 tables, which has a foregin key.Used the custom query in toplink, But the output is the cartition of the first table draged and the first row of the second table.The output required should be in the form of ADF Table. I am able to find the output in JSF data table.
    Two tables:
    Table name:Solutions
    sol_id varchar2(PK)
    sol_name varchar2
    Table name:Solution_details
    sol_id varchar2(FK)
    common_asum_id varchar2(PK)
    common_detail varchar2
    Output Required:
    sol_id,sol_name,common_asum_id,common_detail
    Custom query:
    SELECT * FROM solutions a
    ,solution_details b
    WHERE a.sol_id=b.sol_id

    Hi,
    I am unable to fetch records from 2 tables, which has a foregin key.Used the custom query in toplink, But the output is the cartition of the first table draged and the first row of the second table.The output required should be in the form of ADF Table. I am able to find the output in JSF data table.
    Two tables:
    Table name:Solutions
    sol_id varchar2(PK)
    sol_name varchar2
    Table name:Solution_details
    sol_id varchar2(FK)
    common_asum_id varchar2(PK)
    common_detail varchar2
    Output Required:
    sol_id,sol_name,common_asum_id,common_detail
    Custom query:
    SELECT * FROM solutions a
    ,solution_details b
    WHERE a.sol_id=b.sol_id

  • How to access next record from database on to form

    hi
    i have written the following piece of code to retrieve data from database oon to form...
    Try
                rset = oDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                query = "Select * from [@TEST]  where Code =  ('" + oform.Items.Item("6").Specific.value + "') "
                rset.DoQuery(query)
            Catch ex As Exception
                SBO_Application.MessageBox(ErrorToString)
            End Try
            '  oform.Items.Item("6").Specific.value = rset.Fields.Item("Code").Value
            oform.Items.Item("7").Specific.value = rset.Fields.Item("Name").Value
            oform.Items.Item("8").Specific.value = rset.Fields.Item("U_Sal").Value
    but i can see only one record on my form controls.... i have placed on more button called " Next" so that i can access next records from DB when i click on "Next" button...
    Public Sub NextRecords()
    Try
         rset.MoveFirst()
                While Not rset.EoF
                 '   oform.Items.Item("6").Specific.value = rset.Fields.Item("Code").Value
                   oform.Items.Item("7").Specific.value = rset.Fields.Item("Name").Value
                  oform.Items.Item("8").Specific.value = rset.Fields.Item("U_Sal").Value
                   rset.MoveNext()
                End While
                rset.MoveNext()
          Catch ex As Exception
               SBO_Application.MessageBox(ErrorToString)
          SBO_Application.MessageBox("Updated")
           End Try
    End sub
    i'm not able to access next records...
    plz provide me the solution and code for this how to handle this scenario....

    From your question and code sample given, I think the problem is you are seeing only the last record when pressing the next button.
    In the Next button press, you are coded such a way that it will populate the last record.
    Try removing the do..While.. loop and simply code like
    if Not rset.EoF
    rset.MoveNext()
       oform.Items.Item("6").Specific.value = rset.Fields.Item("Code").Value
       oform.Items.Item("7").Specific.value = rset.Fields.Item("Name").Value
       oform.Items.Item("8").Specific.value = rset.Fields.Item("U_Sal").Value
    end if
    So when you click next, you can see the next record. Not the last record.
    Anoop

  • Hiding first record from database in input text fields.

    Hi,
    I have 2 pages, a main page and a popup page. The main page has attributes from a VO in the form of input texts (I just dragged individual attributes) and a link that brings up the popup page. On the popup page I have an ADF Search Form and a Read-Only Table with selection. A user is able to search for records in the database then select the result and submit that row back to the main page which populates the input texts. When you first load the main page, the input texts that are linked to the VO iterator are already populated with the first row in the database. Is there a way to hide these values (but not the entire text fields) until after the user has searched from the popup?
    Thanks in advance.

    Hi,
    thanks much for the replies. Luc, I tried adding that Refreshcondition to the iterator in the pagedef and the result was when I ran the page, the textboxes and record would be gone but the label remained (close but I still need the empty box to show). Also, after running a search in the dialog box and submitting the result back to the main page, the values would still not show up, it just looked the same as when I first run the page.
    Did I put the RefreshCondition in the wrong place, or is it something else?
    Thanks again.

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

  • ADF BC How to read a record from database in a bean

    Due to the problem I have in this thread Re: Inserting multiple rows programmatically got unique key error I need a work around. One work around is checking whether a record is exist in database prior to insert/commit. This can be achieve whether reading the record and if found that it exists or there is function that I can call to check whether a record is exist. Please note that the search criteria (read criteria) is a combination of two fields.
    Thanks.

    It's kind of unproductive to open a new thread, as we now need to keep track of two threads.
    If you korean a new thread you should provide all info to understand the problem, the jdev version you use and the user case. All this info is missing in this thread, but given in the other thread. Conclusion is that we should continue in the other thread.
    Timo

  • 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 delete the records from database table without using work area

    Hi all,
    The purpose of the down program is to delete the entire contents from all the tables. The deletion of the table should be in sorted manner. Is there any other way to write the code more efficiently,
    TABLES: ZFFMCTL_AP, ZFFMHDR_AP, ZFFM_CHANGE_LOG, ZFFMDTL_AR, ZFFMHDR_AR, ZFFMDTL_JV, ZFFMHDR_JV, ZFFMDTL_SKF,ZFFMHDR_SKF,ZFINVOICE_DETAIL, ZFFMMASTER, ZFFMLOGREAD_CLUS, ZFFMCTL.
    DELETE ZFFMCTL_AP.
    IF SY-SUBRC = 0.
    DELETE ZFFMMHDR_AP.
    IF SY-SUBRC = 0.
    DELETE ZFFM_CHANGE_LOG.
    IF SY-SUBRC = 0.
    DELETE ZFFMDTL_AR.
    IF SY-SUBRC = 0.
    DELETE ZFFMHDR_AR.
    IF SY-SUBRC = 0.
    DELETE ZFFMDTL_JV.
    IF SY-SUBRC = 0.
    DELETE ZFFMHDR_JV.
    IF SY-SUBRC = 0.
    DELETE ZFFMDTL_SKF.
    IF SY-SUBRC = 0.
    DELETE ZFFMHDR_SKF.
    IF SY-SUBRC = 0.
    DELETE ZFINVOICE_DETAIL.
    IF SY-SUBRC = 0.
    DELETE ZFFMMASTER.
    IF SY-SUBRC = 0.
    DELETE ZFFMLOGREAD_CLUS.
    IF SY-SUBRC = 0.
    DELETE ZFFMCTL.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    Waiting for response,
    Thanks in advance
    John

    Write this way....
    TABLES: ZFFMCTL_AP, ZFFMHDR_AP, ZFFM_CHANGE_LOG, ZFFMDTL_AR, ZFFMHDR_AR, ZFFMDTL_JV, ZFFMHDR_JV, ZFFMDTL_SKF,ZFFMHDR_SKF,ZFINVOICE_DETAIL, ZFFMMASTER, ZFFMLOGREAD_CLUS, ZFFMCTL.
    DELETE ZFFMCTL_AP.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMMHDR_AP.
    CHECK SY_SUBRC = 0.
    DELETE ZFFM_CHANGE_LOG.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMDTL_AR.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMHDR_AR.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMDTL_JV.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMHDR_JV.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMDTL_SKF.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMHDR_SKF.
    CHECK SY_SUBRC = 0.
    DELETE ZFINVOICE_DETAIL.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMMASTER.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMLOGREAD_CLUS.
    CHECK SY_SUBRC = 0.
    DELETE ZFFMCTL.

  • Fetch records from Database based on Input value

    Hi Experts,
    In my mobile application, I have designed one input field with F4 help or input assist. I need to fetch records from database based on that input and need to display records in table.
    My question is:
    How to fetch the records from database/back end based on the input value and display them as table format as we are doing in SAP ABAP?
    Here, I need to fetch the records based on input value available in the UI screen and pass that value to gateway, fetch the records from database and need to bind with table in SAPUI5.
    Kindly share the whole process flow with sample code for this requirement. Hope I have explained the requirement in detail.
    Thanks In Advance..
    Regards,
    Arindam Samanta.

    Hi,
    Try something like this.
    In this, I am passing From date, To date, RelGrp, RelStr, Uname as input. Then I am storing those values in variables and passing this data in Odata request.
    OData.read({ requestUri: "http://xxxx:8000/sap/opu/odata/sap/Z188_PO_SRV/pos?$filter=Docdate le datetime'"
                    + todateformat+"T00:00:00' and Docdate ge datetime'"
                    + fromdateformat+"T00:00:00' and RelGrp eq '"
                    + relcode +"'and RelStr eq '"
                    + relstg +"'and Uname eq '"
                    + username+ "' "},
      function (data) {
    console.log(data);
    When we are giving correct inputs it will goes to Success function and get the data from back end.
    In console we can see the data.
    Hope this will helps to you.
    Thanks&Regards
    Sridevi

  • To fetch XML files from database  AND regarding barcodes

    Hi !!
    I am very new to this forum...this is my first mail to this forum...
    1.) Actually I would like to know how to fetch XML files from database and then how to get the datas from that XML files???Right now i am using struts frame work...If u anyone send some sample code for this one,it is Very helpful for me.....
    2.)Using java ,how to generate Barcodes?In database I have Some serial number.While I try to display the serial number in Front end ,I should display with Barcode Corresponding to that number.Plz send some sample codes if u have.....
    Thanks in ADVANCE,

    PonJAVA wrote:
    Hi !!
    I am very new to this forum...this is my first mail to this forum...
    1.) Actually I would like to know how to fetch XML files from databaseStart with a JDBC tutorial. Check out DAO Pattern and Hibernate as well.
    and then how to get the datas from that XML files???Google Java & XML (there are many ways to do this
    Right now i am using struts frame work...Okay...
    If u anyone send some sample code for this one,it is Very helpful for me..... You haven't provided any detail regarding your task so there's no way anyone could post code for you.
    2.)Using java ,how to generate Barcodes?Search Google
    In database I have Some serial number.While I try to display the serial number in Front end ,I should display with Barcode Corresponding to that number.Plz send some sample codes if u have.....Try a JSP/Servlet tutorial.

  • Unable to fetch records from database with huge selection screen

    Hi all,
    I have 20 fields from selection screen.
    I have a z table with these 20 fields .
    Now with the values entered in the selection screen i have to fetch the records from the z table.
    All fields in the selection screen are not mandatory, the user may or may not enter the values.
    I have to fetch the records based on the values entered.
    I wrote a select with where condtion to all those 20 fields. but its not retreving the records.
    All the fields in the selection screeen are parameters.
    Could you help me on this, please. I wrote in the where conditon with field1 = value AND field 2 = value.. etc... field20 = value.
    Please guys help me out.
    KV.
    Edited by: Nithin Kumar on Mar 18, 2008 8:48 AM

    Guys,
    I have a problem with the select query.
    as i said i have 20 fields, ranges are working for few fields.
    But i have couple of fields as descriptions. So i have to fetch the records for pattenr as well.
    Means, user can enter in the description............. like    "ab". So in the description if there is anything   with 'ab' it should fetch.
    it works with a LIKE statement with % symbols.
    but it doenst work with   ranges and patterns in same select. I mean the below is not working.
      SELECT  *
             FROM crmd_orderadm_h
             INTO table itab
             WHERE object_id IN r_obj AND
                   process_type IN r_pro AND
                   description LIKE s_des.
    r_obj, r_pro are ranges  and s_des is the pattern, ex: %ab%.              so in this case how it has to be done... could you please help me on this.. the other fields could be blank( r_obj and r_pro).. 
    kindly help me out......
    KV

  • Fetch the records from cache

    say i have emp table
    eno ename sales
    1 david 1100
    2 lara 200
    3 james 1000
    1 david 1200
    2 lara 5400
    4 white 890
    3 james 7500
    1 david 1313
    eno can be duplicate
    when i give empno is 1
    i want to display his sales i.e 1100,1200,1313
    first time i will go to database and fetch the records
    but next time onwards i dont go to database; i will fetch the records from cache;
    i thought doing it using hashmap or hasptable ;both those two don't allow duplicate values(empno has duplicate values);
    How to solve this problem.

    Hi,
    Ever considered splitting that table up. You are thinking about caching thats a
    very good idea. But doesnt it make it vary evident that the table staructure that you have
    keeps a lot of redundant data. Specially it hardly makes a sense to have sales
    figures in a emp table. Instead you can have Emp table containing eno and
    ename with eno as the primary key and have another table called sales with eno
    and sales columns and in this case the eno references the Emp table.
    If you still want to continue with this structure then I think you can go ahead with
    the solution already suggested to you
    Aviroop

  • Can we split and fetch the records in Database Adapter

    Hi,
    I designed a Database Adapter to fetch the records from oracle Database. Some time, the Database Adapter need to fetch around 5000, or 10,000 records in single shot. In that case my BPEL process is choking and getting error as
    java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2882) at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
    Could someone help me to resolve this?
    In Database Adapter can we split and fetch the records, if number of records more then 1000.
    ex. First 100 rec as one set and next 100 as 2nd set like this.
    Thank you.

    You can send the records as batches useing the debatching feature of db adapter. Refer documentation for implementation details.

Maybe you are looking for