Help me create a procedure to rename plenty of constraints

about 500 tables' constraints require to be renamed from SYS**** to the table's name.
what procedure could you guys think of?
If you've used a previous one please let me know, or if you know where I could download a package, procedure or something, show me the link to get it.
My DB is: version 8173

This Procedure renames PK to PK+TableName(excuse the german comments):
    procedure rename_primary_key
    is
        cursor c_user_cons is
            select
                c.constraint_name,
                c.constraint_type,
                c.r_constraint_name,
                rc.table_name r_table_name,
                c.table_name,
                to_char(NULL) key_columns,
                i.tablespace_name
            from user_constraints c, user_constraints rc, user_indexes i
            where c.constraint_type in ('P','R')
            and (c.r_constraint_name like 'SYS%' or c.r_constraint_name is null)
            and c.constraint_name = i.index_name (+)
            and c.r_constraint_name = rc.constraint_name (+)
            order by c.constraint_type desc, c.table_name, c.constraint_name;
        type cons_list is table of c_user_cons%rowtype;
        key_columns varchar2(1000);
        constraint_liste cons_list := cons_list(NULL);
    begin
        for rec in c_user_cons loop
        -- Liste mit vorhandenen constraints erstellen
            constraint_liste(constraint_liste.last) := rec;
            for rec_col in (
                select column_name, position
                from user_cons_columns
                where constraint_name = rec.constraint_name
                order by position
            ) loop
                if rec_col.position = 1 then
                    key_columns := rec_col.column_name;
                else
                    key_columns := key_columns||','||rec_col.column_name;
                end if;
            end loop;
            constraint_liste(constraint_liste.last).key_columns := key_columns;
            constraint_liste.extend;
        end loop;
        constraint_liste.trim;
        for i in constraint_liste.first..constraint_liste.last loop
        -- Aufgrund der Sortierung des Cursors sind Foreign Keys zuerst in der Liste und
        -- werden vor zugehörigem PK gelöscht
            if constraint_liste(i).constraint_type = 'P' then -- PK löschen und neu anlegen
                if constraint_liste(i).tablespace_name is not NULL then
                -- nur ausführen, wenn eigener Index für PK vorhanden
                    execute immediate 'alter table '||constraint_liste(i).table_name||' drop primary key';
                    execute immediate 'alter table '||constraint_liste(i).table_name||' add (constraint PK'
                        ||substr(constraint_liste(i).table_name, 1, 30)|| ' primary key ('
                        ||constraint_liste(i).key_columns||') using index tablespace '
                        ||constraint_liste(i).tablespace_name||')';
                end if;
            else -- FK löschen
                execute immediate 'alter table '||constraint_liste(i).table_name||' drop constraint '||constraint_liste(i).constraint_name;
            end if;
        end loop;
        for i in constraint_liste.first..constraint_liste.last loop
        -- FK neu anlegen
            if constraint_liste(i).constraint_type = 'R' then
                execute immediate 'alter table '||constraint_liste(i).table_name||' add (constraint '
                    ||constraint_liste(i).constraint_name||' foreign key('||constraint_liste(i).key_columns
                    ||') references '||constraint_liste(i).r_table_name||' deferrable initially deferred)';
            end if;
        end loop;
     end rename_primary_key;

Similar Messages

  • Plz help me create a Procedure with create view cmd

    i want to create a view from the procedure like the following one,
    It creates the proc but while running it show invalid column name please help me;
    create or replace procedure asho2005.mock_pro( fin_fr_dt in date, fin_to_dt in date) is
         ffdt date;
         ftdt date;
    begin
         select to_date(fin_fr_dt,'dd-mm-yyyy') into ffdt from dual;
         select to_date(fin_to_dt,'dd-mm-yyyy') into ftdt from dual;
    execute immediate 'create or replace view mock_vu as select a.amt from cbtran a where chq_dt > ffdt and chq_dt <ftdt';
    end;

    i want to create a view from the procedure like the
    following one,
    It creates the proc but while running it show invalid
    column name please help me;
    create or replace procedure asho2005.mock_pro(
    fin_fr_dt in date, fin_to_dt in date) is
         ffdt date;
         ftdt date;
    begin
    select to_date(fin_fr_dt,'dd-mm-yyyy') into ffdt
    t from dual;
    select to_date(fin_to_dt,'dd-mm-yyyy') into ftdt
    t from dual;
    execute immediate 'create or replace view mock_vu
    vu as select a.amt from cbtran a where chq_dt > ffdt
    and chq_dt <ftdt';
    end;Hallo,
    your problem is , that execute immediate does't recognize ffdt
    You have to concatenate literals
    create or replace procedure asho2005.mock_pro( fin_fr_dt in date, fin_to_dt in date) is
    ffdt date;
    ftdt date;
    begin
    select to_date(fin_fr_dt,'dd-mm-yyyy') into ffdt from dual;
    select to_date(fin_to_dt,'dd-mm-yyyy') into ftdt from dual;
    execute immediate 'create or replace view mock_vu as select a.amt from cbtran a where chq_dt > '''||ffdt||''' and chq_dt <'''||ftd||'''';
    end; BTW, your view doesn't return any rows
    ffdt and < ffdt :-)
    Besides that , it's a very very bad method!
    You must not create views in runtime. Use of literals results in hard parsing .
    The performance will be poor.
    You have to create view in design time, and then simply use select:
    select * from mock_vu where chq_dt > (your_date) and something else
    HTH
    Regards
    Dmytro
    corrected wrong number of quotes (no wonder ) :-)
    Message was edited by:
    Dmytro Dekhtyaryuk

  • A little help for creating a procedure

    Hi,
    I'm new to oracle so i would really appreciate your help. Here is the scenario: i have several table in a database, in one table, let's call it table_a i have some values like: assignment, employee_id, account and so on. In another table, table_b i also have some data the is found in table_a like: employee_id, assignmnet, employee_name... and so on. I must create a procedure to check in table_a by value assignment(pk) and find what assignments are not in table_b and then insert these values in table_b, table_c.... . How do i create the comparison part?

    Hi,
    If It would have to insert only in table_b, then you can go for MERGE, that will be fine instead of procedure.
    Other options would be
    INSERT ALL
    INTO table_b VALUES (<required columns>)
    INTO table_c VALUES (<required columns>)
    SELECT <the columns>
    FROM table_a
    where assignmnet_id not in (select assignmnet From table_b);
    - Pavan Kumar N

  • Help me creating a procedure

    In this practice, create a procedure to monitor whether employees have exceeded their average salary limits.
    a.     Add a column to the EMPLOYEES table by executing the following command:      
         ALTER TABLE employees
         ADD (sal_limit_indicate VARCHAR2(3) DEFAULT 'NO'
         CONSTRAINT emp_sallimit_ck CHECK (sal_limit_indicate IN ('YES', 'NO')));
    a.     Write a stored procedure called CHECK_AVG_SAL. This checks each employee's average salary limit from the JOBS table against the salary that this employee has in the EMPLOYEES table and updates the SAL_LIMIT_INDICATE column in the EMPLOYEES table when this employee has exceeded his or her average salary limit.
    Create a cursor to hold employee IDs, salaries, and their average salary limit – lock the rows with the FOR UPDATE NOWAIT clause in your cursor definition.
    Find the average salary limit possible for an employee's job from the JOBS table. The average salary limit is defined as (max salary + min salary)/2 . Compare the average salary limit possible for each employee to exact salaries and if the salary is more than the average salary limit, set the employee’s SAL_LIMIT_INDICATE column to YES; otherwise, set it to NO.
    Add exception handling to account for a record being locked. This is the only exception you will need to check. This exception is Oracle non-predefined -0054. So you will need to associate it using the PRAGMA EXCEPTION_INIT. Then you can handle it with a standard WHEN clause in the EXCEPTION area of your program.
    It might look like this in your declaration area:
    e_resource_busy EXCEPTION;
    PRAGMA EXCEPTION_INIT(e_resource_busy, -54);
    c.     Execute the procedure, and then test the results.
    EXECUTE check_avg_sal
    Now test the rows lock exception by starting another session executing the procedure again. Remember to SET SERVEROUTPUT ON. In this example I used the RAISE_APPLICATION_ERROR procedure in my exception section– this is what the output will look like. But you could also have printed a nice message using DBMS_OUTPUT.PUT_LINE. Your choice.
    EXECUTE check_avg_sal
         BEGIN check_avg_sal; END;
    ERROR at line 1:
    ORA-20001: Record is busy, try later.
    ORA-06512: at "TEACH.CHECK_AVG_SAL", line 29
    ORA-06512: at line 1
    Query the EMPLOYEES table to view your modifications, and then commit the changes.
    select e.employee_id, e.job_id, j.min_salary, e.salary, j.max_salary, e.sal_limit_indicate
    from employees e , jobs j
    WHERE e.job_id = j.job_id
    EMPLOYEE_ID      JOB_ID      MIN_SALARY      SALARY      MAX_SALARY      SAL
    100      AD_PRES      20000      24000      40000      NO
    101      AD_VP      15000      17000      30000      NO
    102      AD_VP      15000      17000      30000      NO
    200      AD_ASST      3000      4400      6000      NO
    108      FI_MGR      8200      12000      16000      NO
    109      FI_ACCOUNT      4200      9000      9000      YES
    110      FI_ACCOUNT      4200      8200      9000      YES
    111      FI_ACCOUNT      4200      7700      9000      YES
    112      FI_ACCOUNT      4200      7800      9000      YES
    113      FI_ACCOUNT      4200      6900      9000      YES
    205      AC_MGR      8200      12000      16000      NO
    206      AC_ACCOUNT      4200      8300      9000      YES
    145      SA_MAN      10000      14000      20000      NO
    146      SA_MAN      10000      13500      20000      NO
    Commit
              Commit complete.

    The below is what I have.. it is not working.. I am not sure what is wrong.
    set server output on
    ---to add sal_limit_indicate column to employees table
    ALTER TABLE employees
    ADD (sal_limit_indicate VARCHAR2(3) DEFAULT 'NO'
    CONSTRAINT emp_sallimit_ck CHECK (sal_limit_indicate IN ('YES', 'NO')));
    --query employees table to make sure the column is added
    select * from employees
    ----query to check average salary
    select e.JOB_ID, e.SALARY,e.sal_limit_indicate,((min_salary+max_salary)/2) as avg_sal
    from employees e, jobs
    where e.job_id = jobs.job_id
    ---procedure to use in main procedure
    create or replace procedure update_indicator
    (emp_id employees.employee_id% type,
    emp_sallimit employee.sal_limit_indicate% type)
    is
    begin
    update employees
    set sal_limit_indicate ='yes'
    end update_indicator;
    ---procedure to update sal-limit_indicate to yes if salary is greater than average salary
    create or replace procedure CHECK_AVG_SAL is
    cursor sal_cursor is
    select e.employee_id, e.SALARY ,e.sal_limit_indicate,j.avg_sal
    from employees e, (select ((min_salary+max_salary)/2) as avg_sal, job_id from jobs)j
    where e.job_id = j.job_id
    and salary >avg_sal;
    begin
    for sal_rec in sal_cursor
    loop
    update_indicator(sal_rec.employee_id,sal_limit_indicate);
    end loop;
    end;
    end CHECK_AVG_SAL;

  • Help On create Store Procedure

    I need to Create a Store Procedure under a different from the once I am connected.
    Thanks

    If you have the DB rights to do it, use
    create procedure owner.proc_name as ...

  • Need help in creating procedure

    Hi all,
    Can some body please help me in creating a procedure.
    I have a table "NAMES" and the columns as LNAME, FNAME, EMPID
    now I have a sequence EMPID_SEQ.
    I have the data like
    LNAME      FNAME      EMPID
    JOHN        SMITH
    JOHN        SMITH
    PETER      PARKER
    MIKE        JONES
    MIKE        JONES
    MIKE        JONESNow I want to write a procedure in order to give a number(EMPID_SEQ.NEXTVAL) for same first and last names like
    LNAME      FNAME      EMPID
    JOHN        SMITH       1
    JOHN        SMITH       1
    PETER      PARKER       2
    MIKE        JONES        3
    MIKE        JONES        3
    MIKE        JONES        3can anybody please help me in writing this procedure.
    Thanks in advance.

    Better to use SQL
    merge INTO test_tab t USING
      SELECT
        lname,
        fname,
        rownum rn
      FROM
          SELECT DISTINCT
            fname,
            lname
          FROM
            test_tab
    s ON
      t.lname = s.lname AND t.fname = s.fname
    WHEN matched THEN
      UPDATE
      SET
        empid = rn;Possibly that's not what the homework assignment called for, though.

  • Help needed to create a Procedure

    Can anyone help me with a small procedure I have to write?
    Requirement to create Stored Procedure :
    1.  Create tables
         A1
         A2
         B1
         B2
    ----------- this is done------
    Fill the data in those tables
    ------------this is also done----
    Create "Source_table.tx"t file with table names and place them in any location.
    ------------this is also done----
    write a procedure to read the above file "Source_table.txt"  and it should read the tables name 1 by 1 which performs a simple operation inside SP -->  
    Select * from @Table_Name
    Also, it should check if the .txt file is exisiting or not.
    If exists then Read the file and execute the SP.
          SP does this :
             Select * from A1
             Select * from A2
             Select * from B1
             Select * from B2
    After that, write an output file with the counts of records to the same location  where our Source_table.txt exists .
    If doesnt exist then write to a .txt file that "File name and Location doesnt exist"

    What format is the data inside your .txt file?
    If it's just some lines containing the names of the tables then you may as well just use the UTL_FILE package to:
    a) check the existence of the file using the UTL_FILE.FGETATTR procedure
    b) open and read the contents of the file using the UTL_FILE.FOPEN, UTL_FILE.GET_LINE and UTL_FILE.FCLOSE functions/procedures.
    UTL_FILE
    Alternatively you could set up an external table to read the .txt file as though it's a table.
    Managing External Tables
    Once you extract the table names from the .txt file, you'll then have to construct dynamic SQL queries to query the data from them.  Are all of the tables of the same structure or do they change?  If they change you'll have to use the DBMS_SQL package.  If they don't you could do it more statically in PL/SQL code (at least in terms of the structures you're reading the data into), but you may still be better using DBMS_SQL for it.  It depends what you're trying to do exactly and why these table names are being exported to a file and need to be read dynamically in this way.  Often Dynamic coding indicates poor design, but without knowing exactly what you're doing, it's hard to tell if it's really necessary or not.

  • Need help to create export table procedure

    Hi,
    I have created a procedure, which may use to do following things:
    1. first create a duplicate table of sys.aud$ records
    2. export that duplicate table
    here I am enclosing my code:
    1. create or replace procedure crt_tab
    2. is
    3. sqlstring varchar2(100);
    4. tablename varchar2(100);
    5. sys_date varchar2(100);
    6. h1 number;
    7. begin
    8. select to_char(sysdate,'DDMMYYYY_HH12MISSAM') into sys_date from dual;
    9. tablename :='AUDIT_RECORD_'||sys_date;
    10. sqlstring := 'create table ' || tablename|| ' as select * from sys.aud$';
    11. execute immediate sqlstring;
    12. h1 := dbms_datapump.open(operation=>'EXPORT',job_mode=>'TABLE',job_name=>NULL,version=>'COMPATIBLE');
    13. dbms_datapump.add_file(handle =>h1, filename =>tablename||'.dmp',directory =>'AUDIT_RECORD', filetype =>1);
    14. dbms_datapump.add_file(handle =>h1,filename =>tablename||'.log',directory =>'AUDIT_RECORD',filetype =>3);
    15. dbms_datapump.metadata_filter(h1,'NAME_LIST','(''tablename'')');
    16. dbms_datapump.start_job(h1);
    17. dbms_output.put_line('Data Pump job started successfully');
    18. end;
    Well, in line number 15. I am passing a variable tablename as a parameter to dbms_datapump.metadata_filter but it exporting an empty dump. Could you please let me know how to pass a variable value in this.
    looking forward to your early response.
    Regards,
    M.A.Bamboat
    [email protected]

    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2    l_dp_handle     NUMBER;
      3    l_last_job_state VARCHAR2(30) := 'UNDEFINED';
      4    l_job_state     VARCHAR2(30) := 'UNDEFINED';
      5    l_logfilename     VARCHAR2(20) := to_char(sysdate, 'DDMMRRRR') || '.log';
      6    l_expfilename     VARCHAR2(20) := to_char(sysdate, 'DDMMRRRR') || '.dmp';
      7    l_tbl_name     VARCHAR2(30) :='EMP';
      8  BEGIN
      9    l_dp_handle := DBMS_DATAPUMP.OPEN(operation   => 'EXPORT',
    10                          job_mode    => 'TABLE',
    11                          remote_link => NULL,
    12                          job_name    => 'SAUBHIK_EXPORT',
    13                          version     => 'COMPATIBLE');
    14    DBMS_DATAPUMP.ADD_FILE(handle     => l_dp_handle,
    15                     filename     => l_expfilename,
    16                     directory => 'SAUBHIK',
    17                     filetype     => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE);
    18    DBMS_DATAPUMP.ADD_FILE(handle     => l_dp_handle,
    19                     filename     => l_logfilename,
    20                     directory => 'SAUBHIK',
    21                     filetype     => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
    22    dbms_datapump.metadata_filter(handle => l_dp_handle,
    23                         name   => 'NAME_EXPR',
    24                         value  =>'= '||''''||l_tbl_name||'''');
    25    dbms_datapump.start_job(l_dp_handle);
    26    dbms_datapump.detach(l_dp_handle);
    27  EXCEPTION
    28    WHEN OTHERS THEN
    29      dbms_datapump.stop_job(l_dp_handle);
    30      RAISE;
    31* END;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM user_datapump_jobs;
    JOB_NAME                 OPERATION                JOB_MODE                    STATE                    DEGREE ATTACHED_SESSIONS DATAPUMP_SESSIONS
    SAUBHIK_EXPORT                 EXPORT                     TABLE                    EXECUTING                         1       0           2
    SQL> /
    JOB_NAME                 OPERATION                JOB_MODE                    STATE                    DEGREE ATTACHED_SESSIONS DATAPUMP_SESSIONS
    SAUBHIK_EXPORT                 EXPORT                     TABLE                    NOT RUNNING                    0       0           0
    SQL> /
    no rows selected
    SQL>
    oracle@ubuntu-desktop:~/Documents$ pwd
    /home/oracle/Documents
    oracle@ubuntu-desktop:~/Documents$ ls -l 05092011*
    -rw-r----- 1 oracle oinstall 98304 2011-09-05 15:07 05092011.dmp
    -rw-r--r-- 1 oracle oinstall   928 2011-09-05 15:07 05092011.log
    oracle@ubuntu-desktop:~/Documents$

  • Please Help: create a procedure that needs a sys view

    Hi gurus,
    I am trying to create a stored procedure that opens a cursor for a select on a view owned by sys, but the errors says table or view does not exist. I can select * from the view (sys.mgw_gateway) from SQL*Plus or any other tool. Anyone have an idea why I get the ORA-00942: table or view does not exist error when I try to create a procedure? Here is the simple SQL statement for the procedure (I just want the users to see if the messaging gateway is running) and that's all in it.
    open p_MGWStatus for
         select AGENT_STATUS, AGENT_PING, to_char(LAST_ERROR_DATE, 'mm/dd/yyyy hh24:mi') as LastErrorDate,
         LAST_ERROR_MSG
         from sys.mgw_gateway;
    Thanks a lot.
    Ben

    Hi
    To allow the view owned by sys in a procedure, you have to grant select on that particular view to the owner of that procedure.
    Suggestion: may or may not be acceptable: create your own view in system schema (if it has the privilege to select that view else in sys schema) with the required column of the sys view and grant this newly created view to the owner of the procedure.
    Regards
    Opps! Very late reply
    Message was edited by:
    Anurag Tibrewal

  • Need Help to create new screen for RF Sapconsole

    Hi Guru's
    I'm new on RF (but some years in ABAP) since last week.
    I need help to create new screens for RF (SAPLLMOB).
    Can someone explain me the procedure to create screen (with ABAP code after) or perhaps someone have an exemple (simple or not) ?
    I have to develop 2 new screens with really few time.
    And, another subsidiary question :
    how SAP can transfert information between the flash gun and the screen i have developped.
    Is there some code to add to enable this functionality or it is include in SAPLLMOB on standard fields ????
    It's a new strange world for me today...
    Many thanks to everyone who can explain me
    Alain

    hi,
    I am facing this problem as well. Is there any reference to create the new screen?
    Hope someone can help! Thanks!
    Regards,
    Darren

  • Need help in creating a page that populates 3 related tables

    Hi All,
    I am pretty new to Oracle and have been trying to use the wizards in HTML_DB to create one page that will populate three tables. I have thus far have NOT been able to find my solutions. I do not know enough experience in SQL/PL_SQL to create the code on my own.
    Here is my dilemma. I have three tables:
    con (for contacts) - with regular contact info = l_name, f_name, phone...
    pro (for different programs) - with different program info = pro_name, priority..
    procon (Contact/program) - that joins the two together with initial, follow-up and close date fields.
    I created a composite primary key in the procon table that consists of the two pk's of the other two tables (using fk relationships).
    I want to be able to use one page in HTML_DB to enter in the data which will populate all three tables. Is there a way to do this in PL/SQL?
    * Also: Is there a book out there that you can recommend that really teaches SQL/PL_SQL?
    I would really, really, REALLY appreciate the help!!!!!
    Thanks,
    d.

    This isn't as bad as you think. I would create one procedure in a package and pass the parameters to the package via htmldb
    procedure insval(in_a in number, in_b in number, in_c in number)
      begin
       insert into tablea(cola)
        values(in_a);
      insert into tableb(colb)
       values(in_b);
      insert into tablec(colc)
       values(in_c);
      end;and then you call it from htmldb using a process
    schema.package.insval(:p1_a,:p1_b,:p1_c);That's ultra-simplified, but will get the job done.
    -Scott

  • Create a Procedural ALV Report with editable fields and save the changes

    Hi,
    I am new to ABAP. I have created a Procedural ALV Report with 3 fields. I want to make 2 fields editable. When executed, if the fields are modified, I want to save the changes. All this I want to do without using OO concepts. Please help . Also, I checked out the forum and also the examples
    BCALV_TEST_GRID_EDIT_01
    BCALV_TEST_GRID_EDIT_02
    BCALV_TEST_GRID_EDIT_04_FORMS
    BCALV_TEST_GRID_EDITABLE
    BCALV_EDIT_01
    BCALV_EDIT_02
    BCALV_EDIT_03
    BCALV_EDIT_04
    BCALV_EDIT_05
    BCALV_EDIT_06
    BCALV_EDIT_07
    BCALV_EDIT_08
    BCALV_FULLSCREEN_GRID_EDIT
    But all these are using OO Concepts.
    Please help.
    Regards,
    Smruthi

    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
      line_color(4) TYPE c,     "Used to store row color attributes
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE slis_layout_alv,
          gd_repid     LIKE sy-repid.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    fieldcatalog-do_sum      = 'X'.
    fieldcatalog-no_zero     = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
    fieldcatalog-edit             = 'X'
      fieldcatalog-col_pos     = 5.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
      gd_layout-info_fieldname =      'LINE_COLOR'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    FORM display_alv_report.
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = gd_repid
                i_callback_pf_status_set = 'STATUS'
                i_callback_top_of_page   = 'TOP-OF-PAGE'
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
               is_variant              = z_template
           TABLES
                t_outtab                = it_ekko
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      DATA: ld_color(1) TYPE c.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekko.
      LOOP AT it_ekko INTO wa_ekko.
        ld_color = ld_color + 1.
        IF ld_color = 8.
          ld_color = 1.
        ENDIF.
        CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
        MODIFY it_ekko FROM wa_ekko.
      ENDLOOP.
    ENDFORM.                    " DATA_RETRIEVAL
          FORM top-of-page                                              *
    FORM top-of-page.
      WRITE:/ 'This is First Line of the Page'.
    ENDFORM.
          FORM status                                                   *
    FORM status USING rt_extab TYPE slis_t_extab.  .
      SET PF-STATUS 'ALV'.
    ENDFORM.
          FORM USER_COMMAND                                          *
    -->  RF_UCOMM                                                      *
    -->  RS                                                            *
    FORM user_command USING rf_ucomm LIKE sy-ucomm
                             rs TYPE slis_selfield.            
      DATA ref1 TYPE REF TO cl_gui_alv_grid.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = ref1.
      CALL METHOD ref1->check_changed_data.
      CASE rf_ucomm.
    when 'SAVE'.
    get all the modified entries and store them in an internal table and udpate them in to the required transaction or your custom table.
    endcase.
    endform.
    ENDFORM.
    here u need to 2 performs for PF status and USER_COMMAND in the ALV parameters.
    create a custom PF status and create push buttons and assign your ok codes in your PF status.
    if the field has to be edited in the ALV then pass EDIT = 'X' for that field in the fieldcatlog preparation.
    Hope this will help you.
    Regards,
    phani.

  • Need Help With a Stored Procedure

    Help With a Stored Procedure
    Hi everyone.
    I am quite new relative to creating stored procedures, so I anticipate that whatever help I could get here would be very much helpful.
    Anyway, here is my case:
    I have a table where I need to update some fields with values coming from other tables. The other tables, let us just name as tblRef1, tblRef2 and tblRef3. For clarity, let us name tblToUpdate as my table to update. tblToUpdate has the following fields.
    PlanID
    EmployeeIndicator
    UpdatedBy
    CreatedBy
    tblRef1, tblRef2 and tblRef3 has the following fields:
    UserName
    EmpIndicator
    UserID
    In my stored procedure, I need to perform the following:
    1. Check each row in the tblToUpdate table. Get the CreatedBy value and compare the same to the UserName and UserID field of tblRef1. If no value exists in tblRef1, I then proceed to check if the value exists in the same fields in tblRef2 and tblRef3.
    2. If the value is found, then I would update the EmployeeIndicator field in tblToUpdate with the value found on either tblRef1, tblRef2 or tblRef3.
    I am having some trouble writing the stored procedure to accomplish this. So far, I have written is the following:
    CREATE OR REPLACE PROCEDURE Proc_Upd IS v_rec NUMBER;
    v_plan_no tblToUpdate.PLANID%TYPE;
    v_ref_ind tblToUpdate.EMPLOYEEINDICATOR%TYPE;
    v_update_user tblToUpdate.UPDATEDBY%TYPE;
    v_created_by tblToUpdate.CREATEDBY%TYPE;
    v_correct_ref_ind tblToUpdate.EMPLOYEEIDICATOR%TYPE;
    CURSOR cur_plan IS SELECT PlanID, EmployeeIndicator, UPPER(UpdatedBy), UPPER(CreatedBy) FROM tblToUpdate;
    BEGIN
    Open cur_plan;
         LOOP
         FETCH cur_plan INTO v_plan_no, v_ref_ind, v_update_user, v_created_by;
              EXIT WHEN cur_plan%NOTFOUND;
              BEGIN
              -- Check if v_created_by has value.
                   IF v_created_by IS NOT NULL THEN
                   -- Get the EmpIndicator from the tblRef1, tblRef2 or tblRef3 based on CreatedBy
                   SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_created_by
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   ELSIF v_created_by IS NULL THEN
                   -- Get the EmpIndicator based on the UpdatedBy
                        SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_update_user
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   END IF;
              END;
         END LOOP;
         CLOSE cur_plan;
         COMMIT;
    END
    Please take note that the values in the column tblToUpdate.UpdatedBy or tblToUpdate.CreatedBy could match either the UserName or the UserID of the table tblRef1, tblRef2, or tblRef3.
    Kindly provide more insight. When I try to execute the procedure above, I get a DATA NOT FOUND ERROR.
    Thanks.

    Ah, ok; I got the updates the wrong way round then.
    BluShadow's single update sounds like what you need then.
    I also suggest you read this AskTom link to help you see why you should choose to write DML statements before choosing to write cursor + loops.
    In general, when you're being asked to update / insert / delete rows into a table or several tables, your first reaction should be: "Can I do this in SQL?" If you can, then putting it into a stored procedure is usually just a case of putting the sql statement inside the procedure header/footers - can't really get much more simple than that! *{;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help needed in stored procedures

    Hi,
    I wrote a stored procedure when i execute it. i get the error
    ORA-00942: table or view does not exist
    ORA-06512: at "SANDEEP.PROC_INS_TEMP_NAC_GL", line 18
    ORA-06512: at line 9
    I was unable to resolve this error please help.
    CREATE OR REPLACE PROCEDURE PROC_INS_TEMP_NAC_GL(
    p_bu IN STRING,
    p_period IN STRING
    IS
    sql_stmt varchar2(1000);
    cnt number;
    BEGIN
         SELECT count(view_name) INTO cnt FROM sys.all_views where view_name = UPPER(p_bu||'_v_ldga') and owner = 'SUN';
         sql_stmt := 'INSERT INTO temp_nac_gl'||
         ' SELECT ''' || p_bu ||'''BU, gl.ACCNT_CODE , gl.ANAL_T0 , gl.ANAL_T1 , gl.PERIOD , gl.MEMO_AMT , gl.AMOUNT , gl.REGION, gl.ANAL_T3'||
                   ' FROM sun.'|| p_bu ||'_v_ldga gl, temp_acnt_grp acnt' ||
                   ' WHERE gl.accnt_code = acnt.acnt_code ' ||
                   ' AND acnt.bu = '''|| p_bu ||'''' ||
                   ' AND gl.period <= '''|| p_period || '''' ||
                   ' ORDER BY gl.REGION';
    EXECUTE IMMEDIATE sql_stmt;
    END;
    /

    If you are accessing a object from a Oracle procedure/function then you need direct rights and not through roles.
    You can check this by executing a SELECT from SQL plus , if you are able to see the table then type the following commond
    SQL> set role none;
    SQL> SELECT statement
    If it gives an error then you dont have direct rights.
    Thanks
    Edited by: Himanshu Kandpal on May 14, 2009 5:04 PM

  • How to create  a procedure to send a mail if the Database is down?

    Hi,
    I have created the below procedure to send a mail if the count is less than 1300. It scheduled daily @ 15 30 hrs. Its fine.
    CREATE OR REPLACE procedure SCOTT.hrsmail
    is
    v_count number;
    begin
    Select count(*) into v_count from emp;
    if v_count < 1300
    then
    UTL_MAIL.send(sender => '[email protected]',
    recipients => '[email protected]',
    cc => '[email protected]',
    bcc => '[email protected]',
    subject => 'Testing the UTL_MAIL Package',
    message => 'If you get this, UTL_MAIL package
    else
    null; --what you want to do here
    end if ;
    end;
    Sometime the Database is down, so the job is not running.
    How to create a procedure to send a mail if the database is down?
    Pls help me. Its highly appreciated.
    Thanks
    Nihar

    nihar wrote:
    How to create a procedure to send a mail if the database is down?And what if the database is up, but the network down? Or the database up and mail server down? Or mail server undergoing maintenance?
    There are loads of "+What if's+" - and in that respect, playing "+What if database is down..+" in this case does not make any sense. You do not use the database to monitor its own up/down status. You do not rely just on SMTP as notification protocol that the database is down.
    The correct approach would be using something like SNMP as the monitoring protocol. A monitoring system that can process SNMP and perform some basic root cause analysis (e.g. network to the database server down, database server status unknown). And this system supporting notification methods like SMTP, SMS and so on.

Maybe you are looking for

  • Off2013 with windows 8.1

    Hi, New to this forum, have searched and not found anything in regards to my actual issue. Problem, When you install Office 2013 Home and Business onto Windows 8.1 either an upgrade to 8.1 or a fresh install, I've found the mail program in Control Pa

  • How to sign in to the forum using Firefox w/ NoScript

    Apparently this site uses "suspicious cross-site POST requests" according to NoScript in Firefox. Until this changes, you'll need to tweak the NoScript settings a little in order to be able to sign into your community.vzw.com account with NoScript XS

  • How to create a logon process in iWeb

    My version of iWeb does not appear to have the universal password protect of the webpage function [even thought the Apple documentation says you can]. Has anyone created a iWeb page which requires a user to logon with a user name and password [it can

  • Document splitting-based on profit center

    Hi Experts, While posting JV (f-02) document, document was not splitting based on profit center. Dr 520499.......9100  (Profit center 100) Dr 520475.......7888 ( Profit center 200)      To. 199000...... ...    16988 When I am trying to post the above

  • Bloggie share to youtube-invalid response

    When I try to share a video to Youtube from my bloggie software, it says youtube had an invalid response. What does this mean? I am logged into my youtube account but it will not share the video. Any suggestions are greatly appreciated.