Calling functions and inserting tables based on values entered

Hello Everyone,
I am creating a function as below:
create or replace function func(flags in number,Ctry in varchar2) return number
is
maxv number;
flagv number;
begin
flagv:=1;
select max(num) into maxv from A;
if flags =1 then
insert into A(num,nam) values(maxv+1,Upper(Ctry));
else
flagv:=0;
end if;
return flagv;
end;
The function takes two parameters-The first one will be either 0 or 1.The second one will be name of a country.
If the first parameter is 1 then we would insert the country name passed, to the table name A.If its 0 then no insertion occurs and the function would return a value 0.
On compiling the function I get a success!.
When I do a
SQL>select distinct func(0,'UK') from B;
it works well and returns 0
However when I do
SQL>select distinct func(1,'UK') from B;
I expect an output of 1 & also expect UK to be inserted as anew row in the table A.However It throws an error saying "ORA-14551: cannot perform a DML operation inside a query .."
It is very important for me to use select to call the function, as my application would fire a select with that function and based on the value entered would insert or not insert at the back end.
Is there any way out to do this??
variable temps number
exec :number :=func(1,'UK');
does work but I cant use this in my application.
Hope you can help! Thanks!

create or replace function func(flags in number,Ctry in varchar2) return number
is
PRAGMA AUTONOMOUS_TRANSACTION;
maxv number;
flagv number;
begin
flagv:=1;
select max(num) into maxv from A;
if flags =1 then
insert into A(num,nam) values(maxv+1,Upper(Ctry));
COMMIT;
else
flagv:=0;
end if;
return flagv;
end;
Is the above changes in BOLD enough or I need to do something else too in order to incorporate the autonomous transaction??
I am not too familiar with autonomous transaction.Could you please suggest the changes I need if any more required??
Thanks a ton for your suggestions!
Message was edited by:
user579245
Message was edited by:
user579245

Similar Messages

  • Call function and call customer function

    Hi
    Can anybody let me know what is the difference between CALL FUNCTION AND CALL CUSTOMER- FUNCTION .
    i know call customer- function is used while we r working on user exits .
    but is their any specific reason of difference ...
    Thanks

    CALL CUSTOMER-FUNCTION function_exit parameter_list.
    Effect
    This statement can be used in programs delivered by SAP. It includes the function module exit specified in function_exit . The function module exit is a customer exit. In an SAP program, it enables you to call a function module provided by SAP and implemented by the customer.
    The indicator function_exit must be a three-digit text field literal. A function module exit is specified by SAP using the transaction SMOD and can be activated using the transaction CMOD in customer systems.
    Specifications by SAP
    An empty or partly implemented function module must be assigned to the function module exit using the transaction SMOD. The name of the function module consists of EXIT_, the program name, which contains the statement CALL CUSTOMER-FUNCTION, and the three-digit indicator in function_exit. The interface of the function module is completely defined by SAP.
    Activation in the customer system
    The transaction CMOD enables the customer to implement the source code of the function module within an enhancement project and to activate the function module exit. If the function module exit is not activated, the statement CALL CUSTOMER-FUNCTION is ignored. If the function module is activated, the corresponding function module is called in the same way as the general function module call.
    Syntax and meaning of the parameter_list for the assignment of the actual parameters to formal parameters and for the exception handling are the same as in a general function module call. It is not possible to dynamically fill the interface.
    CALL FUNCTION func
    Syntax
    CALL FUNCTION func { parameter_list
                       | parameter_tables }.
    Effect
    This statement calls the function module specified in func. The identifier func must be a character-type data object, which contains the name of a function module in uppercase letters during the statement execution. Each function module of an SAP system has a unique name, which is why you need not specify the function group.
    Use additions parameter_list or parameter_tables (as of release 6.10) to statically or dynamically assign actual parameters to the formal parameters of the function module and return values to the non-class-based exceptions.
    Note
    If the name of a function module is specified by a constant or as a literal, the extended syntax check can check the statement.
    Exceptions
    Catchable Exceptions
    CX_SY_DYN_CALL_ILLEGAL_FUNC
    Cause: The called function is known but not active.
    Runtime Error: CALL_FUNCTION_NOT_ACTIVE
    Cause: The called function is unknown.
    Runtime Error: CALL_FUNCTION_NOT_FOUND
    CX_SY_DYN_CALL_ILLEGAL_TYPE
    Cause: The type of the actual parameter does not fulfill the requirements of the function interface.
    Runtime Error: CALL_FUNCTION_CONFLICT_GEN_TYP
    Cause: The actual parameter does not have the length expected by the function.
    Runtime Error: CALL_FUNCTION_CONFLICT_LENG
    Cause: The actual parameter does not have the type expected by the function.
    Runtime Error: CALL_FUNCTION_CONFLICT_TYPE
    Cause: Only those functions can be called in the update task that are intended for it.
    Runtime Error: CALL_FUNCTION_NO_VB
    Cause: An actual parameter does not fulfill the alignment requirements of the respective formal parameter.
    Runtime Error: CALL_FUNCTION_WRONG_ALIGNMENT
    CX_SY_DYN_CALL_PARAM_MISSING
    Cause: The function expects a parameter, which has not been passed by the caller.
    Runtime Error: CALL_FUNCTION_PARM_MISSING
    CX_SY_DYN_CALL_PARAM_NOT_FOUND
    Cause: The caller has passed a parameter, which is not known to the function.
    Runtime Error: CALL_FUNCTION_PARM_UNKNOWN
    plz reward points if it helps

  • Deleting from a table based on values in a second table

    Is it possible to DELETE from (or for that matter do an UPDATE to) a table based on values in another table? I have gone through the online documentation but can't seem to find anything. I'm trying to delete rows from table A where A.field1 = B.field1 and B.field2 = 'X'. (B being the second table)

    It is done using subqueries in the where clause.
    delete from A
    where A.field1 in (select B.field1 from B where B.field2 = 'X');
    delete from A
    where exists (select 'x' from B where B.field1 = A.field1 and B.field2 = 'X');
    delete from A
    where A.rowid in (select A.ROWID from from A, B where B.field1 = A.field1 and B.field2 = 'X');
    And many other varieties. Eg. more specialised:
    delete from A
    where A.txdate < (select B.prune_date FROM B where B.field1 = A.field1 and B.field2 = 'X')
    and A.txstate in (select S.txstate from S where S.prodlass=a.prodclass and s.deletable='Y');

  • Using power shell function and SQL Table

    I have a table holding file path of over 1 million documents. so like column one is documentID and column two is full file path.
    Now, I want to get the file size of each of the documents. I have a function in power shell that gets the size of a file given file path.
    My problem, is I do not know how to use that function and the table to get the size of each of the files(documents).
    Help Much Appreciated!!
    ebro

    I am not clear with your questions sir. Do you mean the category this question belongs too? If so, may be some body could help redirect the question to the appropriate place.
    So what category does this belong too CM12 or Powershell?
    http://www.enhansoft.com/

  • F4 Help IN ALV (OOPs) based on value entered in Other colunm.

    Hi,
    I have developed a module pool using ALV GRID Display.
    i have two fields in it. and for the second field i should provide F4 help. and the list in the f4 help should be based on the value enterd in first column.
    below is my code.
    MODULE BPO_100 OUTPUT.
    DATA: LT_FCAT TYPE LVC_T_FCAT.
    DATA: ls_fcat    TYPE lvc_s_fcat.
    DATA: wa type t_znout.
    *DATA: it_kd1 LIKE zish_pm_cs_kd1fd OCCURS 0 WITH HEADER LINE.
    SELECT * FROM zish_pm_cs_kd1fd INTO TABLE it_kd1 WHERE einri = rnpa1-einri.
      IF sy-subrc = 0.
        SORT it_kd1 BY sno.
      ENDIF.
      DELETE ADJACENT DUPLICATES FROM it_kd1 COMPARING fieldname.
    LOOP AT it_kd1 into wa.
    clear wa-value.
    MODIFY it_kd1 FROM wa.
    ENDLOOP.
           ls_fcat-fieldname = 'FIELDNAME'.
           ls_fcat-scrtext_l = 'Field name'.
           ls_fcat-scrtext_m = 'Field name'.
           ls_fcat-scrtext_s = 'Field name'.
           ls_fcat-tabname   = '1'.
           ls_fcat-col_pos = '1'.
           ls_fcat-outputlen = 15.
           APPEND ls_fcat TO lt_fcat.
           ls_fcat-fieldname = 'VALUE'.
           ls_fcat-scrtext_l = 'Value'.
           ls_fcat-scrtext_m = 'Value'.
           ls_fcat-scrtext_s = 'Value'.
           ls_fcat-tabname   = '1'.
           ls_fcat-col_pos = '2'.
           ls_fcat-outputlen = 15.
           ls_fcat-edit = 'X'.
           ls_fcat-f4availabl = 'X'.
           APPEND ls_fcat TO lt_fcat.
    IF G_CUSTOM_CONTAINER1 IS INITIAL.
    create a custom container control for our ALV Control
        CREATE OBJECT g_custom_container1
            EXPORTING
                container_name = g_container1
            EXCEPTIONS
                cntl_error = 1
                cntl_system_error = 2
                create_error = 3
                lifetime_error = 4
                lifetime_dynpro_dynpro_link = 5.
            IF sy-subrc ne 0.
    add your handling, for example
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = 'ZISH_SCRN_ALV'
              txt2  = sy-subrc
              txt1  = 'The control could not be created'(510).
        ENDIF.
    create an instance of alv control
        CREATE OBJECT grid1
               EXPORTING i_parent = g_custom_container1.
      CALL METHOD grid1->set_table_for_first_display
               EXPORTING
                i_structure_name = 'ZISH_PA_ZNOUT'
          i_default        = gs_test_1700-vari_default
                 i_default        = 'X'
                i_save           = gs_test_1700-vari_save
                is_variant       = ls_vari
                is_layout        = gs_layout1
               CHANGING
                 it_outtab        = it_kd1
                 IT_FIELDCATALOG  = LT_FCAT.
    ENDIF.
    ENDMODULE.                 " BPO_100  OUTPUT
    Edited by: Guru Ram on Sep 24, 2009 8:58 AM

    See sample code.
    I have 2 fields  MATNR and DESC in screen 100. Change it according to ur needs.
    In screen flow logic,
    PROCESS ON VALUE-REQUEST.
      FIELD  desc MODULE module_desc. " F4 for screen field DESC based on value entered in field MATNR
    In report,
    MODULE module_desc INPUT.
      TABLES: ddshretval.
      DATA:  l_t_dynpread LIKE dynpread OCCURS 0 WITH HEADER LINE,
               l_t_dynpread1 LIKE dynpread OCCURS 0 WITH HEADER LINE.
      DATA: l_t_retdynr TYPE TABLE OF ddshretval,
              l_wa_retdynr LIKE LINE OF l_t_retdynr.
      DATA: BEGIN OF g_t_desc OCCURS 0,
            maktx TYPE makt-maktx,
            END OF g_t_desc,
            wa LIKE g_t_desc.
      l_t_dynpread-fieldname = 'MATNR'.  " Field1 name
      APPEND l_t_dynpread.
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname               = sy-repid
          dynumb               = '0100'
        TABLES
          dynpfields           = l_t_dynpread
        EXCEPTIONS
          invalid_abapworkarea = 1
          invalid_dynprofield  = 2
          invalid_dynproname   = 3
          invalid_dynpronummer = 4
          invalid_request      = 5
          no_fielddescription  = 6
          invalid_parameter    = 7
          undefind_error       = 8
          double_conversion    = 9
          stepl_not_found      = 10
          OTHERS               = 11.
      READ TABLE l_t_dynpread INDEX 1.
      IF l_t_dynpread-fieldvalue IS NOT INITIAL.
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'  " Converting matnr to 18 digits
    EXPORTING
    input = l_t_dynpread-fieldvalue
    IMPORTING
    output = l_t_dynpread-fieldvalue.
        SELECT maktx FROM makt INTO TABLE g_t_desc WHERE matnr = l_t_dynpread-fieldvalue.
        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
                EXPORTING
                  retfield        = 'MAKTX'
                  dynpprog        = sy-repid
                  dynpnr          = sy-dynnr
                  value_org       = 'S'
                TABLES
                  value_tab       = g_t_desc
                  return_tab      = l_t_retdynr
                EXCEPTIONS
                  parameter_error = 1
                  no_values_found = 2
                  OTHERS          = 3.
        READ TABLE l_t_retdynr INTO l_wa_retdynr INDEX 1.
        IF sy-subrc = 0.
          l_t_dynpread1-fieldname = l_wa_retdynr-fieldname.
          l_t_dynpread1-fieldvalue =  l_wa_retdynr-fieldval.
          APPEND l_t_dynpread1.
          l_t_dynpread1-fieldname = 'DESC'. " Field2 name
          APPEND l_t_dynpread1.
          CALL FUNCTION 'DYNP_VALUES_UPDATE'
            EXPORTING
              dyname               = sy-repid
              dynumb               = sy-dynnr
            TABLES
              dynpfields           = l_t_dynpread1
            EXCEPTIONS
              invalid_abapworkarea = 1
              invalid_dynprofield  = 2
              invalid_dynproname   = 3
              invalid_dynpronummer = 4
              invalid_request      = 5
              no_fielddescription  = 6
              undefind_error       = 7
              OTHERS               = 8.
        ENDIF.
      ENDIF.
    ENDMODULE.                 " module_desc  INPUT
    Thanks.

  • Cursor and Update rows based on value/date

    SQL Server 2012
    Microsoft SQL Server Management Studio
    11.0.3128.0
    Microsoft Analysis Services Client Tools
    11.0.3128.0
    Microsoft Data Access Components (MDAC)
    6.1.7601.17514
    Microsoft MSXML 3.0 4.0 5.0 6.0 
    Microsoft Internet Explorer
    9.11.9600.16518
    Microsoft .NET Framework
    4.0.30319.18408
    Operating System
    6.1.7601
    The objective of this is to test the Cursor and use it on a production environment after this is fixed. What I would like to do is update rows in a column i duplicated originally called 'HiredDate' from AdventureWorks2012 HumanResources.Employee table. I
    made a duplicate column called 'DateToChange' and would like to change it based on a date I have picked, which returns normally 2 results (i.e. date is '04/07/2003'). The code runs but will not change both dates. It did run however with an error but changed
    only 1 of the 2 rows because it said ['nothing available in next fetch'].
    The code to add the columns and perform the query to get the results I am running this against:
    -- ADD column 'DateToChange'
    ALTER TABLE [HumanResources].[Employee] ADD DateToChange Date NOT NULL;
    -- Copy 'HireDate' data to 'DateToChange'
    UPDATE HumanResources.Employee SET DateToChange = HireDate;
    -- Change 'DateToChange' to NOT NULL
    ALTER TABLE [HumanResources].[Employee] ALTER COLUMN DateToChange Date NOT NULL;
    SELECT BusinessEntityID,HireDate, CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
    FROM HumanResources.Employee
    WHERE [DateToChange] = '04/07/2003';
    Code:
    USE AdventureWorks2012;
    GO
    -- Holds output of the CURSOR
    DECLARE @EmployeeID INT
    DECLARE @HiredDate DATETIME
    DECLARE @HiredModified DATETIME
    DECLARE @ChangeDateTo DATETIME
    --Declare cursor
    -- SCROLL CURSOR ALLOWS "for extra options" to pul multiple records: i.e. PRIOR, ABSOLUTE ##, RELATIVE ##
    DECLARE TestCursor CURSOR SCROLL FOR
    -- SELECT statement of what records going to be used by CURSOR
    -- Assign the query to the cursor.
    SELECT /*HumanResources.Employee.BusinessEntityID, HumanResources.Employee.HireDate,*/ CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
    FROM HumanResources.Employee
    WHERE DateToChange = '01/01/1901'
    /*ORDER BY HireDate DESC*/ FOR UPDATE OF [DateToChange];
    -- Initiate CURSOR and load records
    OPEN TestCursor
    -- Get first row from query
    FETCH NEXT FROM TestCursor
    INTO @HiredModified
    -- Logic to tell the Cursor while "@@FETCH_STATUS" 0 the cursor has successfully fetched the next record.
    WHILE (@@FETCH_STATUS = 0 AND @@CURSOR_ROWS = -1)
    BEGIN
    FETCH NEXT FROM TestCursor
    IF (@HiredModified = '04/07/2003')/*05/18/2006*/
    -- Sets @HiredModifiedDate data to use for the change
    SELECT @ChangeDateTo = '01/01/1901'
    UPDATE HumanResources.Employee
    SET [DateToChange] = @ChangeDateTo --'01/01/1901'
    FROM HumanResources.Employee
    WHERE CURRENT OF TestCursor;
    END
    -- CLOSE CURSOR
    CLOSE TestCursor;
    -- Remove any references held by cursor
    DEALLOCATE TestCursor;
    GO
    This query is run successfully but it does not produce the desired results to change the dates
    04/07/2003 to 01/01/1901.
    I would like the query to essentially be able to run the initial select statement, and then update and iterate through the returned results while replacing the necessary column in each row.
    I am also open to changes or a different design all together. 
    For this query I need:
    1. To narrow the initial set of information
    2. Check if the information returned, in particular a date, is before [i.e. this current month minus 12 months or
    12 months before current month]
    3. Next replace the dates with the needed date
    [Haven't written this out yet but it will need to be done]
    4. After all this is done I will then need to update a column on each row:
    if the 'date' is within 12 months to 12 months from the date checked
    NOTE: I am new to TSQL and have only been doing this for a few days, but I will understand or read up on what is explained if given enough information. Thank you in advance for anyone who may be able to help.

    The first thing you need to do is forget about cursors.  Those are rarely needed.  Instead you need to learn the basics of the tsql language and how to work with data in sets.  For starters, your looping logic is incorrect.  You open
    the cursur and immediately fetch the first row.  You enter the loop and the first thing in the loop does what?  Fetches another row.  That means you have "lost" the values from the first row fetched.  You also do not test the success of
    that fetch but immediately try to use the fetched value.  In addition, your cursor includes the condition "DateToChange = '01/01/1901' " - by extension you only select rows where HireDate is Jan 1 1901.  So the value fetched into @HiredModified will
    never be anything different - it will always be Jan 1 1901.  The IF logic inside your loop will always evaluate to FALSE.  
    But forget all that.  In words, tell us what you are trying to do.  It seems that you intend to add a new column to a table - one that is not null (ultimately) and is set to a particular value based on some criteria.  Since you intend the
    column to be not null, it is simpler to just add the column as not null with a default.  Because you are adding the column, the assumption is that you need to set the appropriate value for EVERY row in the table so the actual default value can be anything.
     Given the bogosity of the 1/1/1901 value, why not use this as your default and then set the column based on the Hiredate afterwards.  Simply follow the alter table statement with an update statement.  I don't really understand what your logic
    or goal is, but perhaps that will come with a better description.  In short: 
    alter table xxx add DateToChange date default '19010101'
    update xxx set DateToChange = HireDate where [some unclear condition]
    Lastly, you should consider wrapping everything you do in a transaction so that you recover from any errors.  In a production system, you should consider making a backup immediately before you do anything - strongly consider and have a good reason not
    to do so if that is your choice (and have a recovery plan just in case). 

  • Problem with parameters and non table based items

    Hi,
    I have a situation where I have some not table based items on a page (shuttles and select lists). It is parameters that the end user inputs. I have another page with the same items just here they are Display Only and also not table based. When the user press a button I branch from page 1 to page 2 and set the items on page 2. My problem is that the input the user keys in are not copied to the items on page 2. I can see the data in the session state.
    I assume that this is a silly question and I have just set Source Used or Source Type wrong one one of the items but I can not get it working. Can anybody help?
    It works fine if I use a Application Item and creates a process on page 1 where I copy the item value from the session state but that should be needed right?
    Regards Pete

    Thanks Scott,
    I think I got it working. If I remove all the colons from the data it works. I select several entries in a Shuttle and the result is a colon delimited string of values. If I remove these in a process it works fine. Is there a way of escaping the output from a Shuttle?
    Regards Pete

  • Pl/sql function querying 2 tables based on bind variable

    hey guys, I'm pretty new to pl/sql, but basically I just want to use a select statement based on a searchfield that pulls from 1 of 2 tables based on a bind variable. Here's what I've got so far, but I'm gettting an error message:
    declare
    q1 varchar2(32767); -- query
    q2 varchar2(32767); -- query
    begin
    q1 := 'select distinct(CBP_CONTENT_CATEGORY) CATEGORY, ' ||
    ' CBP_FIELDNAME FIELDNAME, ' ||
    ' CBP_CONTENT_DESC DESCRIPTION ' ||
    ' from CBP_METADATA_2005 ' ||
    ' WHERE UPPER(CBP_CONTENT_CATEGORY) LIKE '%' || UPPER(:CBP_SEARCHFIELD) || '%'
    ' or UPPER(CBP_CONTENT_DESC) LIKE '%' || UPPER(:CBP_SEARCHFIELD) || '%';
    q2 := 'select distinct(CBP_CONTENT_CATEGORY) CATEGORY, ' ||
    ' CBP_FIELDNAME FIELDNAME, ' ||
    ' CBP_CONTENT_DESC DESCRIPTION ' ||
    ' from CBP_METADATA_2004 ' ||
    ' WHERE UPPER(CBP_CONTENT_CATEGORY) LIKE '%' || UPPER(:CBP_SEARCHFIELD) || '%'
    ' or UPPER(CBP_CONTENT_DESC) LIKE '%' || UPPER(:CBP_SEARCHFIELD) || '%';
    if :CBP_YEAR = '1' THEN
    q1=q1
    RETURN q1
    ELSIF :CBP_YEAR = '0' THEN
    q2=q2
    end if;
    RETURN q1;
    end;
    and here's the error:
    failed to parse SQL query:
    ORA-06550: line 1, column 8:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    begin function package pragma procedure subtype type use
    form
    current cursor
    The symbol "" was ignored.
    ORA-06550: line 4, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with

    LDub,
    Your function is full of errors. First of all you didn't escape quotes and second, you didn't use the concatination operator properly. Beside that, there was a bit too much of code there. Here is the modified code that will work for you:
    DECLARE
    q1 VARCHAR2 (32767); -- query
    q2 VARCHAR2 (32767); -- query
    BEGIN
    q1 :=
    'select distinct(CBP_CONTENT_CATEGORY) CATEGORY, '
    || ' CBP_FIELDNAME FIELDNAME, '
    || ' CBP_CONTENT_DESC DESCRIPTION '
    || ' from CBP_METADATA_2005 '
    || ' WHERE UPPER(CBP_CONTENT_CATEGORY) LIKE ''%'' || UPPER(:CBP_SEARCHFIELD) || ''%'''
    || ' or UPPER(CBP_CONTENT_DESC) LIKE ''%'' || UPPER(:CBP_SEARCHFIELD) || ''%''';
    q2 :=
    'select distinct(CBP_CONTENT_CATEGORY) CATEGORY, '
    || ' CBP_FIELDNAME FIELDNAME, '
    || ' CBP_CONTENT_DESC DESCRIPTION '
    || ' from CBP_METADATA_2004 '
    || ' WHERE UPPER(CBP_CONTENT_CATEGORY) LIKE ''%''|| UPPER(:CBP_SEARCHFIELD) || ''%'''
    || ' or UPPER(CBP_CONTENT_DESC) LIKE ''%'' || UPPER(:CBP_SEARCHFIELD) || ''%''';
    IF :cbp_year = '1'
    THEN
    RETURN q1;
    ELSIF :cbp_year = '0'
    THEN
    RETURN q2;
    END IF;
    END;
    Denes Kubicek

  • Select from different tables based on value

    Hi Forum,
    I'm stuggling with a problem:
    In a table, I have two columns, pref_type and pref_value. Column pref_type stores a number value that is linked to a preference type, whereas column pref_value stores the value of that preference.
    Unfortunately, the data model is such that per preference type a different tables needs to be used, so for example, if
    pref_type = 1, table to query is A, whereas if
    pref_type = 2, table to query is B.
    I now want to write a query that resolves the preferences, ie it should branch to the respective table based on pref_type and search for pref_value and deliver back a different column of that respective table.
    My first approach was like that:
    select decode (pref_value, 1, (select result from A where pref_value = ???),
    2, (select result from B where pref_value = ???)
    where the three ??? depict the problem I'm having, as Oracle doesn't allow me to have a harmonized subquery here.
    How do I achieve this?
    Thanks for any help,
    J. Sieben

    I believe this is what you are trying to get at:
    SELECT DECODE(m.pref_type, 1, (SELECT result FROM a
                                   WHERE a.pref_value = m.pref_value),
                               2, (SELECT result FROM b
                                   WHERE b.pref_value = m.pref_value)
    FROM my_table mAlthough, if the tables are large, that might be pretty slow. Better than an outer join, but one of those correlated queries is going to be run for each row in my_table. You could lso try something like:
    SELECT m.pref_type, r.result
    FROM my_table m,
         (SELECT 'A' tbl, pref_value, result
          FROM a
          UNION ALL
          SELECT 'B', pref_value, result
          FROM b) r
    WHERE DECODE(m.pref_type, 1, 'A', 'B') = r.tbl and
          m.pref_value = r.pref_valueHTH
    John

  • Deleting rows from table based on value from other table

    Hello Members,
    I am struck to solve the issue said below using query. Would appreciate any suggestions...
    I have two tables having same structures. I want to delete the rows from TableA ( master table ) with the values from TableB ( subset of TableA). The idea is to remove the duplicate values from tableA. The data to be removed are present in TableB. Catch here is TableB holds one row less than TableA, for example
    Table A
    Name Value
    Test 1
    Test 1
    Test 1
    Hello 2
    Good 3
    TableB
    Name Value
    Test 1
    Test 1
    The goal here is to remove the two entries from TableB ('Test') from TableA, finally leaving TableA as
    Table A
    Name Value
    Test 1
    Hello 2
    Good 3
    I tried below queries
    1. delete from TestA a where rowid = any (select rowid from TESTA b where b.Name = a.Name and a.Name in ( select Name from TestB ));
    Any suggestions..
    We need TableB. The problem I mentioned above is part of process. TableB contains the duplicate values which should be deleted from TableA. So that we know what all values we have deleted from TableA. On deleted TableA if I later insert the value from TableB I should be getting the original TableA...
    Thanks in advance

    drop table table_a;
    drop table table_b;
    create table  table_b as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual;
    create table table_a as
    select 'Test' name, 1 value from dual union all
    select 'Test' ,1 from dual union all
    select 'Test' ,1 from dual union all
    select 'Hello' ,2 from dual union all
    select 'Good', 3 from dual;
    /* Formatted on 11/23/2011 1:53:12 PM (QP5 v5.149.1003.31008) */
    DELETE FROM table_a
          WHERE ROWID IN (SELECT rid
                            FROM (SELECT ROWID rid,
                                         ROW_NUMBER ()
                                         OVER (PARTITION BY name, VALUE
                                               ORDER BY NULL)
                                            rn
                                    FROM table_a a
                                   WHERE EXISTS
                                            (SELECT 1
                                               FROM table_b b
                                              WHERE a.name = b.name
                                                    AND a.VALUE = b.VALUE))
                           WHERE rn > 1);
    select * from table_a
    NAME     VALUE
    Test     1
    Hello     2
    Good     3Edited by: pollywog on Nov 23, 2011 1:55 PM

  • Update table based on values from other table

    Hi,
    I am trying to update one table based on the values of another table. Since you can't use From in update statements, how do you execute this?
    For example i have to tables, Table A and Table B. I want to update a column or columns in Table A based on another value in Table B:
    So if the column in Table B was 1 then column in Table A would be Yes, if Table B was 2, then Table A would be Yes, if Table B was 3 then Table A would be N/A and so on...
    Any help would be appreciated.
    thanks,
    scott

    SQL> select * from t1;
    ID ST
    1
    2
    3
    SQL> select * from t2;
    NO
    1
    2
    3
    4
    SQL> update t1 set status=(select decode(no,1,'Y',2,'N','NA') from t2 where t1.id=t2.no);
    3 rows updated.
    SQL> select * from t1;
    ID ST
    1 Y
    2 N
    3 NA
    Daljit Singh

  • Remote call function and destination

    Hi all @SAPforums,
    I used to call remotely a custom function, in a report, from many backends:
    CALL FUNCTION ZFOO destination mydest
    where mydest is a string containing the name of an RFC destination.
    My question is: is there a way, on the destination machine, to get the name/id of the "caller" ?
    The question arises from this task: I have to use the caller ID in a WHERE clause of a SELECT statement I have to write in ZFOO. I can - of course - pass the caller ID by adding a new parameter to the function, but this would make necessary a change on the CALL FUNCTION in every backend (quite expensive task, in terms of time). So if it's possible, from the callee, to get the name of the caller, I could just modify the function leaving the calls in every backend as they are.
    Thanks in advance

    >
    Matteo Montalto wrote:
    > Hello Wolfgang,
    > sorry for the stupid question... what does "destination" stands for?
    > Thanks for the help
    Hi ,
    they are two types of RFC calling is ther..
    1......
    CALL FUNCTION "function0module-name' DESTINATION "DEST" 
    --that means you are picking data from another r/3 sytem using detination from 'DEST'..
    2....
    CALL FUNCTION "function0module-name' IN BACKGROUND TASK DESTINATION "DEST" 
    --that means you are sending data to another r/3 sytem or any other sytem XI or and EDI
    using detination from 'DEST'..
    for 1 and 2..
    --go to t-code SM59 and see the DEST what type of connection is and what system it is connected..
    Regards,
    Prabhudas

  • Update age group picklist based on value entered in date of birth

    Hi Gurus,
    Have a requirement where in user would enter the date of birth on a contact record and would like to populate another custom field called age group at the time of creating a new record.
    The condition is some what like
    Age
    1 – 20 Teens
    21-40 Young Adults
    41-60 Adults
    60 – 100 Seniors
    I have tried using the age field but problem is that age is populated only when the record is saved.
    Update the age group via workflow works fine but the saved record has to be modified before triggering the workflow. we would like to avoid the additional step of modifying the record
    Is there any option to calculate age based on the value entered for date of birth - something like DOB Year - current year before saving a record or via post default without using workflows.
    Thanks in advance,
    Arun

    Hi
    The answer is yes, using the post default functionlaity.
    take a look in the folowign example:
    IIf(ToChar(Timestamp(),'DD/MM/YYYY')- [<DateofBirth>] < 20,'20','30')
    You will need to make something like that, but replace the '30' with another IIf expression, and so on for the next interval.
    note that date of birth should be between suqare brackets [  ] (it is shown here with underline for some reason...)
    Good luck
    Guy
    Edited by: Shinshan on 08:45 30/12/2009
    Edited by: Shinshan on 08:46 30/12/2009
    Edited by: Shinshan on 08:47 30/12/2009
    Edited by: Shinshan on 08:47 30/12/2009

  • Display internal table as per value entered in selection screen

    hi experts,
       i need help on this issue. I have an internal table like this.
         f1  f2   f3  
         a   2    5
         b   3    4
         c   4    3
         d   5    2
         e   2    6
    totf2 =16  totf3= 20
    i am getting this sum displayed using AT END OF.
    Now there is a provision to enter a value for totf2, totf3 in selection screen. so based on this value entered for eg. if totf2 = 9 and totf3 = 13, is entered, then my internal table display shd b like:
    f1  f2  f3
    a   2  5
    b   3  4
    c   4  3
    totf2 = 9, tot f3= 12.
    someone plz help quick.
    thanks.

    Hi,
    Try this..
    DATA: v_totf2 TYPE I.
    DATA: v_totf3 TYPE I.
    * Create a internal table similar to your internal table.
    DATA: ITAB_FINAL LIKE TABLE OF itab.
    LOOP AT itab INTO wa.
    * Sum up the total for fields 2 and 3
      v_totf2 = v_totf2 + wa-f2.
      v_totf3 = v_totf3 + wa-f3.
    * If total exceeds for the field 2 and 3 than given in the selection screen.Then exit.
      IF v_totf2 >= p_totf2.     " p_totf2 - selection screen value
              OR
          v_totf3 >= p_totf3.    " p_totf3 - selection screen value
        EXIT.                         " Exit out of the loop.
      ENDIF.
    * Move the values to the final internal table.
      APPEND wa to ITAB_FINAL.
    ENDLOOP.
    * ITAB_FINAL will have the final values.
    Thanks
    Naren

  • Validate a field on selection screen based on value entered on anothr field

    HI,
    There is a program with some fields in selection screen in EWM. The first field is Warehouse. I need to add another field 'Entity to Dispose' in such that what ever value I enter in Warehouse field, its corresponding values should only be displayed as F4 help for 'Entity to Dispose' field.
    For eg: If I select the warehouse as 0799(lets say), then the F4 help for Entity to Dispose field should display only the values which are related to warehouse 0799 (and any other values pertaining to other warehouse should not appear).
    Could anyone suggest, how this can be achieved?
    Thanks in advance.
    Regards,
    Pavan

    Hi,
    You can use FM
    DYNP_VALUES_READ
    DYNP_VALUES_UPDATE
    to read the another field value and Using that field build your internal table for f4 values.
    and use FM F4IF_INT_TABLE_VALUE_REQUEST for F4 values..
    do this on AT SELECTION-SCREEN ON VALUE REQUEST FOR <YOUR_F4_FIELDNAME>.

Maybe you are looking for

  • Problem with uninstalling Office 2013 SCCM 2012 R2

    Hi, I am in a process of learning SCCM 2012 R2. Currently I am focused on application management so I started by deploying Office 2013 to test collection with only one member - direct rule membership by computer name. Deployment process finished with

  • EKPO-NETPR unit

    Hi,   I am trying to create a view on tables EKPO and ESSR. I've added the field NETPR from table EKPO. When I try to create a DS on this view, its giving me error that the unit of NETPR is missing. So I added field BPRME (Order Price Unit Purchasing

  • Cannot set Block Size

    Hi all, <br><br> When I tried to create a database 11g using DBCA, I noticed the tool did not allow me to select the block size. It was automtically set to 8KB without being able to modify it. <br><br> Is there any reason for that? <br><br> os: windo

  • What to do about quality????

    I shot some video with my Canon G20 in full HD and made a video with adobe premiere pro and encore. The problem is, When I play it on the tv, it is terrible quality. Will someone please help me to figure out how to make the quality of this video the

  • WTK 2.5.1 Network Monitor a bit short

    I'm trying to run a continuous test on an application that communicates a lot of data over the mobile network, and I found that the network monitor log only handles around 900 entries until AWT crashes. Based on the error there seems to be a fixed-si