SELECT query modification

step-1 select * from t1 --has one column c1 number
step-2 select * from t2 --has two columns c1 number, c2 number (FK of t1.c1), c3 number (FK of t3.c1)
step-3 select * from t3 --has two columns c1 number, c2 varchar2
step-4 SELECT t1.*,t2.*,t3.*,
              ROW_NUMBER() OVER ( ORDER BY t3.c2 ASC
                                        ) RowNumber
          FROM t1
                LEFT JOIN t2 ON t2.c2=t1.c1
                LEFT JOIN t3 ON t3.c1 = t2.c3
step-1
c1
101
102
103
104
105
step-2
c1     c2     c3
1     101     1
2     102     2
3     103     0
step-3
c1     c2
0     c
1     b
2     a
step-4
c1     c1     c2     c3     c1     c2     RowNumber
104     NULL     NULL     NULL     NULL     NULL     1
105     NULL     NULL     NULL     NULL     NULL     2
102     2     102     2     2     a     3
101     1     101     1     1     b     4
103     3     103     0     0     c     5
--In above step-4 you will notice that column c2(near RowNumber column) has NULL value. This is because that the record is present in t1 table but it is missing in detail(t2) table. Here I am trying to sort the records on c2 column of t3 table, which is of varchar type. I want to set the default value of column c2 (near RowNumber column) to 'c' and then perform the sorting.
--the expected output is:
c1     c1     c2     c3     c1     c2     RowNumber
102     2     102     2     2     a     1
101     1     101     1     1     b     2
103     3     103     0     0     c     3
104     NULL     NULL     NULL     NULL     c<--     4
105     NULL     NULL     NULL     NULL     c<--     5
--notice the last two row having '<--'
--how can i achieve this by modifying above step-4 query?

Please find the below given script.
CREATE TABLE T1
  C1 NUMBER NOT NULL
CREATE TABLE T2
  C1 NUMBER NOT NULL,
  C2 NUMBER NOT NULL,
  C3 NUMBER NOT NULL
CREATE TABLE T3
  C1 NUMBER NOT NULL,
  C2 VARCHAR2(20) NOT NULL
INSERT INTO T1 (C1) VALUES ('101');
INSERT INTO T1 (C1) VALUES ('102');
INSERT INTO T1 (C1) VALUES ('103');
INSERT INTO T1 (C1) VALUES ('104');
INSERT INTO T1 (C1) VALUES ('105');
INSERT INTO T2 (C1, C2, C3) VALUES ('1', '101', '1');
INSERT INTO T2 (C1, C2, C3) VALUES ('2', '102', '2');
INSERT INTO T2 (C1, C2, C3) VALUES ('3', '103', '0');
INSERT INTO T3 (C1, C2) VALUES ('0', 'c');
INSERT INTO T3 (C1, C2) VALUES ('1', 'b');
INSERT INTO T3 (C1, C2) VALUES ('2', 'a');--for simplicity i have not created constraints.
Thanks,
Jigs

Similar Messages

  • Due to MODIF ID, SELECT query in START-OF-SELECTION not getting triggered

    Dear SAP Gurus,
    I'm stuck with this program, where, my program is not being executed, as in, my SELECT query in my event START-OF-SELECTION is not getting triggered. Since i hav used MODIF ID, for SELECT-OPTIONS, even after putting the entries in select-options...................when i click on the execute button, or press F8, the program still goes into the AT SELECTION-SCREEN OUTPUT event..........but i want it to goto START-OF-SELECTION event where my SELECT query is........what should i do??????????????
    Please find the notepad file having the code, n exucse me for any selection-texts absence.
    Need help from u in this issue.
    Thanks in advance.
    REPORT  ZPPR_CONVSTAT NO STANDARD PAGE HEADING.
    INCLUDE ZPPR_CONVSTAT_TOP.               " data declaration
    INCLUDE ZPPR_CONVSTAT_SEL_CRITERIA.      " selection criteria
    INCLUDE ZPPR_CONVSTAT_PBO.               " event at selection-screen output
    INCLUDE ZPPR_CONVSTAT_START_SELECTION.   " event start-of-selection
    INCLUDE ZPPR_CONVSTAT_F_START_OF_SEL.
    *&  Include           ZPPR_CONVSTAT_TOP
    TABLES  : VBUK,
              VBUP,
              VBAK,
              VBAP,
              VBEP,
              VBPA,
              TVAK,
              EKUB,
              LIKP,
              LIPS,
              MARA,
              MAKT,
              MARC,
              PLAF,
              AUFK,
              AFKO,
              AFPO,
              AFVC,
              AFVV,
              CRHD,
              PBIM,
              KNA1,
              T134,
              IOHEADER,
              IOITEM.
    TYPE-POOLS  : slis.
    TYPES : BEGIN OF ty_final,
            werks   TYPE vbap-werks,  "Plant
            auart   TYPE vbak-auart,  "Sales Order Doc. type
            erdat   TYPE vbak-erdat,  "Sales Order Creation date
            vbeln   TYPE vbak-vbeln,  "Sales Order No.
            posnr   TYPE vbap-posnr,  "Sales Order Item No.
            aedat   TYPE vbak-aedat,  "Sales Order Change Date
            kwmeng  TYPE vbap-kwmeng, "Sales Order qty.
            vdatu   TYPE vbak-vdatu,  "Requested Delivery Date
            lfimg   TYPE lips-lfimg,  "Sales Order Delivered Qty.
            matnr   TYPE vbap-matnr,  "Material ID
            arktx   TYPE vbap-arktx,  "Material Description
            strgr   TYPE marc-strgr,  "Planning Strategy
            vrkme   TYPE vbap-vrkme,  "UOM
            plnum   TYPE plaf-plnum,  "Plan Order No.
            gsmng   TYPE plaf-gsmng,  "Plan Order Qty.
            auffx   TYPE plaf-auffx,  "Plan Order Firming Indicator u2013 Qty.
            stlfx   TYPE plaf-stlfx,  "Plan Order Firming Indicator - Component
            erdat2  TYPE aufk-erdat,  "Production Order Creation Date
            aufnr   TYPE aufk-aufnr,  "Production Order No.
            prdqty  TYPE afko-gamng,  "Production Order qty.
            pckqty  TYPE lips-lfimg,  "Packed Delivered Qty.
            psamg   TYPE afpo-psamg,  "Allotted scrap
            igmng   TYPE afko-igmng,  "Confirmed Yield Qty.
            iasmg   TYPE afko-iasmg,  "Confirmed Scrap Qty
            iamng   TYPE afpo-iamng,  "Expected Yield
            wemng   TYPE afpo-wemng,  "Delivered Qty.
            altscrp TYPE c LENGTH 6,  "Allotted Scrap %
            actscrp TYPE c LENGTH 6,  "Actual Scrap %
            umrez   TYPE afvv-umrez,  "Ups (from Prd. ORD)
            ups     TYPE clobjdat-ausp1,  "Ups (from Material Master)
            crtnstl TYPE clobjdat-ausp1,  "Carton Style
            ppopr   TYPE clobjdat-ausp1,  "Pre-Printing Operation
            brdtyp  TYPE clobjdat-ausp1,  "Board Type
            lsdim1  TYPE clobjdat-ausp1,  "Layout Size u2013 Dim 1
            lsdim2  TYPE clobjdat-ausp1,  "Layout Size u2013 Dim 2
            lsgsm   TYPE clobjdat-ausp1,  "GSM
            inktyp  TYPE clobjdat-ausp1,  "Ink Type
            foiltyp TYPE clobjdat-ausp1,  "Foiling
            wintyp  TYPE clobjdat-ausp1,  "Window Type
            lamin   TYPE clobjdat-ausp1,  "Lamination
            fsvrnsh TYPE clobjdat-ausp1,  "Front Side Varnish
            bsvrnsh TYPE clobjdat-ausp1,  "Back Side Varnish
            emboss  TYPE clobjdat-ausp1,  "Embossing
            punch   TYPE clobjdat-ausp1,  "Punching
            paste   TYPE clobjdat-ausp1,  "Pasting
            oprno   TYPE afvc-vornr,      "Operation No.
            wrkcntr TYPE crhd-arbpl,      "Work Centre
            oprtxt  TYPE afvc-ltxa1,      "Operation Text
            oprqty  TYPE afvv-mgvrg,      "Operation qty.
            yield   TYPE afvv-lmnga,      "Yield
            scrap   TYPE afvv-xmnga,      "Scrap
            jobtyp  TYPE vbak-augru,      "Job Type
            prordst TYPE bsvx-sttxt,      "Production Order Status
            solinst TYPE vbup-lfsta,      "Sales Order Line Item Status
            sldprty TYPE kna1-name1,      "Sold to Party Name
            shpprty TYPE kna1-name1,      "Ship to Party Name
            shpcity TYPE kna1-ort01,      "Ship to party - City
            END OF  ty_final.
    TYPES : BEGIN OF ty_vbak,
            auart   TYPE vbak-auart,
            erdat   TYPE vbak-erdat,  "Doc creation date
            vbeln   TYPE vbak-vbeln,
            aedat   TYPE vbak-aedat,  "Doc change date
            vdatu   TYPE vbak-vdatu,  "Requested delivery date
            kunnr   TYPE vbak-kunnr,
            augru   TYPE vbak-augru,  "Job Type
            END OF ty_vbak.
    TYPES : BEGIN OF ty_vbap,
            vbeln   TYPE vbap-vbeln,
            posnr   TYPE vbap-posnr,
            werks   TYPE vbap-werks,
            matnr   TYPE vbap-matnr,
            arktx   TYPE vbap-arktx,
            kwmeng  TYPE vbap-kwmeng,
            vrkme   TYPE vbap-vrkme,
            END OF ty_vbap.
    TYPES : BEGIN OF ty_pbim,
            pbdnr TYPE pbim-pbdnr,  "Requirements Plan Number
            bdzei TYPE pbim-bdzei,  "Independent requirements pointer
            matnr TYPE pbim-matnr,
            werks TYPE pbim-werks,
            END OF ty_pbim.
    TYPES : BEGIN OF ty_pbhi,
            bdzei TYPE pbhi-bdzei,  "Independent requirements pointer
            pdatu TYPE pbhi-pdatu,  "Requirement date
            laeda TYPE pbhi-laeda,  "Date of Last Change
            END OF ty_pbhi.
    TYPES : BEGIN OF ty_ekko,
            ebeln TYPE ekko-ebeln,  "STO doc no
            bsart TYPE ekko-bsart,
            reswk TYPE ekko-reswk,  "Supplying plant
            aedat TYPE ekko-aedat,  "Doc creation date
            END OF ty_ekko.
    TYPES : BEGIN OF ty_ekpo,
            ebeln TYPE ekpo-ebeln,
            ebelp TYPE ekpo-ebelp,
            aedat TYPE ekpo-aedat,  "Doc change date
            menge TYPE ekpo-menge,
            meins TYPE ekpo-meins,
            matnr TYPE ekpo-matnr,
            txz01 TYPE ekpo-txz01,
            END OF ty_ekpo.
    TYPES : BEGIN OF ty_eket,
            ebeln TYPE eket-ebeln,
            ebelp TYPE eket-ebelp,
            eindt TYPE eket-eindt,  "Requested delivery date
            END OF ty_eket.
    TYPES : BEGIN OF ty_lips,
            vbeln TYPE lips-vbeln,
            posnr TYPE lips-posnr,
            vgbel TYPE lips-vgbel,
            vgpos TYPE lips-vgpos,
            lfimg TYPE lips-lfimg,
            END OF ty_lips.
    TYPES : BEGIN OF ty_plaf,
            plnum TYPE plaf-plnum,
            matnr TYPE plaf-matnr,
            gsmng TYPE plaf-gsmng,
            auffx TYPE plaf-auffx,
            stlfx TYPE plaf-stlfx,
            kdauf TYPE plaf-kdauf,
            kdpos TYPE plaf-kdpos,
            pbdnr TYPE plaf-pbdnr,
            END OF ty_plaf.
    TYPES : BEGIN OF ty_aufk,
            aufnr TYPE aufk-aufnr,
            erdat TYPE aufk-erdat,
            objnr TYPE aufk-objnr,
            END OF ty_aufk.
    TYPES : BEGIN OF ty_afko,
            aufnr TYPE afko-aufnr,
            gamng TYPE afko-gamng,  "Total order quantity
            gasmg TYPE afko-gasmg,  "Total scrap quantity in the order
            igmng TYPE afko-igmng,  "Confirmed Yield Qty
            iasmg TYPE afko-iasmg,  "Confirmed Scrap Qty
            aufpl TYPE afko-aufpl,  "Routing number of operations in the order
            END OF ty_afko.
    TYPES : BEGIN OF ty_afpo,
            aufnr TYPE afpo-aufnr,
            plnum TYPE afpo-plnum,
            matnr TYPE afpo-matnr,
            pgmng TYPE afpo-pgmng,  "Plan Order Qty
            kdauf TYPE afpo-kdauf,
            kdpos TYPE afpo-kdpos,
            psamg TYPE afpo-psamg,  "Allotted scrap
            iamng TYPE afpo-iamng,  "Expected Yield Variance
            wemng TYPE afpo-wemng,  "Delivered Qty
            END OF ty_afpo.
    TYPES : BEGIN OF ty_afvc,
            vornr TYPE afvc-vornr,
            aufpl TYPE afvc-aufpl,  "Routing number of operations in the order
            aplzl TYPE afvc-aplzl,  "General counter for order
            arbid TYPE afvc-arbid,  "Object ID of the resource
            ltxa1 TYPE afvc-ltxa1,
            END OF ty_afvc.
    TYPES : BEGIN OF ty_afvv,
            aufpl TYPE afvv-aufpl,  "Routing number of operations in the order
            aplzl TYPE afvv-aplzl,  "General counter for order
            umrez TYPE afvv-umrez,
            mgvrg TYPE afvv-mgvrg,
            lmnga TYPE afvv-lmnga,
            xmnga TYPE afvv-xmnga,
            END OF ty_afvv.
    TYPES : BEGIN OF ty_mdvm,
            mdkey TYPE mdvm-mdkey,
            disst TYPE mdkp-disst,
            matnr TYPE mdkp-matnr,
            plwrk TYPE mdkp-plwrk,
            END OF ty_mdvm.
    DATA :  it_final  TYPE STANDARD TABLE OF ty_final,
            it_vbak   TYPE STANDARD TABLE OF ty_vbak,
            it_vbap   TYPE STANDARD TABLE OF ty_vbap,
            it_lips   TYPE STANDARD TABLE OF ty_lips,
            it_pbim   TYPE STANDARD TABLE OF ty_pbim,
            it_pbhi   TYPE STANDARD TABLE OF ty_pbhi,
            it_ekko   TYPE STANDARD TABLE OF ty_ekko,
            it_ekpo   TYPE STANDARD TABLE OF ty_ekpo,
            it_eket   TYPE STANDARD TABLE OF ty_eket,
            it_plaf   TYPE STANDARD TABLE OF ty_plaf,
            it_aufk   TYPE STANDARD TABLE OF ty_aufk,
            it_afko   TYPE STANDARD TABLE OF ty_afko,
            it_afpo   TYPE STANDARD TABLE OF ty_afpo,
            it_afvc   TYPE STANDARD TABLE OF ty_afvc,
            it_afvv   TYPE STANDARD TABLE OF ty_afvv,
            it_mdvm   TYPE STANDARD TABLE OF ty_mdvm.
    DATA :  wa_final  TYPE ty_final,
            wa_vbak   TYPE ty_vbak,
            wa_vbap   TYPE ty_vbap,
            wa_lips   TYPE ty_lips,
            wa_pbim   TYPE ty_pbim,
            wa_pbhi   TYPE ty_pbhi,
            wa_ekko   TYPE ty_ekko,
            wa_ekpo   TYPE ty_ekpo,
            wa_eket   TYPE ty_eket,
            wa_plaf   TYPE ty_plaf,
            wa_aufk   TYPE ty_aufk,
            wa_afko   TYPE ty_afko,
            wa_afpo   TYPE ty_afpo,
            wa_afvc   TYPE ty_afvc,
            wa_afvv   TYPE ty_afvv,
            wa_mdvm   TYPE ty_mdvm.
    DATA :  it_object TYPE hum_object_t,
            wa_object TYPE hum_object,
            it_item   TYPE hum_hu_item_t,
            wa_item   TYPE vepovb,
            count1(6) TYPE n.
    DATA :  gv_objek TYPE ausp-objek.       "Put matnr for use in FM u2018CLAF_CLASSIFICATION_OF_OBJECTSu2019
    DATA : BEGIN OF it_sclass OCCURS 0.
            INCLUDE STRUCTURE sclass.
    DATA : END OF it_sclass.
    DATA : BEGIN OF it_clobjdat OCCURS 0.
            INCLUDE STRUCTURE clobjdat.
    DATA : END OF it_clobjdat.
    *&  Include           ZPPR_CONVSTAT_SEL_CRITERIA
      SELECTION-SCREEN FOR 'PLANNING STAGE'
    SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001.
      PARAMETERS: mrpntdn RADIOBUTTON GROUP sel                    DEFAULT 'X' user-command flag,
                  pldord  RADIOBUTTON GROUP sel,
                  prdord  RADIOBUTTON GROUP sel.
    SELECTION-SCREEN END OF BLOCK main.
      SELECTION-SCREEN FOR 'SELECTION BY PLANT AND PLANT DATA'
    SELECTION-SCREEN BEGIN OF BLOCK plant WITH FRAME TITLE text-002.
      PARAMETERS      : p_werks   LIKE  ioheader-werks OBLIGATORY  DEFAULT '1100' MATCHCODE OBJECT H_T001W.
      SELECT-OPTIONS  : so_matnr  FOR   ioitem-matnr                              MATCHCODE OBJECT MAT1.
      PARAMETERS      : so_mtart  TYPE  t134-mtart     OBLIGATORY  DEFAULT 'ZFIN' MATCHCODE OBJECT H_T134.
      SELECT-OPTIONS  : so_plnum  FOR   ioitem-plnum                              MATCHCODE OBJECT plnum  MODIF ID pld,
                        so_aufnr  FOR   ioheader-aufnr                            MATCHCODE OBJECT orde   MODIF ID prd.
      PARAMETERS      : p_prdsta  LIKE  tj02t-txt04                                                       MODIF ID prd.
    SELECTION-SCREEN END OF BLOCK plant.
      SELECTION-SCREEN FOR 'SELECTION BY REQUIREMENT TYPE'
    SELECTION-SCREEN BEGIN OF BLOCK reqtyp  WITH FRAME TITLE text-003.
      PARAMETERS      : cb_so     TYPE AUSWL_EB AS CHECKBOX USER-COMMAND flag,
                        cb_sto    TYPE AUSWL_EB AS CHECKBOX USER-COMMAND flag,
                        cb_pir    TYPE AUSWL_EB AS CHECKBOX USER-COMMAND flag.
    SELECTION-SCREEN END OF BLOCK reqtyp.
      SELECTION-SCREEN FOR 'SELECTION BY DATE AND REQUIREMENT TYPE NOS'
    SELECTION-SCREEN BEGIN OF BLOCK dtreqtypno WITH FRAME TITLE text-004.
      SELECT-OPTIONS  : so_crtdt  FOR vbak-erdat                                                                MODIF ID gen,
                        so_vbeln  FOR vbap-vbeln                                  MATCHCODE OBJECT WTY_F4_VBAP  MODIF ID rso,
                        so_posnr  FOR vbap-posnr                                                                MODIF ID rso,
                        so_ebeln  FOR ekub-ebeln                                  MATCHCODE OBJECT MEKKM        MODIF ID rst,
                        so_ebelp  FOR ekub-ebelp                                                                MODIF ID rst,
                        so_pbdnr  FOR pbim-pbdnr                                                                MODIF ID rpi,
                        so_reqdt  FOR vbep-edatu                                                                MODIF ID gen.
    SELECTION-SCREEN END OF BLOCK dtreqtypno.
      SELECTION-SCREEN FOR 'SELECTION BY OTHER PARAMETERS'
    SELECTION-SCREEN BEGIN OF BLOCK othrparam WITH FRAME TITLE text-005.
      SELECT-OPTIONS  : so_kunnr FOR kna1-kunnr                                   MATCHCODE OBJECT debi   MODIF ID rso,
                        so_auart FOR tvak-auart                                   MATCHCODE OBJECT H_TVAK MODIF ID rso,
                        so_lfsta FOR vbup-lfsta                                                           MODIF ID rso.
    SELECTION-SCREEN END OF BLOCK othrparam.
    *&  Include           ZPPR_CONVSTAT_PBO
    *&   Event AT SELECTION-SCREEN OUTPUT
    AT SELECTION-SCREEN OUTPUT.
      IF mrpntdn = 'X'.
        LOOP AT SCREEN.
          IF ( screen-group1 = 'PLD' OR screen-group1 = 'PRD' ).
            screen-active = 0.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ELSEIF pldord = 'X'.
        LOOP AT SCREEN.
          IF screen-group1 = 'PLD'.
            screen-intensified = 1.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'PRD'.
            screen-active = 0.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ELSEIF prdord = 'X'.
        LOOP AT SCREEN.
          IF ( screen-group1 = 'PLD' OR screen-group1 = 'PRD' ).
            screen-intensified = 1.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
      IF ( cb_so = ' ' AND cb_sto = ' ' AND cb_pir = ' ' ).
        LOOP AT SCREEN.
          IF ( screen-group1 = 'GEN'
          OR screen-group1 = 'RSO'
          OR screen-group1 = 'RST'
          OR screen-group1 = 'RPI' ).
            screen-active = 0.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
      IF cb_so = 'X'.
        LOOP AT SCREEN.
          IF screen-group1 = 'RSO'.
            screen-active = 1.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
        IF cb_sto = ' '.
          LOOP AT SCREEN.
            IF screen-group1 = 'RST'.
              screen-active = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
        IF cb_pir = ' '.
          LOOP AT SCREEN.
            IF screen-group1 = 'RPI'.
              screen-active = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ELSEIF cb_sto = 'X'.
        IF cb_so = ' '.
          LOOP AT SCREEN.
            IF screen-group1 = 'RSO'.
              screen-active = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
        IF cb_pir = ' '.
          LOOP AT SCREEN.
            IF screen-group1 = 'RPI'.
              screen-active = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ELSEIF cb_pir = 'X'.
        IF cb_so = ' '.
          LOOP AT SCREEN.
            IF screen-group1 = 'RSO'.
              screen-active = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
        IF cb_sto = ' '.
          LOOP AT SCREEN.
            IF screen-group1 = 'RST'.
              screen-active = 0.
              MODIFY SCREEN.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.
    *&  Include           ZPPR_CONVSTAT_START_SELECTION
    *&   Event START-OF-SELECTION
    IF mrpntdn = 'X'.
      PERFORM start_of_selection_mrpntdn.
    ELSEIF pldord = 'X'.
      PERFORM start_of_selection_pldord.
    ELSEIF prdord = 'X'.
      PERFORM start_of_selection_prdord.
    ENDIF.
    *&  Include           ZPPR_CONVSTAT_F_START_OF_SEL
    *&      Form  START_OF_SELECTION
          Subroutine for MRP NOT DONE
    FORM start_of_selection_mrpntdn.
        SELECT mdkey INTO TABLE it_mdvm FROM mdvm
                     WHERE GSAEN = 'X'
                       AND AKKEN = 'X'.
          IF sy-subrc = 0.
            LOOP AT it_mdvm INTO wa_mdvm.
              wa_mdvm-disst = wa_mdvm-mdkey(3).
              wa_mdvm-matnr = wa_mdvm-mdkey+3(18).
              wa_mdvm-plwrk = wa_mdvm-mdkey+21(4).
              MODIFY it_mdvm FROM wa_mdvm INDEX sy-index TRANSPORTING disst matnr plwrk.
            ENDLOOP.
          ENDIF.
    ENDFORM.
    *&      Form  START_OF_SELECTION
          Subroutine for PLAN ORDER CREATED
    FORM start_of_selection_pldord.
    ENDFORM.
    *&      Form  START_OF_SELECTION for PRODUCTION ORDER CREATED
          Subroutine for PRODUCTION ORDER CREATED
    FORM start_of_selection_prdord.
    ENDFORM.

    You need to mention START-OF-SELECTION explicitly in your code.
    Change your code as below:
    *& Event START-OF-SELECTION
    START-OF-SELECTION.
    IF mrpntdn = 'X'.

  • Using case when statement in the select query to create physical table

    Hello,
    I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
    I have a physical table based on a select table with one column.
    SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
    I also have a customer table.
    In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
    In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
    EXECUTION
    When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
    everything works as expected. YE!!
    Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
    SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
    FROM DUAL
    Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
    surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
    SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
    If anyone has any explanation to this error and how we can achieve the same, please help.
    Thanks.

    Hello,
    Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
    I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
    Here is what I am trying to do. the select query of the physical table is as follows.
    SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
    The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
    Thanks.

  • Selection screen modification based on various buttons in selection screen

    Hi,
    I have 1 query related with Selection screen modification.
    In my Report Program,I have created GUI Status for my selection screen
    Now 2 buttons in application toolbar are coming on selection sceen.
    For this i used,'At selection screen output' event.
    And there are 2 blocks on selection screen.
    If user press button1 then block2 should not display.
    and if user press button2 then block1 should not display.
    but the problem is i m not getting reqd result and also while doing debugging its not showing me sy-ucomm value.
    Any pointers on this.
    Thanks,
    Mamta

    Hi Mamta,
       have it in a group then you can write code accordingly see sample example,
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS       : p_r1 RADIOBUTTON GROUP rad
                            USER-COMMAND clk DEFAULT 'X'.            " upload Radio Button
    SELECTION-SCREEN COMMENT 5(35) text-003.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN : BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.
    PARAMETERS: p_upl       LIKE rlgrap-filename MODIF ID a           "Upload File
                             DEFAULT 'c:\temp\parbmat.xls',
                p_werks     like t001w-werks MODIF ID a,              "Plant
    PARAMETERS: p_rest      LIKE rlgrap-filename MODIF ID a           "Dwonload File Path
                             DEFAULT 'c:\temp\Success.xls'.
    SELECTION-SCREEN : END OF BLOCK 001.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS : p_r2 RADIOBUTTON GROUP rad.
    SELECTION-SCREEN COMMENT 5(35) text-004.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN : BEGIN OF BLOCK 002 WITH FRAME TITLE text-002.
    PARAMETERS     : p_plant  LIKE marc-werks MODIF ID b.                "Plant
    PARAMETERS     : p_lgort  LIKE mard-lgort MODIF ID b.                "Storage Location
    PARAMETERS     : p_vkorg  LIKE mvke-vkorg MODIF ID b.                "Sales Organization
    PARAMETERS     : p_vtweg  LIKE mvke-vtweg MODIF ID b.                "Distribution Channel
    SELECT-OPTIONS : s_mat FOR  mara-matnr MODIF ID b.                  "Material No No
    SELECT-OPTIONS : s_dat FOR  mara-ersda MODIF ID b.                  "Date on Record Created
    PARAMETERS     : p_down LIKE rlgrap-filename MODIF ID b
                      DEFAULT 'c:\temp\Material Master.xls'.           "Download File Path
    SELECTION-SCREEN : END OF BLOCK 002.
    AT SELECTION-SCREEN OUTPUT.
    *Inactive Fields depending on the radio button
      LOOP AT SCREEN.
        IF p_r1 = 'X'.
          IF screen-group1 = 'B'.
            screen-active = 0.
          ENDIF.
        ELSEIF p_r2 = 'X'.
          IF screen-group1 = 'A'.
            screen-active = 0.
          ENDIF.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    Edited by: suresh suresh on Jul 28, 2009 12:42 PM
    Edited by: suresh suresh on Jul 28, 2009 12:42 PM

  • Unexpected behavior on 5.1.19 Select query

    Hello There,
    We are seeing an unexpected behavior on 11.2.5.1.19 where we are expecting our query should response “X” number of records while it response us back with less number of records in some situation. While looking to the change log we did notice that a fix has been added to 11.2.5.1.25 as follows:
    “Fixed a bug that would return DB_NOTFOUND while searching for an existing item using a cursor on a non-sorted duplicate btree database. [#19210]”
    We were wondering whether that fix could resolve this issue or not? If yes, is there a way we can get a Patch to apply and validate so that we can move to 11.2.5.1.25 or newer versions.
    Here is what we are doing, Within an application we have two threads, One is Inserting/Updating record in the table while the other one is selecting, and all DB operations are done in transaction. Select thread comes after certain time whenever a condition is satisfied. Although it work fine most of the time but there are situation where select response with fewer records that we expected, that causes our program to died as expected. However, if we query the Database (using dbsql) after the application died using the same select query/criteria we could able to select the exact same number of records that we were expecting to see. We are not sure what is going wrong here, any help is appreciated.
    Regards & Thanks

    Hi Rittick,
    I have made some modifications to the example program ex_sql_multi_thread.c,
    based on the information you sent in email. So far I can not reproduce the
    problem either. This does look like something we have seen before:
    Berkeley DB lost data sometimes when I ran the example ex_sql_multi_thread
    but it is difficult to pinpoint without an exact reproducer. One thought is
    if you can try the application with the latest Berkeley DB release which
    is: 5.3.15. Some race conditions were fixed in that release and since you can
    reproduce the behavior with 5.1 and 5.2 you should be able to verify if
    it is present or not in 5.3.15.
    Thanks,
    Sandra

  • Maintenance View select query

    Can we write a select query for maintenace view.
    If no why  please explain.
    What is the purpose of maintenace view

    goto to table maintainance generator of maintainance view...
    in there in menu environment-->modification--->source code or events...
    main purpose of maintainance view is to update the multiple (related)table at a time (ex  mara and makt tables)....

  • Select Query Problem

    Hi Experts,
    I am having a select query in which I am using a variable in the where condition but it is giving error. Please suggest how to use variable in the select query.
    The query I am using is a s below.
    select * from zexc_rec into table it_ZEXC_REC
          where
           LIFNR in S_LIFNR and
          DOCNO in S_DOCNO and
          DOCTYP in doc_typ and
          DATE1 in S_DATE1 and
          MATNR in S_MATNR.
    Here doc_typ is a variable.
    Thanks.

    Rahul,
    use RANGES type variable instead of variable . It acts as a select-options variable. Thn use this variable in SELECT query with IN.
    Eg :
    RANGES r_t510 FOR t510-lgart.
        r_t510-low = '1600'. 
        APPEND r_t510.
        r_t510-low = '3190'. 
        APPEND r_t510.
    Note  : can be use SIGN, OPTIONS properties too in RANGES type.
    More deatils go through on HELP of RANGES
    Rgds,
    Ranjith

  • Oracle 11g :SELECT query blocked..??

    Hi Experts,
    could you please explain why the below SQL query is blocked?
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=469 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=367 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    I am scratching my head without any solution when I had a look at the db today. Thanks in advance for your help.
    Regards,
    Boris
    Edited by: user12075620 on Dec 4, 2012 8:58 AM

    The SELECT statement is not blocking the UPDATE. As I said in the previous reply, the string that this query produces does not match the logic.
    This query is (at least on the surface) correctly identifying that session 1 is blocking session 2. Session 1 holds some lock that session 2 is waiting on. So far, so good. Since session 2 is waiting on the lock, we can easily enough see what session 2 is running (the UPDATE statement). But since session 1 is not blocked, it is potentially off running a ton of other SQL statements (or no SQL statement at all). The query is looking to see what session 1 is running currently. It has no way of determining what session 1 ran at some point in the past to acquire the lock in the first place.
    Going back to my KING example,
    At noon, session 1 runs
    UPDATE emp
       SET sal = sal * 2
    WHERE ename = 'KING'Session 1 now has a lock on the KING row in the EMP table. But session 1 neither commits nor rolls back, it is still in a transaction. Session 1 might not have any more activity for a long time-- the user might go off to lunch, for example (obviously, applications should not be designed to allow users to maintain open transactions indefinitely, but not all applications are designed correctly). Or it might start running other queries. Let's say that session 1 now runs a query that is going to go for an hour
    SELECT *
      FROM giant_view_with_lots_of_computationsNow, at 12:45, session 2 comes in and runs
    UPDATE emp
       SET bonus = 100
    WHERE ename = 'KING'Session 2 is blocked. Session 2 is running the UPDATE statement. Session 1 still holds the lock but it is running some completely unrelated SQL statement.
    If we run the query you posted, the query will correctly report that session 1 is running the query against the GIANT_VIEW_WITH_LOTS_OF_COMPUTATIONS but incorrectly imply that this SELECT query is the source of the lock. It is not. It simply happens to be the query that the session that does hold the lock happens to be executing at the current moment (why the application seems to be running a lot of queries that select a constant from dual is a separate question).
    Justin

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Select query differences between oracle 9 and oracle 8.

    Hi,
    I have a problem using the select query between oracle 7 and oracle 9i I don't have the same result :
    ex:
    With oracle7
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP 'CHAMP
    champ1 champ2
    With Oracle 9
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP1' 'CHAMP2'
    champ1 champ2
    So Can someone tell me how to solve this problem ? Is there a parameter in oracle 9 to set?
    Thanx.

    Whenever you are posting anything over internet forums like this - you should be very careful about not just posting the details which requires to solve the problem - also should be sensible about your question.
    This is not at all desired when you are posting such question. It may be because - you may not well aware of the fact.
    My suggestion is -> First Go through the basics Of SQL in general.
    Then go for any specific product like Oracle/ SQL Server/ Sybase etc.
    And, finally learn the advanced commands of that DB.
    You asked it - may be you thought the difference in output in terms of lines. But, that is not your actual output. That is the graphical display part only.
    Anyway,
    You can get the quite familier output by first type the following command ->
    set lin 310Regards.
    Satyaki De.

  • Select Query resulting in Scientific Notation

    Hello all,
    I am running a Select query through a batch file that extracts data from an Oracle database. Several of the fields that I am extracting from contain numbers that are up to 38 digits long. When I extract the data, it converts the numbers into scientific notation and it is important for me to have the entire field. Is there something I can change to my query that will pull the data in its entire form? This is what I'm running now:
    select * FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy'
    I apologize in advance if this has been answered already.
    Thanks!

    >
    When the extractor finishes, it returns the data into a flat file.
    don't quite understand the TO_CHAR function. Does this function mean I need to say something like this: select "TO_CHAR('column name', 99999999999999999999999999999999999999" FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy')
    >
    Yes- if the tool you use to extract the data (your 'extractor') is converting the numeric data to a string then it is responsible for creating the string in the proper format. If the number is an integer that can have as many digits as you have '9's in your sample format string then that is what you need to do.
    Here is how sql*plus (Oracle's tool) will display the data using default settings
    SQL> select 12345678901234567890123456789012345678 no_format,
      2  to_char(12345678901234567890123456789012345678, '99999999999999999999999999
    999999999999') with_format
      3   from dual;
    NO_FORMAT WITH_FORMAT
    1.2346E+37  12345678901234567890123456789012345678
    SQL>
    ----- TOAD will display something similiar but the default uses more decimal digits in the scientific notation data
    NO_FORMAT,WITH_FORMAT
    1.23456789012346E37, 12345678901234567890123456789012345678You can either format the numeric data in the query using TO_CHAR or the 'extractor' can do it when it converts the data to a string.

  • Select-options in SELECT query - syntax error

    Hi all,
      I get the error below when I try to use the select options in a SELECT query . Please help me.
    "The IN operator with "SO_AWART" is followed neither by an internal
    table nor by a value list."
    The code i have used(Logical database  PNP is used):
    TABLES: pernr,
            catsdb.
    INCLUDE ztime_cwtr_top.    " global Data
    INCLUDE ztime_cwtr_f01.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
    SELECT-OPTIONS SO_AWART FOR CATSDB-AWART.
    PARAMETERS P_THRES TYPE I.
    SELECTION-SCREEN END OF BLOCK B1.
    Get data from CATSDB table. Workdates within the date interval are considered.
      SELECT pernr workdate awart catsquantity beguz enduz status
      FROM catsdb
      INTO TABLE it_catsdb
      WHERE pernr  = pernr-pernr    AND
           workdate GE pn-begda     AND
           workdate LE pn-endda     AND
           status   IN ('20', '30') AND
           awart    IN  so_awart .
          awart    IN ('1100', '1137', '1138', '1139', '1140',
                      '1147', '1148', '1149', '1157', '2003' ).
    when I give the values directly i do not get any syntax error, but when I use select options in the where condition I get the syntax error.
    I have tried different options like using only the select-options in the where condition.
    Thanks in advance.....
    Madhu

    Solved.
    Code with syntax error:
    include z...top .
    include z...fo1.
    select-options: xxxxxxx
    Code  with no syntax error:
    select-options: xxxxxxx
    include z...top .
    include z...fo1.
    Thanks for all your help,
    Madhu

  • Query in Select query operation

    Please excuse me for posting this again.
    I'm stuck up with this for 3 days. Lenghty post pls do read and help me.
    How is the select query going to be changed in the SAP so that the original database behind it understands it. I want to know the operation of IN operation in where clause where in we can use ranges.
    I'm asking this because I'm facing a problem using Native SQL.
    Query is like this:
    EXEC SQl.
    OPEN C1 for
    SELECT field1 from table@domain where field2 IN :ABAP_VAR.
    ENDEXEC.
    EXEC SQL.
    FETCH C1 NEXT INTO :VAR1 , :VAR2
    ENDEXEC.
    Oracle usually recognises this statement IN ( '2222' , '3658' , '6895' )
    But here this field that is build dynamically like this is not recognising them as seperate fileds but instead it is taking them as a single string and not selecting anything.
    But if a single value is passed it is fetching the data into the cursor. And the code is working fine.
    Any help in this is highly appreciable.

    "if a in r_range" is is effectively: does the value held in 'a' comply with the values held in range 'r_range'. Ranges can hold NE, patterns etc so this can get quite complex.
    You can see that it is very different from the SQL type IN.
    If your range hold several values you could unstrip it into a string varaible so that it ended up having a value something like: ( '2222' , '3658' , '6895' ). Not sure if you need the '(' but it would be something like this:
    eg,
    assuming your range is simple and only holds 'I' and 'EQ' values:
    data v_string type string.
    loop at r_range.
    concatenate v_string '@''' r_range-low  '''@' into v_string.
    endloop.
    REPLACE
      ALL OCCURRENCES OF '@'
      IN v_string
      WITH ' '.
    Then you can use:
    SELECT field1 from table@domain where field2 IN :v_string.

  • SELECt query in UNiX environment

    Iam using hp unix with oracle 11g
    when i try to spool 26 lack records it is giving me error
    " There is not enough memory available now.
    O/S Message: Broken pipe"
    is there is any other way SQL commands, we can limit the SELECT query to spool specific number of times other than using
    FOR LOOP.. with LIMIT cluase

    logdata=`${SQLPLUS} -S username/password<< EOF
                        SET ECHO OFF
                        SET LINESIZE 2000
                        SET NEWPAGE 0
                        SET SPACE 0
                        SET PAGESIZE 0
                        SET FEEDBACK OFF
                        SET HEADING OFF
                        SET TRIMSPOOL ON
                        SET TAB OFF
                        set autoprint on               
                        set serveroutput on
                        set spool on
                        spool ${SPOOL_FILE}     
                        set termout off
                   WHENEVER SQLERROR EXIT SQL.SQLCODE
                   whenever oserror exit 1;
                        $GetQuery ==> there come's the SELECT statement which spool's 25 lakh records.
                        spool off
                   EXIT
                        END`
    While spooling records it throws the error
    There is not enough memory available now.
    O/S Message: Broken pipe
    i want u use spooling instead of using util_file to write each and every rows in a file
    Edited by: user9080289 on Apr 29, 2010 5:04 AM

  • Select query in materialized view with two dblinks

    Hi All,
    We have oracle 10g On windows.
    We are trying to create materialized view. Scenario is we have base table on other database and we are creating mview on different database.
    Basa database have two schema's and i am selecting records from that two schema's using two private db links.
    But when i am tryin gto create mview its not getting created. After 15 hrs. its still showing creation command and not finished.
    Query is :-
    Is it good practice to have two db links in select query of materialized view.

    Billy  Verreynne  wrote:
    Chanchal Wankhade wrote:
    Is it good practice to have two db links in select query of materialized view.Same db link being used twice, or two different db links?
    If the former, you ideally want the local Oracle db to send the join to the remote database, and for the remote database to drive the join between those 2 tables. There is a hint (<i>driving_site</i>) that can be used - or the join query can be defined on the remote database as a view, and the local materialised view can then use that remote view.
    If you have 2 different db links and joining across these - usually a bad idea to perform distributed database joins. There are lots of limitations as to how the tables can be joined. Worse case, full table scans of both remote tables, pulling all the rows from the 2 remote database tables to the local database, and joining these on the local database.
    I have seen some severe performance issues in the past as a result of distributed joins. I'll rather use 2 materialised views for pulling both distributed tables's data locally, and then do the join on local data (using indexes, partition pruning, etc)Hi Billy,
    My scenario is i have two database database A and database B. Database A is having two schema's SCOTT AND HR. SCOTT schema have select privileges on HR schema.
    DB LINK is between Database B to Database A. name is db.link.B.A.oracle.com.
    What if i priovide while creating materialized view, the schema name before the table name in database B for this particuler table so it will pick up the table from that schema using same DB LINK(db.link.B.A.oracle.com.) that i am using to fetch records from SCOTT schema.
    Above schnario is like two base schema's and one db link using two schema.

Maybe you are looking for