Best way to write SELECT statement

Hi,
I am selecting fields from one table, and need to use two fields on that table to look up additional fields in two other tables.
I do not want to use a VIEW to do this. 
I need to keep all records in the original selection, yet I've been told that it's not good practice to use LEFT OUTER joins.  What I really need to do is multiple LEFT OUTER joins.
What is the best way to write this?  Please reply with actual code.
I could use 3 internal tables, where the second 2 use "FOR ALL ENTRIES" to obtain the additional data.  But then how do I append the 2 internal tables back to the first?  I've been told it's bad practice to use nested loops as well.
Thanks.

Hi,
in your case having 2 internal table to update the one internal tables.
do the following steps:
*get the records from tables
sort: itab1 by key field,  "Sorting by key is very important
      itab2 by key field.  "Same key which is used for where condition is used here
loop at itab1 into wa_tab1.
  read itab2 into wa_tab2     " This sets the sy-tabix
       with key key field = wa_tab1-key field
       binary search.
  if sy-subrc = 0.              "Does not enter the inner loop
    v_kna1_index = sy-tabix.
    loop at itab2 into wa_tab2 from v_kna1_index. "Avoiding Where clause
      if wa_tab2-keyfield <> wa_tab1-key field.  "This checks whether to exit out of loop
        exit.
      endif.
****** Your Actual logic within inner loop ******
   endloop. "itab2 Loop
  endif.
endloop.  " itab1 Loop
Refer the link also you can get idea about the Parallel Cursor - Loop Processing.
http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing
Regards,
Dhina..

Similar Messages

  • Hi just want to know where is the best way to type the statement?

    just to ask you what is the best way to write the statement please

    Could you please explain what the topic and statement is about?
    Helps to narrow the focus, down to a specific hardware or software
    question pertaining to the Apple products involved, where applicable.
    Basic word processing can be accomplished in TextEdit, if you do
    not have Pages or any other software to write with, for example.
    Yet, there is no indication of the purpose, direction, or problem.
    Good luck & happy computing!

  • Best way to write this sql ?

    Please let me know best way to write this SQL.
    select col1, count(*)
    from TableA
    group by col1
    having count(*) =
    (select max(vals)
    from
    select col1, count(*) as vals
    from TableA
    group by col1
    having count(*) > 1
    )

    post EXPLAIN PLAN
    SELECT col1,
           COUNT(*)
    FROM   tablea
    GROUP  BY col1
    HAVING COUNT(*) = (SELECT MAX(vals)
                       FROM   (SELECT col1,
                                      COUNT(*) AS vals
                               FROM   tablea
                               GROUP  BY col1
                               HAVING COUNT(*) > 1))

  • What is a best way to write SQL ?

    Sample Case
    drop table t;
    drop table b;
    create table t ( a varchar2(4), b number, c varchar2(1));
    insert into t values ('A00', 10, 'R');
    insert into t values ('A01', 11, 'R');
    insert into t values ('A02', 12, 'R');
    insert into t values ('A03', 13, 'R');
    insert into t values ('A00', 10, 'P');
    insert into t values ('A01', 11, 'P');
    insert into t values ('A02', 12, 'P');
    insert into t values ('A03', 13, 'P');
    commit;
    create table b ( j varchar(4), k varchar2(1), l varchar2(5), m number(3), n varchar2(5), o number(3));
    insert into b values ('A00', 'P', 'FIXED', 100, 'FLOAT', 60);
    insert into b values ('A01', 'P', 'FIXED', 101, 'FIXED', 30);
    insert into b values ('A02', 'R', 'FLOAT', 45, 'FLOAT', 72);
    insert into b values ('A03', 'R', 'FIXED', 55, 'FLOAT', 53);
    commit;
    10:19:13 SQL> select * from t;
    A B C
    A00 10 R
    A01 11 R
    A02 12 R
    A03 13 R
    A00 10 P
    A01 11 P
    A02 12 P
    A03 13 P
    8 rows selected.
    10:19:19 SQL> select * from b;
    J K L M N O
    A00 P FIXED 100 FLOAT 60
    A01 P FIXED 101 FIXED 30
    A02 R FLOAT 45 FLOAT 72
    A03 R FIXED 55 FLOAT 53
    1/     In table t each reference having 2 records one with P another is with R
    2/     In table b each refrence merged into single record and there are many records which are not existing in table t
    3/      both t and j tables can be joined using a = j
    4/     If from table t for a reference indicator is 'P' then if have to pick up l and m columns, if it is 'R' then I have to pick up n and o columns
    5/     I want output in following format
    A00     P     FIXED          100
    A00     R     FLOAT          60
    A01     P     FIXED          101
    A01     R     FIXED          30
    A02     P     FLOAT          72
    A02     R     FLOAT          45
    A03     P     FLOAT          53
    A03     R     FIXED          55
    6/     Above example is a sample ouput, In above example I have picked up only l,m,n,o columns, but in real example there are many columns ( around 40 ) to be selected. ( using "case when" may not be practical )
    Kindly suggest me what is a best way to write SQL ?
    thanks & regards
    pjp

    Is this?
    select b.j,t.c as k,decode(t.c,'P',l,n) as l,decode(t.c,'P',m,o) as m
    from t,b
    where t.a=b.j
    order by j,k
    J K L M
    A00 P FIXED 100
    A00 R FLOAT 60
    A01 P FIXED 101
    A01 R FIXED 30
    A02 P FLOAT 45
    A02 R FLOAT 72
    A03 P FIXED 55
    A03 R FLOAT 53
    8 rows selected.
    or is this?
    select b.j,t.c as k,decode(t.c,b.k,l,n) as l,decode(t.c,b.k,m,o) as m
    from t,b
    where t.a=b.j
    order by j,k
    J K L M
    A00 P FIXED 100
    A00 R FLOAT 60
    A01 P FIXED 101
    A01 R FIXED 30
    A02 P FLOAT 72
    A02 R FLOAT 45
    A03 P FLOAT 53
    A03 R FIXED 55
    8 rows selected.

  • Best way to write Pl/Sql

    Dear all,
    Can someone say the best way writing below stored proc:
    procedure missing_authorized_services is
    v_truncate_sql varchar2(200);
    v_sql varchar2(2000);
    BEGIN
    v_truncate_sql := 'truncate table missing_authorized_services';
         execute immediate v_truncate_sql;
         commit;
    v_sql := 'INSERT into missing_authorized_services select distinct trim(service_group_Cd) as service_group_Cd, trim(service_cd) as service_cd from stage_1_mg_service_request
    where (service_group_cd, service_cd) not in (
                        select distinct service_group_cd, service_cd from stage_3_servcd_servgrp_dim)';
    execute immediate v_sql;
         commit;
    END missing_authorized_services;
    /* I am doing select from table and then try to Insert into a different table the result set */
    Please guide,
    Thanks
    J

    Hi,
    The best way to write PL/SQL (or any code) is in very small increments.
    Start with a very simple procedure that does something (anything), just enough to test that it's working.
    Add lots of ouput statments so you can see what the procedure is doing. Remember to remove them after testing is finished.
    For example:
    CREATE OR REPLACE procedure missing_authorized_services IS
            v_truncate_sql  VARCHAR2 (200);
    BEGIN
         v_truncate_sql := 'truncate table missing_authorized_services';
         dbms_output.put_line (  v_truncate_sql
                        || ' = v_truncate_sql inside missing_authorized_services'
    END      missing_authorized_services;If you get any errors (for example, ORA-00955, becuase you're trying to give the same name to a procedure that you're already using for a table), then fix the error and try again.
    When it worls perfectly, then add another baby step. For example, you might add the one line
    EXECUTE IMMEDIATE v_truncate_sql;and test again.
    Don't use dynamic SQL (EXECUTE IMMEDIATE) unless you have to.
    Is there any reason to use dynamic SQL for the INSERT?

  • How to write select statement in XSL-FO type XML program

    Hi All,
    Could you please anyone explain briefly how to write select statement in XSL-FO XML Program.
    Requirement:
    In the seeded program, OAF page is creating one XML file and through XSL-FO type XML Pulisher loading data and generating PDF output. as per the requirement some of the informations are missing in the XML file and for modifing the OAF page will be taking someting. we are planing to write a select query inside the XSL-FO program to get the required information.
    Could you please help me how to write a select statement inside the XSL-FO type programs.
    Please give me some example program for this...
    Thanks in Advance.
    Regards,
    Senthil

    Hi ,
    Please check the below code and modified plant as select-option
    Check the below code :
    tables : mara,
    mast.
    data : begin of i_data occurs 0,
    matnr like mara-matnr,
    end of i_data.
    select-options : s_matnr for mara-matnr,
                           <b>S_werks for mast-werks.</b>
    start-of-selection.
    select a~matnr into table i_data
    from mara as a inner join mast as b on amatnr = bmatnr
    where <b>b~werks in s_werks</b>
    and a~matnr in s_matnr
    and a~mtart = 'AA'
    or a~mtart = 'UT'
    and b~stlan = '1'.
    loop at i_data.
    write:/ i_data-matnr.
    endloop.
    Hope you got it.
    Thanks
    Seshu

  • How to write select statement directly in java file instead of using vo

    Hi,
    I have written the following code in my java file:
    if(empvo==null)
    empvo=worklistamimpl2.createViewObject("InvoiceVO", "xxetfc.oracle.apps.icx.icatalog.shopping.server.InvoiceVO");
    if(empvo!=null){
    OAViewObject oaviewobject2 = (OAViewObject)worklistamimpl2.findViewObject("InvoiceVO");
    OAViewObjectImpl oaviewobjectimpl = (OAViewObjectImpl)oapagecontext.getApplicationModule(oawebbean).findViewObject("InvoiceVO");
    oaviewobject2.setWhereClause("Invoice_num="+" ' " + s + " ' ");
    oaviewobjectimpl.executeQuery();
    String abc = (String)oaviewobjectimpl.first().getAttribute("Invoice_id");
    It is giving me error as
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select invoice_id from ap_invoices_all) QRSLT WHERE (Invoice_num='ERS15022012_3')
    1. Why is this error coming.. how to solve this
    2. Instead of using vo how can i write select statement directly in the above code
    Thanks,
    Edited by: user10873676 on Apr 9, 2012 1:18 AM
    Edited by: user10873676 on Apr 9, 2012 1:21 AM

    it says java.sql.SQLSyntaxErrorException: ORA-00904: "INVOICE_NUM": invalid identifier
    where as invoice_num column is present in my table

  • How to write Select statement for this codition

    I need to check whether SGTXT contains BELNR value.
    SGTXT is a text field and It should be matched with BELNR
    How to write select statement for this.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT should have the given BELNR Value.
    Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.

    Hi,
    data temp(12).
    concatenate '%' belnr '%' into temp.
    Select AUGBL AUGDT into t_BSAD
    from BSAD
    where SGTXT like temp.
    If belnr is having multiple values,just create a internal table as follows.
    types : begin of ty,
            belnr....
            temp(12),
            end of ty.
    data itab_ type standard table of ty.
    data wa type ty.
    loop at itab into wa.
    concatenate '%' wa-belnr '%' into wa-temp.
    modify itab from wa index sy-tabix transporting temp.
    endloop.
    Change your select statement accordingly.
    Kindly reward poits if it helps.

  • How to write SELECT statement using tables ekko,ekpo and eket?

    Hi,
    I got a problem in  performance tuning using below tables?
    how to write SELECT statement using tables EKKO,EKPO and EKET and in conditon ( WHERE clause)  use only fields 
                        ekko~ebeln       IN ebeln
                       ekko~loekz       EQ ' '
                       ekko~lifnr       IN lifnr
                       ekko~ekorg       IN ekorg
                      ekko~ekgrp       IN ekgrp          
                       ekpo~werks       IN werks
                       ekpo~pstyp       EQ  '3'
                       ekpo~loekz       EQ  space
                       ekpo~elikz       EQ  space
                       ekpo~menge       NE  0
                     eket~rsnum       NE space.
    Thanks in Advance.
    bye.

    Hi,
    ekko~ebeln IN ebeln
    ekko~loekz EQ ' '
    ekko~lifnr IN lifnr
    ekko~ekorg IN ekorg
    ekko~ekgrp IN ekgrp
    ekpo~werks IN werks
    ekpo~pstyp EQ '3'
    ekpo~loekz EQ space
    ekpo~elikz EQ space
    ekpo~menge NE 0          " Remove this from where clause
    eket~rsnum NE space.    " Remove this from where clause
    ' instead delete the entries after fetching into the table
    DELETE it_itab WHERE menge EQ '0' AND rsnum EQ ' '.
    Regards
    Bala Krishna

  • Best way to write an Wrapper class around a POJO

    Hi guys,
    What is the best way to write an Wrapper around a Hibernate POJO, given the latest 2.2 possibilities? The goal is, of course, to map 'regular' Java Bean properties to JavaFX 2 Properties, so that they can be used in GUI.
    Thanks!

    what about this:
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    public class PersonPropertyWrapper {
         private StringProperty firstName;
         private StringProperty lastName;
         private Person _person;
         public PersonPropertyWrapper(Person person) {
              super();
              this._person = person;
              firstName = new SimpleStringProperty(_person.getFirstName()) {
                   @Override
                   protected void invalidated() {
                        _person.setFirstName(getValue());
              lastName = new SimpleStringProperty(_person.getLastName()) {
                   @Override
                   protected void invalidated() {
                        _person.setLastName(getValue());
         public StringProperty firstNameProperty() {
              return firstName;
         public StringProperty lastNameProperty() {
              return lastName;
         public static class Person {
              private String firstName;
              private String lastName;
              public String getFirstName() {
                   return firstName;
              public void setFirstName(String firstName) {
                   this.firstName = firstName;
              public String getLastName() {
                   return lastName;
              public void setLastName(String lastName) {
                   this.lastName = lastName;
         public static void main(String[] args) {
              Person p = new Person();
              p.setFirstName("Jim");
              p.setLastName("Green");
              PersonPropertyWrapper wrapper = new PersonPropertyWrapper(p);
              wrapper.firstNameProperty().setValue("Jerry");
              System.out.println(p.getFirstName());
    }Edited by: 906680 on 2012-7-27 上午10:56

  • Best way to write the following query

    Hi ,
    I've the following table structures and data..
    And i've written the query to get the records which are greater than BBB-
    But could you please hint me to write in simpler way.
    create table obj (ob_id )
    as select 1 from dual union all
    select 2 from dual union all
    select 3 from dual union all
    select 4 from dual union all
    select 5 from dual union all
    select 6 from dual
    create table og_dt (or_id , rt_cd,rt_ct_cd)
    AS SELECT 1 ,'B','BRID' FROM DUAL UNION ALL
       SELECT 1 ,'B','BRD' FROM DUAL UNION ALL
       SELECT 2 ,'BB-','ACR' FROM DUAL UNION ALL
       SELECT 2 ,'BB-','AQCR' FROM DUAL UNION ALL
       SELECT 3 ,'BBB','QYRE' FROM DUAL UNION ALL
       SELECT 4 ,'BB+','TUR' FROM DUAL UNION ALL
       SELECT 5 ,'BBB-','KUYR' FROM DUAL
    create table rt_srt (srt_ord,rt_cd,rt_ct_cd)
    as select 50 ,'B','VID' FROM DUAL UNION ALL
       SELECT 50 ,'B','BRD' FROM DUAL UNION ALL
       SELECT 40 ,'BB-','ACR' FROM DUAL UNION ALL
       SELECT 41 ,'BB-','AQCR' FROM DUAL UNION ALL
       SELECT 30 ,'BBB','QYRE' FROM DUAL UNION ALL
       SELECT 33 ,'BB+','TUR' FROM DUAL UNION ALL
       SELECT 20 ,'BBB-','KUYR' FROM DUAL
    select distinct
       from obj,og_dt,rt_srt
      where obj.ob_id=og_dt.or_id
      and og_dt.rt_cd = rt_srt.rt_cd
      and og_dt.rt_ct_cd=rt_srt.rt_ct_cd
    and rt_srt.srt_ord > all (select rt_srt.srt_ord from rt_srt
    where rt_cd='BBB-' I've used the table rt_srt twise in the above query
    Could you please hint to write it in the simple way.
    Thank you

    Here are execution plans for 3 possible solutions (incuding one you posted). Second & third solutions assume rt_srt.srt_ord is not null:
    SQL> explain plan for
      2  select  distinct *
      3    from  obj,
      4          og_dt,
      5          rt_srt
      6    where obj.ob_id = og_dt.or_id
      7      and og_dt.rt_cd = rt_srt.rt_cd
      8      and og_dt.rt_ct_cd = rt_srt.rt_ct_cd
      9      and rt_srt.srt_ord > all (
    10                                select  rt_srt.srt_ord
    11                                  from  rt_srt
    12                                  where rt_cd = 'BBB-'
    13                               )
    14  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 3210303028
    | Id  | Operation              | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |        |     7 |   504 |    16  (25)| 00:00:01 |
    |   1 |  HASH UNIQUE           |        |     7 |   504 |    16  (25)| 00:00:01 |
    |   2 |   MERGE JOIN ANTI NA   |        |     7 |   504 |    15  (20)| 00:00:01 |
    |   3 |    SORT JOIN           |        |     7 |   385 |    11  (19)| 00:00:01 |
    |*  4 |     HASH JOIN          |        |     7 |   385 |    10  (10)| 00:00:01 |
    |*  5 |      HASH JOIN         |        |     7 |   238 |     7  (15)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |   6 |       TABLE ACCESS FULL| OBJ    |     6 |    78 |     3   (0)| 00:00:01 |
    |   7 |       TABLE ACCESS FULL| OG_DT  |     7 |   147 |     3   (0)| 00:00:01 |
    |   8 |      TABLE ACCESS FULL | RT_SRT |     7 |   147 |     3   (0)| 00:00:01 |
    |*  9 |    SORT UNIQUE         |        |     1 |    17 |     4  (25)| 00:00:01 |
    |* 10 |     TABLE ACCESS FULL  | RT_SRT |     1 |    17 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("OG_DT"."RT_CD"="RT_SRT"."RT_CD" AND
    PLAN_TABLE_OUTPUT
                  "OG_DT"."RT_CT_CD"="RT_SRT"."RT_CT_CD")
       5 - access("OBJ"."OB_ID"="OG_DT"."OR_ID")
       9 - access("RT_SRT"."SRT_ORD"<="RT_SRT"."SRT_ORD")
           filter("RT_SRT"."SRT_ORD"<="RT_SRT"."SRT_ORD")
      10 - filter("RT_CD"='BBB-')
    Note
       - dynamic sampling used for this statement (level=2)
    31 rows selected.
    SQL> explain plan for
      2  select  distinct *
      3    from  obj,
      4          og_dt,
      5          rt_srt
      6    where obj.ob_id = og_dt.or_id
      7      and og_dt.rt_cd = rt_srt.rt_cd
      8      and og_dt.rt_ct_cd = rt_srt.rt_ct_cd
      9      and rt_srt.srt_ord > (
    10                            select  max(rt_srt.srt_ord)
    11                              from  rt_srt
    12                              where rt_cd = 'BBB-'
    13                           )
    14  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 3391900174
    | Id  | Operation              | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |        |     1 |    55 |    14  (15)| 00:00:01 |
    |   1 |  HASH UNIQUE           |        |     1 |    55 |    14  (15)| 00:00:01 |
    |*  2 |   HASH JOIN            |        |     1 |    55 |    10  (10)| 00:00:01 |
    |   3 |    MERGE JOIN CARTESIAN|        |     2 |    68 |     6   (0)| 00:00:01 |
    |*  4 |     TABLE ACCESS FULL  | RT_SRT |     1 |    21 |     3   (0)| 00:00:01 |
    |   5 |      SORT AGGREGATE    |        |     1 |    17 |            |          |
    PLAN_TABLE_OUTPUT
    |*  6 |       TABLE ACCESS FULL| RT_SRT |     1 |    17 |     3   (0)| 00:00:01 |
    |   7 |     BUFFER SORT        |        |     6 |    78 |     3   (0)| 00:00:01 |
    |   8 |      TABLE ACCESS FULL | OBJ    |     6 |    78 |     3   (0)| 00:00:01 |
    |   9 |    TABLE ACCESS FULL   | OG_DT  |     7 |   147 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("OBJ"."OB_ID"="OG_DT"."OR_ID" AND
                  "OG_DT"."RT_CD"="RT_SRT"."RT_CD" AND
    PLAN_TABLE_OUTPUT
                  "OG_DT"."RT_CT_CD"="RT_SRT"."RT_CT_CD")
       4 - filter("RT_SRT"."SRT_ORD"> (SELECT MAX("RT_SRT"."SRT_ORD") FROM
                  "RT_SRT" "RT_SRT" WHERE "RT_CD"='BBB-'))
       6 - filter("RT_CD"='BBB-')
    Note
       - dynamic sampling used for this statement (level=2)
    30 rows selected.
    SQL> explain plan for
      2  select  distinct obj.*,
      3                   og_dt.*,
      4                   rt_srt.srt_ord,
      5                   rt_srt.rt_cd,
      6                   rt_srt.rt_ct_cd
      7    from  obj,
      8          og_dt,
      9          (
    10           select  t.*,
    11                   max(case rt_cd when 'BBB-' then srt_ord end) over() max_srt_ord
    12             from  rt_srt t
    13          ) rt_srt
    14    where obj.ob_id = og_dt.or_id
    15      and og_dt.rt_cd = rt_srt.rt_cd
    16      and og_dt.rt_ct_cd = rt_srt.rt_ct_cd
    17      and rt_srt.srt_ord > max_srt_ord
    18  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 998396165
    | Id  | Operation             | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |        |     7 |   476 |    11  (19)| 00:00:01 |
    |   1 |  HASH UNIQUE          |        |     7 |   476 |    11  (19)| 00:00:01 |
    |*  2 |   HASH JOIN           |        |     7 |   476 |    10  (10)| 00:00:01 |
    |*  3 |    HASH JOIN          |        |     7 |   238 |     7  (15)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL | OBJ    |     6 |    78 |     3   (0)| 00:00:01 |
    |   5 |     TABLE ACCESS FULL | OG_DT  |     7 |   147 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |*  6 |    VIEW               |        |     7 |   238 |     3   (0)| 00:00:01 |
    |   7 |     WINDOW BUFFER     |        |     7 |   147 |     3   (0)| 00:00:01 |
    |   8 |      TABLE ACCESS FULL| RT_SRT |     7 |   147 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("OG_DT"."RT_CD"="RT_SRT"."RT_CD" AND
                  "OG_DT"."RT_CT_CD"="RT_SRT"."RT_CT_CD")
       3 - access("OBJ"."OB_ID"="OG_DT"."OR_ID")
    PLAN_TABLE_OUTPUT
       6 - filter("RT_SRT"."SRT_ORD">"MAX_SRT_ORD")
    Note
       - dynamic sampling used for this statement (level=2)
    27 rows selected.
    SQL> SY.
    Edited by: Solomon Yakobson on May 7, 2012 4:46 PM

  • What is the best way to write 10 channels of data each sampled at 4kHz to file?

    Hi everyone,
    I have developed a vi with about 8 AI channels and 2 AO channels... The vi uses a number of parallel while loops to acquire, process, and display continous data.. All data are read at 400 points per loop interation and all synchronously sampled at 4kHz...
    My questions is: Which is the best way of writing the data to file? The "Write Measurement To File.vi" or low-level "open/create file" and "close file" functions? From my understanding there are limitations with both approaches, which I have outlines below..
    The "Write Measurement To File.vi" is simple to use and closes the file after each interation so if the program crashes not all data would necessary be lost; however, the fact it closes and opens the file after each iteration consumes the processor and takes time... This may cause lags or data to be lost, which I absolutely do not want..
    The low-level "open/create file" and "close file" functions involves a bit more coding, but does not require the file to be closed/opened after each iteration; so processor consumption is reduced and associated lag due to continuous open/close operations will not occur.. However, if the program crashes while data is being acquired ALL data in the buffer yet to be written will be lost... This is risky to me...
    Does anyone have any comments or suggestions about which way I should go?... At the end of the day, I want to be able to start/stop the write to file process within a running while loop... To do this can the opn/create file and close file functions even be used (as they will need to be inside a while loop)?
    I think I am ok with the coding... Just the some help to clarify which direction I should go and the pros and cons for each...
    Regards,
    Jack
    Attachments:
    TMS [PXI] FINAL DONE.vi ‏338 KB

    One thing you have not mentioned is how you are consuming the data after you save it.  Your solution should be compatible with whatever software you are using at both ends.
    Your data rate (40kS/s) is relatively slow.  You can achieve it using just about any format from ASCII, to raw binary and TDMS, provided you keep your file open and close operations out of the write loop.  I would recommend a producer/consumer architecture to decouple the data collection from the data writing.  This may not be necessary at the low rates you are using, but it is good practice and would enable you to scale to hardware limited speeds.
    TDMS was designed for logging and is a safe format (<fullDisclosure> I am a National Instruments employee </fullDisclosure> ).  If you are worried about power failures, you should flush it after every write operation, since TDMS can buffer data and write it in larger chunks to give better performance and smaller file sizes.  This will make it slower, but should not be an issue at your write speeds.  Make sure you read up on the use of TDMS and how and when it buffers data so you can make sure your implementation does what you would like it to do.
    If you have further questions, let us know.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • How is the best way to manage the stats table?

    Hello!
    I have the Integration 2.1 working with an Oracle 8.1.7 db. I noticed that the table
    STATS is growing pretty fast.
    How is the best way to manage this table?... I haven't found something related with
    this issue in the documentation, but at least I want to know how to safely delete
    records from this table.
    For example, if I know the minimal time I have to keep in the table, is quite simple
    to create a shell script and/or Oracle pl/sql job to trim the table.
    I hope somebody can help me!!!!
    Thank you!
    Ulises Sandoval

    Write an app people want to buy and rate highly.

  • How to write select statement into SCRIPT editor

    hello,
    i build a sap script for purchase order printing for exporting.
    now after all po order print fine then our client want some more should be print into layout regarding po header.
    At the soul my q is can i write select query into script editor itself.
    thanks and regards
    amit.

    You cannot write your select statement inside your SAPscript, to overcome this SAP has provided us an option of calling sub-routines.. go through the below example
    Go through this example
    Ex. SAPSCRIPT
    /: PERFORM <Subroutine name> IN PROGRAM <subroutine prog name>
    /:USING &<field name>&
    /:CHANGING &<field name1&    "It will be returned back from sub-routine
    /:ENDPERFORM
    Then create subroutine pool program(of your own name) and you have to write the code.
    FORM ><subroutine name> tables int_cond structure itcsy
    outt_cond structure itcsy.
    data : value(20), value1(20). "do your own declarations
    Read int_cond table index 1.
    value = int_cond-value.
    value1 = value1 + value.
    *****Write your select statement
    Read outt_cond table index 1.
    outt_cond-value = value1.
    Modify outt_cond index 1. 
    ENDFORM.
    Just rough idea given above.
    Regards,
    SaiRam

  • How to write select statement ?

    Hi,
    i have requirement like below :
    In selection screen we have material number as selection options  and plant as single entry.
    Based on the input.
    We have to extract  the material number and plant based on MTART = AA or UT in MARA table and STLAN = 1 in MAST table.
    how to write a select statment to pick values from selection option and extract those material and plant which fullfill above conditions.
    Please let me know..
    its urgent
    please help..
    i have written code like below..
    types: begin of x_it_mat,
           matnr type mkal-matnr,
           werks type mkal-werks,
           stlan type mast-stlan,
           end of x_it_mat.
    types: begin of x_it_mat1,
           matnr type mkal-matnr,
           werks type mkal-werks,
           mtart type mara-mtart,
           end of x_it_mat1.
    data : it_mat type table of x_it_mat,
           wa_mat like line of it_mat.
    data : it_mat1 type table of x_it_mat1,
           wa_mat1 like line of it_mat1.
    TABLES: MKAL , MAST , MARA.
    SELECTION-SCREEN BEGIN OF BLOCK matnr
                              WITH FRAME TITLE TEXT-001.
    select-options :
      so_matnr for mkal-matnr.
    SELECTION-SCREEN END OF BLOCK matnr.
    SELECTION-SCREEN BEGIN OF BLOCK plant
                              WITH FRAME TITLE TEXT-002.
    parameter p_werks type mkal-werks.
    SELECTION-SCREEN END OF BLOCK plant.
    select matnr
           werks
           stlan
           from mkal INTO table it_mat
           where matnr in so_matnr
           and werks = p_werks.
    after this how to write another select statement to extract material by satisfiying above 2 conditions..

    Hi ,
    Please check the below code and modified plant as select-option
    Check the below code :
    tables : mara,
    mast.
    data : begin of i_data occurs 0,
    matnr like mara-matnr,
    end of i_data.
    select-options : s_matnr for mara-matnr,
                           <b>S_werks for mast-werks.</b>
    start-of-selection.
    select a~matnr into table i_data
    from mara as a inner join mast as b on amatnr = bmatnr
    where <b>b~werks in s_werks</b>
    and a~matnr in s_matnr
    and a~mtart = 'AA'
    or a~mtart = 'UT'
    and b~stlan = '1'.
    loop at i_data.
    write:/ i_data-matnr.
    endloop.
    Hope you got it.
    Thanks
    Seshu

Maybe you are looking for

  • Restoring/Formatting my ipod classic?

    After replacing my ipod classic for a third time, the sales representative, to test my ipod, plugged it into his mac. The ipod began to optimize itself for a mac. he assured me this was no problem, and so I went on my way. When I home, I plug in the

  • Mac pro won't do VGA

    I just upgraded to a Mac Pro, dual core 3.0, 2008 model, I don't ahve any more info then that currently, I can't see inside my puter. My vga monitor does't work on the DVI connections on the display card. I am using the simple dvi-vga adapter, but th

  • Need Help. Never could view movie on my new Apple TV

    Christmas gift of Apple TV has been very disappointing.  It appears our DSL Download spead is less than desireable for an Apple TV, however I started downloaded a movie - waiting 6 hours and went to bed.   Movie was ready the next afternoon, we sat d

  • Vms 2.1 can't link up with the vpn 3030 series concentrator

    Hi Netpro, Currently I had installed the vms 2.1 server, but I have no clue how make the vms 2.1 to communicate with the vpn 3030 series concentrator. Can anyone give me the guideline? Thanks in advanced. Regards, stephen yap

  • Is it possible to set GRID Computing

    This Question is not relevant to this forum but i want to get some information on GRID We have more that 20 standalone server in our office. Is it possible to deploy GRID computing on this environment Please share your thoughts ANy ideas.... Message