Doubt in writing a function

i have a table like the following
C1     C2      C3
1     1/21/2005     200
1     1/25/2005     300
1     2/22/2005     500
2     4/20/2005     500
2     3/24/2005     5000
I have to write a function where i pass a number.
The function should search C1 for that number and compare the last 2 entries based on date for same Number in C1
this should return teh difference of the last 2 entries for a particular value in C1
For eg
C1     C2          C3
1     1/22/2005     200
1     2/24/2005     300
Since there is a increase comparing the last 2 entries of C1 the output should be
the last value in C2 and the difference of 100
Pls help me wiht a similar function for this
If

Like This..?
SQL> select *
  2  from test;
        C1 C2                C3                                                
         1 21-JAN-05        200                                                
         1 25-JAN-05        300                                                
         1 28-JAN-05        500                                                
         2 28-JAN-05        500                                                
SQL> select c1,c2,c3,diff
  2  from(
  3  select c1,c2,c3,row_number() over(partition by c1 order by c2 desc) rn,
  4           c3-lead(c3) over(partition by c1 order by c2 desc) diff
  5  from test)
  6  where rn=1
  7  and c1=1;
        C1 C2                C3       DIFF                                     
         1 28-JAN-05        500        200                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Help needed in writing a function.

    I am using Oracle 11g and SQL plus. I am a complete newbie, so I need some help here in writing a function. I guess my question is more about writing the trigonometric functions within the function.
    latA, longA latB, longB // these are the four input parameters,
    theta = longA - longB
    distX = sin( latA * PI / 180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180)
    distY = acos(distX) // this is arc cosine
    distZ = distY * 180 / PI // PI refers to the mathematical PI
    distP = distZ * 60 * 1.1515; // this value should be returned. Of course the intermediate variable names don't matter.
    Please help. Thanks.

    CREATE OR REPLACE FUNCTION fucntion_name(latA IN NUMBER, longA IN NUMBER, latB IN NUMBER, longB IN NUMBER) RETURN NUMBER
    IS
    pi      CONSTANT NUMBER:=3.14159;
    theta NUMBER;
    distX  NUMBER;
    distY  NUMBER;
    distZ  NUMBER;
    distP  NUMBER;
    BEGIN
    theta :=longA - longB;
    distX :=sin( latA * PI /180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180);
    distY :=acos(distX); --this is arc cosine
    distZ :=distY * 180/PI;  --PI refers to the mathematical PI
    distP :=distZ * 60 * 1.1515; --this value should be returned. Of course the intermediate variable names don't matter.
    RETURN distP;
    END;Edited by: Ora on May 3, 2011 11:46 PM

  • Urgent : Doubt in writing a code in start routine

    Hi all ,
                 I am BI 7.0 system , I have doubt in writing a code in start routine .
    1) i have to extract the data first from a custom table based on one condition and then placing it into internal table .
    2) Now i have to loop at source_package for a particular region field say "ASIA". with this result i have to check for the correponding entries in custoom table .
       if condition is not true (i.e ) with entries or not matching then delete that particular record from source_package.
    i have written a small logic for this . but this is producing any ouput , Please check it and also let me know for modifications .
    thanks in advance.
    select * from zcsp
        into corresponding fields of TABLE itab_T
        where
        ZBUSINESSUNIT = 'BC'.
    loop at SOURCE_PACKAGE into ls_SOURCE_PACKAGE where /BIC/DPREGION = 'XE'.
                 loop at itab_t into itab_w where zcategory =
                   ls_source_package-/BIC/DPMAT/BIC/DPCAT.
                       if sy-subrc ne 0.
                         delete SOURCE_PACKAGE.
                       endif.
               endloop.
           endloop.

    You're deleting the entire input package.  You only want to delete the one row.
    DATA: g_tabix TYPE sy-tabix.
    SELECT * FROM zscp
    INTO CORRESPONDING FIELDS OF TABLE itab_t
    WHERE zbusinessunit = 'BC'.
    SORT itab_t BY zcategory.
    LOOP AT source_package INTO ls_source_package WHERE /bic/dpregion = 'XE'.
      g_tabix = sy-tabix.
      READ TABLE itab_t WITH KEY zcategory = ls_source_package-/bic/dpmat/bic/dpcat TRANSPORTING NO FIELDS BINARY SEARCH.
      IF sy-subrc NE 0.
        DELETE source_package INDEX g_tabix.
      ENDIF.
    ENDLOOP.

  • How to optimize this sql by writing MINUS function.

    Hi all,
    how to optimize the sql by writing MINUS function.
    these are my tables
    1. CREATE TABLE POSTPAID
    RECORD VARCHAR2(2000 BYTE),
    FLAG NUMBER
    Record format:
    Mobile no in 1:10 of that length
    2. CREATE TABLE SUBSCRIBER
    PHONE_NO VARCHAR2(10 BYTE)
    My requirement is following sql need write using ‘minus’ as this one is very slow
    select record record from POSTPAID where substr(record,9,10) NOT in (select PHONE_NO from SUBSCRIBER)
    Thanks

    Why are you very particular about using "MINUS". You can optimize the sql by using "NOT EXISTS" instead of "NOT IN" as below:
    SELECT RECORD FROM POSTPAID A WHERE NOT EXISTS (SELECT 1 FROM SUBSCRIBER B WHERE SUBSTR(A.RECORD,9,10) = B.PHONE_NO)

  • Doubts with certain standard functions!

    Hi Experts,
          1. What is the differece  in standard functions  - Boolean function : if and ifS.
          2.Sender: what and how value is populated in it!
    I believe Text equals can take text values like Jonny = Jony and not numeric,
        but is boolean equals only to 0 and 1. and what will be the difference majorly?
    Regards,
    Arnab.

    >
    Arnab Mondal wrote:
    > Hi Experts,
    >       1. What is the differece  in standard functions  - Boolean function : if and ifS.
    >       2.Sender: what and how value is populated in it!
    > I believe Text equals can take text values like Jonny = Jony and not numeric,
    >     but is boolean equals only to 0 and 1. and what will be the difference majorly?
    >
    >
    >  Regards,
    > Arnab.
    1. there is if without else and if with else in boolean
    2. Sender populates the value of sender system in runtime (only). The logic is as same as mapping runtime constants - http://help.sap.com/saphelp_nw04/helpdata/en/b3/9a2aeb24dc4ab6b1855c99157529e4/frameset.htm
    3. Dateafter is used to check if one date comes after another in a calendar. Eg you wanna check if 22011982 comes after 22011975, this function will return true. But what is your doubt here?
    4. Text equals expects string as input similarly other boolean and numeric.

  • Doubts about some popular function modules?

    Hi all,
    I have doubts about these function modules (see in parenthesis)
    ws_filename_get (to get the file name at ...?)
    ws_query (to get file size and environment variables from the presentation server to the ...?)
    upload and download (what are the new function modules used in place of these (I know they are obsolete now)
    what is the Object oriented equivalents of these functions?
    Thanks.
    Charles.
    ++++++++++++++++++++++++++++++++++++

    <i>(1)What is the use of ws_filename_get? Please be specific in your answer, about where the file resides: application server, presentation server or the ABAP program.</i>
    It is simply providing an interface for the user to choose a filename which resides on the frontend PC(presentation server). As suggested already, this has been replaced with FILE_OPEN_DIALOG method of the class CL_GUI_FRONTEND_SERVICES.
    <i>2)What is the use of ws_query? Please be specific in your answer, about where the file resides: application server, presentation server or the ABAP program.</i>
    Again, already answered,  this has been replace by multiple more specific methods of the same class mentioned above.
    <i>How can GUI_UPLOAD be a substitute of Upload? It is a substitute of WS_UPLOAD as upload is used to transfer data from presentation server to the ABAP program, whereas the other two are used to get it from presentation server to the application server.</i>
    They all transafer data from the presentation to your application.  They are all interchangable(in a sense), but you should be using the GUI_UPLOAD method of the class CL_GUI_FRONTEND_SERVICES.
    Regards
    Rich Heilman

  • Avoiding writing same function twice

    Hello,
    I want to avoid writing XMLSocket.prototype.onData = function(msg) twice.
    The msg static data are sent only at the first time.  It includes data for populating combo.  Depening on the combo selection, different set of data from msg are displayed.
    mySocket = new XMLSocket();
    mySocket.connect("127.0.0.1", 9999);
    System.security.loadPolicyFile("http://localhost/sockets/flash_policy.php");
    mySocket.onConnect = function(success) {
        if (success) {
            msgArea.htmlText += "<b>Server connection established!</b>";
            mySocket.send("connected"+"\n");
        } else {
            msgArea.htmlText += "<b>Not Connected</b>";
    mySocket.onClose = function() {
        msgArea.htmlText += "<b>Server connection lost</b>";
    //for displaying static data
    XMLSocket.prototype.onData = function(msg) {
        //trace(msg);
        arr = msg.split("&");
        textHeadline.htmlText += arr[0];
            comboBox(arr);   
    function displayData(combo_id)
    XMLSocket.prototype.onData = function(msg) {
        arr = msg.split("&");
        textA.htmlText += arr[1];   
        textB.htmlText += arr[2];
    function comboBox(arr)
      //combo code
      //selected combo id is sent to displayData
       displayData(combo_id);
    Thanks

    I have been thinking along the lines of what Wayne said.
    Can I initialise the Assistant by calling it outside the loop, but with a True constant on the 'stop' input, and then run the rest of the function as normal? Would I not get the error about 'resource is reserved ' or in use or whatever it is?
    Stephen : I have tried troubleshooting by stepping through the execution, but I find it doesn't run accurately. Since the function stops recording when a succession of near-identical points are detected (when the piston stops), if I run it in 'highlight execution' mode it will get 5000 points each for retract and extend (assistant is set to 1k buffer size, 5 successive similar points stops the execution). 
    I will fool around with setting up the function before the loop, until someone gives more suggestions.

  • Need some help in writing a function

    Hi all,
    I need to write a function....
    the data in a table is of varchar2 type and its a ,separated values.
    its in many forms
    sample ex:1,2,3,4,,,,,76,
    12,32,,,,,,,,
    12,32
    12,,,,,23,,,,
    the total numbers in that field must be 10.
    So i need to write sthg which takes the data,remove the commas and return as an array.As in the example some numbers are missing and only ,'s are there.
    If a number is missing i need to load NULL in place of that.the output must be an array containng 10 values(if no value a NULL).
    Can anyone help me regardng this....

    create table x1 (x varchar2(100))
    insert into x1 (x) values ('1,2,3,4,5,6,7,8,9,10');
    insert into x1 (x) values ('1,,3,,5,,7,,9,');
    insert into x1 (x) values ('1,,,,,,,,10');
    insert into x1 (x) values ('1,2,3,,,,,8,9,10');
    insert into x1 (x) values ('1,,3,,5,,7,,9,');
    create type vc20_ttyp is varray(10) of varchar2(20)
    create or replace function tokenize(p_str               in varchar2,
                                        p_seperator               in varchar2 default ',')
      return vc20_ttyp is
    v_tab     vc20_ttyp;
    v_tmp     varchar2(32767);
    v_token     varchar(256);
    x     integer;
    begin
    v_tab := vc20_ttyp();
    v_tmp := ltrim(rtrim(p_str));
    while v_tmp is not null
    loop
      x := instr(v_tmp, p_seperator);
      if x = 0
       then x := length(v_tmp)+1;
      end if;
      v_token := ltrim(rtrim(substr(v_tmp, 1, x-1)));
      if v_token is not null
       then v_tab.extend;
            v_tab(v_tab.count) := v_token;
       else v_tab.extend;
            v_tab(v_tab.count) := null;
      end if;
      v_tmp := substr(v_tmp, x+length(p_seperator));
    end loop;
    return v_tab;
    end tokenize;
    SQL> declare
      2   x vc20_ttyp;
      3  begin
      4   for rec in (select * from x1) loop
      5     x := vc20_ttyp();
      6     x := tokenize(rec.x,',');
      7    
      8     for i in 1..x.COUNT loop
      9       dbms_output.put_line(nvl(x(i),'null'));
    10     end loop;
    11 
    12   end loop;
    13  
    14  end;
    15  /
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    1
    null
    3
    null
    5
    null
    7
    null
    9
    1
    null
    null
    null
    null
    null
    null
    null
    10
    1
    2
    3
    null
    null
    null
    null
    8
    9
    10
    1
    null
    3
    null
    5
    null
    7
    null
    9
    PL/SQL procedure successfully completed.

  • Do I need to use a semaphore when reading/writing a functional global from reentrant VIs?

    I have a program that spawns multiple reentrant VIs running simultaneously.  These VIs write their status to a functional global.  The VI that monitors them periodically polls this global to check out how they're doing and takes action based on their collective status.  (BTW, I'll mention that this monitoring VI is NOT the parent that spawned the reentrants, just in case this might affect memory management as it pertains to my question.)
    Anyway, 90% of the time, stuff goes off without a hitch.  However, once in a while the whole thing hangs.  I'm wondering if there's any chance that I've overlooked something and that some kind of collision is occurring at the global.  If that's the case, then should I be setting a semaphore for the global read/writes?
    And, if this is a problem, then there is something deep about functional globals that I don't yet understand.  My notion of them is that they should negate the need for a semaphore, since there is only one global instance, which cannot be simultaneously called by the various reentrants.  Indeed, this is arguably THE WHOLE POINT about functional globals, is it not?  Or am I missing something?
    Thanks,
    Nick 
    "You keep using that word. I do not think it means what you think it means." - Inigo Montoya

    Thanks Uwe,
    This is a good hunch.  However, functional globals typically run at "subroutine" priority.  With this priority, it is not possible to select a specific execution system; it is always "same as caller."
    I will try your suggestion by switching to "time-critical" priority.  However, I do not know if this could lead to a different set of issues (non-determinism?).  It will probably take a little while to hear back from my guys on whether this makes a difference or not, because the error is sporadic, and sometimes doesn't come along for quite a while.
    While probing all of this, I looked at the execution settings for my reentrant VI.  It has standard settings: "normal" priority, running in the "same as caller" execution system.  My impression has always been that LV creates the clones with unique names.  This allows the clones to be in the same execution system with no problem, and the fact that the execution dialog allows me to choose "same as caller" for a reentrant VI supports this assertion.  This is logical, since there could potentially be many more clones than available execution systems.  "Preallocate clone for each instance" is selected, which is what I want, I think, though I don't know if it matters in my application.
    In summary, I am trying out your suggestion, but with skepticism.  Any other suggestions from anyone out there?  Any misunderstandings on my part that need clarification?
    Thanks,
    Nick 
    "You keep using that word. I do not think it means what you think it means." - Inigo Montoya

  • Writing a function to find whether a value is present in a sql query output

    Hi gurus,
    I would like to write a function to which i will pass a value and a sql query as parameters.
    Now the function needs to execute that sql query and find whether the given value is present in the output list
    when the query is executed. If it is present it should return 'T' otherwise 'F'
    My function will look like
    CREATE FUNCTION CHECK_VALUE(VALUE VARCHAR2,V_SQL VARCHAR2) RETURN VARCHAR2
    SELECT CHECK_VALUE('Dallas','SELECT LOCATION_CODE FROM HR_LOCATIONS')
    It should check whether the value 'Dallas' is present in the output list returned by the sql query.
    Any help will be appreciated.
    Thank you.

    CREATE OR REPLACE
      FUNCTION CHECK_VALUE(
                           VALUE VARCHAR2,
                           V_SQL VARCHAR2
        RETURN VARCHAR2
        IS
            RETVAL VARCHAR2(4000);
            REFCUR SYS_REFCURSOR;
        BEGIN
            OPEN REFCUR FOR V_SQL;
            LOOP
              FETCH REFCUR INTO RETVAL;
              EXIT WHEN REFCUR%NOTFOUND;
              IF RETVAL = VALUE
                THEN
                  CLOSE REFCUR;
                  RETURN 'T';
              END IF;
            END LOOP;
            CLOSE REFCUR;
            RETURN 'F';
    END;
    Function created.
    SQL> SET SERVEROUTPUT ON
    SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('DALLAS','select loc from dept'));
    T
    PL/SQL procedure successfully completed.
    SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('PARIS','select loc from dept'));
    F
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Help with writing a function

    Hello there
    I got a table with data like this:
    http://www.geocities.com/crisrobin100/ex_input.gif
    This table give me the amount of hours (value) starting in a date I can query from another table according to the owner_id and the amount of consecutive days(Repeats_count) this amount of hours refer to.
    I need to select this table and get something more friendlily so I can sum the hour for each month.
    The result need to look something like this:
    http://www.geocities.com/crisrobin100/ex_output.gif
    How can I do it?
    Chris

    SQL> create table mytable
      2  as
      3  select 30020 owner_id
      4       , 'FORECAST' owner_type
      5       , 0 compressed_entry_seq
      6       , 4 repeats_count
      7       , 8 value
      8    from dual union all
      9  select 30020, 'FORECAST', 1, 2, 0 from dual union all
    10  select 30020, 'FORECAST', 2, 5, 8 from dual union all
    11  select 30020, 'FORECAST', 3, 2, 0 from dual union all
    12  select 30020, 'FORECAST', 4, 5, 8 from dual union all
    13  select 30020, 'FORECAST', 5, 2, 0 from dual union all
    14  select 30020, 'FORECAST', 6, 5, 8 from dual union all
    15  select 30020, 'FORECAST', 7, 3, 0 from dual union all
    16  select 30020, 'FORECAST', 8, 3, 8 from dual
    17  /
    Tabel is aangemaakt.
    SQL> var P_STARTDATE varchar2(8)
    SQL> exec :P_STARTDATE := '01052007'
    PL/SQL-procedure is geslaagd.
    SQL> select owner_id
      2       , owner_type
      3       , d
      4       , value
      5    from mytable t
      6   model
      7         partition by (owner_id,owner_type,compressed_entry_seq)
      8         dimension by (0 i)
      9         measures ( to_date(:P_STARTDATE,'ddmmyyyy')
    10                    + sum(repeats_count) over (partition by owner_id,owner_type order by compressed_entry_seq)
    11                    - repeats_count d
    12                  , repeats_count rc
    13                  , value
    14                  )
    15         rules
    16         ( d[for i from 1 to rc[0]-1 increment 1] = d[0] + cv(i)
    17         , value[i<>0] = value[0]
    18         )
    19   order by owner_id
    20       , owner_type
    21       , d
    22  /
      OWNER_ID OWNER_TY D                        VALUE
         30020 FORECAST 01-05-2007 00:00:00          8
         30020 FORECAST 02-05-2007 00:00:00          8
         30020 FORECAST 03-05-2007 00:00:00          8
         30020 FORECAST 04-05-2007 00:00:00          8
         30020 FORECAST 05-05-2007 00:00:00          0
         30020 FORECAST 06-05-2007 00:00:00          0
         30020 FORECAST 07-05-2007 00:00:00          8
         30020 FORECAST 08-05-2007 00:00:00          8
         30020 FORECAST 09-05-2007 00:00:00          8
         30020 FORECAST 10-05-2007 00:00:00          8
         30020 FORECAST 11-05-2007 00:00:00          8
         30020 FORECAST 12-05-2007 00:00:00          0
         30020 FORECAST 13-05-2007 00:00:00          0
         30020 FORECAST 14-05-2007 00:00:00          8
         30020 FORECAST 15-05-2007 00:00:00          8
         30020 FORECAST 16-05-2007 00:00:00          8
         30020 FORECAST 17-05-2007 00:00:00          8
         30020 FORECAST 18-05-2007 00:00:00          8
         30020 FORECAST 19-05-2007 00:00:00          0
         30020 FORECAST 20-05-2007 00:00:00          0
         30020 FORECAST 21-05-2007 00:00:00          8
         30020 FORECAST 22-05-2007 00:00:00          8
         30020 FORECAST 23-05-2007 00:00:00          8
         30020 FORECAST 24-05-2007 00:00:00          8
         30020 FORECAST 25-05-2007 00:00:00          8
         30020 FORECAST 26-05-2007 00:00:00          0
         30020 FORECAST 27-05-2007 00:00:00          0
         30020 FORECAST 28-05-2007 00:00:00          0
         30020 FORECAST 29-05-2007 00:00:00          8
         30020 FORECAST 30-05-2007 00:00:00          8
         30020 FORECAST 31-05-2007 00:00:00          8
    31 rijen zijn geselecteerd.Regards,
    Rob.
    Message was edited by:
    Rob van Wijk
    Added owner_type to the partition clause of the sum analytic function. Output wasn't affected.

  • New help writing a function

    I am refreshing this an open a new case to see if I get more help( I do apologize, but I do need to move this to production). I am providing scripts:
    The Problem: I want to write a procedure to update a column in a table (rprawrt_paid_amt) the amount can not be greater than what is in the RPRAWRt_ACCEPT_AMT, the process is run every payroll period, the payroll table is PHREART (provide a script)
    The amount can not exceed the RPRAWRD_ACCEPT_AMT, The procedure is updating the RPRAWRT_PAID_AMT, it is going to be update every pay period, there are going to be cases when SUM(NVL(A.PHREARN_AMT,0)) is going to be greater than the RPRAWRD_ACCEPT_AMT, BUT the update CAN'T exceed the amount in RPRAWRT_ACCEPT_AMT (this value never change, it is set up at the begining of the payroll period(fiscal year).
    Please, see more explanation at the end..
    SELECT * FROM V$VERSION
    results
    racle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE     10.2.0.3.0     Production
    Payroll table, I am just using the columns I need there are more columns in the table(s)
    CREATE TABLE PHREART
    PHREART_YEAR VARCHAR2(4),
    PHREART_PAYNO NUMBER(3),
    PHREART_PIDM NUMBER(8),
    PHREART_AMT NUMBER(12,2),
    PHREART_ACTIVITY_DATE DATE
    CREATE TABLE RPRAWRT
    RPRAWRT_AIDY_CODE VARCHAR2(4),
    RPRAWRT_PIDM NUMBER(8),
    RPRAWRT_FUND_CODE VARCHAR2(6),
    RPRAWRT_ACCEPT_AMT NUMBER(11,2),
    RPRAWRT_PAID_AMT NUMBER(11,2)
    I am only inserting one record but you can manipulate the data or insert more records(explain later)
    INSERT INTO RPRAWRT
    RPRAWRT_AIDY_CODE ,
    RPRAWRT_PIDM ,
    RPRAWRT_FUND_CODE ,
    RPRAWRT_ACCEPT_AMT ,
    RPRAWRT_PAID_AMT
    SELECT
    0910,
    2285428,
    'CFWS',
    60,
    45
    FROM DUAL
    I am inserting to payrolls PHREART_PAYNO  = 20 for the same PHREART_PIDM (PK)
    INSERT INTO PHREART
    PHREART_YEAR ,
    PHREART_PAYNO ,
    PHREART_PIDM ,
    PHREART_AMT ,
    PHREART_ACTIVITY_DATE
    SELECT
    2009,
    20,
    2285428,
    20,
    TO_DATE('9/28/2009','MM/DD/RRRR')
    FROM DUAL
    I am inserting to payrolls PHREART_PAYNO  = 21
    INSERT INTO PHREART
    PHREART_YEAR ,
    PHREART_PAYNO ,
    PHREART_PIDM ,
    PHREART_AMT ,
    PHREART_ACTIVITY_DATE
    SELECT
    2009,
    21,
    2285428,
    25,
    TO_DATE('10/28/2009','MM/DD/RRRR')
    FROM DUAL
    Here is the query that I want to use in my cursor, I do want to do this in a pl\sql function
    query 1
    SELECT rprawrt_aidy_code, rprawrt_pidm, rprawrt_fund_code,
    NVL (rprawrt_accept_amt, 0),
    NVL (rprawrt_paid_amt, 0) paid_amt,
    NVL (rprawrt_paid_amt, 0) pay_amt_sf,
    SUM (NVL (a.phreart_amt, 0))
    FROM phreart a, rprawrt b
    WHERE
    rprawrt_pidm = a.phreart_pidm
    AND rprawrt_fund_code = 'CFWS'
    AND rprawrt_pidm = 2285428
    AND rprawrt_aidy_code = 0910
    AND a.phreart_year = 2009
    AND (rprawrt_accept_amt IS NOT NULL AND rprawrt_accept_amt > 0
    GROUP BY rprawrt_pidm,
    rprawrt_aidy_code,
    rprawrt_fund_code,
    rprawrt_accept_amt,
    rprawrt_paid_amt,
    rprawrt_accept_amt;
    I am giving this example for just one pidm the
    AND rprawrt_pidm = 2285428
    AND rprawrt_aidy_code = 0910
    AND a.phreart_year = 2009
    are parameters passing to the function p_pidm, p_aidy_code, p_year
    Okay this is how my logic needs to work, if I run the query 1 I got this results
    RPRAWRT_AIDY_CODE = 0910
    RPRAWRT_PIDM = 2285428
    RPRAWRT_FUND_CODE = 'CWS'
    NVL(RPRAWRT_ACCEPT_AMT,0) = 60
    PAID_AMT = 45
    PAY_AMT_SF = 45
    SUM(NVL(A.PHREART_AMT,0)) = 45
    {code)
    ok this is the result for the pay period 20 and 21, let's say that for the period 22 the sum amout is 100.
    so, if we run the query 1 (that I am going to use in the cursor, I got) SUM(NVL(A.PHREART_AMT,0)) = 100
    BUT
    the RPRAWRT_ACCEPT_AMT is 60, so I can not update the accept amount for more than 60 that is the limit, this amount never change, it is set up in the begining of the period, the person said I accept 60, but lots of times they do made more than the accept amount (over time), we need to report to the government what they said in the begining in this case, 60
    so for the run of the PHREART_PAYNO 22, I should update this record on RPRAWRT_PAID_AMT = 60, so I need to substract the 15 dollars that are needed to get to 60..right 20 + 25 + 15 (forget about the rest, they will get pay, but my report don't need the rest the 85).
    Now when the next pay period comes this records should not be update again, it reaches the top (60) the RPRAWRT_ACCEPT_AMT is now 60... ]
    here is the insert
    INSERT INTO PHREART
    PHREART_YEAR   ,
    PHREART_PAYNO  ,
    PHREART_PIDM  ,
    PHREART_AMT   , 
    PHREART_ACTIVITY_DATE  
    SELECT
    2009,
    22,
    2285428,
    55,
    TO_DATE('10/28/2009','MM/DD/RRRR')
    FROM DUAL
    The person made 55 dollars on the PHREART_PAYNO 22, so now we have
    PHREART_PAYNO   20  20 dollars
    PHREART_PAYNO    21  25 dollars
    PHREART_PAYNO    22  55 dollars
    I would like to do this in a pl\sql function
    something like this
    Fetch the results from the cursor in variables the use if statements to do the updates, what I got it works but sometimes does not...
    rprawrd the equilant of prawrt, I just created the T tables with the columns I need.
    BEGIN
          IF update_rprawrd_cur%ISOPEN
          THEN
             CLOSE update_rprawrd_cur;
          END IF;
          OPEN update_rprawrd_cur;
          LOOP
             FETCH update_rprawrd_cur
              INTO v_aidy_code, v_pidm, v_fund_code, v_accept_amt, v_paid_amt,
                   v_need_to_upd, v_pay_amt_sf,v_phrearn_amt;
             ---amount to update
             --v_this_upd := NVL (v_paid_amt, 0) + NVL (v_need_to_upd, 0);
             --- v_this_upd := NVL (v_phrearn_amt, 0) - NVL (v_paid_amt, 0) + NVL(v_pay_amt_sf,0);
             EXIT WHEN update_rprawrd_cur%NOTFOUND;
             IF
                 v_accept_amt > v_phrearn_amt
             THEN
                LOCK TABLE faismgr.rprawrd IN SHARE UPDATE MODE;
              UPDATE faismgr.rprawrd
                        SET rprawrd_activity_date = SYSDATE,
                       rprawrd_paid_amt = v_phrearn_amt,
                       rprawrd_paid_date = SYSDATE,
                       rprawrd_data_origin = 'rz_upd_pkg',
                       rprawrd_user_id = p_user
                 WHERE rprawrd_pidm = v_pidm
                   AND rprawrd_fund_code = 'CFWS'
                   AND rprawrd_aidy_code = v_aidy_code;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Thank you, I certainly will look at your recommendations, and I agree with not locking the table, that is something I learned from a piece of code and I saw but I always have question about it, I believe Oracle automaticly look the table when is doing an update, I will never use again.
    I don't have any expereience using bulk collector, I will look at your documenntation and I will try to learn it, but It will be helpful if someone can help with the following:
    If you run the query 1 after you do the inserts(previous email) you will get
    RPRAWRT_AIDY_CODE = 0910
    RPRAWRT_PIDM = 2285428
    RPRAWRT_FUND_CODE = 'CWS'
    NVL(RPRAWRT_ACCEPT_AMT,0) = 60
    PAID_AMT = 45
    PAY_AMT_SF = 45
    SUM(NVL(A.PHREART_AMT,0)) = 45
    The RPRAWRT_ACCEPT_AMT is always 60, so I can not update the accept amount for more than 60 that is the limit, this amount never change, it is set up in the begining of the period, the person said I accept 60, but lots of times they do made more than the accept amount (over time), we need to report to the government what they said in the begining in this case, 60
    so for the run of the PHREART_PAYNO 22, I should update this record on RPRAWRT_PAID_AMT = 60, so I need to substract the 15 dollars that are needed to get to 60..right 20 + 25 + 15 (forget about the rest, they will get pay, but my report don't need the rest the 85).
    Now when the next pay period comes this records should not be update again, it reaches the top (60) the RPRAWRT_ACCEPT_AMT is now 60... ]
    here is the insert
    INSERT INTO PHREART
    PHREART_YEAR ,
    PHREART_PAYNO ,
    PHREART_PIDM ,
    PHREART_AMT ,
    PHREART_ACTIVITY_DATE
    SELECT
    2009,
    22,
    2285428,
    55,
    TO_DATE('10/28/2009','MM/DD/RRRR')
    FROM DUAL
    The person made 55 dollars on the PHREART_PAYNO 22, so now we have
    PHREART_PAYNO 20 20 dollars
    PHREART_PAYNO 21 25 dollars
    PHREART_PAYNO 22 55 dollars
    Then for period 23 if the person make some money the table SHOULD not be update because it reaches the limit 60
    Thank you
    Edited by: peace4all on Feb 20, 2010 6:31 AM

  • Doubt in Basic Bapi function

    Hi experts,
    I have a small doubt in BAPI, Actually i want to add the vendor price only in MEK1. For that am using BAPI to add the vendor price.
    Can anyone tell where we need to write the source code? We need to write a report program? How it will trigger the particular transaction?
    Can any one explain this?
    Mohana

    Hi Mohana,
    for that you need to seacrh for the BADI or Userexit,...when ever any changes are maded in that transaction based one the situation your BADI or userexit will trigger and that will update to the data base...if you use that BAPI in that EXIT.....
    if you are using separatly the program...every time you need to execute that program for updating that field in that transaction...
    Thanks!

  • Writing a function

    Hi,
    i want to write a function or a pipelined function which will process data from a given table. the structure of the table is as below :
    clasec_menu_m
    MENU_LEVEL
    IS_MENU_A_LEAF
    MENU_ID
    MENU_NAME
    MENU_TITLE
    MENU_DESCRIPTION
    MENU_PARENT_ID
    MENU_SCREEN_URI
    SCREEN_TARGET_FRAME
    MENU_ICON_URL
    now i need to convert it only a xml using these steps
    1. if menu_level=1 then
    a root node called menu has to be created and another node under it has to be created this will be called subemenu.
    2. a) If menu_level =1 and is_menu_a_leaf =1 then add item node to the above menu or submenu node with MENU_SCREEN_URI.
    b). If menu_level =1 and is_menu_a_leaf <>1 then add item node to the above menu and a subitem node to the menu node.
    this process has to be repeated untill menu_level=1 im that case go to step2 again.
    This is very urgent. U can mail me at [email protected]
    Regards,
    Vikas Kumar

    You have asked this question about XML menu generation in 3 postings thus far in this forum, if I'm not mistaken.
    I still struggle to understand what your actual problem is. And perhaps the reason for that is you have not accurately identify The Problem - and that is mandatory when you want to solve it.
    Whenever dealing with any problem, you need to break it down into simpler problems.
    How to write hierarchical queries? This is one of the problems as a typical menu structure is hierarchical. And when dealing with a hierarchical SQL problem, first make it simpler. Use a basic and simple data set that you understand - limited number of rows and columns. Understand how it works and then apply this to the real data set.
    Need to generate XML? This is another Problem Block to solve. On its own first. There are numerous source examples on this forum about how to generate XML (including some of mine). A simple search should turn these up. Referring to the Oracle manuals is always an excellent idea (http://tahiti.oracle.com).
    Problems with any of these two Problem Blocks, ask specific technical questions in this forum:
    - showing the Oracle version you're using
    - describing the basic problem
    - listing your attempts (you providing the basic code and test data make it a lot easier for forum members to assist you)
    The next Problem Block is to combine the solutions of the previous two problems into a single all-encompassing solution.
    Is a pipeline table function the answer? That depends on numerous factors such as the type of client making the call, the format the data is expected in, etc.
    Do you return it as a CLOB? As an Oracle XML DOM type? As series of varchar2 lines? Do you return it using a PL/SQL interface? Do you return it using a SQL interface? How do you address issues like the client passing parameters, security, etc?
    It seems to me that you are jumping from one problem issue to another, not really solving anyone specifically and then making the assumption that a pipeline table is The Answer.
    The Answer can only be found when The Question is unambiguous and clear. And in order to have a meaningful answer, the question need to be specific. In other words, deal with actual basic problems separately instead of describing the global problem here (that simply raises more questions) and then asking for an answer.

  • Writing a function to that sorts any object

    I am trying to write a function that sorts any type of array of objects. For example, I want to call
    NewArray = exampleclass.sort(ObjectOfAnyType).
    The sort function has to return a new array. I have run into two errors, however.
    Error #1
    as3.java [21:1] cannot resolve symbol
    symbol : variable Object
    location: class as3
    if (Object instanceof Comparable)
    ^
    Error #2
    as3.java [25:1] incompatible types
    found : java.lang.Object
    required: java.lang.Object[]
    Object [] rtn = obj.clone();
    *** Below is my source code ***
    import java.*;
    public class as3 {
    /** Creates new as3 */
    public static Object sort(Object [] obj)
         if (Object instanceof Comparable)
         if (Object instanceof Cloneable)
         Object [] rtn = obj.clone();
    for (int i = 0; i<obj.length-1; i++)
    for (int j=i+1; j<obj.length; j++)
    if (rtn.compareTo(rtn[j]) == 1)
    Object [] tmp = rtn[i];
    rtn[i] = obj[j];
    rtn[j] = tmp;
    else
    throw new ObjectIsNotComparableException("Object not comparable");
    Any help appreciated. Thanks!

    Changing from "Object" to the name "obj" fixed the
    statement:
    if (obj instanceof Cloneable) but not if (obj
    instanceof Comparable).
    I don't know what's causing this one yet... worry about that in a sec
    I am also getting one new error now:
    as3.java [28:1] cannot resolve symbol
    symbol : method compareTo (java.lang.Object)
    location: class java.lang.Object
    if (rtn[ i].compareTo(rtn[j])
    This one is because rtn[ i] (and rtn[j]) is an Object, which has no method compareTo. Try casting it to a Comparable...
    I think I just worked out why it let you go with the cloneable, but not with the comparable. obj is an array, and sure an array is cloneable, but how could you compare an array? Sure you can compare the elements in the array... So either check if obj[0] instanceof Comparable, or drop the test all together.
    Note: checking obj[0] will give you an exception if someone asks you to sort an array of 0 length (no elements)
    Hope this helps,
    Radish21

Maybe you are looking for