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

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 ?

  • 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.

  • 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...

  • Select query from 2 schema & database

    Hi,
    what privileges should i give to execute select query from 2 schema & database in oracle
    thanks

    Hi,
    not so clear, if you are looking for this
    -- for other schema access
    GRANT SELECT ON <scheman_name>.<table_name> TO <schema_name>;
    or create the synonym
    --for other database access you need to create db link                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Generating an XML schema for a TABLE

    Hi,
    I know I can easily export DATA into an XML file, but Sql Developer can also generate an XML schema for a table LAYOUT. Does anyone know how this is done?
    I did it some time ago and have been unable to do it again.
    Thanks

    Hi Thanks for the response. Yes, what you say is the type of thing I mean. The snippet below was actually created using SqlDeveloper, but I just can't seem to be able to do it again :-(
    <?xml version='1.0' encoding='Cp1252' ?>
    <results>
         <row>
              <Column_Name><![CDATA[AD_UNIT_ID]]></Column_Name>
              <Data_Type><![CDATA[NUMBER(5,0)]]></Data_Type>
              <Nullable><![CDATA[Yes]]></Nullable>
              <Data_Default><![CDATA[]]></Data_Default>
              <COLUMN_ID><![CDATA[1]]></COLUMN_ID>
              <Primary_Key><![CDATA[]]></Primary_Key>
              <COMMENTS><![CDATA[]]></COMMENTS>
         </row>
         <row>
              <Column_Name><![CDATA[AD_UNIT_NAME]]></Column_Name>
              <Data_Type><![CDATA[CHAR(30 CHAR)]]></Data_Type>
              <Nullable><![CDATA[Yes]]></Nullable>
              <Data_Default><![CDATA[]]></Data_Default>
              <COLUMN_ID><![CDATA[2]]></COLUMN_ID>
              <Primary_Key><![CDATA[]]></Primary_Key>
              <COMMENTS><![CDATA[]]></COMMENTS>

  • Script for Compare same table 'TAB1' structures in different schemas

    Hello, i am having three schema and in all schema i have same table for example TAB1 and i want to Compare TAB1 table structures in all three schema but i don't know the script. the different should content at least  DATA_TYPE,DATA_LENGTH,DECODE(DATA_PRECISION,NULL,NULL,DATA_PRECISION||','||DATA_SCALE) columns in query. Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi Thanks..

    If you want a generic script use below function to get the difference.. Run the below script and let me know in case of any issues
    CREATE OR REPLACE TYPE nt_username IS TABLE OF VARCHAR2(50);
    CREATE OR REPLACE TYPE obj_struc IS OBJECT (user_name1     VARCHAR2(30),
                                               user_name2      VARCHAR2(30),
                                               column_name1    VARCHAR2(30),
                                               column_name2    VARCHAR2(30),
                                               data_type1      VARCHAR2(106),
                                               data_type2      VARCHAR2(106),
                                               data_length1    NUMBER(10),
                                               data_length2    NUMBER(10),
                                               data_precision1 VARCHAR2(50),
                                               data_precision2 VARCHAR2(50),
                                               column_id1      NUMBER(10),
                                               column_id2      NUMBER(10)
    CREATE OR REPLACE TYPE nt_struc IS TABLE OF obj_struc;
    CREATE OR REPLACE FUNCTION tabstruc_script (p_tabnm   VARCHAR2,
                                                p_usernm  nt_username
    RETURN nt_struc
    AS
    v_nt_struc nt_struc := nt_struc();
    v_ntusrnm nt_username := p_usernm;
    TYPE rec_stru IS RECORD (column_name    all_tab_columns.column_name%TYPE,
                             data_type      all_tab_columns.data_type%TYPE,
                             data_length    all_tab_columns.data_length%TYPE,
                             data_precision all_tab_columns.data_precision%TYPE,
                             data_scale     all_tab_columns.data_scale%TYPE,
                             column_id      all_tab_columns.column_id%TYPE
    TYPE nt_stru IS TABLE OF rec_stru;
    v_ntstru nt_stru  := nt_stru();
    v_columnname all_tab_columns.column_name%TYPE;
    v_reccnt NUMBER;
    v_cnt NUMBER;
    v_precision1 VARCHAR2(50);
    v_precision2 VARCHAR2(50);                    
    BEGIN
    FOR i IN 1..v_ntusrnm.COUNT
      LOOP
         SELECT COUNT(*) INTO v_reccnt
         FROM all_tables
         WHERE owner = v_ntusrnm(i)
         AND table_name = p_tabnm;
          IF v_reccnt >= 1 THEN
             SELECT column_name,  
                    data_type,    
                    data_length, 
                    data_precision,
                    data_scale,
                    column_id
             BULK COLLECT INTO v_ntstru
             FROM all_tab_columns
             WHERE owner = v_ntusrnm(i)
             AND table_name = p_tabnm;
              FOR j IN i+1..v_ntusrnm.COUNT
                LOOP
                     FOR k IN 1..v_ntstru.COUNT
                       LOOP
                          SELECT COUNT(*) INTO v_cnt
                          FROM all_tab_columns
                          WHERE owner = v_ntusrnm(j)
                          AND table_name = p_tabnm
                          AND column_name = v_ntstru(k).column_name;
                           IF v_cnt >= 1 THEN
                             FOR l IN (SELECT column_name,  
                                              data_type,    
                                              data_length, 
                                              data_precision,
                                              data_scale,
                                              column_id
                                       FROM all_tab_columns
                                       WHERE owner = v_ntusrnm(j)
                                       AND table_name = p_tabnm
                                       AND column_name = v_ntstru(k).column_name)
                                LOOP
                                  IF ((v_ntstru(k).column_id <> l.column_id)
                                      OR (v_ntstru(k).data_type <> l.data_type)
                                      OR (NVL(v_ntstru(k).data_length,0) <> NVL(l.data_length,0))
                                      OR (NVL(v_ntstru(k).data_precision,0) <> NVL(l.data_precision,0))
                                      OR (NVL(v_ntstru(k).data_scale,0) <> NVL(l.data_scale,0))) THEN
                                     v_nt_struc.EXTEND;
                                     SELECT DECODE(v_ntstru(k).data_precision,NULL,NULL,v_ntstru(k).data_precision||','||v_ntstru(k).data_scale),
                                            DECODE(l.data_precision,NULL,NULL,l.data_precision||','||l.data_scale)
                                     INTO v_precision1,
                                          v_precision2
                                     FROM DUAL;
                                     v_nt_struc(v_nt_struc.COUNT) := obj_struc(v_ntusrnm(i),
                                                                               v_ntusrnm(j),
                                                                               v_ntstru(k).column_name,
                                                                               l.column_name,
                                                                               v_ntstru(k).data_type,
                                                                               l.data_type,
                                                                               v_ntstru(k).data_length,
                                                                               l.data_length,
                                                                               v_precision1,
                                                                               v_precision2,
                                                                               v_ntstru(k).column_id,
                                                                               l.column_id);
                                  END IF;
                                END LOOP;
                           END IF;
                       END LOOP;
                      FOR m IN(SELECT column_name,  
                                      data_type,    
                                      data_length, 
                                      data_precision,
                                      data_scale,
                                      column_id
                               FROM all_tab_columns
                               WHERE owner = v_ntusrnm(i)
                               AND table_name = p_tabnm
                               AND column_name NOT IN(SELECT column_name
                                                      FROM all_tab_columns
                                                      WHERE owner = v_ntusrnm(j)
                                                      AND table_name = p_tabnm))
                          LOOP                                         
                            v_nt_struc.EXTEND;
                            SELECT DECODE(m.data_precision,NULL,NULL,m.data_precision||','||m.data_scale)
                            INTO v_precision1
                            FROM DUAL;
                            v_nt_struc(v_nt_struc.COUNT) := obj_struc(v_ntusrnm(i),
                                                                      v_ntusrnm(j),
                                                                      m.column_name,
                                                                      NULL,
                                                                      m.data_type,
                                                                      NULL,
                                                                      m.data_length,
                                                                      NULL,
                                                                      v_precision1,
                                                                      NULL,
                                                                      m.column_id,
                                                                      NULL);
                          END LOOP;
                         FOR n IN(SELECT column_name,  
                                          data_type,    
                                          data_length, 
                                          data_precision,
                                          data_scale,
                                          column_id
                                   FROM all_tab_columns
                                   WHERE owner = v_ntusrnm(j)
                                   AND table_name = p_tabnm
                                   AND column_name NOT IN(SELECT column_name
                                                          FROM all_tab_columns
                                                          WHERE owner = v_ntusrnm(i)
                                                          AND table_name = p_tabnm))
                           LOOP
                            v_nt_struc.EXTEND;
                            SELECT DECODE(n.data_precision,NULL,NULL,n.data_precision||','||n.data_scale)
                            INTO v_precision2
                            FROM DUAL;
                            v_nt_struc(v_nt_struc.COUNT) := obj_struc(v_ntusrnm(j),
                                                                      v_ntusrnm(i),
                                                                      n.column_name,
                                                                      NULL,
                                                                      n.data_type,
                                                                      NULL,
                                                                      n.data_length,
                                                                      NULL,
                                                                      v_precision2,
                                                                      NULL,
                                                                      n.column_id,
                                                                      NULL);
                           END LOOP;
                        END LOOP;
            END IF;
      END LOOP;
    RETURN v_nt_struc;
    EXCEPTION
    WHEN OTHERS THEN
      RAISE;
    END tabstruc_script;
    SELECT * FROM TABLE(tabstruc_script(:tabnm,nt_username(:user1,:user2,:user3)));
    You need to pass tablename and username to calling this function. Username is a nested table here so you can pass like nt_username(:user1,:user2,:user3)

  • Different Schemas in different environments for same tables used in a Universe

    Hi,
    I have a Universe in Development where I have tables pointed to a schema (DW) in DEV but in TEST/INT I have the same tables under a different schema (TESTDW). So when I promote the Universe & reports from DEV to TEST, I will be getting errors as the schema is incorrect. So we need to find a way so that we can define the schema globally instead of having it at the individual table.
    I know we can repoint the schemas, etc but i need to avoid extra work in other environments.
    Known Solutions: Promote the reports to TEST, then select all the tables & change the schema by Right Clicking the selected tables and selecting Change Qualifier/Owner.
    One of the few reasons, I don't want to follow this route, because I have lot of derived tables which I need to change it manually by editing the SQL Statement,  &  also If I add new tables or columns again in future & promote them to TEST, then again I have to change the schema.
    Did anyone faced this kind of issue?Is there any other way that we can use like Begin_Sql , etc?
    (FYI, I am using BO4.0 SP5)

    Mark, Thanks a lot for your concern. We actually have same schema name across all 3 environments but there is a huge project going on in my company which is kind of hard to explain, so our team has decided to go ahead with a different names for schemas as 2 different teams will be working on paralelly on these schemas & they will combine them after a year or so. (I know this is not a solution)
    Thanks Swapnil for Synonyms solution. Your solution might have worked, if we were using BO 4.1 SP5 but unfortunately we are using BO 4.0 and in this version I can't view any synonym tables in the universe.

  • EP: Does it support diff content for same user (Intranet vs internet)....

    Hi,
    Can a user say "abc" can have different content displayed while he logins from Internet or intranet.
    I am trying to find an answer to above question:
    We want to have one single production portal and this portal will be behind the outer firewall, DMZ and
    If one user "abc" when trying to login from internet, he can access only the vendor information of the company and when the same user "abc" login from intranet, he can access both vendor information and HR information.
    My research so far:
    help.sap.com &
    The SDN topic:
    Landscape with two Production Portals., was intresting and informative.
    In the link below, the slide 17, describes for the two different users can have two diff content.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/7c3ba590-0201-0010-f4b1-953e107b9b57
    The multitenant EP was intresting, got an impression, it supports for different ABAP clients. question, Can Multi tenant portal implemented for same ABAP client and have the user abc have different content coming from the internet vs intranet?
    Based on Note 863837, multi tenant portal capabilities will removed from nw04s SP08, any idea what this note talking about
    Second question: Planning to install Apache in DMZ. Does Apache installation is supported on the Virtual machine.
    Any leads or answers are well appreciated and will be rewarded.

    Holger,
    Thanks for the reply, that was useful.
    I posted this message in service markeplace, and got a reply from SAP, and they do not have out of box solution. Since the project is on aggressive schedule, may be this issue, which involves lot of devlopment needs to tackle in next proect cycle.
    Qustion regarding the Apache was also resolved. Reply from SAP is posted below.
    Thanks,
    Durga
    HI Mr Durga,
    Can a user say "abc" can have different content displayed while he
    logins from Internet or intranet.
    This feature is not provided with the standard Delivered NWO4 suite.
    I would ask you to take this query in the sdn forum,as these type of
    questions are answered by SAP consulting guys.
    As far as multitenant EP is concerned,
    Based on ramp-up experience and customer feedback, SAP has decided to
    not release the IT scenario variant "Implementing a Multitenant Portal"
    for general availability after SAP NetWeaver 2004s ramp-up.
    Refer to the documentation link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/44/
    615ad7dfeb4688e10000000a11466f/frameset.htm
    Second question:
    Does Apache installation is supported on the Virtual machine.
    Installation of Apache as DMZ is not Recommended by SAP.
    SAP Recommends SAP Web Dispacher.
    But SAP supports to a certain extend,if the client is using Apache.
    Please refer to the attached Note
    Note 480520 Integration of SAP J2EE Engine 6.20 / 6.40 with Apache

  • URGENT Select Query Returning No Records take same time as that of insert

    Hello Everrybody,
    I am facing a wierd problem...
    I have table with 15 fields and I am selecting a record with some condition...
    for e.g
    select field1,field2,field3....... from tablea where field1=123
    Now I have index on field1
    When I do SQL Trace it show me time taken as
    00:00:00:60 in oracle 817 SQL PLUS
    and using
    oracle 92 sql plus it show as
    00:00:00:01 in oracle 817 SQL PLUS
    Now Query is what does this 60 denotes milliseconds or what in oracle 92 and in oracle 817 sql plus.....
    Also this query does not return any rows...
    When I run the SP that insert records in same table...That sp take about same time as that of select returning no rows......
    Why is ORACLE Taking so much time for that select ????
    Please help.....

    8i measures timings in 100th of a second but I believe that 9i measures stuff in 1000th of a second. However, from your output it looks like SQL*Plus trace is rounding up to the nearest centisecond.
    Time is a very poor way of judging performance when you're talking less than a second per operation. You'd be better off looking at CPU usage and IO activity.
    Anyway, here are some questions for you to research:
    (1) Is field1 a unique index?
    (2) How many rows does this table hold?
    (3) How fresh are the statistics on the table and the index?
    (4) What's the explain plan? What's the TKPROF output?
    (5) Are all of the above the same on both databases?
    Cheers, APC

  • 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})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do we maintain diff price for same material diff customer

    Hi Experts,
    Wish you all a very happy new year 2010.
    Here is the question which I have for you..very elementary.
    I need to maintain different price for different customer for same material in the same sales area, for the same plant
    Can anyone let me know how to do it !!
    There are more than 10k customers for whom different price needs to be maintained.
    P.S: I tried to search in the forum a lot about this, but was not able to find one correct answer.
    Thanks and Regards
    Rohit Dujari

    Hello,
    You can take help of ABAPer to create a batch input session or you may use LSMW .  You can split these 10000 customers into some practicle numbers (group) depending on your policy.
    You may also explore rules for creating condition records which frankly i am not awareyou get a select rule tab on bottom side of screen when you go to  vk11/vk12
    Regards
    Vivek

  • 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.

  • How to apply 1 pamment check to multiple invo in diff OU for Same Supplier

    We have a payment check for a supplier. AP accountant want to a apply single payment check againest multiple invoices in different operating units for same supplier but he can’t do it. How it can be solved.

    Hi
    You can use the same project for multiple PJM organizations.
    In each PJM organization you need to set up the Assign Project Parameters. That means you need to allow that PJM organization to act on the specific project.
    Since the PJM organization belong to a different operating unit, you should also setup the project itself to allow charges from other operating units, and setup the provider-receiver transfer price rules, to allow cross charge and intercompany billing.
    Wip jobs are organization specific. That means there is no way two separate organizations will act on the same work order. You will need to open a workorder in the US organization and complete it there (for the project and task). Then transfer the goods to the INTL organization and receive it to the same project and task locator. In INTL organization you will need to create a new work order (for the same project and task). Issue the items from stocks to the work order to complete the finished goods. Issue the finished goods from the INTL to the customer sale order.
    The INTL PJM/Inventory/WIP organization can receive items from external vendors and from the sibling US organization.
    Dina

  • How to apply pamment to invoice in diff OU for Same Supplier

    We have a payment check for a supplier. AP accountant want to a apply this payment to invoices in different operating units for same supplier but he can’t do it. How it can be solved.

    Yep I understand that.
    Let's say I overlap track 2 as I don't like the beginning of it. . .so I want the transition from the end of track one to track two to occur in the middle of track 2 - should I just trim the track to the point I want the transition to occur as opposed to have it overlapping?

Maybe you are looking for

  • Not able to display data in separate columns using Unicode encoding

    Hi, Iam using Unicode encoding in my Java appln to support Japanese characters while downloading CSV report. But using the Unicode encoding displays all data in the first column of Excel sheet. Please let me know how to display data in different colu

  • How to create a delivery for Sales Order

    Hi, I am in process of creating a delivery(T-Code: VL01N). for the Sales Order. in one of the Fields it is Asking for ORDER. i am not sure what details to pass here. as i already created a sales order any body tell me where can i get this ORDER detai

  • Material usage change

    Hello everyone, I have to change a purchase order, the material usage is wrong, but this field is not able to change. This purchase order is released, is it because of that? If so, is there another way to change the material usage? Thanks in Advance

  • Classpath issues when executing from a jar

    I have a jar that I built for an RMI server that has a need to access another jar. (log4j). I run the jar from the command line using: java -jar -Djava.rmi.server.codebase=my.jar my.jar and the code runs fine but when I try to add in the log4j.jar I

  • Blurry camera

    Blurry rear camera?