ABAP routine - looping a result set from table.

I am trying to access a table and pass the resulting rows to an internal table.
However, before passing, I need to do some data manipulation on one of the columns of the table and then pass it.
If I didn't have to do this, I could have just said
INTO CORRESPONDING FIELDS OF TABLE
But since I have do data manipulation, I cannot do this. This is what I am doing now.
SELECT * FROM /BI0/QEMPLOYEE WHERE JOB = '1234' AND DATETO = '99991231'.
MOVE /BI0/QEMPLOYEE-EMPLOYEE TO INT_EMP-EMPN.
MOVE /BI0/QEMPLOYEE-JOB TO STR1.
STR2 = STR1 + 0(4)
SEARCH STR2 FOR ' ' STARTING AT 1 ENDING AT 1.
IF SY-SUBRC EQ 0.
REPLACE ' ' WITH '0' INTO STR2.
ENDIF.
MOVE STR2 TO INT_EMP-FAC.
But this will move only one row. How can I move all the rows? Is there a loop that I can use? I can see a loop for internal tables but I need to loop the result set and then send it. I posted this question twice but haven't gotten the right answer.
Thanks.

Hi,
Are you trying to write the code in Update Routine or a Start Routine.?
If you want to update all the records, you can use the start routine.
So you need to use a loop for doing all the records.
If you are using a Update routine then you dont have to use the loop.
But here I recommend the Start Routine is the best choice.
Here is a document which can be helpful for you:
http://bluestonestep.com/component/option,com_docman/task,doc_download/gid,13/
Happy Tony

Similar Messages

  • Performance to fetch result set from stored procedure.

    I read some of related threads, but couldn't find any good suggestions about the performance issue to fetch the result set from a stored procedure.
    Here is my case:
    I have a stored procedure which will return 2,030,000 rows. When I run the select part only in the dbartisan, it takes about 3 minutes, so I know it's not query problem. But when I call the stored procedure in DBArtisan in following way:
    declare cr SYS_REFCURSOR;
    firstname char(20);
    lastname char(20);
    street char(40);
    city char(20);
    STATE varchar2(2);
    begin DISPLAY_ADDRESS(cr);
    DBMS_OUTPUT.ENABLE(null);
    LOOP
    FETCH cr INTO firstname,lastname,street, city, state;
    EXIT WHEN cr%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE( firstname||','|| lastname||','|| street||',' ||city||',' ||STATE);
    END LOOP;
    CLOSE cr;
    end;
    It will take about 100 minutes. When I used DBI fetchrow_array in perl code, it took about same amount of time. However, same stored procedure in sybase without using cursor, and same perl code, it only takes 12 minutes to display all results. We assume oracle has better performance. So what could be the problem here?
    The perl code:
    my $dbh = DBI->connect($databaseserver, $dbuser, $dbpassword,
    { 'AutoCommit' => 0,'RaiseError' => 1, 'PrintError' => 0 })
    or die "couldn't connect to database: " . DBI->errstr;
    open OUTPUTFILE, ">$temp_output_path";
    my $rc;
    my $sql="BEGIN DISPLAY_ADDRESS(:rc); END;";
    my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->bind_param_inout(':rc', \$rc, 0, { ora_type=> ORA_RSET });
    $sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
    while($address_info=$rc->fetchrow_arrayref()){
    my ($firstname, $lastname, $street, $city, $STATE) = @$address_info;
    print OUTPUTFILE $firstname."|".$lastname."|".$street."|".$city."|".$STATE;
    $dbh->commit();
    $dbh->disconnect();
    close OUTPUTFILE;
    Thanks!
    rulin

    Thanks for you reply!
    1) The stored procedure has head
    CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    cv_1 IN OUT SYS_REFCURSOR
    AS
    err_msg VARCHAR2(100);
    BEGIN
    --Adaptive Server has expanded all '*' elements in the following statement
    OPEN cv_1 FOR
    Select ...
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    err_msg := SQLERRM;
    dbms_output.put_line (err_msg);
    ROLLBACK;
    END;
    If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
    2) But when call stored procedure, it will take 80-100 minutes .
    3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
    CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    AS
    BEGIN
    select ..
    The select part is exact same.
    4) The perl code is almost exact same, except the query sql:
    sybase verson: my $sql ="exec DISPLAY_ADDRESS";
    and no need bind the cursor parameter.
    This is batch job, we create a file with all information, and ftp to clients everynight.
    Thanks!
    Rulin

  • How to export result set from mysql query browser to .sql in oracle

    Hi folks:
    I was trying to export result set from MySql query browser to Oracle. I could able to do
    File->Export Result Set-> Excel format...
    What I am trying to get is .sql file so that I can run it as a script in my oracle db. Is there any way we can get .sql file with inserts and delimeters ....?
    Did you guys get my question.?
    Please throw some light on this....
    Could be very appreciable ....
    Thanks
    Sudhir Naidu

    Hi
    Create a sql statement which generates the insert statements.
    Something like this:
    select 'insert into table1 (column1, column2, column3) values (' ||
    column1 || ', ' || column2 || ', ' || column3 || ');' from table 1;
    The || sign is the string concatenation sign in Oracle, replace it the appropriate sign in MySql. Export the result set of this query into a file, and you can run it in a SqlPlus.
    Ott Karesz
    http://www.trendo-kft.hu

  • It is required to get the result set from the last query.

    I need this SP to return the result set from the last query.
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO
    alter        proc spQ_GetASCBillingRateIDs2
    @ScheduleID CHAR(15),
    @startdate smalldatetime,
    @enddate smalldatetime
    as
    set nocount on
    truncate table tbltmpgroup
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbltmptbltest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[tbltmptbltest]
    exec sp_CreateTblTmpGroup
    insert into tbltmpgroup
    SELECT DISTINCT
    case when pd.billparent = 'N' then org.eligibleorgid
    else isnull(af.parentid, org.eligibleorgid) end as billorgid,
    pd.individualbill , pd.cobrabill, pd.billparent,
    org.eligibleorgid, org.polid, org.orgpolicyid,
    pp.planid,  pp.rateid,
    ps.ascinvoicedate,
    case when ps.ascclaimfromdate > @startdate then ps.ascclaimfromdate
    else @startdate end as premiumrundayFrom,
    case when ps.ascclaimtodate < @enddate then ps.ascclaimtodate
    else @enddate end as premiumrundayTo,
    fts.effdate, fts.termdate,
    case when fts.effdate > @startdate then fts.EffDate
    else @startdate end as ascStartDate,
    case when fts.termdate < @enddate then fts.termdate
    else @enddate end as ascEndDate
    FROM premiumschedule ps (nolock)
    inner join orgpolicy org (nolock)
    on org.ascinvoicerungroup between ps.premiumrundayfrom and ps.premiumrundayto
    inner join FundingTypeStatus fts
    on fts.orgpolicyid = org.orgpolicyid
    and fts.fundtype = 'ASC'
    and ((fts.effdate between @startdate and @enddate)
    or (fts.termdate between @startdate and @enddate)
    or (fts.effdate < @startdate and fts.termdate > @enddate))
    inner join eligibilityorg o (nolock)
    on org.eligibleorgid = o.eligibleorgid
    inner join policydef pd (nolock)
    on pd.polid = org.polid
    inner join policyplans pp (nolock)
    on pp.polid = org.polid
    inner join program p (nolock)
    on pd.programid = p.programid
    left join orgaffiliation af with (nolock)
    on org.eligibleorgid = af.childid
    WHERE ps.premiumscheduleid = @ScheduleID
    AND org.orgpolicyid <> ''
    go
    SELECT DISTINCT z.rateid, e.enrollid, z.ascstartdate, z.ascenddate
    into tbltmptbltest FROM enrollment E (nolock)
    inner join tbltmpgroup z
    on e.rateid = z.rateid
    go
    CREATE UNIQUE CLUSTERED INDEX IDXTempTable  ON tbltmptbltest(enrollid)
    create index IDXTemptableDates on tbltmptbltest(ascstartdate,ascenddate)
    go
    select distinct t.*
    from tbltmpgroup t
    where rateid in (
    select distinct t.rateid from VW_ASC_Billing)
    order by billorgid
    set nocount off
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules (you have no idea).
    Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    What you did post is bad SQL. 
    The prefix “tbl-” is a design flaw called tibbling and we do not do it. We seldom use temp tables in RDBMS; it is how magnetic tape file programmers fake scratch tapes. 
    If the schema is correct, then SELECT DISTINCT is almost never used. 
    Your “bill_parent” looks like a assembly language bit flag; we never use those flags in SQL. 
    “Funding_Type_Status” is an absurd name for a table. A status is a state of being, not an entity. A type is an attribute property. So this table ought to be column that is either a “funding_type” or “funding_status” (with the time period for the state of being
    shown in other columns). But this hybrid is not possible in a valid data model. 
    Want to try again, with DDL and some specs? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Looping through result set

    Hello, I am experience a heapdump while looping through a result set from a query I amr unning.
    Our system creates an instance of a transfer object representing one row in the result set for each row as it loops through. The result set brings back 36000 rows, so it is creating 36000 objects. As a result, a heapdump is occurring. What can be done to fix this error?

    even if it holds 360000 rows,
    I still think [zadok] idea is a great idea.
    you can get, for example first 1000 rows, cacluate it save result, and then get the next 1000 rows, is it make sense?
    if you still want to get it by one time, extend your vm mem, normal setting is 64M(I am not sure)

  • Need help in restricting a result set from a UNION in MERGE

    Hello,
    Would really appreciate if anybody could help me out with the issue I am facing with the below statements (I am new to Oracle ):
    merge into table_name_1 p
    using
      select p_key, value_1, value_2
      from some_tables
      UNION
      select p_key, value_1, value_2
      from some_tables
      UNION
    )t
    on (p.p_key = t.p_key)
    when matched then
      update table_name_1 with value_1 and value_2
    when not matched then
      insert table_name_1 with p_key, value_1, value_2;
    Now, the union of all those selects gives me distinct values and it works most of the times but when I get values like below, the merge fails:
    p_key-----value_1-----value_2
    100-----25-----50
    100-----NULL-----50
    I browsed the net and understood the reason behind this: the result set becomes ambiguous and merge doesn't know which row to insert first and which one to update.
    Now, my requirement is: I could have any of the below scenario/result sets from the union and I need only 1 row per p_key -
    result_set_1
    p_key-----value_1-----value_2
    100-----25-----50 ***************need this row
    100-----NULL-----50
    100-----NULL-----NULL
    result_set_2
    p_key-----value_1-----value_2
    100-----25-----NULL ***************need this row
    100-----NULL-----NULL
    result_set_3
    p_key-----value_1-----value_2
    100-----25-----NULL ***************need this row (p_key = 100)
    100-----NULL-----NULL
    200-----NULL-----75 ***************need this row (p_key = 200)
    200-----NULL-----NULL
    300-----90-----95 ***************need this row (p_key = 300)
    So, I basically need a way to restrict the values that I will get from the UNION of all those selects to fit the requirement above, hope I was able to explain the issue I am facing.
    Any help would be greatly appreciated.
    Thanks,
    Dpunk

    In all cases the goal is to find an order by value that will make the row you want be first.
    The query I gave is calculating a priority for each row by adding up values showing whether each column is null or not null. The case statements check whether each column is null and need to be added up to give a total priority value.
    Value_1   Value_2   Priority
    Not Null  Not Null  2 + 1 = 3
    Not Null  Null      2 + 0 = 2
    Null      Not Null  0 + 1 = 1
    Null      Null      0 + 0 = 0
    The priority value ends up being a bitmap showing whether each value is null or not null. I think that reflects my mathematics background.
    Another way of getting the same result (suggested to me by your asking why it needs the "+") would be to use two CASE expressions as separate order by items:
    select p_key, value_1, value_2 from
    (select p_key, value_1, value_2, row_number() over
              (partition by p_key
               order by case when value_1 is null then 0 else 1 end DESC,
                        case when value_2 is null then 0 else 1 end DESC
              ) as rn
      from (your UNION query here)
    where rn = 1
    A third way is to use a more complex case statement:
    select p_key, value_1, value_2 from
    (select p_key, value_1, value_2, row_number() over
              (partition by p_key
               order by case when value_1 is NOT null and value_2 is NOT null then 1
                             when value_1 is NOT null and value_2 is     null then 2
                             when value_1 is     null and value_2 is NOT null then 3
                             when value_1 is     null and value_2 is     null then 4
                         end  ASC
              ) as rn
      from (your UNION query here)
    where rn = 1

  • JDBC Result Set from Non-Database Source

    In Java, is it possible to create a result set from a non-database data source?, for example an XML file, text file, vectors, java beans
    We have a Swing application that currently makes direct JDBC calls to the DB2 database for creating result sets. We want to replace JDBC calls with calls to web service, but want to still create result sets on the client, so the replacement of the datasource from database to web service call is transparent to the rest of the code.

    In Java, is it possible to create a result set from a
    non-database data source?, Yes.
    for example an XML file,
    text file, vectors, java beans
    We have a Swing application that currently makes
    direct JDBC calls to the DB2 database for creating
    result sets. We want to replace JDBC calls with calls
    to web service, but want to still create result sets
    on the client, so the replacement of the datasource
    from database to web service call is transparent to
    the rest of the code.You might want to think carefully about what you are doing.
    It is fairly easy, although somewhat tedious (many methods,) to create a new type of ResultSet.
    But if the above application is doing SQL via statements and expecting the result via a ResultSet then you are not just creating a ResultSet but an entire driver and one that will have to deal with SQL as well. And if you have to handle the SQL itself that means you will probably need a parser and interpreter.

  • Random result set from cursor

    Hello all,
    I have a cursor defined that simply performs a SELECT. I would like to be able to dynamically state whether I'd like the entire result set returned or a random selection.
    The issue I'm having is that because the cursor is already defined I am trying to build this functionality into the LOOP. I am able to return random sets by using DBMS_RANDOM but I've only been able to do this when modifying the SELECT statement. I have considered an ORDER BY in the cursor and then simply EXIT'ing when the ROWNUM meets a certain number of returned results. This would, at least, provide the ability to return a user specified number of random records. Perhaps the ORDER BY could be modified by a cursor parameter?
    I'm hoping there's an elegant solution that I'm missing.
    Thanks for any help!
    Mark

    user10368702 wrote:
    Thanks for pointing out this feature to me. The problem is that my cursors are currently doing multi-table joins and the SAMPLE clause will not work with them. To clarify, I would like to programatically decide whether I'd like to return all the rows from the cursor, or just a sampling. The current method being used it to generate a random number and loop through the entire cursor until that rownum is found. I dislike the table walk, but am unable to come up with a way to return a specific sample size or record num. Ideally I'd like to be able to perform the equivalent of ROWNUM = X with the results from the cursor.
    Thanks for any help!Probably you can't use dynamic SQL (using OPEN or EXECUTE IMMEDIATE) for a particular reason? Because in that case you could just use your query as an inline view like that:
    SELECT * FROM (
    <YOUR_QUERY_INCLUDING DBMS_RANDOM_VALUE>
    WHERE <RANDOM_VALUE> <= <YOUR_LIMIT>and construct your query dynamically.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Sep 29, 2008 11:21 PM
    Removed unnecessary ORDER BY

  • Returning result set from procedure out parameter, display with anon block

    I'm trying to do something pretty simple (I think it should be simple at least). I want to use a pl/sql procedure to return a result set in an OUT parameter. If I run this code by itself (in the given anonymous block at the end, without trying to display any results), toad says that the PL/SQL procedure successfully completed.
    How can I display the results from this procedure? I am assuming that the result set should be stored in the O_RETURN_REDEEM_DTL, but how can I get anything out of it?
    I have this package with the following procedure:
    /* FUNCTION - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              --OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN, REGISTER_NBR_IN, TRANS_NBR_IN);
              OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;and call it in an anonymous block with:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RETURN_REDEEM_DTL_OUT PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ_CUR%rowtype;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
    REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN O_RETURN_REDEEM_DTL
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || item.ZL_DIVN_NBR);
      END LOOP;
    END; And end up with an error:
    ORA-06550: line 25, column 15:
    PLS-00221: 'O_RETURN_REDEEM_DTL' is not a procedure or is undefined
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredMessage was edited by:
    user607908

    Aha, I knew I forgot something!
    I actually had it defined as a REF CURSOR in PSAPP.CY_SALESPOSTING package spec:
    TYPE REDEEM_DTL_TYPE IS REF CURSOR;since I wasn't sure what to make it.
    Cursor used in procedure:
    CURSOR REDEEM_DTL_READ_CUR (
      zl_divn_nbr_in IN NUMBER,
      greg_date_in IN DATE,
      zl_store_nbr_in IN NUMBER,
      register_nbr_in IN NUMBER,
      trans_nbr_in IN NUMBER)
    IS
    SELECT ZL_DIVN_NBR, GREG_DATE, ZL_STORE_NBR, REGISTER_NBR, TRANS_NBR, PAYMENT_TYP_NBR
    FROM REDEEM_DTL
    WHERE ZL_DIVN_NBR = zl_divn_nbr_in AND GREG_DATE = greg_date_in AND
       ZL_STORE_NBR = zl_store_nbr_in AND REGISTER_NBR = register_nbr_in AND
       TRANS_NBR = trans_nbr_in;Updated code:
    /* PROCEDURE - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
                   REGISTER_NBR_IN, TRANS_NBR_IN);
              --OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
              LOOP
                  FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
                   EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
                   DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL.ZL_DIVN_NBR);
                END LOOP;
               CLOSE REDEEM_DTL_READ_CUR;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;the updated anon block:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
         REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN 1..O_RETURN_REDEEM_DTL.COUNT
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL(item).ZL_DIVN_NBR);
      END LOOP;
    END;and the new error:
    ORA-06550: line 25, column 38:
    PLS-00487: Invalid reference to variable 'O_RETURN_REDEEM_DTL'
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredAlso, it would be nice if the forums would put a box around code so that it would be easy to
    distinguish between what is supposed to be code and what should be regular text...
    Message was edited by:
    user607908

  • Returning result sets from PL/SQL procedure to client app.

    I was wondering if its possible in Oracle PL/SQL to DECLARE, OPEN a cursor and exit
    the procedure without closing the cursor
    and then retrieve the resultset from
    the client.
    Pl let me know..
    null

    Yes, you need to use one OUT parameter in your PL/SQL procedure
    to pass the cursor variable to
    Java code. You can also return that as a return variable of
    PL/SQL function. Get the cursor variable from the resultset using
    Types.CURSOR data type and then proceed as usual.
    Enrique (guest) wrote:
    : Thank you Rajib for your prompt reply. I have been programming
    a
    : lot in Transact SQL( MSSQL ), but I am new to Oracle and I need
    : to migrate MSSQL procedures to Oracle. I will try to use the
    : refCursors. One more question, how do I pass the cursors back?
    : With OUT parameters? In MSSQL you do not need to specify OUT
    : parameters if you are returning a result set.
    : Once Again,
    : Thank you
    : Rajib (guest) wrote:
    : : You can return a variable of refcursor type from your PL/SQL
    : : procedure (PL/SQL 2.3 or higher) to Java code. Oracle JDBC
    has
    : a
    : : refcursor data type. Now you can use this cursor as a
    : resultset.
    : : Enrique (guest) wrote:
    : : : Hi All,
    : : : I am trying to write some store procedures( PL/SQL )
    : : that
    : : : will select rows from my tables, and then pass then back to
    : my
    : : : JDBC application as result sets....Does anyone know how can
    I
    : : do
    : : : that? Do I need to use output parameters? Or Return
    : functions?
    : : : Any help or hint wourl be be gladly appreciate it.
    : : : Enrique
    : : : Thank you.
    null

  • Displaying large result sets in Table View u0096 request for patterns

    When providing a table of results from a large data set from SAP, care needs to be taken in order to not tax the R/3 database or the R/3 and WAS application servers.  Additionally, in terms of performance, results need to be displayed quickly in order to provide sub-second response times to users.
    This post is my thoughts on how to do this based on my findings that the Table UI element cannot send an event to retrieve more data when paging down through data in the table (hopefully a future feature of the Table UI Element).
    Approach:
    For data retrieval, we need to have an RFC with search parameters that retrieves a maximum number of records (say 200) and a flag whether 200 results were returned. 
    In terms of display, we use a table UI Element, and bind the result set to the table.
    For sorting, when they sort by a column, if we have less than the maximum search results, we sort the result set we already have (no need to go to SAP), but otherwise the RFC also needs to have sort information as parameters so that sorting can take place during the database retrieval.  We sort it during the SQL select so that we stop as soon as we hit 200 records.
    For filtering, again, if less than 200 results, we just filter the results internally, otherwise, we need to go to SAP, and the RFC needs to have this parameterized also.
    If the requirement is that the user must look at more than 200 results, we need to have a button on the screen to fetch the next 200 results.  This implies that the RFC will also need to have a start point to return results from.  Similarly, a previous 200 results button would need to be enabled once they move beyond the initial result set.
    Limitations of this are:
    1.     We need to use custom RFC function as BAPI’s don’t generally provide this type of sorting and limiting of data.
    2.     Functions need to directly access tables in order to do sorting at the database level (to reduce memory consumption).
    3.     It’s not a great interface to add buttons to “Get next/previous set of 200”.
    4.     Obviously, based on where you are getting the data from, it may be better to load the data completely into an internal table in SAP, and do sorting and filtering on this, rather than use the database to do it.
    Does anyone have a proven pattern for doing this or any improvements to the above design?  I’m sure SAP-CRM must have to do this, or did they just go with a BSP view when searching for customers?
    Note – I noticed there is a pattern for search results in some documentation, but it does not exist in the sneak preview edition of developer studio.  Has anyone had in exposure to this?
    Update - I'm currently investigating whether we can create a new value node and use a supply function to fill the data.  It may be that when we bind this to the table UI element, that it will call this incrementally as it requires more data and hence could be a better solution.

    Hi Matt,
    i'm afraid, the supplyFunction will not help you to get out of this, because it's only called, if the node is invalid or gets invalidated again. The number of elements a node contains defines the number of elements the table uses for the determination of the overall number of table rows. Something quite similar to what you want does already exist in the WD runtime for internal usage. As you've surely noticed, only "visibleRowCount" elements are initially transferred to the client. If you scroll down one or multiple lines, the following rows are internally transferred on demand. But this doesn't help you really, since:
    1. You don't get this event at all and
    2. Even if you would get the event, since the number of node elements determines the table's overall rows number, the event would never request to load elements with an index greater than number of node elements - 1.
    You can mimic the desired behaviour by hiding the table footer and creating your own buttons for pagination and scrolling.
    Assume you have 10 displayed rows and 200 overall rows, What you need to be able to implement the desired behaviour is:
    1. A context attribute "maxNumberOfExpectedRows" type int, which you would set to 200.
    2. A context attribute "visibleRowCount" type int, which you would set to 10 and bind to table's visibleRowCount property.
    3. A context attribute "firstVisibleRow" type int, which you would set to 0 and bind to table's firstVisibleRow property.
    4. The actions PageUp, PageDown, RowUp, RowDown, FirstRow and LastRow, which are used for scrolling and the corresponding buttons.
    The action handlers do the following:
    PageUp: firstVisibleRow -= visibleRowCount (must be >=0 of course)
    PageDown: firstVisibleRow += visibleRowCount (first + visible must be < maxNumberOfExpectedRows)
    RowDown/Up: firstVisibleRow++/-- with the same restrictions as in page "mode"
    FirstRow/LastRow is easy, isn't it?
    Since you know, which sections of elements has already been "loaded" into the dataSource-node, you can fill the necessary sections on demand, when the corresponding action is triggered.
    For example, if you initially display elements 0..9 and goto last row, you load from maxNumberOfExpected (200) - visibleRows (10) entries, so you would request entries 190 to 199 from the backend.
    A drawback is, that the BAPIs/RFCs still have to be capable to process such "section selecting".
    Best regards,
    Stefan
    PS: And this is meant as a workaround and does not really replace your pattern request.

  • Loop through result set and delete row

    so here is what I need -
    I have a query that pulls rows from the Database through a stored procedure.(these are properties in an area)
    Before I start looping through the query, I need to check the distance between my current location and the property. If it less than 5 miles, only then should I display that property. The distance in miles will be chosen while submitting the search form.
    So is there a way to delete rows from the result set based on the criteria? Or
    Is there a better way to accomplish this? I am using the the google api to get the latitudes and longitudes. The other issue to keep in mind is the load time.
    Thanks

    You can do this the easy way or the hard way.  Depends on whether your condition that needs to be checked can be expressed in the form of a SQL where clause.  If it can, then do what BKBK suggested, and use a query of query to create a new resultset that only has the rows from the original resultset that don't meet your condition.
    If the calculation of the condition is more complex, then do a CFLOOP over the query and examine each row to see if you want to keep it or toss it.  if you want to toss it, the delete that row - there is a function in CFLIB.ORG called querydeleterow that should help you.  Or, you could just clear out the row's contents and then do the query of query as described in BKBK's post to create a new resultset that doesn't include the blank rows.

  • Multiple result sets from stored procedure into CachedRowSet

    How can you obtain multiple sets of data from a stored procedure that returns multiple result sets, when you'd like to use CachedRowSet rather than ResultSet?
    My database's stored procedures return multiple result sets, but I'm not sure how to manipulate that using CallableStatements and CachedRowSets... I read the RowSet tutorial from java.sun.com but that didn't cover the case of multiple result sets and CallablStatements.
    How might I do this? Thanks a lot.

    SELECT columns..
    FROM table
    FOR XML PATH('NodeName'),('Rootname')
    Thank you for replying.
    I dont have to generate XML from a query. I have to generate from a SP and that too without modifying it.
    Thanks,
    Tauhid
    thats ok you can do like this
    1. Create a table with structure same as SP resultset
    2. Populate table with SP result as per below
    INSERT table
    EXEC SPName param1value,...
    3. Add a query like below
    SELECT columns..
    FROM tablename
    FOR XML PATH('NodeName'),('RootName')
    see
    http://visakhm.blogspot.com/2014/05/t-sql-tips-fun-with-for-xml-path.html
    4. Use sp_send_dbmail to sent it through mail
    http://msdn.microsoft.com/en-IN/library/ms190307.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Not able to access the result set from one member function to another

    Im new to jdbc
    I have declared a connection object , a result set object and statement object in one member function and i am not able to access these in another member function. But both are in the same class
    Kindly help
    Thanks
    Shasi

    Kindly refrain from double-posting:
    http://forum.java.sun.com/thread.jspa?threadID=700659&tstart=0
    - Saish

  • Which is more efficient way to get result set from database server

    Hi,
    I am working on a project where I require to query database to fetch result set and then iterate through the resultset. Now, What I want is that I want to create one single java code that would call many different SQLs and create a list out of resultset. There are two approaches for me.
    1.) To create a txt file where I can store my queries. My java program can read this file and get the appropriate query to be used.
    2.) To create a stored procedure containing the queries and call the stored procedure from my java program. Also, not that some of the queries needs to be created dynamically depending upon the parameteters supplied.
    Out of these two approches which is optimum and why?
    Also, following things to be noted.
    1. At times I want to create where clause of the query dynamically depenending upon the parameters passed.
    2. I want one single java file that will handle all database calls.
    3. Paramters to the stored procedure can be passed using array descriptor.
    4. Conneciton I am making using JNDI.
    Please do provide me optimum way of out these two. You may also suggest some other approaches, if any.
    Thanks,
    Rajan
    Edited by: RP on Jun 26, 2012 11:11 PM

    RP wrote:
    In case of queries stored in text files. I will require to replace some pre defined placeholder with actual parameters and then pass that modified query to db engine. Even I liked the second approach as it is more easily maintainable. There are a couple of issues. Shared SQL is one. Irrespective of the method used, the SQL cursor that is created needs to have bind variables. This ensures re-usability of the cursor. This reduces the risk of Shared Pool fragmentation. This lowers hard parsing and reduces CPU utilisation.
    Another issue is flexibility. If the SQL cursors are created by stored procedures, this code resides on the server and abstracts the Java client from the complexities of SQL and SQL performance. The code can easily be updated and fine tuned to deliver faster/better SQL cursors, or modified to take new Oracle features, changes in data model, and so on, into consideration. This stored proc can be updated without having to touch or recompile a single byte of Java client code.
    There's also the security issue. What is more secure? SQL encapsulated in stored procs in a secure database and server environment? Or SQL "encapsulated" in text files on the client?
    The less code you have running on the client, the less code you have running in the wild that can be compromised without having to first compromise the server.
    Only I was worried about any performace issue might happen using this approach. Performance is not a factor of who creates the SQL cursor.
    Whether Java client creates a SQL cursor, or a PL/SQL stored proc creates a SQL cursor, or a .Net client creates a SQL cursor - that SQL cursor does not know what the client is. It does not care what the client is. The SQL cursor performs as well as it is capable of.. given the execution plan, data volumes, server resources and speed/performance of the server.
    The client language and SQL cursor interface used by the client (there are several in PL/SQL), determines the performance of the client's interaction with the cursor (e.g. round trips to the database when interfacing with the cursor). The client language (and its client interface to the cursor) does not dictate the actual performance of that SQL cursor on the database (does not make joins faster, or I/O faster)
    One more question, Will my java program close the cursor that I opened in Procedure?That you need to ask your Java code. Java code leaking ref cursors are unfortunately all too common. You need to make sure that your Java client interface to SQL cursors, closes the cursor handle when done.

Maybe you are looking for

  • PO created using fm BAPI_PRODORD_CREATE...Fails to create for some material

    Hi, I am creating PO using BAPI_PRODORD_CREATE...... I am passing order data  and afs data.... For some material PO is not created.... Before passing data to function mo. BAPI_PRODORD_CREATE all the data is correct.... But after executing bapi PO is

  • You've been signed out (28-04-2014)

    Hey. I keep getting this message from Creative cloud app "you've been signed out" when I try to log in. (Desktop app, I can fine log on through a browser) Running Windows 8.1 and the problem happened after I updated photoshop and indesign (2 weeks ag

  • Stock Report on Key date.

    Hi, I want to have a report which gives stock available on key dates. Is there any standard report available in sap. Thanks in advance VRH

  • Validation on Enter key

    When Enter key is pressed the a/p invoice gets added.I want to perform some validations when enter is pressed.I have a function ValidateWarehouse which returns boolean value.If it returns false I want to stop the add or update event.

  • Safari Not Opening Pages That Require Login

    Since I installed the latest security update Safari won't open a couple of pages I use to use all the time. Most notably the My eBay sign in page and the Bigpond Log In page and just now the Apple Login Page (I had to use Camino to get to here). When