Tables statement in procedure.

hi experts:
today i get a program:
report ytest_table1.
tables:proj.
form frm_f1.
proj-pspnr = '12345678'.
endform.
report ytest_table.
form frm_f.
   tables:proj.
  if proj is initial.
  endif.  "breakpoint1
  clear proj-pspnr.
  if proj is initial.
  endif.  "breakpoint2
endform.
start-of-selection.
  perform frm_f1 in program ytest_table1.
  perform frm_f.
write: 1. "breakpoint3
when i run ytest_table and found:
the value is 12345678 when break1
the value is initial when break2
the value is 12345678 when break3
break 1 and break 2 i can understand that is a table work area,
but why break 3 is still 12345678?

Hi,
please read the follwing note from the keyword help for TABLES:
Table work areas declared with TABLES can be declared in subroutines and function modules. However, this is not recommended. A table work area declared in a procedure is not local but belongs to the context of a framework program. The table work area can be viewed starting from the declaration in the framework program and lives as long as the framework program. In contrast to normal program-global data, the content of the table work areas declared in subroutines and function modules is stored temporarily when these subroutines and function modules are called. Value assignments that were made during runtime of the procedure are preserved until the procedure is completed. When exiting the procedure, the table work areas are filled with the contents that they contained when the procedure was called. Table work areas declared in procedures behave like global data to which the statement LOCAL is applied in the procedure.
Regards,
Klaus

Similar Messages

  • SAP HANA - How to run alter table statement in HANA procedure?

    I am trying to run alter table statement in a procedure. HANA gives error saying
    SAP DBTech JDBC: [257] (at 1338): sql syntax error: ALTER TABLE is not allowed in SQLScript: line 36 col 8 (at pos 1338)
    How to run alter table statements in procedure?
    Thanks,
    Suren.

    Hi Rich Heilman,
    Thanks for your response.  I have tried with dynamic SQL. I am trying to add partitions to a non portioned table.
    EXECUTE IMMEDIATE 'ALTER TABLE ' || :SCHEMA_NAME || '.TARGET_TABLE PARTITION BY RANGE (TARGET_TYPE_ID) (PARTITION VALUE = 1, PARTITION VALUE = 2, PARTITION VALUE = 3, PARTITION VALUE = 4, PARTITION OTHERS)';
    Execution fails with error
    Could not execute 'CALL PARTITION_TARGET_TABLE('SUREN_TEST')' in 1.160 seconds .
    [129]: transaction rolled back by an internal error:  [129] "SUREN_TEST"."PARTITION_TARGET_TABLE": line 53 col 3 (at pos 2173): [129] (range 3)
    Any reasons for this error?
    Thanks,
    Suren.

  • Create table statement inside a procedure.

    Hi,
    I'm trying to write a procedure creates some tables. The procedure has not arguments. I have written it in this way:
    CREATE OR REPLACE PROCEDURE MIGRAZIONE
    IS
        var varchar2(2000);
    BEGIN
    --INIZIO tabella dominio spr_klers_bor_borsa
    CREATE TABLE SPR_KLERS_BOR_BORSA34
      ID           VARCHAR2(4 BYTE)                 NOT NULL,
      DESCRIPTION  VARCHAR2(80 BYTE)
    CREATE UNIQUE INDEX SPR_KLERS_IAZ_BORSA_PK ON SPR_KLERS_BOR_BORSA
    (ID)
    LOGGING
    TABLESPACE FIN_DATA
    PCTFREE    10
    INITRANS   2
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       2147483645
                PCTINCREASE      0
                BUFFER_POOL      DEFAULT
    NOPARALLEL;
    ALTER TABLE SPR_KLERS_BOR_BORSA ADD (
      CONSTRAINT SPR_KLERS_IAZ_BORSA_PK
    PRIMARY KEY
    (ID)
        USING INDEX
        TABLESPACE FIN_DATA
        PCTFREE    10
        INITRANS   2
        MAXTRANS   255
        STORAGE    (
                    INITIAL          64K
                    MINEXTENTS       1
                    MAXEXTENTS       2147483645
                    PCTINCREASE      0
    --FINE tabella spr_klers_bor_borsa
    END MIGRAZIONE;When I compile I receive this message:
    PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    What does it mean?
    How can I solve?
    I have tried to change the procedure in this way:
    CREATE OR REPLACE PROCEDURE MIGRAZIONE
    IS
        var varchar2(2000);
    BEGIN
    --INIZIO tabella dominio spr_klers_bor_borsa
    var := 'CREATE TABLE SPR_KLERS_BOR_BORSA
      ID           VARCHAR2(4 BYTE)                 NOT NULL,
      DESCRIPTION  VARCHAR2(80 BYTE)
    CREATE UNIQUE INDEX SPR_KLERS_IAZ_BORSA_PK ON SPR_KLERS_BOR_BORSA
    (ID)
    LOGGING
    TABLESPACE FIN_DATA
    PCTFREE    10
    INITRANS   2
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       2147483645
                PCTINCREASE      0
                BUFFER_POOL      DEFAULT
    NOPARALLEL;
    ALTER TABLE SPR_KLERS_BOR_BORSA ADD (
      CONSTRAINT SPR_KLERS_IAZ_BORSA_PK
    PRIMARY KEY
    (ID)
        USING INDEX
        TABLESPACE FIN_DATA
        PCTFREE    10
        INITRANS   2
        MAXTRANS   255
        STORAGE    (
                    INITIAL          64K
                    MINEXTENTS       1
                    MAXEXTENTS       2147483645
                    PCTINCREASE      0
    execute immediate var;
    --FINE tabella spr_klers_bor_borsa
    END MIGRAZIONE;And when I compile the version above I receive:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    How can I solve?
    Thanks all, bye bye.

    Here you have to user dynamic sql for create table, cerate index etc.
    like
    CREATE OR REPLACE PROCEDURE MIGRAZIONE
    IS
        var varchar2(2000);
    BEGIN
    --INIZIO tabella dominio spr_klers_bor_borsa
    var := 'CREATE TABLE SPR_KLERS_BOR_BORSA
      ID           VARCHAR2(4 BYTE)                 NOT NULL,
      DESCRIPTION  VARCHAR2(80 BYTE)
    Execute immediate var;
    var := 'CREATE UNIQUE INDEX SPR_KLERS_IAZ_BORSA_PK ON SPR_KLERS_BOR_BORSA
    (ID)
    LOGGING
    TABLESPACE FIN_DATA
    PCTFREE    10
    INITRANS   2
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       2147483645
                PCTINCREASE      0
                BUFFER_POOL      DEFAULT
    NOPARALLEL' ;
    Execute immediate var;
    var := 'ALTER TABLE SPR_KLERS_BOR_BORSA ADD (
      CONSTRAINT SPR_KLERS_IAZ_BORSA_PK
    PRIMARY KEY
    (ID)
        USING INDEX
        TABLESPACE FIN_DATA
        PCTFREE    10
        INITRANS   2
        MAXTRANS   255
        STORAGE    (
                    INITIAL          64K
                    MINEXTENTS       1
                    MAXEXTENTS       2147483645
                    PCTINCREASE      0
    execute immediate var;
    --FINE tabella spr_klers_bor_borsa
    END MIGRAZIONE;YOu can specify all the ddl statements in one execute immediate.
    Edited by: s_2 on Oct 17, 2008 6:59 PM

  • Why we use Tables statement in case of using SELECT-OPTIONS:

    hi all,
    Why we use Tables statement in case of using the following coding in an ABAP program ...
    tables: vbak.
    SELECT-OPTIONS: s1 for vbak-vbeln.
    here if we dont provide the tables statement why it does not work ????
    pls answwer ....???

    Hi
    This statement is not allowed in classes and declares a data object table_wa as a table work area whose data type is adopted from the identically named structured data type table_wa from the ABAP Dictionary. table_wa must be defined as a flat structure in the ABAP Dictionary. You can specify database tables or Views for table_wa.
    Work table areas declared with TABLES are interface work areas and should only be declared in the global declaration section of a program for the following purpose:
    reward if usefull
    The statement TABLES is required for exchanging data between screen fields that were defined in a program screen when transferring from the ABAP Dictionary and the ABAP program. For the screen event PBO, the content of the table work area is transferred to identically named screen fields; for PAI, the system adopts the data from identically named screen fields.
    In executable programs, flat table work areas can be used for adopting data that were provided for the event GET table_wa from a linked logical database. TABLES is synonymous with the statement NODES for this purpose.
    Work table areas declared with TABLES behave like the data declared with the addition COMMON PART, meaning the data are used by the programs of a program group.
    Table work areas declared with TABLES can be declared in subroutines and
    function modules. However, this is not recommended. A table work area declared in a procedure is not local but belongs to the context of a framework program. The table work area can be viewed starting from the declaration in the framework program and lives as long as the framework program. In contrast to normal program-global data, the content of the table work areas declared in subroutines and function modules is stored temporarily when these subroutines and function modules are called. Value assignments that were made during runtime of the procedure are preserved until the procedure is completed. When exiting the procedure, the table work areas are filled with the contents that they contained when the procedure was called. Table work areas declared in procedures behave like global data to which the statement LOCAL is applied in the procedure.
    The form TABLES * is obsolete.

  • Using temporary tables in stored procedures

    Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
    What is the way of using temporary tables in stored procedures?

    It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
    But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
    Example:
    Create or Replace Procedure Proc_TestDynamicSQL is
    Begin
    Execute Immediate 'Create table myTable as select * from user_tables' ;
    Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
    End;
    In this case, Oracle wouldn't care about the table references during compilation.

  • Visual Basic, DAO, Temp tables in stored procedures

    Client code currently uses DAO with SQLPassthrough option in VB to connect to SQl 6.5 db.
    I migrated all stored procedures with default options except Oracle 8i temp tables. For every procedure a package and a procedure was created. We use SQL server temporary tables extensively in a few hundred stored procedures. The ref cursor created refers to the temporary table. While migratiing, Create table statement is commented. How are SQL6.5 equivalent of temp tables handled in Oracle? Is there an alternative to temp tables?
    I also migrated to another oracle db using the INOUT type for stored procedures. This time only procedures were created. Can these procedures return a record set in DAO with SQLPAssthrough?
    How do you call a procedure using DAO in VB to get recordsets?
    What is the best way to migrate to Oracle with minimal client code changes?
    Thank you in advance.
    Umesh
    null

    Karthick_Arp wrote:
    BluShadow wrote:
    I agree with Karthick, there's no need for a temporary table in this situation.
    And to add, temporary tables should not be created at runtime, they should be part of the initial design of the database, created once and used as needed. Creating them at runtime is just wrong.The problem is the name oracle has given to GTT. The word Temporary mislead lot of SQL Server developers and they think its something same as the temporary table used in SQL Server :)Yeah, Ingres does something similar to SQL Server too, in that you can create a temporary table (Ingres assigned it a unique name and tells you what it is), and you set an expiry time on it (i.e. set it to expire in 1 days time), and then a background process is supposed to clean up the tables that have expired. Unlike Oracle, they are not session specific, but become visible to all once created.
    I think there's room for both types of temporary table, but Oracle's does the job (except when you want to use them from a stateless application front end).

  • For loop to iterate through temp table in store procedure in pl/sql

    Hi,
    how to create For loop to iterate through the temporary table in the store procedure?

    Neha RK wrote:
    hi,
    its not working , i need to check each record of table and do some task using if else loop inside that for..
    if not possible to loop each row of table using for then how to use while loop.
    please helpWhat's not working? We haven't got psychic powers so we can't see the code you say isn't working.
    Please provide more information like create table statements, insert statements with test data, the code you've tried
    and the output you are expecting from the input data.
    Read {message:id=9360002} and follow the advice there.

  • Creating a table in a Procedure

    Hi All,
    Creating a table in a procedure is recommended or not. Please share me some knowledge on what kind of implications/ problems would be if my code forced me to do like this below.
    CREATE OR REPLACE
    PROCEDURE P12
    AS
    BEGIN
      EXECUTE IMMEDIATE 'CREATE TABLE T1( N NUMBER )';
    --some statements
    END;Thanks,

    Hi,
    968217 wrote:
    Hi All,
    Creating a table in a procedure is recommended or not. As the others have said, it is not recommended. Creating tables in PL/SQL is almost always a very bad idea.
    Please share me some knowledge on what kind of implications/ problems would be if my code forced me to do like this below.What do you mean by "my code forced me to do like this"? How can your code force you to do anything?
    CREATE OR REPLACE
    PROCEDURE P12
    AS
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE T1( N NUMBER )';
    --some statements
    END;Why would you even consider doing that? Isn't it simpler to say
    CREATE TABLE T1( N NUMBER );
    --some statements?

  • How to read I$ table using ODI procedure

    Hi
    Can any one help me how to drop a I$ table from out sie of interface.
    I have tried below approches but no luck
    I have created ODI procedure with technology oracle and target logical schema (I$ tables are creating on target DB) with and with out begin and end;
    Approch 1:
    Given below code in ODi procedure
    drop table <%=odiRef.getTable("L", "INT_NAME", "W")%> <% if (new Integer(odiRef.getOption( "COMPATIBLE" )).intValue() >= 10 ) { out.print( "purge" ); }; %>
    Approch 2:
    drop table I$_<%=odiRef.getTable("L", "TARG_NAME", "A") %>;
    Approch 3:
    drop table <%=odiRef.getTable("L", "INT_NAME", "W")%> (but it is fetching target dtabase schema anme not I$ table)
    Please help me any other alternative way to drop a I$ table, more over this code should be unique for all interface
    Regards,
    Phanikanth

    Thanks bhabani,
    Actaul my requirement is some time my scenario is stoping due some issue at Merge Rows Step (I am using IKM Oracle Incremental Update(Merge) KM) when the next iteration starts it is thwoing and error at create flow table I$ step and error is table name is already exists, so i am doing is if the interface went failed I am storing those information in one table using ODI procedure (INF--ko-->ODI procedure) in same ODI procedure I want to call a I$ table to drop.
    Can you please provide the steps so it will very useful for me using Java variable.
    I have gievn a step as below on create I$ table step (after create I$ statement)
    <@ java.lang.String Idollertable = <%=odiRef.getTable("L", "INT_NAME", "W")%> ; @>
    I am calling Idollertable variable in ODI procedure which is ko>* of INF as <@=Idollertable@>
    Note: I have followed below approch
    ODI Procedure Code:
    drop table <@=Idollertable@>; --> *2nd approch*
    begin
    insert into ODI_EXECUTION_ERROR_DETAILS
    (SESSION_NO,
    SCENARIO_NAME,
    CONTEXT_NAME,
    ERR_MESSAGE,
    INSERT_COUNT,
    ERROR_COUNT)
    values
    <%=snpRef.getSession("SESS_NO")%>,
    '<%=odiRef.getPrevStepLog("STEP_NAME")%>',
    '<%=odiRef.getContext( "CTX_NAME" )%>',
    '<%=odiRef.getPrevStepLog("MESSAGE")%>',
    '<%=odiRef.getPrevStepLog("INSERT_COUNT")%>',
    '<%=odiRef.getPrevStepLog("ERROR_COUNT")%>'
    commit;
    drop table <@=Idollertable@>; --> * first approch *
    end;
    Please help me
    Regards,
    Phanikanth
    Edited by: Phanikanth on Mar 3, 2013 9:52 PM
    Edited by: Phanikanth on Mar 3, 2013 9:52 PM

  • Updating a temporary table thru a procedure

    Hi, let's say i have a reference table named LP_TEST.  From this table I get records and insert them into a temporary table named LP_TEMP.  After inserting the records, i run a procedure named CALC_AREA, which is used to update a certain column AREA in table LP_TEMP (putting values into the column AREA from NULL).  Inside my procedure CALC_AREA, i have a commit.  After running the procedure, I query the value of AREA from LP_TEMP table but it seemed that the column AREA was not updated.  However, i did the same exact thing but instead of using a temporary table, i used a regular table named LP_TEMP_TEST.  In this, table, i get an output for column AREA.
    What is the problem with my temporary table?  I have ON_COMMIT, PRESERVE ROWS and NO_CACHE set on my temporary table.  Does update table in a procedure run on temporary tables?  I am using Form Builder 10.1.2.0.2.  Please help.  Thanks

    Is your procedure by any chance declared as an autonomous transaction? Also are you 100% sure your update statement *really* updates data in your temp table? I'd fire up the debugger to make sure of that...
    cheers

  • Update Table statement in pre-commit trigger

    Hi,
    I would need to update one table before commit in the form and hence I need to write an update table statement in pre-commit trigger. Can anyone help me with the sample code or how sould i be able to write a Update table statement from form-level trigger. Normal update statement is throwing me errors.
    Thanks in adv

    I wouldn't recommend the PRE-COMMIT trigger unless it is your requirement to execute the UPDATE statement every time the form commits, whether it is updating or inserting or deleting.
    Other wise you can use the PRE-UPDATE, PRE-DELETE and PRE-INSERT triggers; for this case you create a procedure under Program Units node in the Form's navigator that includes your "UPDATE" SQL statement and you call this procedure from the triggers you need to execute it from.
    Example:
    PROCEDURE UPDATE_MYTABLE IS
    BEGIN
      UPDATE MYTABLE SET MY_COLUMN1 = MY_VALUE1,
                                       MY_COLUMN2 = MY_VALUE2,
                                       MY_COLUMN3 = MY_VALUE3
      WHERE ... condition;
    END;
    PRE-UPDATE trigger code:
    BEGIN
      UPDATE_MYTABLE;
    END;Try it and let us know if this is your requirement.
    Tony
    Edited by: Tony Garabedian on Sep 5, 2008 10:29 AM

  • URGENT : select from table statement in ABAP OO

    Hi all,
    I am an absolute ABAP OO beginner and need some quick help from an expert. How can I make a selection from an existing table (eg MARA) in an BADI which is programmed according to ABAP OO principles.
    In the old ABAP school you could make a TABLES statement at the beginning and the do a SELECT¨* FROM but this does not work in ABAP OO.
    How should i define such simple selections from existing tables. Anyone ?
    Thanks a lot,
    Eric Hassenberg

    *define internal table
    data: i_mara like standard table of mara.
    *select to this table
    select * from mara into table i_mara.
    Also you have to define work area for this internal table in order to use it.
    data:w_mara like line of i_mara.

  • How to get the number of hits ("returned rows") in read table statement

    Hi Experts
    I have the statement shown below, which seems not to work as I would like it to. My problem is that I would like to do two different things depending on weather or not a read table statement results in 0 hits or 1 (or more) hits.
        READ TABLE g_ship_item
            WITH KEY
         l_ztknum = DATA_PACKAGE-/bic/ztknum
         BINARY SEARCH.
          IF sy-subrc is initial.
          no hits found
            DATA_PACKAGE-/BIC/ZSTAGEERR = 1.
          ELSE.
          hits where found and we will do something else...
            DATA_PACKAGE-/BIC/ZSTAGEERR = 0.
    Hope someone can help me out of my problem...
    Thanks in advance, regards
    Torben

    Hi,
    As you are using READ statement with Binary search, check whether the internal table g_ship_item is sorted with field /bic/ztknum or not. If it is not sorted then the result of this READ statement is not correct.
    Below is the correct code.
    sort  g_ship_item by /bic/ztknum.
    READ table g_ship_item with key g_ship_item = xxx.
    Thanks,
    Satya

  • Can we use return statement in procedure?

    Can we use return statement in procedure or we can use more than one return statement in procedure?

    HamidHelal wrote:
    NOReally? Did you at least test it? You can use RETURN in procedure or in anonymous PL/SQL block. The only restriction is you can't specify return value:
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return;
      4      dbms_output.put_line('After return');
      5  end;
      6  /
    Before return
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Procedure created.
    SQL> exec p1;
    Before return
    PL/SQL procedure successfully completed.
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return 99;
      4          dbms_output.put_line('After return');
      5  end;
      6  /
        return 99;
    ERROR at line 3:
    ORA-06550: line 3, column 5:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 3, column 5:
    PL/SQL: Statement ignored
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return 99;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    5/9      PL/SQL: Statement ignored
    5/9      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    SQL> SY.

  • Can I create a table in a procedure submitted to job queue?

    I have created a package (with AUTHID CURRENT_USER) where some of the procedures create temporary tables to facilitate processing. These procedures run just fine when executed directly from within an anonymous block at the SQL*PLUS level. However, when I submit the procedures to the job queue (via DBMS_JOB.SUBMIT), the job is submitted successfully but fails when run. Investigating the Alert Log shows an error of insufficient privilege on the CREATE TABLE command in the procedure.
    QUESTION:
    Can I create a table from a procedure running in the Job Queue? If so, then how to get it to work? Does the job run in a different environment that needs Create Table privileges set to my schema?
    Thanks for any info you can provide.
    John

    FYI: Found the problem. In the Administrator's Guide (of course not in the supplied packages documentation about DBMS_JOB) I found:
    "How Jobs Execute
    SNP background processes execute jobs. To execute a job, the process creates a session to run the job.
    When an SNP process runs a job, the job is run in the same environment in which it was submitted and with the owner's default privileges.
    When you force a job to run using the procedure DBMS_JOB.RUN, the job is run by your user process. When your user process runs a job, it is run with your default privileges only. Privileges granted to you through roles are unavailable."
    And of course we had set up our users to get all privileges through Roles, so CREATE TABLE wasn't one of my DEFAULT PRIVILEGES!
    It sure would be nice if Oracle documentation could get its act together and provide ALL information about a topic in a logical place. The effort to find the information about privileges occurred after it took me 1/2 hour to figure out why my submissions were failing - I didn't have the ';' included in the quoted string for the procedure to be called - which I only figured out after looking at the code for DBMS_JOB where it made the note to make sure you include the ';'. Wouldn't it be good to have that MINOR DETAIL mentioned in the description of DBMS_JOB.SUBMIT?????

Maybe you are looking for