How to use cursors in abap

Hi,
    How to use cursor(sql Cursor) in abap program  could any one help me..
Advance Thanks
Regards
Guhapriyan

Hi Guhapriyan,
Have a look at demo programs DEMO_SELECT_CURSOR_1, DEMO_SELECT_CURSOR_2 and DEMO_SELECT_CURSOR_3.
Thanks
Lakshman

Similar Messages

  • Why and how to use events in abap objects

    Dear all,
      Please explain me why and how to use events in abap objects with real time example
    regards
    pankaj giri

    Hi Pankaj,
    I will try to explain why to use events... How to use is a different topic.. which others have already answered...
    This is same from your prev. post...
    Events :
    Technically speaking :
    " Events are notifications an object receives from, or transmits to, other objects or applications. Events allow objects to perform actions whenever a specific occurrence takes place. Microsoft Windows is an event-driven operating system, events can come from other objects, applications, or user input such as mouse clicks or key presses. "
    Lets say you have an ALV - An editable one ...
    Lats say - Once you press some button  you want some kind of validation to be done.
    How to do this ?
    Raise an Event - Which is handled by a method and write the validation code.
    Now you might argue, that I can do it in this way : Capture the function code - and call the validate method.
    Yes, in this case it can be done.. But lets say .. you change a field in the ALV and you want the validation to be done as soon as he is done with typing.
    Where is the function code here ? No function code... But there is an event here - The data changed event.
    So you can raise a data changed event that can be handled and will do the validation.
    It is not user friendly that you ask the user to press a button (to get the function code) for validation each time he enters a data.
    The events can be raised by a system, or by a program also. So in this case the data changed event is raised by a system that you can handle.
    Also, Lets say on a particular action you want some code to trigger. (You can take the same example of validation code). In this case the code to trigger is in a separate class. The object of which is not available here at this moment. (This case happens very frequently).
    Advantage with events : Event handlers can be in a separate class also.
    e.g : In the middle of some business logic .. you encounter a error. You want to send this information to the UI (to user - in form of a pop up) and then continue with some processing.
    In many cases - A direct method call to trigger the pop up is not done. Because (in ideal cases) the engine must not interact with UI directly - Because the UI could be some other application - like a windows UI but the error comes from some SAP program.
    So - A event is raised from the engine that is handled in the UI and a pop up is triggered.
    Here -- I would have different classes (lets say for different Operating Systems). And all these classes must register to the event ERROR raised in application.
    And these different classes for different Operation systems will have different code to raise a pop-up.
    Now you can imagine : If you coded a pop-up for Windows (in your application logic) .. it will not work for Mac or Linux. But of you raise a event.. that is handled separately by a different UI classes for Win, Linux or Mac  they will catch this event and process accordingly.
    May be I complicated this explanation .... but I couldn't think of a simpler and concrete example.
    Cheers.
    Varun.

  • How to use wildcards in ABAP query where condition?

    Hi,
    Please tell me how to use wildcards in ABAP qurey where condition.
    e.g. select * from mara where matnr = * (wildcard we need to use.
    Thanks & Regards,
    Gaurav T

    Do you want to query asterix * ?
    select * from mara where matnr = '*'.  "then just put it in apstrophes
    or you want certain part of string be used as * ?
    select * from mara where matnr like '%*'  "then use % sign before it
    or maybe you want something like this
    select * from mara where matnr like '%1' . "then it will look for all materials having '1' inside it
    Regards
    Marcin

  • How to use RSAN_PROCESS_EXECUTE in abap program

    Hi all,
    Does someone know how to use RSAN_PROCESS_EXECUTE in a abap program to execute an analytical process created in the transaction RSANWB?
    I create a variant 'ZPC_ALIM_DL' for RSAN_PROCESS_EXECUTE. I would like to execute this program with this variant in a background job, but it seems that the job executed but it does nothing.
    See below a part of the code.
    SUBMIT RSAN_PROCESS_EXECUTE
                 WITH VARIANT = 'ZPC_ALIM_DL'
                 USER SY-UNAME VIA JOB L_JOBNM1 NUMBER L_JOBCOUNT1
                 AND RETURN.
    Thanks in advance,
    L.

    Hi Ludovic,
              I am using RSAN_PROCESS_EXECUTE with a variant in process chain. simply include 'abap program' type in process chain mention RSAN_PROCESS_EXECUTE as the program name and mention the variant you created for your apd process and run. I have tested it in dev and it has worked for me. let me know if this helps!
    Thanks
    Suresh R Kovvuru

  • How to use cursor function for nested xml

    Hi,
    i have a query for XMLQuery like
    select * from bills where bill_id=????
    it results in something like
    <bills>
    <bill>
    <city>london</city>
    <amount>44</amount>
    </bill>
    <bill>
    <city>london</city>
    <amount>988</amount>
    </bill>
    <bill>
    <city>new york</city> <amount>59</amount> </bill>
    </bills>
    but i want xml output to be sorted for city names adding one more level location like
    <bills>
    <location city="london">
    <bill>
    <amount>44</amount>
    </bill>
    <bill>
    <amount>988</amount> </bill>
    </location>
    <location city="new york">
    <bill>
    <amount>59</amount> </bill>
    </location>
    </bills>
    it should be possible to iterate through the same table to gather informaton with the help of cursor function, but never used CURSOR before.
    any idea?

    sreese wrote:
    p_desig works as a comma delimited string without the NVL function, that's not the issue.
    It IS the issue .. you need to provide  a SAMPLE so we can see what you're doing ..
    How are you "passing it in" ?
    option A:
    procedure ( in_var  in  VARCHAR2 )
    AS
    and nvl(sn.c_attribute1,'x@#$%') in nvl(in_var,'x@#$%')
    option B:
    and nvl(sn.c_attribute1,'x@#$%') in nvl(&1,'x@#$%')
    .. or some other method?

  • How to use cursor in php?

    for example:
    CURSOR CUR_ORDER IS
    select distinct a.sales_branch segment2,a.order_number,
    a.delivery_id,
    a.sold_to_customer_id customer_id,
    a.bill_to_customer_id,
    a.ship_to_customer_id,
    a.purchase_order,to_char(a.ordered_date,'yyyy-mm-dd') order_date
    from vv_ar_temp_tl a;
    how to use it in php program?

    Hi,
    I do not know what exactly is Your question about. I'll try to give an overview:
    1. "CURSOR CUR_ORDER IS" is PL/SQL syntax, not PHP
    2. result of oci_parse call is in fact a CURSOR, so I think You already know how to use it.
    3. if Your question is on how to pass cursor between PL/SQL and PHP, I use:
    a) PL/SQL procedure:
    CREATE OR REPLACE
    PROCEDURE TEST_P (PO_REF_CURSOR OUT SYS_REFCURSOR) AS
    BEGIN
    OPEN PO_REF_CURSOR FOR -- Opens ref cursor for query
    SELECT OBJECT_NAME, OBJECT_TYPE FROM USER_OBJECTS WHERE ROWNUM <= 5;
    END;
    b) in PHP:
    $conn = ocinlogon($database_user, $database_passwd, $database); // connect database
    $outrefc = ocinewcursor($conn); //Declare cursor variable
    $mycursor = ociparse ($conn, 'begin test_p(:curs); end;'); // prepare procedure call
    ocibindbyname($mycursor, ':curs', $outrefc, -1, OCI_B_CURSOR); // bind procedure parameters
    $ret = ociexecute($mycursor); // Execute function
    $ret = ociexecute($outrefc); // Execute cursor
    $nrows = ocifetchstatement($outrefc, $data); // fetch data from cursor
    ocifreestatement($mycursor); // close procedure call
    ocifreestatement($outrefc); // close cursor
    ocilogoff($conn); // close database connection
    var_dump($data); // show content fo $data variable
    Now $data contains arrays of columns with arrays of rows from query.
    Hope it helps You,
    Regards,
    Pawel

  • How to use Cursor Paramter

    Hi all,
    My query will written values by passing 5 parameter values.
    Now i want to use this query in plsql cursor, For that i need to use cursor parameter concepts and its very new to me. so pls any one help me how to use this cursor parameter to pass the values when i run my procedure.
    Regards
    Ajantha

    If you mean writing cursor with parameters you could try this way.
    CURSOR c1 (name VARCHAR2, salary NUMBER) IS SELECT ...
    --- open the cursor:
    OPEN c1(emp_name, 3000);
    Link for more info
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/06_ora.htm#36656
    Thanks

  • How to use cursors on Smith Chart?

    Hi everybody,
        Last 7 days , i was trying to point some markers on Smith chart.
    Please suggest any method to implement this. i want to mark some points on smith chart and get data.
    thank you,
    dg7318
    Solved!
    Go to Solution.

    thankyou nyc,
    I am seeing the demos.llb but nothing is mentioned about using cursors or markers. 
    I am plotiing impedance on smith chart. I want to put some markers on the chart. I also want to control the placement of those markers. I wish to get data (impedance and frequency) wherever the marker is positioned. 
    Again thanks for ur help.
    dg,
    the things that seems to be impossible first, after completion gives u real happiness..

  • How to use cursor data in more than one location in form?

    hi all.
    is it possible to make cursor as global or public in the form so i can use its data in more than location for testing like in buttons triggers.
    for example:
    if i declare the following cursor in "WHEN-NEW-FORM-INSTANCE" trigger
    CURSOR cur
    IS
    SELECT ID, NAME
    FROM PERSON;how can i use this cursor in other triggers in other buttons in the form?
    thanks

    kareem wrote:
    now i have the old data- from cursor and the new- from tableNo, you have not. When you open the cursor you get the state of the database at the current SCN.
    If you
    - open your cursor, fetch the data and close the cursor
    - update some data
    - open your cursor, fetch the data and close the cursor
    you will get the updated data from your cursor the second time (unless your update isn't a uncommited autonomous transaction but I wouldn't go down that route).
    You will have to save your data somewhere or you might take a look at flashback: http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/consist.htm#i20759
    cheers

  • How to use cursor data in more than one location in the form?

    hi all.
    is it possible to make cursor as global or public in the form so i can use its data in more than location for testing like in buttons triggers.
    for example:
    if i declare the following cursor in "WHEN-NEW-FORM-INSTANCE" trigger
    CURSOR cur
    IS
    SELECT ID, NAME
    FROM PERSON;how can i use this cursor in other triggers in other buttons in the form?
    thanks

    kareem wrote:
    now i have the old data- from cursor and the new- from tableNo, you have not. When you open the cursor you get the state of the database at the current SCN.
    If you
    - open your cursor, fetch the data and close the cursor
    - update some data
    - open your cursor, fetch the data and close the cursor
    you will get the updated data from your cursor the second time (unless your update isn't a uncommited autonomous transaction but I wouldn't go down that route).
    You will have to save your data somewhere or you might take a look at flashback: http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/consist.htm#i20759
    cheers

  • How to use Cursor's Fetch to return multiple column Data

    Hi ,
    This is my Table :
    SQL> select * from Login;
    USERNAME PASSWORD CONFIRMPASSWORD
    RAvi SAI SAI
    Kiran Keyboard Keyboard
    VARNU JAINA JAINA
    This is my stored Procedure , for that Table , this is working fine , where he Cursor's Fetch is returning only a Single column of Data .
    CREATE OR REPLACE PROCEDURE getEmpName(EMP_ID IN VARCHAR2)
    IS
    EMPNAME VARCHAR2(50);
    CURSOR MYCUR
    IS
    SELECT USERNAME from login where USERNAME=EMP_ID;
    BEGIN
    OPEN MYCUR ;
    LOOP
    FETCH MYCUR  INTO EMPNAME;
    DBMS_OUTPUT.PUT_LINE(EMPNAME);
    EXIT WHEN MYCUR%NOTFOUND;
    END LOOP;
    close MYCUR ;
    END;
    Now , I have a requirement as , i need to get the Password also along with Username ,
    Please tell me how can i use FETCH of Cursor to populate Details into the Declared Variables
    FETCH MYCUR  INTO EMPNAME;
    CREATE OR REPLACE PROCEDURE getEmpName(EMP_ID IN VARCHAR2)
    IS
    EMPNAME VARCHAR2(50);
    PASSWORD VARCHAR2(50);
    CURSOR MYCUR
    IS
    SELECT USERNAME , PASSWORD from login where USERNAME=EMP_ID;
    BEGIN
    OPEN MYCUR ;
    LOOP
    FETCH MYCUR  INTO EMPNAME; // Help needed here**
    DBMS_OUTPUT.PUT_LINE(EMPNAME);
    EXIT WHEN MYCUR%NOTFOUND;
    END LOOP;
    close MYCUR ;
    END;
    Edited by: user10503747 on Oct 14, 2010 11:51 AM
    Edited by: user10503747 on Oct 14, 2010 11:52 AM

    1) I'm hoping that this is a homework assignment. You would never, in the real world, store a password in clear text. And you would never, from a database design, have separate Password and ConfirmPassword columns.
    2) The INTO clause can accept a list of variables. So
    FETCH your_cursor_name INTO local_variable1, local_variable2;would be valid.
    3) You would generally want to avoid having local variables that share the name of a column-- that leads to some pretty serious confusion related to scoping. One common convention is to prefix local variables with a "l_".
    4) You would generally want local variables to inherit the type of the column rather than explicitly declaring the length of a string in your procedure. That way, if you change the table in the future, your code will continue to work.
    5) And finally, a procedure that just calls DBMS_OUTPUT would cause all sorts of red flags in reality. It would make far more sense for this to be a function that returns a value than a procedure that tries to write to a buffer that the client application may or may not have created.
    Justin

  • How to use FORMULA in ABAP for calculation

    hi all,
    i have to do some calculation in my report and because of this reason i want to use formula. Could any body tell me the best way to use of formula for calculation purpose in ABAP or any other way?
    Thansk,
    abapfk
    Moderator Message: You don't need to open a thread to know the answer for this basic question. A simple search or using ABAP Help will help in getting the answer.
    Edited by: kishan P on Oct 4, 2010 11:20 AM

    There is another option to do the same thing.
    What can be done is, create running total. You can create running total from field explorer by right clicking and then new. Create Running Total Field dialog box appears. In that, provide the following:
    i)     Field to summarize - provide the field to maximize (i.e. id)
    ii)     Type of summary u2013 Maximum
    iii)     Evaluate u2013 On change of field (provide the name)
    iv)     Reset u2013 Never
    Keep this Running total field on the details section and suppress if you do not want to show it in the details section. Place this field wherever you want in the report.
    Hope this helps you. Let me know your comments.

  • How to use structure in ABAP program

    I developing a report in smartforms but i want some fields to be display on the report but unable to find the relvent table as the field is show in structure.i can not find the actual table . is there any specfic way to find the table .or is there any way to use the fields defind in structure in my ABAP program.

    Hi,
      May be iam not clear with the question. But why you want to use structure. In report you can define your own structure, also you can declare your fields directly using standard datatypes.
    Hope this will help!!!
    Amol

  • How to use PUSHBUTTON in ABAP Program?

    Hi, I'm not able to get any output for the below code.
    SELECTION-SCREEN BEGIN OF BLOCK TT WITH FRAME TITLE TEXT-004.
    PARAMETERS : X(15) TYPE C DEFAULT 'HI SAPERS'.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(70) TEXT-000.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN SKIP 2.
    SELECTION-SCREEN ULINE.
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN PUSHBUTTON 1(10) TEXT-001 USER-COMMAND pb01.
    SELECTION-SCREEN PUSHBUTTON 20(10) TEXT-002 USER-COMMAND pb02.
    SELECTION-SCREEN END OF BLOCK TT.
    *DATA: OK_CODE LIKE SY-UCOMM.
    AT SELECTION-SCREEN.
    AT USER-COMMAND.
      CASE SY-UCOMM.
      WHEN 'PB01'.
      write:/ 'hello'.
        WRITE : / 'STRING ENTERED IS :', X.
      WHEN 'PB02'.
        LEAVE PROGRAM.
    ENDCASE.
    WRITE : / '!! AFTER EVENT !!'.
    ty

    Hi
       Check below sample code.
    TABLES sscrfields.
    DATA flag(1) TYPE c.
    SELECTION-SCREEN:
        BEGIN OF LINE,
          PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
          PUSHBUTTON 12(10) but2 USER-COMMAND cli2,
        END OF LINE,
        BEGIN OF LINE,
          PUSHBUTTON 2(10) but3 USER-COMMAND cli3,
          PUSHBUTTON 12(10) but4 USER-COMMAND cli4,
        END OF LINE.
    AT SELECTION-SCREEN.
      CASE sscrfields-ucomm.
        WHEN 'CLI1'.
          flag = '1'.
        WHEN 'CLI2'.
          flag = '2'.
        WHEN 'CLI3'.
          flag = '3'.
        WHEN 'CLI4'.
          flag = '4'.
      ENDCASE.
    INITIALIZATION.
      MOVE: 'Button1' to but1,
            'Button2' to but2,
            'Button3' to but3,
            'Button4' to but4.
    START-OF-SELECTION.
      CASE flag.
        WHEN '1'.
          WRITE / 'Button 1 was clicked'.
        WHEN '2'.
          WRITE / 'Button 2 was clicked'.
        WHEN '3'.
          WRITE / 'Button 3 was clicked'.
        WHEN '4'.
          WRITE / 'Button 4 was clicked'.
        WHEN OTHERS.
          WRITE / 'No Button was clicked'.
      ENDCASE.
      Note that WRITE statements will not work in AT SELECTION-SCREEN events, alternativey you can use some popup to display the same.
       You can also check demo program: DEMO_SEL_SCREEN_PUSHBUTTON
       Hope this clarifies you.
    Kind Regards
    Eswar

  • How to use classes in ABAP report

    I have classes
    1. CL_HRRCF_CANDIDATE_BUPA_BL:-
    to get the name of the candiidate
    to get the add of the candiidate
    to get the telephone no of the candiidate
    2. CL_HRRCF_CANDIDATE_INFOTYPE_BL
    to get the education data of the candiidate
    but i don't know hw to get data from these classes,
    so pls help me outwith an example
    thanks.

    Try this sample code,
      DATA: lr_cdcy                    TYPE REF TO cl_hrrcf_candidacy_bl,
            lr_cand                    TYPE REF TO cl_hrrcf_candidate_bupa_bl,
            stru_requisitions          TYPE if_componentcontroller=>element_requisitions ,
            lt_h_cdcy_list             TYPE rcf_t_list_candidacies_x,
            ls_h_cdcy_list             TYPE rcf_s_list_candidacies_x,
            lt_cdcy_list               TYPE if_componentcontroller=>elements_candidate,
            ls_cdcy_list               TYPE if_componentcontroller=>element_candidate,
            lt_addr                    TYPE rcf_t_addressdata_bp,
            ls_addr                    TYPE rcf_s_addressdata_bp,
            lt_email                   TYPE rcf_t_emaildata_bp,
            ls_email                   TYPE rcf_s_emaildata_bp.
    get all declared attributes
      parent_element->get_static_attributes(
        IMPORTING
          static_attributes = stru_requisitions ).
      CALL METHOD cl_hrrcf_candidacy_bl=>get_instance
        RECEIVING
          return = lr_cdcy.
      CALL METHOD cl_hrrcf_candidate_bupa_bl=>get_instance
        RECEIVING
          return = lr_cand.
    Hole Kandidatur-Informationen der Kandidaten
      TRY.
          lr_cdcy->get_candidacy_list_x(
            EXPORTING
              ps_req_hrobject  = stru_requisitions-hrobject
       ps_cand_hrobject =
       ps_appl_hrobject =
       p_exclude_draft  = 'x'
            IMPORTING
              pt_candidacies_x = lt_h_cdcy_list
        CATCH cx_hrrcf .
      ENDTRY.
    Ergänzen der Informationen mit BusinessPartner-Infos
      LOOP AT lt_h_cdcy_list INTO ls_h_cdcy_list.
        TRY.
            lr_cand->get_contact_data(
              EXPORTING
                ps_cand_hrobject = ls_h_cdcy_list-cand_hrobject
              IMPORTING
                pt_addressdata   = lt_addr
       pt_telefondata   =
       pt_faxdata       =
                pt_emaildata     = lt_email
          CATCH cx_hrrcf .
        ENDTRY.
        READ TABLE lt_addr INDEX 1 INTO ls_addr.
        READ TABLE lt_email INDEX 1 INTO ls_email.
        MOVE-CORRESPONDING ls_h_cdcy_list TO ls_cdcy_list.
        ls_cdcy_list-postcode1 = ls_addr-postl_cod1.
        ls_cdcy_list-city1 = ls_addr-city.
        ls_cdcy_list-email = ls_email-e_mail.
        APPEND ls_cdcy_list TO lt_cdcy_list.
      ENDLOOP.
      CALL METHOD node->bind_table
        EXPORTING
          new_items = lt_cdcy_list.
    ENDMETHOD.
    Regards,
    Pavan

Maybe you are looking for

  • Contacts and Calendar Services Broken

    I have a new build of Mountain Lion Server 10.8.2 and am having problems with the Contacts and Calendar services. The server is an Open Directory Master. I did this build by installing Mountain Lion 10.8 on a new hard drive. I had no interest in migr

  • Power consumption when PowerOFF: 24" iMac 2009

    I really wonder about my iMac 2009 Modell: when using sleep mode I got 11-12 watts power consumption. But when shutting down the iMac (Power Off in Apple Menu), the same iMac takes 10 watts Is this normal and how can I get sleep mode with far less or

  • Cold Fusion Standart Edition Configuring iis7 Help!

    Hi, Well i just got this great task to install and configure a server for the first time. I am a coder, not a network specialist, and IIS7 differs from previous versions and i am still getting used to the interface. Anyways, so i have ColdFusion stan

  • Problem button Controller

    Hi , I'm very new to OAF and have this problem: I have a page with 2 buttons (A) and (B). (A) is added via personalization. when user click (A) have to disable button ( B ), under some conditions. ( ( A) action is to return in the same page ( refresh

  • Icant see installed fp11 in my comp

    i installed fp11.operation was succefully done/received congrat.from adobe site,i cant see no labels,cant find the program in comp.only in uninstallers.help me to solve this problem.