Select query as input in PARAMETERS.

Hi Expert,
We need to give input as Select query. Like below are examples.
1) Select * from ekko into table it_data where bukrs = 3000. or
2) select fld1 fld2 fld3 from tablename into it_data up to 10 rows where fld4 = XXXXX.
We want to pass only such query as input and want result according to them. User can put any table name, can chose any table fields, also he can use inner join group by statements also.
Remember we want to pass only select query by user in PARAMETERS as below.
parameters: option type string.
In Option we need to wright that select query.
Please provide some coding samples.
Thanks And Regards
Ranjeet Singh

I think you should stay in strong oposition to customer requirement like that. This is like dynamic SQL, which if not authenticated properly would give a user to insight very sensitive data (like salaries, payments etc). Actually in SAP there is some sophisticated tool like that, called SAP Query. The user who have proper authorization can create any query he likes with no ABAP knowledge at all. I would really stick to what SAP provides by standard.
If your custmer, is however persistent in his decision (he pays, he decides), you should developed such tool with dynamic program generation, which as mentioned above can be achieved with [GENERATE SUBROUTINE POOL|http://help.sap.com/abapdocu_70/en/ABAPGENERATE_SHORTREF.htm]. RTTS will not help here as they can be used only for dynamic structure/tables generation, not queries themselves.
Regards
Marcin

Similar Messages

  • How to write XSJS Select Query with input parameters

    Hello Experts,
    I am creating a xsjs file and in that file I am trying to write a Select Query based on a Calculation View
    I have tried it the following way:
    var query = 'SELECT TOP 100 \"Name\", \"Address\", \"City\", \"Country\" FROM \"_SYS_BIC\".\"Test.HL/AddressView\"'
        + 'WITH PARAMETERS(\'PLACEHOLDER\' = (\'$$P_Name$$\', \' Akhil \'),'
      + '\'PLACEHOLDER\' = (\'$$P_City$$\', \' Lucknow \'))';
    But it gives me the "Mixed spaces and tabs error".
    How should I write XSJS Select Query with input parameters?
    Regards,
    Rohit

    >But it gives me the "Mixed spaces and tabs error".
    Mixed spaces and tabs has nothing to do with the syntax of the statement. You used both spaces and the tab in the content - which JSLint doesn't like.  Remove the beginning spaces of each line and use only one or the other.
    The actual syntax of your statement doesn't look right.  The problem is that you are escaping the \ when you don't need to if you are using ' instead of " for your string.  You escape with \" in the first line but then escape with \' in the 2nd and 3rd line.  That is going to cause serious parsing problems with the command.

  • Select (query) details by passing parameters through a calender

    Hi All,
    I have a scenario like below;
    i have a report and it returns 1000s of details which is not necessary @ all.
    what i want to do is, place a calender in top of the report and select date range (probably 2 calenders)
    and query the data accordingly by clicking a button or something.
    I know i can do this using default filter... but initially i have to pass select * from table; query for that. it returns unnecessary data.
    ----scenario in brief----
    user login to the page
    nothing comes until enter data range
    once he pick the date range.... after click on the button
    then returns the related data according to the date range...
    i think you got my question.
    can anybody give me a hand to solve this problem.
    It will be a great help.....
    Thanks in advance
    Max
    ------------------------------

    Hey Jeff,
    I got a problem again. when i try to query the data using a db link... i cant fetch the data using this data time picker... when click the button.. it doesnt fetch the data.
    but when i pass the query through the sql workshop. then i get the actual result... dont understand why the same thing does not apply in both places.....
    if i hard coded the date... then it works....
    here is my query...
    SELECT
    ATN.ATN_TRANSACTION_DATE RECEIPT_DATE,
    --CD.CDL_CHEQUE_NUMBER CHEQUE_NUMBER,
    ATN.ATN_VOUCHER_NUMBER RECEIPT_NO ,
    ATN.ATN_RECEIPT_PAYMENT_MODE PAY_MODE,
    ATN.ATN_JOURNAL_REFERENCE_NUMBER PROPOSAL_NUMBER,
    ATN.ATN_TOTAL_AMOUNT ATN_AMOUNT,
    CD.CDL_CHEQUE_AMOUNT CD_AMOUNT,
    ACT.ACC_GL_CODE GL_CODE,
    ATN.ATN_CREATED_BY USER_C,
    DECODE(ATN.ATN_RECEIPT_PAYMENT_MODE,'C',ATN.ATN_TOTAL_AMOUNT) CASH,
    DECODE(ATN.ATN_RECEIPT_PAYMENT_MODE,'B',ATN.ATN_TOTAL_AMOUNT) IBT,
    DECODE((DECODE(ACT.ACC_GL_CODE,'CF20000002','Q')),'Q',ATN.ATN_TOTAL_AMOUNT) HNB_Green_path_1,
    DECODE((DECODE(ACT.ACC_GL_CODE,'CF20000005','Q')),'Q',ATN.ATN_TOTAL_AMOUNT) HNB_Green_path_2,
    DECODE((DECODE(ACT.ACC_GL_CODE,'CF20000006','Q')),'Q',ATN.ATN_TOTAL_AMOUNT) HNB_Green_path_3,
    DECODE(ATN.ATN_RECEIPT_PAYMENT_MODE,'R',ATN.ATN_TOTAL_AMOUNT) Credit_Card,
    DECODE((DECODE(ACT.ACC_GL_CODE,'CF20000008','Q')),'Q',ATN.ATN_TOTAL_AMOUNT) HNB_Kollupitiya,
    DECODE((DECODE(ACT.ACC_GL_CODE,'CF20000009','Q')),'Q',ATN.ATN_TOTAL_AMOUNT) Commercial_Bank,
    DECODE((DECODE(ACT.ACC_GL_CODE,'CF20000010','Q')),'Q',ATN.ATN_TOTAL_AMOUNT) HNB_Green_path_USD
    FROM T_ACCOUNTING_TRANSACTION@racprod ATN
    ,T_ACCOUNTING_TRN_DETAIL@racprod ATD
    ,T_ACCOUNT@racprod ACT
    ,T_CHEQUE_DETAIL@racprod CD
    WHERE ATN.ATN_ACCOUNTING_TRANSACTION_ID =ATD.ATD_ATN_ACCOUNTING_TRN_ID
    AND ATD.ATD_ACC_ACCOUNT_ID=ACT.ACC_ACCOUNT_ID
    AND ATN.ATN_ACCOUNTING_TRANSACTION_ID=CD.CDL_ATN_ACCOUNTING_TRN_ID
    AND ATN.ATN_TRANSACTION_DATE >=to_date(:P4_FROM_DATE,'dd/mm/yyyy')
    AND ATN.ATN_TRANSACTION_DATE <=to_date(:P4_TO_DATE,'dd/mm/yyyy')
    AND ATN.ATN_VOUCHER_TYPE IN ('RV','SR')
    AND ATN.ATN_ACCOUNTING_TRN_CODE IN ('L1000','S001','S002','S003','S004','S005','S006','S007','S008','S009','S010','S011','S012','S013','S014'
    ,'L1021','L1031','L1032','L1033','L1034','L1035','L1036','L1037','L1038','L1039','L1040')
    AND substr(ATN.ATN_VOUCHER_NUMBER,9,3)=(select branch from user_login where username=:app_user)
    AND ATD.ATD_DR_CR_INDICATOR='DR'
    AND ATN.ATN_ATN_ACCOUNTING_TRN_ID IS NULL
    ORDER BY ATN.ATN_VOUCHER_NUMBER
    can u please suggest me a solution...???
    Thanks again,
    Max

  • Passing parameters to select query in DB link from invoke...

    I am having a DB partner link which executes the select query based on user specified parameter.
    Now i have created an invoke activity and specified input[this needs to be passed to query] and output parameters[this is query result]. This invoke activity calls DB partner link in which one parameter has been created to be used in select query. So my doubt is , will DB partner link take up the input parameter of invoke activity automatically or do we need to specify any mapping for this?

    When you create a db partnerlink the parameter you create for your select is the input and when you create the input variable in the invoke for this partnerlink it is created with the right type for the parameter.
    Create an Assign before your invoke and assign a value to the input variable you created in the invoke. That value will be passed and used as the parameter in the select.
    Heidi.

  • In Select query how to fetch values through multiple parameters  where conditon

    Dear Experts,
    I have one table(T) with 4 fields: f1, f2, f3, f4. In that based on f2, f3, f4 and parameter condition( f2 values) how to fetch f1 values. I have attached screen shot. What is the where condition in select query?
    DATA: it_T type standard table of ty_T,
              wa_T type ty_T.
    parameters: p_f2_1 type T-f3,
                      p_f2_2 type T-f3,
                      p_f2_3 type T-f3,
                      p_f2_4 type T-f4,
                      p_f2_5 type T-f4,
                      p_f2_6 type T-f4.
    select f1  f2  f3  f4 from T into table it_T where ?
    What is the where condition ?.
    Regards,
    Abbas.

    Hi Syed,
    Do all the parameters p_f2_1 ... p_f2_6 contain values for the same field f2? And do you need all the entries from the table T which contain f2 = any of the entered value? If yes, Then you can try the following where condition -
    select f1  f2  f3  f4 from T into table it_T
      where f2 =  p_f2_1  OR
                 f2 =  p_f2_2  OR
                 f2 =  p_f2_3  OR
                 f2 =  p_f2_4  OR
                 f2 =  p_f2_5  OR
                 f2 =  p_f2_6.
    P.S: If any of the above parameters are optional as per your requirement it will be better to build a dynamic query and use it in the where condition.
    Regards,
    Rachna.

  • URGENT: To change the where condition in select query at runtime ?

    Hi,
    I have to develop a report, 4 which I have created a selection screen with 7 Input Parameters whose value is to be filled by the user while executing the report.
    On the basis of this I do the desired selection of output.
    But the problem is that how do I write my select Query(where condition) if the user enetrs only 2 Input parameters or 3 or whatever he feels like.
    Pls help me out...

    hi,
    check this sample code.
    Here i am populating where condition at runtime.
    DATA: V_WHERE TYPE STRING.
    SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN,
                     S_ERDAT FOR VBAK-ERDAT.
    SELECTION-SCREEN END OF BLOCK INPUT.
    START-OF-SELECTION.
      PERFORM POPULATE_WHERE.
      PERFORM GET_VBAK_DATA.
    *&      Form  POPULATE_WHERE
    *       Populate Where
    FORM POPULATE_WHERE .
      IF NOT S_ERDAT[] IS INITIAL.
        CONCATENATE 'VBELN IN S_VBELN'
                    'AND'
                    'ERDAT IN S_ERDAT'
              INTO V_WHERE
              SEPARATED BY SPACE.
      ELSE.
        V_WHERE = 'VBELN IN S_VBELN'.
      ENDIF.
    ENDFORM.                    " POPULATE_WHERE
    *&      Form  GET_VBAK_DATA
    *       GET VBAK DATA
    FORM GET_VBAK_DATA .
      SELECT VBELN
             ERDAT
             VBTYP
             NETWR
             WAERK
             VKORG
             VTWEG
             SPART
        INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
        FROM VBAK
        WHERE VBELN IN S_VBELN
        AND   ERDAT IN S_ERDAT.
       WHERE (V_WHERE).
    endform.
    Regards
    Sailaja.

  • Search Page based on select Query...

    I want to create a simple search page base on a select query.
    The select query will not be based on Table.Its based on functions.
    I have created a view object like this
    select xx_test_accruals(:p_date) ACCRUAL,:p_date DT from dual
    I have created a Search page
    In Main Page layout region i have added a query region.In that Query region i have created a result based search Table.
    When i run the page is opening with field
    Dt
    When i enter date and click go i am getting error like this..
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select xx_test_accruals(:p_date) ACCRUAL,:p_date DT from dual) QRSLT WHERE (( UPPER(DT) like :1 AND (DT like :2 OR DT like :3 OR DT like :4 OR DT like :5)))
    Please help
    Edited by: [email protected] on Oct 4, 2009 2:04 PM

    Hi,
    i tried it on my machine....there's a little change on the approach.
    See we have a View Object : XxAccrualsSummaryVO
    the query is
    select xx_test_accruals(to_date(:1,'YYYY-MM-DD')) ACCRUAL,to_date(:2,'YYYY-MM-DD') DT from dual
    Create a Property View Object : say DateTestPVO and in that create a Transient Attribute of DATE type say InputDate. How to create property View Object(read in dev guide).
    Bind the date text input to DateTestPVO and InputDate Attribute.
    Now as the page loads in process request initialise the PVO not XxAccrualsSummaryVO.
    public void initialisePVO()
    OAViewObject vo = (OAViewObject)getDatePVO1();
    if (!vo.isPreparedForExecution())
    vo.setMaxFetchSize(0);
    Row row = vo.createRow();
    vo.insertRow(row);
    row.setNewRowState(Row.STATUS_INITIALIZED);
    And when the Go button is pressed then grab the date being entered and set the where clause of XxAccrualsSummaryVO.
    if(pageContext.getParameter("Go")!=null)
    //Get the value entered by user in date field.
    OAMessageDateFieldBean dateField = (OAMessageDateFieldBean)webBean.findIndexedChildRecursive("text");
    String datetest = (String)dateField.getValue(pageContext).toString();
    //Now set the where clause parameters of VO.
    OAViewObject vodate = (OAViewObject)am.findViewObject("invoicetestVO1");
    vodate.setWhereClauseParams(null);
    vodate.setWhereClauseParam(0,datetest);
    vodate.setWhereClauseParam(1,datetest);
    vodate.executeQuery();
    It works perfectly...I have tested it.
    Thanks,
    Gaurav

  • Mac Pro HDMI lost signal in 2 seconds after selecting the HDMI input

    Since a few days I am using my Mac Pro (Late 2013) as media server. The Mac is connected to my  TV using the HDMI port, that handles the 1080p (60Hz) and audio signals. My problem is that after I select the HDMI input on my TV (as turning the TV on or just changing the input) I can see the Mac desktop for like 2 seconds and then I lost the signal.
    At the moment the only way to get the signal back is to log in via remote desktop and rotate the image, and then back again.
    This is really annoying and renders the Pro useless as a media server, I would really appreciate some ideas.

    The Mac uses a highly-parameterized Driver for every display. The parameters are set by sending a query to the display, which MUST answer with its capabilities. Based on the claimed capabilities, the parameters for a good picture are set.
    The query is sent at Power-on, and when the cables are changed. And it is also sent when you sleep-and-wake your Mac, so you can use that to your advantage. If the display is set to a different port, it will often will not answer the query and the screen will go black.
    First, set your display to the correct input port. Then try to sleep-and-wake your Mac to have it send the capabilities query again, and set the parameters for a good display.
    To sleep your Mac when the screen is blank, you can use Control Eject. That puts up this familiar screen, even if you cannot see it:
    press the R key to Restart, the S key and it will Sleep, ESC to Cancel and return to shut down.
    Wait a moment to confirm it is sleeping, then press the spacebar or Command key to wake it up.

  • 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

  • Select query in a report

    Hi!
    Is it possible to modify a select query for a report in the following way:
    I have created two fields where users input values and operators.
    Operators selection is a static list consisting of: =, like , in
    Value field is a text field.
    The current query is:
    SELECT
    A,
    B,
    C
    from TABLE
    I would like to add:
    WHERE
    A : P1_OPERATOR : P1_VALUE
    but it doesn't work; I get a notification that the operator is incorrect.
    It has a defaulft value = and when I set let's say 5 in the value field the whole query should be:
    SELECT
    A,
    B,
    C
    from TABLE
    WHERE
    A = 5
    Regards!

    Hmm, I get the following error:
    Updatable report parse error:
    ORA-20001: Query must begin with SELECT or WITH
    The only difference I see is that your type is SQL Query (PL/SQL function body returning SQL query) while I have SQL Query (updateable report) hardcoded.
    I have APEX 4.2.2, I'm not quite sure how to change this...
    This is my code:
    begin
    :P7_QUERY := 'select ROWID,BNK_ID,MSR_PRD_ID,SRC_STM_ID,ID,ID_RETKA,RSP,OZNAKA_RETKA,DATUM_STANJA,OZNAKA_IZVJESCA,OZNAKA_KOMITENTA,MBR_KOMITENTA,KOMITENT_NEREZ,ZUPANIJA,DRZAVA,SEKTOR_NEREZIDENTA,VRSTA_POVEZANOSTI,INSTRUMENT,ISIN,VALUTA,OTKAZNI_ROK,IZVORNO_DOSPIJECE,VRSTA_INDEKSACIJE,VALUTA_INDEKSACIJE,PORTFELJ,UTRZIVOST_KREDITA,ZNACAJKE_KAPITALA,RIZICNA_SKUPINA,UGRADJENI_DERIVAT,ODNOSNA_VARIJABLA,PREDZNAK,IZNOS,IZNOS_ACTUAL,VRSTA_IZNOSA,KOMITENT_PBR,UDJELI_POVEZ_C,AR_ID,AU_ID,ACT_AR_BAL_KN,ACT_AR_BAL,AR_BUSS_ID,MTI_CCY_TP_ID,REG_NO,REG_SFX,JMBG_ID_NO,IP_ID,NO_DYS_OO,TAX_ID_NO,INSTRUMENT_OLD,PREDZNAK_OLD,IZNOS_ACTUAL_OLD,ACT_AR_BAL_KN_OLD,ACT_AR_BAL_OLD,NAPOMENA,NOVI_POSAO_F,LISTA_SUMARNA,LISTA_REKAP,POSTOTAK1,POSTOTAK2,POSTOTAK3,DZS_IDY_CL_ID,HNB_IP_CL_ID,EXG_RT_CRD_RSK_F from DWP.IZV_SLOG_DET
    where ' || :P7_X_FC1 || :P7_X_O1 || :P7_X_O1;
    return :P7_QUERY;
    end;
    I have also set Use Generic Column Names (parse query at runtime only) nad P7_QUERY as page item to submit.
    Regards,
    Ivan

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

  • Can I retrieve data from a multiple select query?

    I recently have been able to consolidate many queries into one large one, or into large compound queries. I found an instance where I am using a select query in a for loop that may execute up to 400 times. I tried building a huge compound query, and using DB Tools Execute Query vi, followed by the DB Tools Fetch Recordset Data vi. The query executes at the database without an error, but the Fetch Recordset Data vi only returns the first instance. Is there a way to retrieve all the data without having to send up to 400 separate select queries?

    Sorry I didn't replt earlier, I was on vacation. The query I am using is to check serial numbers, and determine if they are all valid. The programs purpose is to define a serial number to a pre-existing part number. Our company makes inclinometers and accelerometers, and this entire series of LabVIEW programs is designed to automate the calibration and testing of these units. The part number definitions can contain 3 or 4 hundred parameters, so the database itself consistes of 44 tables with potentially several hundred columns per table. It is designed to not only provide definitions to every part number, but also to store all potential raw unit data to be calculated and formed into a report at any time. The logistics of getting that much data in and out of the database have forced me to do things more effeciently. The actual query in question is to take each serial number either manually entered, or automatically picked, and see if they already exist with the part number they are being defined as. If there are any duplicates, then the program will alert the operator that serial numbers x, y, and z for instance have already been asigned as the part number in question. Currently I run a simple query once for each serial number. This works, but there may be 200 serial numbers assigned. Also the serial numbers can contain upper or lower case letters. By making all the serial number letters into capitals, then into lower case, it could mean up to 400 individual queries going out over the LAN. This is a bandwidth hog, and time consuming. I started experimenting with compound queries. The actual query used is below.
    SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000005';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000006';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000007';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000008';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000009'
    When I execute this query, SQL Server 2000 has no problem with it, but the DB Tools Fetch Recordset Data vi only returns the first match. I think my answer may lie with OR statements. Rather than sending what amounts to potentially dozens of individual queries, I should be able to chain them into one query with a lot of OR statements. As long as the OR statement is not an exclusive OR statement, I think it should work. I haven't tried it yet, and it may take some time to get the syntax right. The query is built in a for loop with the number of iterations equal to the number of serial numbers being defined. Once I get this working I will alter it to include both upper and lower case letters that can be included in the query. Any suggestiona of how the query should be structured would be most helpful, or another way to achieve what I am trying to accomplish.
    SciManStev

  • How to pass the feild names of a select query dynamically?

    Hi
    How can we pass the feilds names in select query dynamically?
    For example in my selection screen i wil be giving the table name, and feilds in that table.....
    those feilds should be taken in my select query...
    instead of
    PARAMETERS : tab_name TYPE ddobjname .
      SELECT *
        FROM (tab_name)
        INTO TABLE <newtab>
       UP TO 25 ROWS.
    parametrs : feild1 like-------
                     feild2----
    i need select feild1 feild2 feild3    FROM (tab_name)
        INTO TABLE <newtab>
       UP TO 25 ROWS.

    by the way, contrary to popular belief there is no performance problem when using
    SELECT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE ...
    as long as the structure of itab contains only the required fields.
    I ran some benchmarks against this and above construct is maybe 0.1% slower (Oracle 10g) than a
    SELECT f1 f2 f3 f4 ... FROM dbtab INTO TABLE itab WHERE ...
    but is saves you from maintaining a potentially very long field list in your code. So when you need additional fields later on, you just add them to the DDIC structure or type definition and that's it.
    Maybe something you want to factor in here.
    Cheers
    Thomas

  • Improving a SELECT query

    I have an interactive application that periodically feeds a legacy batch transaction application with data to keep it in sync with my app. For demonstrating my problem I am using a similar but much simpler example here, using two tables only: CUST and ORD. The CUST table contains customer specific data and the ORD table contains orders placed by each customer. The primary key of CUST table is the CU_CODE that is also a foreign key (OR_CU_CODE) in the ORD table. The PK of ORD table is the OR_CODE column. See their description below:
    Table: CUST
    Name               Null?     Type
    CU_CODE          NOT NULL     VARCHAR2(6)
    CU_TYPE          NOT NULL     VARCHAR2(2)
    CU_NAME          NOT NULL     VARCHAR2(80)
    CU_ADDR                    VARCHAR2(120)
    Table: ORD
    Name               Null?     Type
    OR_CODE          NOT NULL     VARCHAR2(8)
    OR_CU_CODE          NOT NULL     VARCHAR2(6)
    OR_DATE          NOT NULL     DATE
    OR_TERMS               VARCHAR2(40)
    The legacy app needs to get both a customer and an order transaction for any order whose date is more recent than a given date. To create those transactions, I run a SELECT query like this:
    SELECT 'UPD,CUST='||CU_CODE||',TYPE='||CU_TYPE||',NAME='||CU_NAME
    ||',ADDR='||CU_ADDR
    FROM (SELECT DISTINCT CU_CODE, CU_TYPE, CU_NAME, CU_ADDR
    FROM CUST, ORD WHERE OR_CU_CODE = CU_CODE
    AND OR_DATE > SOME_DATE
    ORDER BY 1)
    UNION ALL
    SELECT 'UPD,ORD='||OR_CODE||',CUST='||OR_CU_CODE||',DATE='
    ||TO_CHAR(OR_DATE, 'YYYYMMDD')||',TERMS='||OR_TERMS
    FROM (SELECT OR_CODE, OR_CU_CODE, OR_DATE, OR_TERMS
    FROM ORD WHERE OR_DATE > SOME_DATE
    ORDER BY 2, 1);
    This produces a batch update transaction file similar to the following:
    UPD,CUST=CU1111,TYPE=COM,NAME=ACME,ADDR=ACME Address
    UPD,CUST=CU2222,TYPE=RES,NAME=John Q,ADDR=John Q Address
    UPD,CUST=CU3333,TYPE=GOV,NAME=IRS,ADDR=IRS Address
    UPD,ORD=OR001234,CUST=CU1111,DATE=20061204,TERMS=Term1
    UPD,ORD=OR001235,CUST=CU1111,DATE=20061206,TERMS=Term1
    UPD,ORD=OR001236,CUST=CU1111,DATE=20061207,TERMS=Term1
    UPD,ORD=OR002234,CUST=CU2222,DATE=20061205,TERMS=Term2
    UPD,ORD=OR002235,CUST=CU2222,DATE=20061207,TERMS=Term2
    UPD,ORD=OR003237,CUST=CU3333,DATE=20070102,TERMS=Term3
    Both transaction types are sorted by the customer code first but customer update transactions also need a DISTINCT clause because we only want to send one custumer update per customer even if there were more orders placed by that customer.
    This thing has been working fine in most cases except when a large transaction file is generated because the legacy app can only handle input files of only certain max. size. In such cases the operators need to manually split up the file into several smaller ones but still making sure that each file segment has customer and order transactions belonging to the same customers only. This can be really tedious with hundreads of customers and their orders. The file splitting would be much easier if I could rewrite the original SELECT statement to produce the transaction data in the following order:
    UPD,CUST=CU1111,TYPE=COM,NAME=ACME,ADDR=ACME Address
    UPD,ORD=OR001234,CUST=CU1111,DATE=20061204,TERMS=Term1
    UPD,ORD=OR001235,CUST=CU1111,DATE=20061206,TERMS=Term1
    UPD,ORD=OR001236,CUST=CU1111,DATE=20061207,TERMS=Term1
    UPD,CUST=CU2222,TYPE=RES,NAME=John Q,ADDR=John Q Address
    UPD,ORD=OR002234,CUST=CU2222,DATE=20061205,TERMS=Term2
    UPD,ORD=OR002235,CUST=CU2222,DATE=20061207,TERMS=Term2
    UPD,CUST=CU3333,TYPE=GOV,NAME=IRS,ADDR=IRS Address
    UPD,ORD=OR003237,CUST=CU3333,DATE=20070102,TERMS=Term3
    Here a given customer update transaction would be followed by all orders for that customer and so on.
    I want the new query also in pure SQL, not in PL SQL. As dealing with DB and Oracle is only a small part of my job, I just can't figure out a solution to this problem. I suspect many of the regulars here can help me.
    Thanks,
    Joe
    PS: Sorry, the table descriptions looked much better in the edit screen but I hope you can still figure it out from the display window.

    Try something like the following (not tested)
    SELECT transaction FROM (
    SELECT CU_CODE,1,'UPD,CUST='||CU_CODE||',TYPE='||CU_TYPE||',NAME='||CU_NAME
    ||',ADDR='||CU_ADDR transaction
    FROM (SELECT DISTINCT CU_CODE, CU_TYPE, CU_NAME, CU_ADDR
    FROM CUST, ORD WHERE OR_CU_CODE = CU_CODE
    AND OR_DATE > SOME_DATE)
    UNION ALL
    SELECT OR_CU_CODE,2,'UPD,ORD='||OR_CODE||',CUST='||OR_CU_CODE||',DATE='
    ||TO_CHAR(OR_DATE, 'YYYYMMDD')||',TERMS='||OR_TERMS transaction
    FROM (SELECT OR_CODE, OR_CU_CODE, OR_DATE, OR_TERMS
    FROM ORD WHERE OR_DATE > SOME_DATE)
    ORDER BY 1,2;Basically, I added some columns to your query for sorting purposes then used that query as an inline view to only get the data you are interested in. Hope it runs. If not, let me know and I'll create the table and actually test it.

  • Help with multipule drop down lists in a select query

    Hi I am trying to design a search query using 5 drop down lists coming from tables.  the front end looks like this
    I have the selections going to variables then by $_POST into the msqyl query my other code is
    MY CODE FOR THE FORM IS
      <form action="horse-events-devon.php?url_countyid=<?php echo  urlencode ($url_countyid ['url_countyid'])  ; ?>&go" method="POST">
        <table id="searchtable">
          <tr>
            <th>Find By Discipline</th>
            <th>Find By Venue</th>
            <th>Find By Championship</th>
            <th>Find By Organiser</th>
            <th>Equine Association</th>
            <th>Submit Your Selections</th>
            </tr>
          <tr>
            <td><select name="dis_id">
                                        <?php
                                            $upcomingdis = upcomingdis($url_countyid);
                                            $upcoming_dis_bycounty = mysql_fetch_assoc ($upcomingdis);
                                        ?>
                                        <?php
                                        do {
                                          ?>   <option value="<?php echo $upcoming_dis_bycounty ['dis_id']; ?>" >
                                        <?php echo $upcoming_dis_bycounty ['dis_description']; ?></option>
                                        <?php
                                        } while ($upcoming_dis_bycounty = mysql_fetch_assoc ($upcomingdis));
                                        ?></select></td>
            <td><select name="ven_id">
                                        <?php
                                            $upvenbycounty_set = upcoming_venevents_bycounty($url_countyid);
                                            $upcoming_ven_bycounty = mysql_fetch_assoc ($upvenbycounty_set);
                                        ?>
                                        <?php
                                        do {
                                          ?>   <option value="<?php echo $upcoming_ven_bycounty ['ven_id']; ?>" >
                                        <?php echo $upcoming_ven_bycounty ['ven_name']; ?></option>
                                        <?php
                                        } while ($upcoming_ven_bycounty = mysql_fetch_assoc ($upvenbycounty_set));
                                        ?></select></td>
            <td><select name="champ_id">
                                        <?php
                                            $championship_set = findchampionships();
                                            $champlist = mysql_fetch_assoc ($championship_set);
                                        ?>
                                        <?php
                                        do {
                                        ?>   <option value="<?php echo $champlist ['champ_id']; ?>" >
                                        <?php echo $champlist ['champ_description']; ?></option>
                                        <?php
                                        } while ($champlist = mysql_fetch_assoc ($championship_set));
                                        ?></select></td>
            <td>
            <select name="org_id">
                            <?php
                                $uporgbycounty_set = upcoming_organevents_bycounty($url_countyid);
                                $upcoming_org_bycounty = mysql_fetch_assoc ($uporgbycounty_set);
                            ?>
                            <?php
                            do {
                            ?>   <option value="<?php echo $upcoming_org_bycounty ['org_id']; ?>" ><?php echo $upcoming_org_bycounty ['org_name']; ?></option>
                            <?php
                            } while ($upcoming_org_bycounty = mysql_fetch_assoc ($uporgbycounty_set));
                            ?></select>
            </td>
            <td><select name="***_id">
                                        <?php
                                            $upassbycounty_set = upcoming_assevents_bycounty($url_countyid);
                                            $upcoming_assbycounty = mysql_fetch_assoc ($upassbycounty_set);
                                        ?>
                                        <?php
                                        do {
                                        ?>   <option value="<?php echo $upcoming_assbycounty ['***_id']; ?>" >
                                        <?php echo $upcoming_assbycounty ['***_description']; ?></option>
                                        <?php
                                        } while ($upcoming_assbycounty = mysql_fetch_assoc ($upassbycounty_set));
                                        ?></select></td>
              <td><input name="submit" type="submit" /><input name="countyid" type="hidden" value="<?php echo $url_countyid ['url_countyid']; ?>" /></td>
            </tr>
          </table>
      </form>
      <?php
    if (isset($_POST['submit'])){
        if (isset($_GET['go'])){
        $countyid = $_POST['countyid'];
        $ven_id = $_POST['ven_id'];
        $dis_id = $_POST['dis_id'];
        $champ_id = $_POST['champ_id'];
        $org_id = $_POST['org_id'];
        $event_id = $row['event_id'];
            $sql = "SELECT DATE_FORMAT (events.startdate, '%a, %d, %b')
                       AS stdate, events.event_id, events.title, events.ven_id, events.org_id,
                       venue.county_id, venue.ven_id, eventdisciplines.event_id, eventdisciplines.dis_id, county.county_id, discipline.dis_id \n"
                . "FROM events \n"
                . "LEFT OUTER JOIN eventdisciplines \n"
                . "ON events.event_id = eventdisciplines.event_id \n"
                . "LEFT OUTER JOIN discipline \n"
                . "ON eventdisciplines.dis_id = discipline.dis_id \n"
                . "LEFT OUTER JOIN venue \n"
                . "ON events.ven_id = venue.ven_id \n"
                . "LEFT OUTER JOIN county \n"
                . "ON venue.county_id = county.county_id \n"
                . "WHERE events.ven_id = ({$ven_id} OR events.org_id = {$org_id})\n"
                . "AND events.startdate > NOW()\n"
                . "AND venue.county_id = {$countyid}  \n"
                . "ORDER BY startdate ASC";
        $result = mysql_query ($sql, $connection);
    ?>
    My problem is at the WHERE point,  how do I code for single and multipule selections,  The       . "WHERE events.ven_id = ({$ven_id} OR events.org_id = {$org_id})\n" throws and error.
    How am I best programing this type of query,  ??  Should it be with php ??

    The best thing is to dynamically build your where clause based on the user selection. Test the values of all form fields and if the user does not make a selection, do not include that in the where clause.
    Trying to build a single, static where clause that accounts for all possible user input permutations is extremely difficult.

Maybe you are looking for

  • Windows 8 will not accept the win8.1 upgrade button offer

    I have windows 8 Hp notebook and im trying to upgrade to 8.1  it takes me to the page with the app 8.1 and says click here and will take you to the store.  It takes me to the store but there is nothing there.  It says troubleshoot, then it does nothi

  • IPad USB Code 43 in Windows 7

    So I just got an iphone and upgraded the OS.   Now ever time I connect my Ipad to the Computer (Windows 7 Desktop), I get a code 43 error on the device.   Ipad and Ipod touch work ok as well.   Just the IPAD seems to not want to connect. Seems to be

  • Command to Convert X Window Dump file to JPEG file

    Is there a command in Solaris 2.6 that I can use to convert XWD files to JPEG files? The command should accept two arguments, the name of the file to be converted and the destination file. Thanks a lot!

  • Windows 8.1 evaluation install on XP PC

    During the installation process of Windows 8.1 enterprise evaluation I format the disk drive so I think don't have XP anymore. And now the evaluation period expire. I need to know if I have to install a full version of Windows 8.1 or an upgrade for m

  • How do I split the Browser into 4 sections?

    I am using firefox 4.0.1 browser and I would like to know that how do I split the browser screen into 4 different sections with 4 different sites? The solution should be work on any version on the firefox.