Simple SELECT query to generate  INSERT for a table

Hi,
I am looking for a SELECT query which generates INSERT statements for a table.Please guide.
Thanks
PG.

Like this?
SQL> SELECT * from kons;
     COL1      COL2
        1         1
        2         2
SQL> SELECT 'INSERT INTO kons VALUES('||col1||','||col2||');' statement FROM kons;
STATEMENT
INSERT INTO kons VALUES(1,1);
INSERT INTO kons VALUES(2,2);
SQL> If you have character and / or date columns you will have to change my example,
but you might get the idea from it.
You can spool the result to a file.
Regards,
Guido
Edit: ';' added to end of statement...

Similar Messages

  • Sinlge select query in different schemas for same table(Indentical Structu)

    Scenario :
    Table XYZ is created in Schema A
    After an year, the old data from the previous year would be moved to different schema. However in the other schema the same table name would be used.
    For eg
    Schema A contains table XYZ with data of 2012 yr
    Schema B contains table XYZ with data of 2011 yr
    Table XYZ in both the schemas have identical structure.
    So can we fire a single select query to read the data from both the tables in effective way.
    Eg select * from XYZ where date range between 15-Oct-2011 to 15-Mar-2012.
    However the data resides in 2 different schema altogether.

    Thanks for the reply
    Creating an view is an option.
    But my problem, there is ORM layer(either Hibernate or Eclipse Top Link) between the application and the database.
    So the queries would be formed by the ORM layer and are not hand generated.
    So i cannot use view.
    So is there any option that would allow me to use single query on different schema's ?

  • Sinlge select query in diff schemas for same table(Indentical Structure)

    Scenario :
    Table XYZ is created in Schema A
    After an year, the old data from the previous year would be moved to different schema. However in the other schema the same table name would be used.
    For eg
    Schema A contains table XYZ with data of 2012 yr
    Schema B contains table XYZ with data of 2011 yr
    Table XYZ in both the schemas have identical structure.
    So can we fire a single select query to read the data from both the tables in effective way.
    Eg select * from XYZ where date range between 15-Oct-2011 to 15-Mar-2012.
    However the data resides in 2 different schema altogether.
    Creating an view is an option.
    But my problem, there is ORM layer(either Hibernate or Eclipse Top Link) between the application and the database.
    So the queries would be formed by the ORM layer and are not hand generated.
    So i cannot use view.
    So is there any option that would allow me to use single query on different schema's ?

    Hi,
    970773 wrote:
    Scenario :
    Table XYZ is created in Schema A
    After an year, the old data from the previous year would be moved to different schema. However in the other schema the same table name would be used.
    For eg
    Schema A contains table XYZ with data of 2012 yr
    Schema B contains table XYZ with data of 2011 yr
    Table XYZ in both the schemas have identical structure.
    So can we fire a single select query to read the data from both the tables in effective way.That depends on what you mean by "effective".
    Eg select * from XYZ where date range between 15-Oct-2011 to 15-Mar-2012.
    However the data resides in 2 different schema altogether.You can do a UNION, so the data from the two years appears together. The number of actual tables may make the query slower, but it won;t change the results.
    Given that you have 2 tables, the fact that they are in different schemas doesn't matter. Just make sure the user running the query has SELECT privileges on both of them.
    Creating an view is an option.Is it? You seem to say it is not, below.
    But my problem, there is ORM layer(either Hibernate or Eclipse Top Link) between the application and the database.
    So the queries would be formed by the ORM layer and are not hand generated.
    So i cannot use view.So creating a view is not an option. Or is it?
    So is there any option that would allow me to use single query on different schema's ?Anything that you can do with a view, you can do with sub-queries. A view is merely a convenience; it just saves a sub-query, so you don't have to re-code it every time you use it. Assuming you have privilges to query the base tables, you can always avoid using a view by repeating the query that defines the view in your own query. It will not be any slower

  • A simple select query taking forever

    Hi All
    I am not able to execute a simple select query, I traced my session and here is TKPROF of that Trace.
    Solaris 8 , Oracle 10.2.0.4.0
    TKPROF: Release 10.2.0.4.0 -
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: 502_ora_28260.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select OBJECT_ID , ORACLE_USERNAME , SESSION_ID
    from
      v$locked_object
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.03      32.86          0          0          6           0
    total        3      0.03      32.86          0          0          6           0
    Misses in library cache during parse: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS
    Rows     Row Source Operation
          0  MERGE JOIN  (cr=0 pr=0 pw=0 time=60 us)
          0   SORT JOIN (cr=0 pr=0 pw=0 time=58 us)
          0    MERGE JOIN  (cr=0 pr=0 pw=0 time=42 us)
          1     SORT JOIN (cr=0 pr=0 pw=0 time=2443 us)
       1105      FIXED TABLE FULL X$KSUSE (cr=0 pr=0 pw=0 time=1204 us)
          0     SORT JOIN (cr=0 pr=0 pw=0 time=41 us)
       1001      FIXED TABLE FULL X$KTCXB (cr=0 pr=0 pw=0 time=16132 us)
          0   SORT JOIN (cr=0 pr=0 pw=0 time=0 us)
          0    FIXED TABLE FULL X$KTADM (cr=0 pr=0 pw=0 time=0 us)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      buffer busy waits                              34        0.97         32.83
      SQL*Net break/reset to client                   1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.03      32.86          0          0          6           0
    total        3      0.03      32.86          0          0          6           0
    Misses in library cache during parse: 1
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      SQL*Net message from client                     1       19.00         19.00
      buffer busy waits                              34        0.97         32.83
      SQL*Net break/reset to client                   1        0.00          0.00
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        1  user  SQL statements in session.
        0  internal SQL statements in session.
        1  SQL statements in session.
    Trace file: 502_ora_28260.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           0  session in tracefile.
           1  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           1  SQL statements in trace file.
           1  unique SQL statements in trace file.
          64  lines in trace file.
          32  elapsed seconds in trace file. There is nothing fishy in alert logs... Please guide
    Thanks

    There it is TOP
    $ RUMPSHAKER>top
    load averages:  6.63,  7.45,  7.88;                    up 33+12:02:33           
    3631 processes: 3616 sleeping, 5 zombie, 1 stopped, 9 on cpu
    CPU states: 58.6% idle, 18.2% user, 23.2% kernel,  0.0% iowait,  0.0% swap
    Memory: 192G phys mem, 92G free mem, 96G swap, 96G free swap
       PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
    13752 ora0005    1  19    0 4243M 4219M sleep    5:21 62.78% oracle
    17758 ora0005    1  25    0 1174M 1156M cpu      1:05 37.12% oracle
    17923 root       1  57    0   18M   14M sleep  689:07 13.59% ecap_monitor
    20777 root      12  58    0   14M   13M sleep  864:33 11.55% OracleAgent
    18884 ora0004    1   1    0  830M  813M sleep    0:01  9.54% oracle
    12070 ora0004   61  58    0  320M  315M sleep   28.5H  8.29% emagent
    20347 root      16  59    0   33M   25M sleep   26.0H  6.34% caiUxsA2
    17949 ist0005    1  53    0 7984K 4984K cpu      0:00  3.93% top
         1 root       1  59    0 2912K 1288K sleep   32.2H  3.75% init
    15035 ora0001    1  46    0   32M   22M sleep  166:43  2.98% tnslsnr
      5748 ora0004   11  54    0  516M  496M sleep  389:37  2.78% oracle
    20567 ora0004    1  55    0   27M   22M sleep    0:00  2.69% sqlplus
      6730 ora0001    1  33    0  632M  616M sleep    0:06  2.67% oracle
    20557 ora0004    1  56    0   27M   23M sleep    0:00  2.53% sqlplus
      5355 ora0005    1  59    0 1154M 1137M sleep    0:04  2.46% oracleand VMSTAT 2 5
    $ RUMPSHAKER> vmstat 2 5
    kthr      memory            page            disk          faults      cpu
    r b w   swap  free  re  mf pi po fr de sr s0 s1 s2 sd   in   sy   cs us sy id
    6 8 0 143125576 74272080 4628 24012 488 150 149 0 0 4 4 -2 0 25037 192698 65249 38 26 36
    1 3 0 162803992 95246464 1989 6989 0 4 4 0 0 6 6 0  0 9170 57822 26434 8 13 79
    1 7 0 162801352 95240296 3043 15633 4 9737 9682 0 0 0 0 0 0 11277 73516 38200 16 16 68
    3 10 0 162801560 95227920 3326 12729 16 16862 16774 0 0 1 1 0 0 11377 86054 44758 16 17 68
    1 10 0 162784520 95186488 9638 48359 24 11682 11626 0 0 13 13 0 0 13484 149366 44205 23 29 47

  • How to reduce functions with simple select query?

    I have a function to identify the root parent of a particular id. I use this in function in select query,which invokes function for every row in table.I need to merge the function inside the query itself.Please suggest  me.
    Function
    CREATE OR REPLACE FUNCTION fnroot(v_id int ) return int as
    v_left int;
    v_right int;
    v-result int;
    begin
    select left,right into v_left,v_right from sam where id=v_id;
    select id into v_result from sam
    where id in (select id from mst m where m.depth=2 )
    and left < v_left and right > v_right;
    return v_result;
    end
    query:
    select fnroot(s.id) from master s;

    Hi,
    Ramin's idea is very good. You must use joins in function as below
    CREATE OR REPLACE FUNCTION fnroot(v_id int ) return int as
        v_result int;
    Begin
    select  s.id into v_result
      from sam s on s.id = v_id
               left join sam s2 on (s2.id in (select id from mst m where m.depth = 2) and s2.left < s.left and s2.right > s.right)
    return v_result;
    End;
    Regards
    Mahir M. Quluzade

  • Generate script for filling table

    Hi all,
    I've got table at test Oracle server table1 with columns ID, BTYPE, MYDESCRIPTION. Rows of this table have been inserted manually. Now my need is to write script for creating table (structure + data). I think about writing something like
    CREATE TABLE table 1
    AS
    SELECT 1 AS ID, 'TYPE1' AS BTYPE, 'SOME TEXT' AS MYDESCRIPTION
    UNION ALL
    SELECT 2 AS ID, 'TYPE2' AS BTYPE, 'SOME TEXT 2' AS MYDESCRIPTION
    But rows are too many to type... Could you please suggest some way of generating script for creating table at working server using existing table at test server? The problem is I don't have an access to working server.
    Thanks ahead.

    Use the view user_tab_cols
    say
    declare
    cursor c1 is
    select 'e_'||column_name ||' '||data_type||' ('||data_length||') ' col
      from user_tab_cols
      where table_name = 'DEPARTMENTS'
    union
    select 'd_'||column_name ||' '||data_type||' ('||data_length||') ' col
      from user_tab_cols
      where table_name = 'EMPLOYEES';
    v1 varchar2(500);
    begin
    v1 := 'create table new_tabl (';
    for i in c1 loop
    v1 := v1||i.col||',';
    end loop;
    v1 := substr(v1,1,length(v1)-1);
    dbms_output.put_line(v1||')');
    end;
    /i am using employees and departments table of hr schema.
    now as both the tables have some column column so i have used e for employees and d for departments
    just do one thing remove the length for date data type in o/p i dont know why it is not working.
    this will give you structure for data use any sql stmt
    Edited by: 810345 on Jun 9, 2011 9:58 PM

  • Unable to generate statistics for the table

    I have got a staging table of more than 600 columns which has got range portioning. Size of the table is 4GB. The average size of the row is around 3 MB. I have created a Functional index on one of the column ABC VARCHAR2(50) and it has only number values. Now when I try generating statistics for this table through ANALYZE or DBMS_STAT, it gives Invalid Number error but when I drop this index and try analyzing, it works.
    Executed TO_NUMBER(ABC) query on the table and it works fine.
    I have got Functional Indexes on other tables also but I don't get such problem with those tables. I tried dropping the index and re-creating it but it didn't work out.
    I was suspecting DATA BLOCK CORRUPTION so checked ALERT LOG and TRACE FILES but found nothing.
    So what is this magic called?

    I am using TO_NUMBER on the column.
    I have checked the MetaLink for the same problem but could not find anything on that. I still suspect datafile error which I am unable to get in ALERT LOG or TRACE FILES. So I am going to try it this way:
    1) Create new Tablespace with New Datafile
    2) Transfer the table from existing Tablespace to new Tablespace
    3) Create the functional index in the same new Tablespace
    4) Try generating the statistics.
    5) If it works then create seprate Tablespace for data and Index.
    Hope it works !!
    Thanks for the reply guys.

  • Is table maintenance generator only for custom table?

    hi ,
    i have doubt is table maintenance generator only for custom table?

    hi swamya,
    Table Maintanance Generator is used to create/change/delete table entries in a particular table.
    In the production system, end-users will not be having access to transaction codes like SE11 and SE16. Developers will not be having access to many transaction codes including the above two.To view the contents of the database table, we will use SE16n in Production system. All these authorizations will be maintained by BASIS team, by creating access profiles.So in order to edit or create the contents of a database table, we should go for table maintenance generator. In real time, authorizations will be maintained in production system.
    The second reason is, we can edit or create multiple entries at a time, using tablemaintenance generator.
    Apart from that we have options like 'Enter conditions' in table maintenance screen SM30.
    hope this helps in clearing ur doubt.
    Regards
    Saurabh

  • Select query in not working for Count(*)

    Hi,
    Our batch team running one query that is selecting one table TSFHEAD and this query is hanging. Below are diffrent shenario in which the select query is running on this table.
    select * from tsfhead where create_id = 'BATCH' and create_date = '26-OCT-12';
    --not returning any rows and hanging
    select * from tsfhead where create_id = 'BATCH' ---returning rows
    select * from tsfhead where create_date = '26-OCT-12'; --- returning rows
    select count(*) from tsfhead ----not returning rows and hanging
    This table TSFHEAD has 59000 rows.
    SQL> explain plan for select * from tsfhead where create_id = 'BATCH' and create_date = '26-OCT-12';
    Explained.
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 415503093
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 67 | 215 (1)| 00:00:03 |
    |* 1 | TABLE ACCESS FULL| TSFHEAD | 1 | 67 | 215 (1)| 00:00:03 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    1 - filter("CREATE_ID"='BATCH' AND "CREATE_DATE"='26-OCT-12')
    I don't know why this query behaving in this manner.Please help.

    RanVijai_dba wrote:
    Thanks for your reply. But +"select count(*) from tsfhead"+ is hanging and +"select * from tsfhead where create_date = '26-OCT-12' "+ is showing records.It might be showing records, but not necessarily the correct records.
    As sb points out, you are treating dates as strings rather than the DATE datatype. That means you could be querying the wrong data, and your query is also not safe in different environments. It could also effect the query execution plan. Also, as pointed out, you should be ideally using 4 digit years. There were many headaches caused by the use of 2 digit years that most companies corrected as part of the millenium bug fixes prior to the year 2000... well over a decade ago, and most good designs now ensure that 4 digit years are used as standard.
    So your query would be better written as:
    select * from tsfhead where create_date = TO_DATE('26-OCT-2012','DD-MON-YYYY')When you say:
    select count(*) from tsfhead... is hanging, you say the table has around 59000 rows in it, and in reality that's a small amount of records, so a count(*) shouldn't take long at all, even doing a full table scan.
    Post the explain plan for that simple count(*) query for us. (and ensure you use {noformat}{noformat} tags to keep the formatting on the forum, as described in {message:id=9360002})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Simple Select Query Taking 5-10s

    We have a web server on the same lan as the DB server.
    A simple select * from tablename (~100 entries) is taking
    anywhere from 30ms to 10 seconds lan. ASP code on the web server
    provides instant (30ms) queries. Ping is never <1ms. If I point
    to a remote DB server, the same query is never more than 300ms
    (which is great for over the internet).
    I enabled logging in CFAdmin -> Datasources and shortly
    after my select * from tablename I see this:
    spy(2009/02/28 16:39:00.539)>>
    Connection[2].setReadOnly(boolean readOnly)
    spy(2009/02/28 16:39:00.539)>> readOnly = false
    spy(2009/02/28 16:39:00.539)>> OK
    spy(2009/02/28 16:39:05.726)>> OK (true)
    We need to get this up and running ASAP. Please help!!

    > I'm connecting to SQL Server 2000 on a Win2k3 box.
    > The default CF8 Installation.
    > Every table this happens for.
    OK. I think CF8 runs the most recent JDBC drivers too. It
    might pay to
    check that though.
    > Select * is needed, because we have existing sites we
    are migrating a lot of
    > which use select *.
    Sure. But just for the purposes of experimentation, change
    your test code
    to specify columns to see if it makes any difference.
    It might pay to get hold of FusionReactor to check what CF is
    doing with
    the queries, under the hood.
    Adam

  • Select query in driver program for sapscript

    Hi All,
    I want to select buzei, zuonr,sgtxt,meins from bseg ,temp (a temporary variable of type p deciamls 2), tmp (another temporary variable) and dmbtr from HBSEG (a structure of type bseg) . under the cond
    koart ne 's' or
    xauto ne 'x' or
    buzid ne 't'.
    I have to write this select query usinf a WORKAREA . After this select query i give WRITE_FORM as i call there vairables in script.Its very urgent.
    thanks much

    Hi,
    You can use inner join. Consider this simple example.
    data : a type zvijirank occurs 10 with header line,
              b type zvijirank1 occurs 10 with header line.
    data : name like zvijirank-name,
           total like zvijirank1-total,
           reg_no like zvijirank.
    *       regno type i.
    data : begin of wa,
           name type zvijirank-name,
           total type zvijirank1-total,
           branch type zvijirank1-branch,
           reg_no type zvijirank-reg_no,
    *       FNAME TYPE ZVIJIRANK2-F_NAME,
    *       MNAME TYPE ZVIJIRANK2-M_NAME,
    *       CITY TYPE ZVIJIRANK2-CITY,
    *       TEL_NO TYPE ZVIJIRANK2-TEL_NO,
           end of wa.
    data : it like standard table of wa with header line,
             it1 like standard table of wa with header line.
    call selection-screen 9010.
    select a~name b~total b~branch a~reg_no into table it from zvijirank as a inner join zvijirank1 as b on a~reg_no = b~reg_no .
    loop at it.
    if it-reg_no eq regno.
    write : 'NAME   :', it-name,
            'REG_NO :', it-reg_no,
             'TOTAL :', it-total.
    ENDIF.
    endloop.
    Thanks,
    Reward If Helpful.

  • Doubt on simple select query

    Hello experts,
    please check this code.
    CHECK NOT T_DELIVERIES[] IS INITIAL.
      SELECT MANDT VBELV POSNV VBELN POSNN INTO TABLE T_VBFA FROM VBFA
        FOR ALL ENTRIES IN T_DELIVERIES
        WHERE VBELN EQ T_DELIVERIES-VBELN
          AND POSNN EQ T_DELIVERIES-POSNR
    *{   INSERT         DE1K903920                                      2
          AND VBELV EQ T_OUTPUT-VBELV
          AND POSNV EQ T_OUTPUT-POSNV
    *}   INSERT
    AND ( VBTYP_V EQ 'C' OR VBTYP_V  'H' ).                 "AO03
      SORT T_VBFA BY VBELN VBELV.
    Check the inserted lines and let me know whether it is correct or not.

    Hi
    it is not correct the itab T_OUTPUT-VBELV is not mentioned in the same
    look for the same fields in  T_DELIVERIES
    CHECK NOT T_DELIVERIES[] IS INITIAL.
    SELECT MANDT VBELV POSNV VBELN POSNN INTO TABLE T_VBFA FROM VBFA
    FOR ALL ENTRIES IN T_DELIVERIES
    WHERE VBELN EQ T_DELIVERIES-VBELN
    AND POSNN EQ T_DELIVERIES-POSNR
    *{ INSERT DE1K903920 2
    AND VBELV EQ  T_DELIVERIES-VBELV
    AND POSNV EQ  T_DELIVERIES-POSNV
    *} INSERT
    AND ( VBTYP_V EQ 'C' OR VBTYP_V 'H' ). "AO03
    SORT T_VBFA BY VBELN VBELV.
    regards
    Shiva

  • Simple select query is taking a lot of time

    hi gems...
    my table has 7267563 rows...and i am doing a simple select * from table;
    but it is taking a lot of time nearly 25minutes but not completed...
    when i did select count(1) from table then it gave the result instantly also select * from table where rownum < 10 is also fine...even when i am selecting all the records using rownum i.e. select * from table where rownum < 7267563 is also giving result instantly...
    but the entire table is not getting result i.e. select * from table...also there is no lock in the table(though i know that select is nothing to do with lock)..
    what may be the issue..please suggest...thanks in advance...
    Edited by: user12780416 on Dec 12, 2011 11:08 PM

    Hi;
    Please see below thread
    query takes too long ...
    help in solving long run query
    HOW TO: Post a SQL statement tuning request - template posting
    Hope it helps
    Regard
    Helios

  • How to alter Select Query while altering selectionscreen for same output?

    Hi,
    i have to change the selection screen fields with some new fields , but i dont know how to change the selection query accordingly, because i need the same output with the same fields but with a different set of fields in the selection screen.
    The original code is
    TYPES: BEGIN OF ty_output,
           mblnr TYPE mseg-mblnr,
           mjahr TYPE mseg-mjahr,
           zeile TYPE mseg-zeile,
           bwart TYPE mseg-bwart,
           werks TYPE mseg-werks,
           lgort TYPE mseg-lgort,
           ebeln TYPE mseg-ebeln,
           ebelp TYPE mseg-ebelp,
           lfbnr TYPE mseg-lfbnr,
           lfpos TYPE mseg-lfpos,
           sjahr TYPE mseg-sjahr,
           dmbtr TYPE mseg-dmbtr,
           menge TYPE mseg-menge,
           matnr TYPE mseg-matnr,
           mtart TYPE mara-mtart,
           matkl TYPE mara-matkl,
           bismt TYPE mara-bismt,
           meins TYPE mara-meins,
           bedat TYPE ekko-bedat,
           waers TYPE ekko-waers,
           wkurs TYPE ekko-wkurs,
           verkf TYPE ekko-verkf,
          EFFWR TYPE EKPO-EFFWR,
           tax TYPE ekpo-effwr,
           maktx TYPE makt-maktx,
           budat TYPE mkpf-budat,
           usnam TYPE mkpf-usnam,
           m_menge TYPE ekpo-menge,
           ablad TYPE mseg-ablad,
           wempf TYPE mseg-wempf,
           END OF ty_output.
    TYPES: BEGIN OF ty_mseg_103,
           mblnr TYPE mseg-mblnr,
           mjahr TYPE mseg-mjahr,
           zeile TYPE mseg-zeile,
           bwart TYPE mseg-bwart,
           werks TYPE mseg-werks,
           lgort TYPE mseg-lgort,
           ebeln TYPE mseg-ebeln,
           ebelp TYPE mseg-ebelp,
           lfbnr TYPE mseg-lfbnr,
           lfpos TYPE mseg-lfpos,
           sjahr TYPE mseg-sjahr,
           dmbtr TYPE mseg-dmbtr,
           menge TYPE mseg-menge,
           matnr TYPE mseg-matnr,
           mtart TYPE mara-mtart,
           matkl TYPE mara-matkl,
           bismt TYPE mara-bismt,
           meins TYPE mara-meins,
           bedat TYPE ekko-bedat,
           waers TYPE ekko-waers,
           wkurs TYPE ekko-wkurs,
           verkf TYPE ekko-verkf,
          EFFWR TYPE EKPO-EFFWR,
           tax TYPE ekpo-effwr,
           maktx TYPE makt-maktx,
           budat TYPE mkpf-budat,
           usnam TYPE mkpf-usnam,
           m_menge TYPE ekpo-menge,
           ablad TYPE mseg-ablad,
           wempf TYPE mseg-wempf,
           END OF ty_mseg_103.
    TYPES: BEGIN OF ty_mseg_105,
           mblnr TYPE mseg-mblnr,
           mjahr TYPE mseg-mjahr,
           zeile TYPE mseg-zeile,
           bwart TYPE mseg-bwart,
           werks TYPE mseg-werks,
           lgort TYPE mseg-lgort,
           ebeln TYPE mseg-ebeln,
           ebelp TYPE mseg-ebelp,
           lfbnr TYPE mseg-lfbnr,
           lfpos TYPE mseg-lfpos,
           sjahr TYPE mseg-sjahr,
           dmbtr TYPE mseg-dmbtr,
           menge TYPE mseg-menge,
           matnr TYPE mseg-matnr,
           mtart TYPE mara-mtart,
           matkl TYPE mara-matkl,
           bismt TYPE mara-bismt,
           meins TYPE mara-meins,
           bedat TYPE ekko-bedat,
           waers TYPE ekko-waers,
           wkurs TYPE ekko-wkurs,
           verkf TYPE ekko-verkf,
           effwr TYPE ekpo-effwr,
           tax TYPE ekpo-effwr,
           maktx TYPE makt-maktx,
           budat TYPE mkpf-budat,
           ablad TYPE mseg-ablad,
           wempf TYPE mseg-wempf,
           END OF ty_mseg_105.
    DATA: Begin with W_                                                 *
    DATA : it_fcat TYPE slis_t_fieldcat_alv. " alv field catalog
    DATA  : listhead TYPE slis_t_listheader WITH HEADER LINE.
    DATA: event TYPE slis_t_event WITH HEADER LINE.
    INTERNAL TABLES: Begin with IT_                                     *
    DATA : it_output TYPE STANDARD TABLE OF ty_output WITH KEY mblnr mjahr,
           it_mseg_103 TYPE STANDARD TABLE OF ty_mseg_103,
           it_mseg_105 TYPE STANDARD TABLE OF ty_mseg_103,
           it_mseg_106 TYPE STANDARD TABLE OF ty_mseg_103,          " LNTDEV1 ADDED
           it_mara TYPE STANDARD TABLE OF ty_mara,
           it_ekko TYPE STANDARD TABLE OF ty_ekko,
           it_ekpo TYPE STANDARD TABLE OF ty_ekpo,
           it_makt TYPE STANDARD TABLE OF ty_makt,
           it_mkpf TYPE STANDARD TABLE OF ty_mkpf WITH KEY mblnr.
    WORKAREAS: Begin with WA_                                           *
    DATA : wa_fcat LIKE LINE OF it_fcat.
    DATA : wa_output LIKE LINE OF it_output,
           wa_mara LIKE LINE OF it_mara,
           wa_ekko LIKE LINE OF it_ekko,
           wa_ekpo LIKE LINE OF it_ekpo,
           wa_makt LIKE LINE OF it_makt,
           wa_mkpf LIKE LINE OF it_mkpf,
           wa_mseg_103 LIKE LINE OF it_mseg_103,
           wa_mseg_105 LIKE LINE OF it_mseg_105,
           wa_mseg_106 LIKE LINE OF it_mseg_106.                        " LNTDEV1 ADDED
    DATA : w_menge LIKE ekpo-menge.
    FIELD-SYMBOLS: Begin with FS_                                       *
    PARAMETERS: Begin with PR_                                          *
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    PARAMETERS  : pr_werks LIKE mseg-werks OBLIGATORY.
    SELECT-OPTIONS : so_budat FOR mkpf-budat.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECT-OPTIONS: Begin with SO_                                      *
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
    SELECT-OPTIONS : so_mtart FOR mara-mtart.
    SELECT-OPTIONS : so_matkl FOR mara-matkl.
    SELECT-OPTIONS : so_matnr FOR mara-matnr.
    SELECT-OPTIONS : so_bismt FOR mara-bismt.
    SELECT-OPTIONS : so_ebeln FOR mseg-ebeln.
    SELECT-OPTIONS : so_verkf FOR ekko-verkf.
    SELECT-OPTIONS : so_bedat FOR ekko-bedat.
    SELECT-OPTIONS : so_mblnr FOR mseg-mblnr.
    SELECTION-SCREEN END OF BLOCK b2.
    *AT SELECTION-SCREEN.
    *SO_BUDAT-HIGH = SO_BUDAT-HIGH + 1.
    Query for getting all the Document Segment: Material data from MSEG *
    Table which having Movement Types 103 and put into it_mseg table,   *
    Filtering by reference document and material document number        *
    Filtering by selection criteria (Material Docu No, Purchase order   *
    and Plant)                                                          *
    START-OF-SELECTION.
      SELECT pmblnr smblnr p~mjahr zeile bwart lfbnr werks lgort ebeln
             ebelp lfpos sjahr dmbtr usnam menge sbudat pmatnr q~mtart
             pablad pwempf
             FROM mseg AS p INNER JOIN mara AS q
               ON pmatnr = qmatnr
               JOIN mkpf AS s ON smblnr EQ pmblnr
               INTO CORRESPONDING FIELDS OF
             TABLE it_mseg_103
             WHERE bwart EQ 103
             AND p~matnr IN so_matnr
             AND werks EQ pr_werks
             AND ebeln IN so_ebeln
             AND q~mtart IN so_mtart
             AND p~mblnr IN so_mblnr
             AND s~budat IN so_budat.
      IF sy-subrc = 0.
      ENDIF.
      SELECT pmblnr smblnr p~mjahr zeile bwart lfbnr werks lgort ebeln
             ebelp lfpos sjahr dmbtr usnam menge sbudat pmatnr q~mtart
             pablad pwempf
             FROM mseg AS p INNER JOIN mara AS q
               ON pmatnr = qmatnr
               JOIN mkpf AS s ON smblnr EQ pmblnr
               INTO CORRESPONDING FIELDS OF
             TABLE it_mseg_105
          WHERE bwart EQ 105 OR bwart EQ 104 OR bwart EQ 124 OR bwart EQ 124
             AND p~matnr IN so_matnr
             AND werks EQ pr_werks
             AND ebeln IN so_ebeln
             AND q~mtart IN so_mtart
             AND p~mblnr IN so_mblnr
             AND s~budat IN so_budat.
      IF sy-subrc = 0.
      ENDIF.
      LOOP AT IT_MSEG_103 INTO WA_MSEG_103.
        READ TABLE IT_MSEG_105 INTO WA_MSEG_105 WITH KEY LFBNR =
                                               WA_MSEG_103-MBLNR.
          IF SY-SUBRC <> 0.
            APPEND WA_MSEG_103 TO IT_OUTPUT.
          ENDIF.
       ENDLOOP.
      SELECT pmblnr smblnr p~mjahr zeile bwart lfbnr werks lgort ebeln  
             ebelp lfpos sjahr dmbtr usnam menge sbudat pmatnr q~mtart
             pablad pwempf
             FROM mseg AS p INNER JOIN mara AS q
               ON pmatnr = qmatnr
               JOIN mkpf AS s ON smblnr EQ pmblnr
               INTO CORRESPONDING FIELDS OF
             TABLE it_mseg_106
             WHERE bwart EQ 106
             AND p~matnr IN so_matnr
             AND werks EQ pr_werks
             AND ebeln IN so_ebeln
             AND q~mtart IN so_mtart
             AND p~mblnr IN so_mblnr
             AND s~budat IN so_budat.
      LOOP AT it_mseg_103 INTO wa_mseg_103.
        READ TABLE it_mseg_106 INTO wa_mseg_106 WITH KEY
                                           lfbnr = wa_mseg_103-mblnr.
        IF sy-subrc = 0.
          APPEND wa_mseg_106 TO it_output.
          clear wa_mseg_106.
        ENDIF.
      ENDLOOP.                        
    Present selection criteria is
    1. Plant
    2. Posting Date
    3. Material Type
    4. Material Group
    5. Material No.
    6. Old Material No.
    7. PO Order No.
    8. Old PO No.
    9. PO Date
    10. Material Document No.
    New selection criteria is
    1. PO no.
    2. PO date
    3. PO value (Ex: >=10000 <=50000)
    4. Purch org
    5. Doc type
    6. Vendor
    7. Material
    8. Account assignment category
    9. Order

    Hi,
    i have to change the selection screen fields with some new fields , but i dont know how to change the selection query accordingly, because i need the same output with the same fields but with a different set of fields in the selection screen.
    The original code is
    TYPES: BEGIN OF ty_output, mblnr TYPE mseg-mblnr, mjahr TYPE mseg-mjahr, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, werks TYPE mseg-werks, lgort TYPE mseg-lgort, ebeln TYPE mseg-ebeln, ebelp TYPE mseg-ebelp, lfbnr TYPE mseg-lfbnr, lfpos TYPE mseg-lfpos, sjahr TYPE mseg-sjahr, dmbtr TYPE mseg-dmbtr, menge TYPE mseg-menge, matnr TYPE mseg-matnr, mtart TYPE mara-mtart, matkl TYPE mara-matkl, bismt TYPE mara-bismt, meins TYPE mara-meins, bedat TYPE ekko-bedat, waers TYPE ekko-waers, wkurs TYPE ekko-wkurs, verkf TYPE ekko-verkf, * EFFWR TYPE EKPO-EFFWR, tax TYPE ekpo-effwr, maktx TYPE makt-maktx, budat TYPE mkpf-budat, usnam TYPE mkpf-usnam, m_menge TYPE ekpo-menge, ablad TYPE mseg-ablad, wempf TYPE mseg-wempf, END OF ty_output. TYPES: BEGIN OF ty_mseg_103, mblnr TYPE mseg-mblnr, mjahr TYPE mseg-mjahr, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, werks TYPE mseg-werks, lgort TYPE mseg-lgort, ebeln TYPE mseg-ebeln, ebelp TYPE mseg-ebelp, lfbnr TYPE mseg-lfbnr, lfpos TYPE mseg-lfpos, sjahr TYPE mseg-sjahr, dmbtr TYPE mseg-dmbtr, menge TYPE mseg-menge, matnr TYPE mseg-matnr, mtart TYPE mara-mtart, matkl TYPE mara-matkl, bismt TYPE mara-bismt, meins TYPE mara-meins, bedat TYPE ekko-bedat, waers TYPE ekko-waers, wkurs TYPE ekko-wkurs, verkf TYPE ekko-verkf, * EFFWR TYPE EKPO-EFFWR, tax TYPE ekpo-effwr, maktx TYPE makt-maktx, budat TYPE mkpf-budat, usnam TYPE mkpf-usnam, m_menge TYPE ekpo-menge, ablad TYPE mseg-ablad, wempf TYPE mseg-wempf, END OF ty_mseg_103. TYPES: BEGIN OF ty_mseg_105, mblnr TYPE mseg-mblnr, mjahr TYPE mseg-mjahr, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, werks TYPE mseg-werks, lgort TYPE mseg-lgort, ebeln TYPE mseg-ebeln, ebelp TYPE mseg-ebelp, lfbnr TYPE mseg-lfbnr, lfpos TYPE mseg-lfpos, sjahr TYPE mseg-sjahr, dmbtr TYPE mseg-dmbtr, menge TYPE mseg-menge, matnr TYPE mseg-matnr, mtart TYPE mara-mtart, matkl TYPE mara-matkl, bismt TYPE mara-bismt, meins TYPE mara-meins, bedat TYPE ekko-bedat, waers TYPE ekko-waers, wkurs TYPE ekko-wkurs, verkf TYPE ekko-verkf, effwr TYPE ekpo-effwr, tax TYPE ekpo-effwr, maktx TYPE makt-maktx, budat TYPE mkpf-budat, ablad TYPE mseg-ablad, wempf TYPE mseg-wempf, END OF ty_mseg_105. *----------------------------------------------------------------------* * DATA: Begin with W_ * *----------------------------------------------------------------------* DATA : it_fcat TYPE slis_t_fieldcat_alv. " alv field catalog DATA : listhead TYPE slis_t_listheader WITH HEADER LINE. DATA: event TYPE slis_t_event WITH HEADER LINE. *----------------------------------------------------------------------* * INTERNAL TABLES: Begin with IT_ * *----------------------------------------------------------------------* DATA : it_output TYPE STANDARD TABLE OF ty_output WITH KEY mblnr mjahr, it_mseg_103 TYPE STANDARD TABLE OF ty_mseg_103, it_mseg_105 TYPE STANDARD TABLE OF ty_mseg_103, it_mseg_106 TYPE STANDARD TABLE OF ty_mseg_103, " LNTDEV1 ADDED it_mara TYPE STANDARD TABLE OF ty_mara, it_ekko TYPE STANDARD TABLE OF ty_ekko, it_ekpo TYPE STANDARD TABLE OF ty_ekpo, it_makt TYPE STANDARD TABLE OF ty_makt, it_mkpf TYPE STANDARD TABLE OF ty_mkpf WITH KEY mblnr. *----------------------------------------------------------------------* * WORKAREAS: Begin with WA_ * *----------------------------------------------------------------------* DATA : wa_fcat LIKE LINE OF it_fcat. DATA : wa_output LIKE LINE OF it_output, wa_mara LIKE LINE OF it_mara, wa_ekko LIKE LINE OF it_ekko, wa_ekpo LIKE LINE OF it_ekpo, wa_makt LIKE LINE OF it_makt, wa_mkpf LIKE LINE OF it_mkpf, wa_mseg_103 LIKE LINE OF it_mseg_103, wa_mseg_105 LIKE LINE OF it_mseg_105, wa_mseg_106 LIKE LINE OF it_mseg_106. " LNTDEV1 ADDED DATA : w_menge LIKE ekpo-menge. *----------------------------------------------------------------------* * FIELD-SYMBOLS: Begin with FS_ * *----------------------------------------------------------------------* *----------------------------------------------------------------------* * PARAMETERS: Begin with PR_ * *----------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME. PARAMETERS : pr_werks LIKE mseg-werks OBLIGATORY. SELECT-OPTIONS : so_budat FOR mkpf-budat. SELECTION-SCREEN END OF BLOCK b1. *----------------------------------------------------------------------* * SELECT-OPTIONS: Begin with SO_ * *----------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME. SELECT-OPTIONS : so_mtart FOR mara-mtart. SELECT-OPTIONS : so_matkl FOR mara-matkl. SELECT-OPTIONS : so_matnr FOR mara-matnr. SELECT-OPTIONS : so_bismt FOR mara-bismt. SELECT-OPTIONS : so_ebeln FOR mseg-ebeln. SELECT-OPTIONS : so_verkf FOR ekko-verkf. SELECT-OPTIONS : so_bedat FOR ekko-bedat. SELECT-OPTIONS : so_mblnr FOR mseg-mblnr. SELECTION-SCREEN END OF BLOCK b2. *AT SELECTION-SCREEN. * *SO_BUDAT-HIGH = SO_BUDAT-HIGH + 1. *---------------------------------------------------------------------* * Query for getting all the Document Segment: Material data from MSEG * * Table which having Movement Types 103 and put into it_mseg table, * * Filtering by reference document and material document number * * Filtering by selection criteria (Material Docu No, Purchase order * * and Plant) * *---------------------------------------------------------------------* *---------------------------------------------------------------------* START-OF-SELECTION. *---------------------------------------------------------------------* SELECT p~mblnr s~mblnr p~mjahr zeile bwart lfbnr werks lgort ebeln ebelp lfpos sjahr dmbtr usnam menge s~budat p~matnr q~mtart p~ablad p~wempf FROM mseg AS p INNER JOIN mara AS q ON p~matnr = q~matnr JOIN mkpf AS s ON s~mblnr EQ p~mblnr INTO CORRESPONDING FIELDS OF TABLE it_mseg_103 WHERE bwart EQ 103 AND p~matnr IN so_matnr AND werks EQ pr_werks AND ebeln IN so_ebeln AND q~mtart IN so_mtart AND p~mblnr IN so_mblnr AND s~budat IN so_budat. ** IF sy-subrc = 0. ENDIF. SELECT p~mblnr s~mblnr p~mjahr zeile bwart lfbnr werks lgort ebeln ebelp lfpos sjahr dmbtr usnam menge s~budat p~matnr q~mtart p~ablad p~wempf FROM mseg AS p INNER JOIN mara AS q ON p~matnr = q~matnr JOIN mkpf AS s ON s~mblnr EQ p~mblnr INTO CORRESPONDING FIELDS OF TABLE it_mseg_105 WHERE bwart EQ 105 OR bwart EQ 104 OR bwart EQ 124 OR bwart EQ 124 AND p~matnr IN so_matnr AND werks EQ pr_werks AND ebeln IN so_ebeln AND q~mtart IN so_mtart AND p~mblnr IN so_mblnr AND s~budat IN so_budat. IF sy-subrc = 0. ENDIF. LOOP AT IT_MSEG_103 INTO WA_MSEG_103. READ TABLE IT_MSEG_105 INTO WA_MSEG_105 WITH KEY LFBNR = WA_MSEG_103-MBLNR. IF SY-SUBRC 0. APPEND WA_MSEG_103 TO IT_OUTPUT. ENDIF. ENDLOOP. SELECT p~mblnr s~mblnr p~mjahr zeile bwart lfbnr werks lgort ebeln ebelp lfpos sjahr dmbtr usnam menge s~budat p~matnr q~mtart p~ablad p~wempf FROM mseg AS p INNER JOIN mara AS q ON p~matnr = q~matnr JOIN mkpf AS s ON s~mblnr EQ p~mblnr INTO CORRESPONDING FIELDS OF TABLE it_mseg_106 WHERE bwart EQ 106 AND p~matnr IN so_matnr AND werks EQ pr_werks AND ebeln IN so_ebeln AND q~mtart IN so_mtart AND p~mblnr IN so_mblnr AND s~budat IN so_budat. LOOP AT it_mseg_103 INTO wa_mseg_103. READ TABLE it_mseg_106 INTO wa_mseg_106 WITH KEY lfbnr = wa_mseg_103-mblnr. IF sy-subrc = 0. APPEND wa_mseg_106 TO it_output. clear wa_mseg_106. ENDIF. ENDLOOP.
    Present selection criteria is 1. Plant 2. Posting Date 3. Material Type 4. Material Group 5. Material No. 6. Old Material No. 7. PO Order No. 8. Old PO No. 9. PO Date 10. Material Document No. New selection criteria is 1. PO no. 2. PO date 3. PO value (Ex: >=10000 <=50000) 4. Purch org 5. Doc type 6. Vendor 7. Material 8. Account assignment category 9. Order
    I hope the code is readable now.
    Thanks in advance.

  • Problem with SImple Select Query

    Hi
    I am trying to write a simple Select SQL to a table and find out whether certain data exist or not. I have done this before but now for some reason this one is not working.
    I started like this
    select single * from ANLH where ANLN1 = rec-Asset
                                                 and BUKRS = Comp_Cd.
    * Error Handler for non-existent empno in the database
      if sy-subrc = 0 or rec-asset = ''.
         rec_failed = 'T'.
         concatenate 'Asset does not exist' rec-asset into asst_err.
      endif.
    when i debugged the code i found out that sy-subrc  is returning 4 all the time. (i have passes some numbers in rec-Asset which i know doesn't exist in that table.
    So i have modified the code to see if its pulling anything.
    like this
    select single ANLN1 into v_Asset from ANLH where ANLN1 = rec-Asset
                                                 and BUKRS = Comp_Cd.
    * Error Handler for non-existent empno in the database
      if sy-subrc = 0 or rec-asset = ''.
         rec_failed = 'T'.
         concatenate 'Asset does not exist' rec-asset into asst_err.
      endif.
    in debug v_asset is always empty (for real number and for the madeup number)
    Please help.
    Thanks
    Edited by: Anwarul Kabir on Apr 3, 2008 9:27 PM
    Edited by: Anwarul Kabir on Apr 3, 2008 9:29 PM
    Edited by: Anwarul Kabir on Apr 3, 2008 9:30 PM

    Thanks for the answer. But i thought i was doing the same. Anyway I replaced my code with yours but result is the same. I also did this
    select single
    ANLN1 into v_Asset
    from ANLH where
    ANLN1 = '20000544'
    and BUKRS = '3000'.
    I did SE11 and entered the table name and i can see that data.
    but on my code i get sy-subrc=4 and v_Asset is blank
    again i tried with this madeup number which i know its not in the table
    select single
    ANLN1 into v_Asset
    from ANLH where
    ANLN1 = '2056555433544'
    and BUKRS = '3000'.
    Get sy-subrc=4 and v_Asset is blank...
    Is there anything special about the Table?

Maybe you are looking for

  • Macbook Pro isn't connecting to the internet unless it's on the guest profile

    I recently purchased a brand new Macbook Pro less than a week ago and I've never been able to connect it to the Internet on my log in. This is my first Mac and honestly I don't believe it was worth the price since I can not use the Internet on it. Th

  • Do I need to install  Mac OS X 10.4.8 Update (Intel) and firmware

    Hiya, I recently bought a new Macbook Pro,it is Mac OS X version 10.4.8, i am just wondering whether I need to install Mac OS X 10.4.8 Update (Intel)? I also tried to install MacBook Pro EFI Firmware Update 1.2, however it says the computer doesn't n

  • Slow-moving items

    Hi, How is it that the standard report 0IC_MC01_Q0001, displays just slow-moving as it doesnt seem to have any condition on issued or valued stock it seems to just display all the values but not the above key figures with zero values. Should we creat

  • Sending a BufferedImage to a printer.

    I have a BufferedImage object that I want to send to a specific color printer. First, I send the BufferedImage to this method, which sets up the printer job. public static void printOutChart(BufferedImage imageToPrint, int intCopies, String name) {  

  • Pb00 and pbxx

    HI, if the condition PB00 copied from inforecord system , should not allow  PBXX to input manually . pls can anybody tell me the configuration needed. thanks laxman