Stored Procedure to create table for PdO Change Log

Hi Experts,
I have read in the forums that the only way to get a Change Log was to create a Stored Prodedure and create a new Table that is populated with the Change when ever a User update a Production Order.
I started on this Stored Procedure and have hit a wall on a error. I'm fairly new to queries...
Here is what I have so far:
if((@transaction_type = 'U')and(@object_type = '202'))
BEGIN
set @PdO = case @object_type
          INSERT INTO ChangeLogPdO2 (DocEntry, Status, ItemCode, PlannedQty, DueDate)
          SELECT T0.DocEntry, T0.Status, T0.ItemCode, T0.PlannedQty, T0.DueDate
          FROM OWOR T0      
          WHERE T0.DocEntry = @list_of_cols_val_tab_del
    END
if(@PdO = 'true')
begin
      select @error = 1
      select @error_message = N'My Error message'
end
I plan to add more columns, but only started with these. Also how do I put a time stamp on this?
Thanks,
Marli
Edited by: Marli Schutte on Feb 3, 2010 7:09 PM

Gordon,
I created a new UDT named CLPdO.
Then I did as you suggested and I get the error message 'Incorrect syntax near the keyword 'INSERT''.
Here is how the Sotred Procedure now look:
[code}
if((@transaction_type = 'U')and(@object_type = '202'))
BEGIN
set @PdO = case @object_type
          INSERT INTO dbo@CLPdO (DocEntry, Status, ItemCode, PlannedQty, DueDate)
          SELECT T0.DocEntry, T0.Status, T0.ItemCode, T0.PlannedQty, T0.DueDate
          FROM OWOR T0      
          WHERE T0.DocEntry = @list_of_cols_val_tab_del
    END
if(@PdO = 'true')
begin
      select @error = 1
      select @error_message = N'My Error message'
end
Any help will be appreciated.
Marli

Similar Messages

  • Problem using stored procedure to populate table for report

    I have a report that in one instance the user wants the quantity data pulled from a smaller subset of data. My thought was to create a global temporary table and then use a stored procedure to populate this table then pass the table name in a lexical that contains the table name. So my query in the report stays the same except for the lexical table name. This all seems to work except for the procedure populating the table. I thought it might be the global temporary table so I created a real table. When I run the procedure from the command prompt the table gets populated. When I run the procedure in the before report trigger I get nothing. When I run the procedure from the command line and leave the data, then run the report I get updated data in the table, but nothing returned to the report. Any ideas, questions, solutions?
    Thanks
    Andy Hendrickson

    Hi Andy Hendrickson,
    Let me understand your problem correctly.
    1) When you run the procedure from command prompt the table gets populated. It is clear.
    2)When you run the procedure in before report trigger you get nothing. Let us analyze why but for now it is clear.
    3) What you mean by "I run the procedure from the command line and leave the data, then run the report I get updated data in the table, but nothing returned to the report."
    Can you please explain a bit more and also update code snippets of what you are using ?
    Thanks,
    Vinod
    Oracle Reports Team

  • Stored Procedure that creates a trigger on new tables

    I am trying to create a stored procedure that creates a trigger on new tables whenever the table is created.  The procedure should receive the new project table's name, and then create a dml trigger on that procedure.  When the procedure
    is run, I get an error "Incorrect syntax near keyword 'TRIGGER.'"  This is how my Stored Procedure looks in SQL Management Studio.  Any suggestions?
    USE [RIDB_DynamicDesign]
    GO
    /****** Object: StoredProcedure [dbo].[sp_CreateTriggerMarkLatest] Script Date: 11/08/2014 16:43:20 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[sp_CreateTriggerMarkLatest] @ProjectTable nvarchar(128), @ItExists int OUTPUT
    AS
    DECLARE @SQL nvarchar(4000)
    DECLARE @MarkLatest nvarchar(30)
    DECLARE @LatTrue bit
    DECLARE @LatFalse bit
    SET @LatTrue = 'True'
    SET @LatFalse = 'False'
    SET @SQL = 'CREATE TRIGGER tr_MarkLatest ON ' + @ProjectTable + ' AFTER INSERT
    AS
    UPDATE ' + @ProjectTable + ' SET Latest = @LatFalse
    UPDATE ' + @ProjectTable + ' SET Latest = @LatTrue WHERE
    ID IN (SELECT ID FROM ' + @ProjectTable + ' p WHERE
    NOT EXISTS (SELECT 1 FROM ' + @ProjectTable + ' WHERE
    Name = p.Name AND Vers = p.Vers
    AND Date > p.Date))'
    EXEC sp_executesql @SQL, N'@ProjectTable nvarchar(128), @LatTrue bit, @LatFalse bit',
    @ProjectTable, @LatTrue, @LatFalse
    Gina

    First you have to debug the dynamic SQL string with a PRINT statement. I see some problems:
    CREATE PROCEDURE [dbo].[uspCreateTriggerMarkLatest] @ProjectTable nvarchar(128), @ItExists int OUTPUT
    AS BEGIN
    DECLARE @SQL nvarchar(4000)
    DECLARE @MarkLatest nvarchar(30)
    DECLARE @LatTrue bit
    DECLARE @LatFalse bit
    SET @LatTrue = 'True'
    SET @LatFalse = 'False'
    SET @SQL = 'CREATE TRIGGER tr_MarkLatest ON ' + @ProjectTable + ' AFTER INSERT
    AS
    UPDATE ' + @ProjectTable + ' SET Latest = @LatFalse
    UPDATE ' + @ProjectTable + ' SET Latest = @LatTrue WHERE
    ID IN (SELECT ID FROM ' + @ProjectTable + ' p WHERE
    NOT EXISTS (SELECT 1 FROM ' + @ProjectTable + ' WHERE
    Name = p.Name AND Vers = p.Vers
    AND Date > p.Date))'
    PRINT @SQL;
    -- EXEC sp_executesql @SQL, N'@ProjectTable nvarchar(128), @LatTrue bit, @LatFalse bit', @ProjectTable, @LatTrue, @LatFalse
    END
    GO
    DECLARE @ItExists int, @ProjectTable nvarchar(128) = N'TestTrigger';
    EXEC [dbo].[uspCreateTriggerMarkLatest] @ProjectTable, @ItExists OUTPUT
    CREATE TRIGGER tr_MarkLatest ON TestTrigger AFTER INSERT
    AS
    UPDATE TestTrigger SET Latest = @LatFalse
    UPDATE TestTrigger SET Latest = @LatTrue WHERE
    ID IN (SELECT ID FROM TestTrigger p WHERE
    NOT EXISTS (SELECT 1 FROM TestTrigger WHERE
    Name = p.Name AND Vers = p.Vers
    AND Date > p.Date))
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Creating a Oracle 10g stored procedure as a datasource for  crystal 9 repor

    Can someone direct me to instructions or information on how to create a Oracle 10g stored procedure as a datasource for  my Crystal  Reports 9.0  report?

    i've found this example for you
    http://www.pdssoftware.com/newsletter/mar07/page6.htm
    and you could be able to get the guides from the SAP guide website for the products
    http://help.sap.com/businessobject/product_guides/
    hope this was helpful
    good luck
    Amr

  • Stored procedure accessing system table

    I am using a stored procedure to access tables in other schemas. I pass the schema and table name as parameters to the stored procedure. I use these two variables to create a cursor of column names from all_tab_columns table. When I access all_tab_columns from SQL Plus, the right result is returned. When the procedure executes the same select statement in the same schema and using the same search criteria, the table I am looking for can not be found.
    Example:
    select count(column_name) from all_tab_columns where owner = 'MYADM' and table_name = 'MYTABLE';
    This will return the correct number of columns when executed in SQL Plus.
    cursor mycursor is
    select count(column_name) from all_tab_columns where owner = p_owner and table_name = p_table;
    This cursor, when used in my stored procedure, finds nothing when p_owner is set to MYADM and p_table is set to MYTABLE.
    I've tried granting all permissions to the calling schema with no positive results. I am aware that the calling schema is not required to have the necessary privileges when a procedure accesses data in other schemas. So I don't understand what the problem is. I greatly appreciate anyone's help.
    Cyrus

    Hi,
    try this, probaly this'll give you the desired output :
    Procedure Column_cnt
    ( p_owner IN varchar2,
    p_table IN varchar2 ) IS
    cursor c1 is
    select count(column_name) col_cnt from all_tab_columns where owner = upper(p_owner)
    and table_name = upper(p_table);
    BEGIN
    for i in c1 loop
    dbms_output.put_line(i.col_cnt);
    end loop;
    END;
    Now from SQLPLUS type :
    exec column_cnt('OWNER','TABLE_NAME')
    Note: parameters are in Varchar2, so they should be within quotes.
    But do you really want a cursor to store a single row, single column value, cursors are for fetching multiple rows/columns that means for a result set.
    if you want to get only count(column_name) then you could re-write the procedure like this way :
    Procedure Column_cnt
    ( p_owner IN varchar2,
    p_table IN varchar2 ) IS
    col_cnt number;
    BEGIN
    select count(column_name) into col_cnt from all_tab_columns where owner = upper(p_owner)and table_name = upper(p_table);
    dbms_output.put_line(i.col_cnt);
    END;
    Thanks
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by cyrus eslami ([email protected]):
    I am compiling and invoking the procedure in a schema that has the correct privileges granted to it.
    -Cyrus<HR></BLOCKQUOTE>
    null

  • Do I need to install Oracle database 12c on PC to create tables for Weblogic server

    Hi,
    I am new to WebLogic and I am following a book Java EE Development
    with Eclipse published by PACKT Publishing to learn  Java EE.  I have installed Oracle Enterprise Pack for Eclipse
    on the PC and I am able to log into the WebLogic Server
    Administration Console and set up a Data Source.  However the next step is to create
    tables for the database.  The book says that the tables can be
    created using SQL script run from the SQL command line.
    I cannot see any way of inputting SQL script into the WebLogic
    Server Admistration Console.  Aslo there is no SQL Command line
    in DOS.
    I have put a previous question on the Oracle Forum about the above and I  was advised to use SQL Plus
    to create the tables for the weblogic server but no mention was made of installing Oracle database.
    I have downloaded InstantClient SQL Plus and Instantclient Basic on a PC and
    put the files into the same directory C:\SQLPlus but now I am having a problem in that it is
    looking for a username and password when I run the sqlplus.exe file.
    Now I assume that I need to have an installation of Oracle databse on the
    PC so as to be able to use SQL Plus.  Am I correct in this or can I create tables for the
    datasource in weblogic without an Oracle database?
    Thanks in advance for your help. Brian

    You should install it separately and also need to change the OBIEE's user.sh to tell it where is your Oracle client installed.

  • Tables for PIR change documents

    Dear Experts ,
    I need to know the tables for PIR change documents , as shown in t code ME14.
    Can anyone please let me know the same ?
    Regards
    Anis

    Hi,
    Check below tables
    CDHDR- Change document Header
    CDPOS- Change socument Item
    SAM

  • Tables for PO changes and message output

    Hi Experts
    I wish to capture the changes in PO in the respective change out put. For this purpose, i need to fetch the relevant infmrmation applicable for the change output.
    Please let me know the appropriate tables for:
    -PO changes -item and header
    -PO message output
    Warm regards
    ramSiva

    Hi,
    Please check the following link :
    [Re: PO not showing Header Changes Log]
    Hope it helps,
    Best regards
    Amit Bakshi

  • Joining vbak to cdhdr table for document changes

    Hi Expert
    I am hanging for a week in this project please need some advice
    I want to join vbak table with cdhdr and select
    vbak.vkbur (plant) and want to show that vkbur in the internal table of it_cdhdr
    so as to select only those plant belong to vkbur so how can I join base on the below coding................
    REPORT ZCHGDOC
    NO STANDARD PAGE HEADING LINE-SIZE 120.
    WRITE: sy-title, 40 'Page', sy-pagno.
    ULINE.
    TABLES: CDHDR,
             CDPOS,
             t001w,
             "VKBUR,
             "VBELN,
             VBAK,
             VBAP.
    SELECTION-SCREEN BEGIN OF BLOCK DOCUMENT WITH FRAME TITLE TEXT-701.
    SELECTION-SCREEN END OF BLOCK DOCUMENT.
    SELECT-OPTIONS:
                     V1 FOR VBAK-VKBUR,
                     S_WERKS for T001W-werks,
                     objectid for  cdhdr-objectid,
                     udate for cdhdr-udate.
    PARAMETER: USERNAME LIKE CDHDR-USERNAME.
    DATA: BEGIN OF IT_VBAP OCCURS 0,
             OBJECTCLAS LIKE CDHDR-OBJECTCLAS,
             OBJECTID LIKE CDHDR-OBJECTID,
             VBELN LIKE VBAP-VBELN,
              END OF IT_VBAP.
    DATA: BEGIN OF IT_CDHDR OCCURS 0,
             OBJECTCLAS LIKE CDHDR-OBJECTCLAS,
             OBJECTID LIKE CDHDR-OBJECTID,
             CHANGENR LIKE CDHDR-CHANGENR,
             USERNAME LIKE CDHDR-USERNAME,
             UDATE LIKE CDHDR-UDATE,
             UTIME LIKE CDHDR-UTIME,
             FNAME LIKE CDPOS-FNAME,
             TABNAME LIKE CDPOS-TABNAME,
             TABKEY LIKE CDPOS-TABKEY,
             VALUE_NEW LIKE CDPOS-VALUE_NEW,
             VALUE_OLD LIKE CDPOS-VALUE_OLD,
    END OF IT_CDHDR.
    DATA: WA LIKE LINE OF IT_CDHDR.
    DATA: WA LIKE LINE OF IT_CDPOS.
    DATA: BEGIN OF IT_CDPOS OCCURS 0,
             OBJECTCLAS LIKE CDHDR-OBJECTCLAS,
             OBJECTID LIKE CDHDR-OBJECTID,
             CHANGENR LIKE CDHDR-CHANGENR,
             TABNAME LIKE CDPOS-TABNAME,
             TABKEY LIKE CDPOS-TABKEY,
             FNAME LIKE CDPOS-FNAME,
             VALUE_NEW LIKE CDPOS-VALUE_NEW,
             VALUE_OLD LIKE CDPOS-VALUE_OLD,
    END OF IT_CDPOS.
    Move-corresponding it_cdhdr to wa.
    Move-corresponding it_cdpos to wa.
    SELECT OBJECTCLAS
            OBJECTID
            CHANGENR
            USERNAME
            UDATE
            UTIME FROM CDHDR
            INTO CORRESPONDING FIELDS OF TABLE IT_CDHDR
    WHERE OBJECTCLAS = 'VERKBELEG' or
          objectclas = 'BETRIEB'
          ORDER BY UDATE.
    WHERE OBJECTCLAS = 'VERKBELEG'
    OR OBJECTCLAS = 'BETRIEB' ORDER BY UDATE.
    Filter data based upon Plant selection criteria.
    IF NOT S_WERKS[] IS INITIAL.
    DELETE IT_CDHDR WHERE NOT OBJECTID IN S_WERKS.
    ENDIF.
    IF IT_CDHDR[] IS NOT INITIAL.
       SELECT OBJECTCLAS
              OBJECTID
              CHANGENR
              VALUE_NEW
              VALUE_OLD
              FNAME
              TABNAME
              TABKEY
              FROM CDPOS
              INTO CORRESPONDING FIELDS OF TABLE IT_CDPOS
              FOR ALL ENTRIES IN IT_CDHDR
              WHERE
              OBJECTCLAS = IT_CDHDR-OBJECTCLAS
              AND OBJECTID = IT_CDHDR-OBJECTID
              AND CHANGENR = IT_CDHDR-CHANGENR.
              "or tabname = 'VBAP'.
       SORT IT_CDPOS BY OBJECTCLAS OBJECTID CHANGENR.
    ENDIF.
    Add tables CDPOS DATA TO CDHDR.
    DATA: INDEX TYPE i.
    LOOP AT IT_CDHDR.
       INDEX = SY-TABIX.
       READ TABLE IT_CDPOS WITH KEY OBJECTCLAS = IT_CDHDR-OBJECTCLAS
       OBJECTID = IT_CDHDR-OBJECTID
       CHANGENR = IT_CDHDR-CHANGENR BINARY SEARCH.
       IF SY-SUBRC = 0.
         IT_CDHDR-VALUE_NEW = IT_CDPOS-VALUE_NEW.
         IT_CDHDR-VALUE_OLD = IT_CDPOS-VALUE_OLD.
         MODIFY IT_CDHDR INDEX index TRANSPORTING value_new value_old.
       ENDIF.
       WRITE:/ SY-DATUM,SY-UZEIT,
              50 'DOCUMENT CHANGE REPORT',
             80 'Page', SY-PAGNO,
    "  WRITE: / SY-REPID
              50 'DETAIL REPORT BY PLANT '.
       SKIP.
       ULINE.
    *& T O P - O F - P A G E *
    WRITE:/ 'UDATE:' ,SY-DATUM.
    FORMAT COLOR 4 INTENSIFIED on.
    Write: /35                           ' DOCUMENT CHANGES REPORT '.
       WRITE: /5 'DOCUMENT-NO'.
    20 'TABNAME', 30 'TEXT_CASE', 50 'FNAME'.
       WRITE: /5 'DATE',  20 'FNAME', 45 'CHANGE-NO',65 'OLD-VALUE',80 'NEW-VALUE',95 'USER-NAME'.
       ULINE.
       LOOP AT IT_CDHDR INTO WA.
       on change of wa-objectid.
       Write: / wa-objectid UNDER'DOCUMENT-NO' ."color col_key.
       ENDON.
    ULINE.
         " CDPOS-tabname UNDER'TABNAME', CDPOS-TEXT_CASE UNDER'TEXT_CASE',CDPOS-fname UNDER'FNAME'. "color col_key ,
         write: / wa-udate dd/mm/yyyy under'DATE' NO-GAP,wa-fname under'FNAME' NO-GAP,wa-changenr under 'CHANGE-NO',
         wa-value_old under'OLD-VALUE' LEFT-JUSTIFIED NO-GAP,
         wa-value_new under'NEW-VALUE' LEFT-JUSTIFIED NO-GAP ,wa-username under'USER-NAME' NO-GAP.
    ENDON.
    Move-corresponding it_cdhdr to wa.
    *Write: / wa-objectid UNDER'DOCUMENT-NO' "color col_key.
    *" CDPOS-tabname UNDER'TABNAME', CDPOS-TEXT_CASE UNDER'TEXT_CASE',CDPOS-fname UNDER'FNAME'. "color col_key ,
    *write: / wa-udate dd/mm/yyyy under'DATE' NO-GAP,wa-utime under'TIME' NO-GAP,wa-changenr under 'CHANGE-NO',
    ltrim(wa-value_old) under'OLD-VALUE' NO-GAP,
    *wa-value_new under'NEW-VALUE' NO-GAP ,wa-username under'USER-NAME' NO-GAP.
       ENDLOOP.
    ENDLOOP.

    Hai everybody.
    I am new to this forum. i got a job in abap recently. The below is my requirement.I want solution for this one. Anybody plz help me.
    The change logs were captured in DBTABLOG for table ZWPRFRUND (in transaction ZWPG).
    The only report which is currently used to get the change logs is RSVTPROT
    Now my requirement is,
    we need to display the change logs in the form of ALV.
    We should divert the changes to CDHDR table instead of DBTABLOG, then we can use the RSSCD100 to display change logs.
    The Important items for the change LOG needed in case of changes to table in “ZWPG” are,DATE ,TIME,USER,FIRST NAME,FILED NAME,OLD VALUE,NEW VALUE
    The above fields need to be displayed in the grid. In the above list “FIELD NAME” denotes any field of the table in the transaction in “ZWPG”
    Thanks & Regards,
    Sujatha.T.

  • How to create tables for control data

    HI
    How to create  tables for controls of types of data (screen control)? what is the process for this
    Regards,
    Anil

    Well, do you want to do it the easy way?  If so, then just create a table maintenance program.  You can do this via SE11, utilites, table maintenance generator. The table maintenance will be generated and you can then maintain the table via SM30. 
    If you want to go the more challenging way, you can write your own table maintenance program using a table control on your screen.  You can use the table control wizard to help you along.
    Regards,
    Rich Heilman

  • Use global temp table for DML error logging

    our database is 11.2.0.4 enterprise edition on solaris 10
    we are wondering if anyone has an opinion of or has done this before, to use a global temp table for DML error logging. We have a fairly busy transactional database with 2 hot tables for inserts. The regular error table created with dbms_errlog has caused many deadlocks which we don't quite understand yet. we have thought using global temp table for the purpose, and that seemed to work, but we can't read error from the GTT, the table is empty even reading from the same session as inserts. Does anyone have an idea why?
    Thanks

    The insert into the error logging table is done with a recursive transaction therefore it's private from your session which is doing the actual insert.
    Adapted from http://oracle-base.com/articles/10g/dml-error-logging-10gr2.php
    INSERT INTO dest
    SELECT *
    FROM  source
    LOG ERRORS INTO err$_dest ('INSERT') REJECT LIMIT UNLIMITED;
    99,998 rows inserted.
    select count(*) from dest;
      COUNT(*)
        99998
    SELECT *
    FROM  err$_dest
    WHERE  ora_err_tag$ = 'INSERT';
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    1000        Description for 1000
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    10000        Description for 10000
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    1000        Description for 1000
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    10000        Description for 10000
    rollback;
    select count(*) from dest;
      COUNT(*)
            0
    SELECT *
    FROM  err$_dest
    WHERE  ora_err_tag$ = 'INSERT';
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    1000        Description for 1000
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    10000        Description for 10000
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    1000        Description for 1000
    1400    "ORA-01400: cannot insert NULL into ("E668983_DBA"."DEST"."CODE")"        I    INSERT    10000        Description for 10000

  • User exit or BADI for standard change Log ?

    Is there user exit or BADI for standard change log update ?
    I want to update a customer fields into standard change log table.
    Could someone tell me about it?

    Could anbody tell me ?

  • Table for Output Processing log

    Hi,
    Can anyone tell me the table for Output processing Log.
    I need to take this info for some interface issue. 
    Muthu

    Hello,
    Check out the table "CMFP" for output processing log.
    Regards,
    SARTHAK

  • Error in stored procedure while using dbms_datapump for transportable

    Hi,
    I'm facing following issue:
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    ====================================================================================
    I'm trying to do transportable tablespace through stored procedure with help of DBMS_DATAPUMP, Following is the code :
    ==================================================================================
    create or replace
    procedure sp_tts_export(v_tbs_name varchar2) as
    idx NUMBER; -- Loop index
    JobHandle NUMBER; -- Data Pump job handle
    PctComplete NUMBER; -- Percentage of job complete
    JobState VARCHAR2(30); -- To keep track of job state
    LogEntry ku$_LogEntry; -- For WIP and error messages
    JobStatus ku$_JobStatus; -- The job status from get_status
    Status ku$_Status; -- The status object returned by get_status
         dts           varchar2(140):=to_char(sysdate,'YYYYMMDDHH24MISS');
         exp_dump_file varchar2(500):=v_tbs_name||'_tts_export_'||dts||'.dmp';
         exp_log_file varchar2(500):=v_tbs_name||'_tts_export_'||dts||'.log';
         exp_job_name varchar2(500):=v_tbs_name||'_tts_export_'||dts;
         dp_dir varchar2(500):='DATA_PUMP_DIR';
         log_file UTL_FILE.FILE_TYPE;
         log_filename varchar2(500):=exp_job_name||'_main'||'.log';
         err_log_file UTL_FILE.FILE_TYPE;
         v_db_name varchar2(1000);
         v_username varchar2(30);
         t_dir_name VARCHAR2(4000);
    t_file_name VARCHAR2(4000);
    t_sep_pos NUMBER;
         t_dir varchar2(30):='temp_0123456789';
         v_sqlerrm varchar2(4000);
    stmt varchar2(4000);
         FUNCTION get_file(filename VARCHAR2, dir VARCHAR2 := 'TEMP')
    RETURN VARCHAR2 IS
    contents VARCHAR2(32767);
    file BFILE := BFILENAME(dir, filename);
    BEGIN
              DBMS_LOB.FILEOPEN(file, DBMS_LOB.FILE_READONLY);
              contents := UTL_RAW.CAST_TO_VARCHAR2(
    DBMS_LOB.SUBSTR(file));
              DBMS_LOB.CLOSE(file);
              RETURN contents;
         END;
    begin
    --execute immediate ('drop tablespace test including contents and datafiles');
    --execute immediate ('create tablespace test datafile ''/home/smishr02/test.dbf'' size 10m');
    --execute immediate ('create table prestg.test_table (a number) tablespace test');
    --execute immediate ('insert into prestg.test_table values (1)');
    --commit;
    --execute immediate ('alter tablespace test read only');
    --dbms_output.put_line('11111111111111111111');
    dbms_output.put_line(log_filename||'>>>>>>>>>>>>>>>>>>>>>>>>>>>'|| dp_dir);
    log_file:=UTL_FILE.FOPEN (dp_dir, log_filename, 'w');
    UTL_FILE.PUT_LINE(log_file,'#####################################################################');
    UTL_FILE.PUT_LINE(log_file,'REPORT: GENERATED ON ' || SYSDATE);
    UTL_FILE.PUT_LINE(log_file,'#####################################################################');
    select global_name,user into v_db_name,v_username from global_name;
    UTL_FILE.PUT_LINE(log_file,'Database:'||v_db_name);
    UTL_FILE.PUT_LINE(log_file,'user running the job:'||v_username);
    UTL_FILE.PUT_LINE(log_file,'for tablespace:'||v_tbs_name);
    UTL_FILE.NEW_LINE (log_file);
    stmt:='ALTER TABLESPACE '||v_tbs_name || ' read only';
    dbms_output.put_line('11111111111111111111'||stmt);
    execute immediate (stmt);
    UTL_FILE.PUT_LINE(log_file,' '||v_tbs_name || ' altered to read only mode.');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,'#####################################################################');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Initiating the Datapump engine for TTS export..............');
    UTL_FILE.NEW_LINE (log_file);
    dbms_output.put_line('11111111111111111111');
    JobHandle :=
    DBMS_DATAPUMP.OPEN(
    operation => 'EXPORT'
    *,job_mode => 'TRANSPORTABLE'*
    *,remote_link => NULL*
    *,job_name => NULL*
    --,job_name => exp_job_name
    --        ,version => 'LATEST'
    UTL_FILE.PUT_LINE(log_file,'Done');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Allocating dumpfile................');
    DBMS_DATAPUMP.ADD_FILE(
    handle => JobHandle
    ,filename => exp_dump_file
    ,directory => dp_dir
    ,filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE
    -- ,filesize => '100M'
    UTL_FILE.PUT_LINE(log_file,'Done');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Allocating logfile................');
    DBMS_DATAPUMP.ADD_FILE(
    handle => JobHandle
    ,filename => exp_log_file
    ,directory => dp_dir
    ,filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE
    UTL_FILE.PUT_LINE(log_file,'Done');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Setting attributes................');
    DBMS_DATAPUMP.set_parameter(handle => JobHandle,
    name=>'TTS_FULL_CHECK',
    value=>1);
    DBMS_DATAPUMP.METADATA_FILTER(
    handle => JobHandle
    ,NAME => 'TABLESPACE_EXPR'
    ,VALUE => 'IN ('''||v_tbs_name||''')'
    -- ,object_type => 'TABLE'
    UTL_FILE.PUT_LINE(log_file,'Done');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Now starting datapump job................');
    DBMS_DATAPUMP.START_JOB(JobHandle);
    UTL_FILE.PUT_LINE(log_file,'Done');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Monitoring the job................');
    --------------Monitor the job
    PctComplete := 0;
    JobState := 'UNDEFINED';
    WHILE(JobState != 'COMPLETED') and (JobState != 'STOPPED')
    LOOP
    DBMS_DATAPUMP.GET_STATUS(
    handle => JobHandle
    ,mask => 15 -- DBMS_DATAPUMP.ku$_status_job_error + DBMS_DATAPUMP.ku$_status_job_status + DBMS_DATAPUMP.ku$_status_wip
    ,timeout => NULL
    ,job_state => JobState
    ,status => Status
    JobStatus := Status.job_status;
    -- Whenever the PctComplete value has changed, display it
    IF JobStatus.percent_done != PctComplete THEN
    DBMS_OUTPUT.PUT_LINE('*** Job percent done = ' || TO_CHAR(JobStatus.percent_done));
    PctComplete := JobStatus.percent_done;
    END IF;
    -- Whenever a work-in progress message or error message arises, display it
    IF (BITAND(Status.mask,DBMS_DATAPUMP.ku$_status_wip) != 0) THEN
    LogEntry := Status.wip;
    ELSE
    IF (BITAND(Status.mask,DBMS_DATAPUMP.ku$_status_job_error) != 0) THEN
    LogEntry := Status.error;
    ELSE
    LogEntry := NULL;
    END IF;
    END IF;
    IF LogEntry IS NOT NULL THEN
    idx := LogEntry.FIRST;
    WHILE idx IS NOT NULL
    LOOP
    DBMS_OUTPUT.PUT_LINE(LogEntry(idx).LogText);
    idx := LogEntry.NEXT(idx);
    END LOOP;
    END IF;
    END LOOP;
         --copy the datafiles to data dump dir     
         UTL_FILE.PUT_LINE(log_file,'Done');
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Copying datafiles to dump directory................');
    -- grant select on dba_directories to prestg;
    declare
    cnt number;
    begin
    select count(*) into cnt from dba_directories
    where directory_name=upper(t_dir);
    if cnt=1 then
    execute immediate('DROP DIRECTORY '||t_dir);
    end if;
    end;
         FOR rec in (select file_name from sys.dba_data_files where tablespace_name=v_tbs_name)
         LOOP
         t_sep_pos:=instr(rec.file_name,'/',-1);
    t_dir_name:=substr(rec.file_name,1,t_sep_pos-1);
    t_file_name:=substr(rec.file_name,t_sep_pos+1,length(rec.file_name));
    dbms_output.put_line(t_dir_name|| ' ' || t_dir);
    dbms_output.put_line(t_file_name);
         execute immediate('CREATE DIRECTORY '||t_dir||' AS '''||t_dir_name||'''');
         UTL_FILE.PUT_LINE(log_file,' Copying '||rec.file_name||'................');
         utl_file.fcopy(t_dir, t_file_name, dp_dir, t_file_name);
         UTL_FILE.PUT(log_file,'Done');
         execute immediate('DROP DIRECTORY '||t_dir);
         END LOOP;
    UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' Altering tablespace to read write................');
         execute immediate ('ALTER TABLESPACE '||v_tbs_name || ' read write');
    UTL_FILE.PUT(log_file,' Done');
         err_log_file:=utl_file.fopen(dp_dir, exp_log_file, 'r');
         UTL_FILE.NEW_LINE (log_file);
    UTL_FILE.PUT_LINE(log_file,' content of export logfile................');
         loop
    begin
         utl_file.get_line(err_log_file,v_sqlerrm);
         if v_sqlerrm is null then
         exit;
         end if;
         UTL_FILE.PUT_LINE(log_file,v_sqlerrm);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    EXIT;
    END;
         end loop;
              utl_file.fclose(err_log_file);
    utl_file.fclose(log_file);
    END;
    I'm getting following error when DBMS_DATAPUMP.OPEN is called in procedure:
    SQL> exec sp_tts_export('TEST');
    BEGIN sp_tts_export('TEST'); END;
    ERROR at line 1:
    ORA-31626: job does not exist
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
    ORA-06512: at "SYS.DBMS_DATAPUMP", line 938
    ORA-06512: at "SYS.DBMS_DATAPUMP", line 4566
    ORA-06512: at "PRESTG.SP_TTS_EXPORT", line 78
    ORA-06512: at line 1
    ==============================================================================================
    This procedure is part of user ABC. I'm getting the above when I'm running this under ABC schema. However I have tested the same procedure under sys schema. When I'm creating same procedure in SYS schema it is running fine. I am clueless on this. Pls help
    Thanks
    Shailesh
    Edited by: shaileshM on Jul 28, 2010 11:15 AM

    Privileges acquired via ROLE do NOT apply within named PL/SQL procedures.
    Explicit GRANT is required to resolve this issue.

  • Stored Procedure uses Temp Tables

    C#, asp.net app.
    I have a stored procudure that outputs data to temp tables. The data in these tables is only there for the life of that connection. The stored procedure does NOT return data.
    Options I see so far:
    1) If I open a connection and execute the stored procudure, how can I get crystal to use the SAME connection object?
    2) Can I get crystal to call the stored procedure for me first (but remember, it doesn't use the sp as the actual data source). Would I still be able to supply parameters to the SP?
    3) I guess I could do everything myself, even load all the data out of the temp tables into local datasets. And then supply the datasets to the tables. I tried this and I called SetDataSource on all my tables but then it looks like it still tried to go to the server again as I got a login screen.

    Hello Happy,
    No, Crystal does not have any access to those temp tables. They are locked by the owner who made the call and we have no API available in .NET that you can ride on to get access. Unless you can figure out a way at runtime to give full permission to the temp table then CR can use it. You just need to set the datasource to the temp table name at runtime. You will need to create the table so a report can be designed off it first but once done as long as the structure doesn't change the report will continue to work.
    Other options are as you have tried using data sets. Another option is to export that data into a database so CR has access to it rather than using temp tables. Once the report is done you can use MS API's to delete all rows of data.
    Thank you
    Don

Maybe you are looking for

  • To All IPod Users having Trouble with Live Updating playlists.

    I thought I should share this with other IPod users as there is quite a bit of discussion on the net about it. After 3 days trying to get "Smart Playlists"to live update on my IPod touch, reading, researching and reading more, I finally got my Ipod p

  • Can someone help with this stuppid Media Encoder?!

    I'm tired of reading hunderts of topics. Can someone please tell me why the Media Encoder is not encoding at all. I've tried everything, but my progressbar always shows loading 00:00:00. That is not normal. I'm sick of using expensive software, full

  • How to call formhandler handler method using js onclick function

    I need to call formhandler handle method when user clicks on a link. I want to call that method in js function. any help will be appreciated.

  • 'Assertion has failed' Error when using Save for Web (PSCS)

    This problem is due to the Save for Web preferences becoming corrupted. Delete the Safe For Web Preferences by holding down CTRL+ALT whilst clicking on File>Save for Web. (the Save foe Web preference file is saved at: C:\Documents and Settings\~usern

  • Printing POs documents.

    Hi, in trx ME21N when I click on "print preview" button the system generates the following message error: Processing routine OLD_ENTRY_NEU in program Z_SFM06P does not exist How about?