Head count select statement

Dear Experts,
                  for calculating headcount i had written the select statment as follows,
SELECT  DISTINCT a~pernr INTO TABLE it_pa00001
                         FROM pa0000 AS  a
                         INNER JOIN pa0001 AS b
                         ON apernr = bpernr
                         WHERE a~stat2 <> 0
                         AND abegda LE p_date21 AND aendda GE p_date11
                         AND b~persg = '1'.             "#EC CI_NOFIRST
Check whether it is correct or wrong ...
Thanks in Advance,
ThiruKumaran. R

Hi stat2 should be other than 0.
i.e. stat2 ne 0.
Regards,
Dilek

Similar Messages

  • HTML DB  Select Statement in HTML HEADER

    Can I put a select statement that return a value in the HTML HEADER?
    If I can How? Would point the way.
    Second Question
    Can I call store function from HTML HEADER? Help!

    I have a report screen that has Delete button. Each record on the screen has a checkbox
    What I would like to do is:
    when the user puts a check in the checkbox and click the Delete button. a message will pop up and ask "Are you usre?" If the user click Yes then the system will check for child record. If there no No child record go head delete the record. If there is a child record then another message pop up and ask "This Schedule is currently active. Do you really want to delete this." If the user answers Yes then it will delete both parent and child records. If the user answer no then no record will be deleted.
    I have been struggle with this in HTML DB for a bit, but I did not find the solution yet. Please Help!!!!

  • Count(*) in select statement having group by clause

    Hi
    I would like to use count(*) in select statement having group by clause. say for example there is a state with a number of cities listed. I would like to get the count of cities for each state.
    the sql stement is grouped by city and it is joined with 5 more tables.
    Thanks

    I suspect you want to look into analytic functions (assuming you have a recent version of Oracle). asktom.oracle.com has numerous examples if you do a search.
    Justin

  • Count the number of rows resulting from a select statement

    Hi,
    Is there any way of counting the number of rows resulting from a select statement. i.e I have a select distinct statement and I then want to perform an IF statement on the number of rows resulting from the select statement.
    Any help appreciated
    Thanks
    Gary

    Declare
    var1 number;
    Begin
    select count(distinct column_name) into
    var1 from table_name;
    If var1 > x Then
    End IF;
    End;
    Hope I understood the problem correctly
    null

  • Count(*) function in select statement having group by condition

    Hi
    I would like to use count(*) in select statement having group by clause. say for example there is a state with a number of cities listed. I would like to get the count of cities for each state.
    the sql stement is grouped by state and it is joined with 5 more tables.
    Thanks
    ps: ignore the previous post

    Assuming there is one record per city per state, then
    SELECT state,count(*)
    FROM state_tbl
    GROUP BY stateWill get one record per state with the number of cities in each state. If you want to join that result set to other tables you need to either create a view with that statement or use an in-line view viz.
    SELECT c.cust_name,c.state,s.num_cities
    FROM customers c,
         (SELECT state,count(*) num_cities
          FROM state_tbl
          GROUP BY state) s
    WHERE c.state = s.stateTTFN
    John

  • Adding count from two select statements

    Hi,
    How to add counts from two select statements in a single SQL statement.
    For ex: I have
    SELECT COUNT(DISTINCT COL1) FROM table1
    and
    SELECT COUNT(DISTINCT COL2) FROM table2.
    I want to add the counts from these two sqls in a single select query. How to do this.
    Thanks & Regards,
    Sunil.

    select ((SELECT COUNT(DISTINCT COL1) FROM table1) + (SELECT COUNT(DISTINCT COL2) FROM table2)) as "total" from dual;
    regards,

  • How to compare two fields from the same table in the select statement

    Hi, friends
    I try to compare tow fields from the same table, but no result,
    For example, this
    data: cptotchek tyep i.
    select count(*) into cptotchek
    from aufk where erdat = aufk-idat2 .
    The result is  cptotchek = 0, but there are the records in aufk , where,  aufk-erdat = aufk-idat2.
    Please, help me, i don't use the loop statement for optimize my program.
    Regards

    Hi  ,
           it will not return  any value   when you are using   column of same table 
           such as Date Field   , Because  while Using Aggregate Function  it will not check with self column
    .      For that you have to take data in one internal table and then you can work on it  .
         And if you are worried about Performance  it will not affect  , untill you are selecting only required data  .
    you can try this way  .
    data: cptotchek type i.
    types : begin of  w_aufk.
            include structure aufk  .
          types : end of  w_aufk .
    data : it_aufk type standard table of w_aufk with header line  .
    select * into corresponding fields of table it_aufk
    from aufk  .
    loop at it_aufk .
    if it_aufk-erdat  = it_aufk-idat2 .
    write : / it_aufk-erdat , it_aufk-idat2 .
    else .
    delete it_aufk .
    endif  .
    endloop.
    Regards
    Deepak.

  • Is it possible to nest SELECT statements?

    Greetings community,
    Another newbie’s question it is. Looking tutorials and some posts here I’ve been advised not to pull entire table through the local network, and torture client machines’ processors and memory. It’s been said that better solution is to
    pull just one part of the table.
    So, imagine this: you want to make a part of your app that would allow your user to view list of orders. So you put one data grid view on the form, pull last 20 headers from the table into it and leave to user to choose one to be opened
    in another form. If user doesn’t find header they want, they press page up for example and previous 20 headers are loaded into data grid view. Of course, user could filter headers list by customer, or by distribution lane (having all customers residing in
    one part of the town), or whatever more, but let’s not complicate things at this moment, because I’m practically in the beginning.
    I’m trying to make a stored procedure that would load penultimate 20 headers when user presses page up. So, not knowing any better, I created table variable that has the same structure as Orders table with one difference: OrderID column,
    which is identity (auto incremented) in Orders table, here is simply defined as bigint not null. Community member Visakh16 warned me few months ago it’s the bad practice to put self-incrementing columns in table variables.
    At this moment there’s a query on my screen, which waits to become store procedure. After boring part with table variable definition, it goes like this:
    INSERT INTO @OrdersTemp SELECT TOP 40 * FROM dbo.Orders ORDER BY OrderID DESC
    SELECT TOP 20 * FROM @OrdersTemp ORDER BY OrderID ASC
    To put that simply, I pull last 40 headers into table variable, and then pull first 20 from there. This thing works, and I just have to replace 40 with parameter, for every page up or down.
    Now I have few questions.
    -Is there some better way (considering performance) to achieve that? Here is the place where I wanted to ask the question from the title of the post. I don’t know much about T-SQL, and I’m not sure about the proper syntax to nest SELECT
    statements, if something like that is even possible
    -Is there any better way (some built-in function) to find about the count of the rows in one table than
    SELECT COUNT(OrdersID) FROM dbo.Orders
    Thanks for any suggestions.

    Hi Erland,
    Sorry for the very late reply, but I said that I would start another thread when I find more free time to dedicate it to this, so I didn’t really expected you to reply anymore. I didn’t really check here for more than a week, and I glanced
    at mail accidentally.
    As for the negative result I got, its measurement unit is microsecond, so it doesn’t go out of margins you had experienced.
    As for the number of cores, you got me surprised there. I use express edition of SQL server. Last time I checked was SQL server 2012 express, and in specifications it said that express edition is limited to 1 processor core, 1GB of RAM
    and creates up to 10GB database file. I don’t believe they changed any of those specifications. It was generous enough when they doubled size of DB file few editions ago. Still, it appears that “one processor core for express edition” statement has some gray
    areas in it.
    However, at this moment I’m just learning, and I just wanted some way to test how efficient my queries are. I don’t have a real biz problem to solve. I don’t expect that any real performance problem should rise in years of everyday work
    of populating database. What I expect is performance impact when it comes to creating reports, but after all, I don’t think that my boss would create reports by himself. I believe that creating reports would be my task, and I will be doing it after hours,
    being the only user at the moment. Or maybe I could make de-normalized copy of database that would be populated after hours to make it possible for my boss to get his reports faster by himself, as I’ve heard that was the way of making BI in older non-express
    editions.
    So, I do suggest that we finally close this thread for sake of other readers. I’ll start another one with this subject when I find the time to do it.
    Again, thanks for being with me along this journey.

  • I can't use my field-symbols in my select statement...

    Hello experts,
    I am have been having problems with my report for the past days. My problem is,
    I declared a dynamic field symbol so that I can use it in my select statement
    instead of the standard internal table. But it is giving me a dump. Below is my code:
    REPORT zfr_forex_rev_acctg
           NO STANDARD PAGE HEADING
           LINE-COUNT 0
           LINE-SIZE 100.
    Data dictionary tables                       *
    TABLES: bsis,
            bsas,
            tcurr,
            t001.
    FIELD-SYMBOLS: <fs_dyntable> TYPE STANDARD TABLE,
                   <fs_dynline>  TYPE ANY,
                   <fs_fld>      TYPE ANY,
                   <fs_data>     TYPE REF TO data,
                   <fs_1>        TYPE ANY,
                   <fs_2>        TYPE ANY TABLE.
    CLASS lcl_main DEFINITION.
      PUBLIC SECTION.
        METHODS: build_table,
                 get_data,
                 combine_data,
                 display_header,
                 display_results.
      PRIVATE SECTION.
        TYPES: BEGIN OF t_bsis_bsas,
                zuonr  TYPE bsis-zuonr,
                gjahr  TYPE bsis-gjahr,
                belnr  TYPE bsis-belnr,
                bldat  TYPE bsis-bldat,
                waers  TYPE bsis-waers,
                blart  TYPE bsis-blart,
                dmbtr  TYPE bsis-dmbtr,
                wrbtr  TYPE bsis-wrbtr,
                hkont  TYPE bsis-hkont,
                amount TYPE bsis-wrbtr,
               END OF t_bsis_bsas.
        DATA: it_bsis_bsas TYPE STANDARD TABLE OF t_bsis_bsas,
              v_counter TYPE i.
      data declarations for internal table
        DATA: lt TYPE lvc_t_fcat,
              ls TYPE lvc_s_fcat,
              fldname(50) TYPE c,
              it_ddfields TYPE TABLE OF ddfield,
              wa_ddfields LIKE LINE OF it_ddfields.
    ENDCLASS.
    CLASS lcl_main IMPLEMENTATION.
    METHOD build_table
      METHOD build_table.
        DATA: lv_from    TYPE bsis-gjahr,
              lv_asof    TYPE bsis-gjahr,
              lv_check   TYPE i,
              lt_data TYPE REF TO data,
              lt      TYPE lvc_t_fcat.
        FIELD-SYMBOLS: <fs_year> TYPE gjahr.
        ASSIGN lv_asof TO <fs_year>.
        lv_from = p_year.
        lv_asof = p_asof+0(4).
        v_counter = lv_asof - lv_from.
        wa_ddfields-fieldname = 'ZUONR'.
        wa_ddfields-position  = '0001'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000018'.
        wa_ddfields-decimals  = '00000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'GJAHR'.
        wa_ddfields-position  = '0002'.
        wa_ddfields-datatype  = 'NUMC'.
        wa_ddfields-leng      =  '000004'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'BELNR'.
        wa_ddfields-position  = '0003'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000010'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'BLDAT'.
        wa_ddfields-position  = '0004'.
        wa_ddfields-datatype  = 'DATS'.
        wa_ddfields-leng      =  '000008'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'WAERS'.
        wa_ddfields-position  = '0005'.
        wa_ddfields-datatype  = 'CUKY'.
        wa_ddfields-leng      =  '000005'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'BLART'.
        wa_ddfields-position  = '0006'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000002'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'DMBTR'.
        wa_ddfields-position  = '0007'.
        wa_ddfields-datatype  = 'CURR'.
        wa_ddfields-leng      =  '000013'.
        wa_ddfields-decimals  = '000002'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'WRBTR'.
        wa_ddfields-position  = '0008'.
        wa_ddfields-datatype  = 'CURR'.
        wa_ddfields-leng      =  '000013'.
        wa_ddfields-decimals  = '000002'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'HKONT'.
        wa_ddfields-position  = '0009'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000010'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
        wa_ddfields-fieldname = 'AMOUNT'.
        wa_ddfields-position  = '0010'.
        wa_ddfields-datatype  = 'CURR'.
        wa_ddfields-leng      =  '000010'.
        wa_ddfields-decimals  = '000002'.
        APPEND wa_ddfields TO it_ddfields.
        DATA: lv_position TYPE i.
        lv_position = 0011.
        WHILE lv_check < v_counter.
         <fs_year> = lv_asof.
          wa_ddfields-fieldname = <fs_year>.
          wa_ddfields-position  = lv_position.
          wa_ddfields-datatype  = 'NUMC'.
          wa_ddfields-leng      =  '000004'.
          wa_ddfields-decimals  = '000000'.
          APPEND wa_ddfields TO it_ddfields.
          lv_asof = lv_asof - 1.
          ADD 1 TO: lv_check, lv_position.
        ENDWHILE.
        CLEAR lv_position.
        lv_position = 1.
        LOOP AT it_ddfields INTO wa_ddfields.
          ls-col_pos   = lv_position.
          ls-row_pos   = lv_position.
          ls-fieldname = wa_ddfields-fieldname.
          APPEND ls TO lt.
          ADD 1 TO lv_position.
        ENDLOOP.
        CLEAR lv_position.
        ASSIGN lt_data TO <fs_data>.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
         EXPORTING
          it_fieldcatalog = lt
         IMPORTING
          ep_table = <fs_data>
         EXCEPTIONS
          generate_subpool_dir_full = 1
         OTHERS = 2.
        IF sy-subrc <> 0.
        ENDIF.
        ASSIGN <fs_data>->* TO <fs_1>.
        ASSIGN <fs_1> TO <fs_2>.
        ASSIGN <fs_1> TO <fs_dyntable>.
      ENDMETHOD.
    METHOD get_data
      METHOD get_data.
    *get records from BSIS
        SELECT zuonr gjahr belnr bldat waers blart dmbtr wrbtr hkont
        FROM bsis
        INTO  CORRESPONDING FIELDS OF TABLE <fs_dyntable>
        WHERE bukrs = p_bukrs
          AND hkont IN s_hkont
          AND budat <= p_asof.
    *get records from BSAS
        SELECT zuonr gjahr belnr bldat waers blart dmbtr wrbtr hkont
        FROM bsas
        APPENDING CORRESPONDING FIELDS OF TABLE <fs_dyntable>
        WHERE bukrs = p_bukrs
          AND hkont IN s_hkont
          AND budat <= p_asof
          AND augdt > p_asof.
      ENDMETHOD.
    START-OF-SELECTION.
      DATA: main TYPE REF TO lcl_main.
      CREATE OBJECT main.
      CALL METHOD main->build_table.
      CALL METHOD main->get_data.
    Need help on this problem. Thanks a lot guys and take care!

    Hi guys,
    I found out the problem  and Andreas is right. Now, I am having problems when including DMBTR, WRBTR in my select statement. All the others are ok. Here is my modified code. Please suggest what I need to add/modify. Thanks a lot!
    CLASS lcl_main IMPLEMENTATION.
    METHOD build_table
      METHOD build_table.
        DATA: lv_from    TYPE bsis-gjahr,
              lv_asof    TYPE bsis-gjahr,
              lv_check   TYPE i,
              lt_data TYPE REF TO data,
              lt      TYPE lvc_t_fcat.
        FIELD-SYMBOLS: <fs_year> TYPE gjahr.
        ASSIGN lv_asof TO <fs_year>.
        lv_from = p_year.
        lv_asof = p_asof+0(4).
        v_counter = lv_asof - lv_from.
      ZUONR
        wa_ddfields-fieldname = 'ZUONR'.
        wa_ddfields-position  = '0001'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000018'.
        wa_ddfields-decimals  = '00000'.
        APPEND wa_ddfields TO it_ddfields.
      GJAHR
        wa_ddfields-fieldname = 'GJAHR'.
        wa_ddfields-position  = '0002'.
        wa_ddfields-datatype  = 'NUMC'.
        wa_ddfields-leng      =  '000004'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
      BELNR
        wa_ddfields-fieldname = 'BELNR'.
        wa_ddfields-position  = '0003'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000010'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
      BLDAT
        wa_ddfields-fieldname = 'BLDAT'.
        wa_ddfields-position  = '0004'.
        wa_ddfields-datatype  = 'DATS'.
        wa_ddfields-leng      =  '00008'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
      WAERS
        wa_ddfields-fieldname = 'WAERS'.
        wa_ddfields-position  = '0005'.
        wa_ddfields-datatype  = 'CUKY'.
        wa_ddfields-leng      =  '000005'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
      BLART
        wa_ddfields-fieldname = 'BLART'.
        wa_ddfields-position  = '0006'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000002'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
      DMBTR
        wa_ddfields-fieldname = 'DMBTR'.
        wa_ddfields-position  = '0007'.
        wa_ddfields-datatype  = 'CURR'.
        wa_ddfields-leng      =  '000013'.
        wa_ddfields-decimals  = '000002'.
        APPEND wa_ddfields TO it_ddfields.
      WRBTR
        wa_ddfields-fieldname = 'WRBTR'.
        wa_ddfields-position  = '0008'.
        wa_ddfields-datatype  = 'CURR'.
        wa_ddfields-leng      =  '000013'.
        wa_ddfields-decimals  = '000002'.
        APPEND wa_ddfields TO it_ddfields.
      HKONT
        wa_ddfields-fieldname = 'HKONT'.
        wa_ddfields-position  = '0009'.
        wa_ddfields-datatype  = 'CHAR'.
        wa_ddfields-leng      =  '000010'.
        wa_ddfields-decimals  = '000000'.
        APPEND wa_ddfields TO it_ddfields.
      AMOUNT
        wa_ddfields-fieldname = 'AMOUNT'.
        wa_ddfields-position  = '0010'.
        wa_ddfields-datatype  = 'CURR'.
        wa_ddfields-leng      =  '000010'.
        wa_ddfields-decimals  = '000002'.
        APPEND wa_ddfields TO it_ddfields.
        DATA: lv_position TYPE i.
        lv_position = 0011.
      Additional fields for the years
        WHILE lv_check < v_counter.
          wa_ddfields-fieldname = <fs_year>.
          wa_ddfields-position  = lv_position.
          wa_ddfields-datatype  = 'NUMC'.
          wa_ddfields-leng      =  '000004'.
          wa_ddfields-decimals  = '000000'.
          APPEND wa_ddfields TO it_ddfields.
          lv_asof = lv_asof - 1.
          ADD 1 TO: lv_check, lv_position.
        ENDWHILE.
        CLEAR lv_position.
        lv_position = 1.
        LOOP AT it_ddfields INTO wa_ddfields.
          CASE wa_ddfields-fieldname.
            WHEN 'BLDAT'.
              ls-col_pos   = lv_position.
              ls-row_pos   = lv_position.
              ls-fieldname = wa_ddfields-fieldname.
              ls-inttype   = 'D'.
              ls-ref_table = 'BSIS'.
              ls-ref_field = 'BLDAT'.
            WHEN 'WAERS'.
              ls-col_pos   = lv_position.
              ls-row_pos   = lv_position.
              ls-fieldname = wa_ddfields-fieldname.
              ls-ref_table = 'BSIS'.
              ls-ref_field = 'WAERS'.
            when 'DMBTR'.
              ls-col_pos   = lv_position.
              ls-row_pos   = lv_position.
              ls-fieldname = wa_ddfields-fieldname.
              ls-ref_table = 'BSIS'.
              ls-ref_field = 'DMBTR'.
            when 'WRBTR'.
              ls-col_pos   = lv_position.
              ls-row_pos   = lv_position.
              ls-fieldname = wa_ddfields-fieldname.
              ls-ref_table = 'BSIS'.
              ls-ref_field = 'WRBTR'.
            WHEN OTHERS.
              ls-col_pos   = lv_position.
              ls-row_pos   = lv_position.
              ls-fieldname = wa_ddfields-fieldname.
          ENDCASE.
          APPEND ls TO lt.
          ADD 1 TO lv_position.
        ENDLOOP.
        CLEAR lv_position.
        ASSIGN lt_data TO <fs_data>.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
         EXPORTING
          it_fieldcatalog = lt
         IMPORTING
          ep_table = <fs_data>
         EXCEPTIONS
          generate_subpool_dir_full = 1
         OTHERS = 2.
        IF sy-subrc <> 0.
        ENDIF.
        ASSIGN <fs_data>->* TO <fs_1>.
        ASSIGN <fs_1> TO <fs_2>.
        ASSIGN <fs_1> TO <fs_dyntable>.
      ENDMETHOD.

  • ABAP Select statement performance (with nested NOT IN selects)

    Hi Folks,
    I'm working on the ST module and am working with the document flow table VBFA. The query takes a large amount of time, and is timing out in production. I am hoping that someone would be able to give me a few tips to make this run faster. In our test environment, this query take 12+ minutes to process.
        SELECT vbfa~vbeln
               vbfa~vbelv
               Sub~vbelv
               Material~matnr
               Material~zzactshpdt
               Material~werks
               Customer~name1
               Customer~sortl
          FROM vbfa JOIN vbrk AS Parent ON ( Parentvbeln = vbfavbeln )
                 JOIN vbfa AS Sub ON ( Subvbeln = vbfavbeln )
                 JOIN vbap AS Material ON ( Materialvbeln = Subvbelv )
                 JOIN vbak AS Header ON ( Headervbeln = Subvbelv )
                 JOIN vbpa AS Partner ON ( Partnervbeln = Subvbelv )
                 JOIN kna1 AS Customer ON ( Customerkunnr = Partnerkunnr )
          INTO (WA_Transfers-vbeln,
                WA_Transfers-vbelv,
                WA_Transfers-order,
                WA_Transfers-MATNR,
                WA_Transfers-sdate,
                WA_Transfers-sfwerks,
                WA_Transfers-name1,
                WA_Transfers-stwerks)
          WHERE vbfa~vbtyp_n = 'M'       "Invoice
          AND vbfa~fktyp = 'L'           "Delivery Related Billing Doc
          AND vbfa~vbtyp_v = 'J'         "Delivery Doc
          AND vbfa~vbelv IN S_VBELV
          AND Sub~vbtyp_n = 'M'          "Invoice Document Type
          AND Sub~vbtyp_v = 'C'          "Order Document Type
          AND Partner~parvw = 'WE'       "Ship To Party(actual desc. is SH)
          AND Material~zzactshpdt IN S_SDATE
          AND ( Parentfkart = 'ZTRA' OR Parentfkart = 'ZTER' )
          AND vbfa~vbelv NOT IN
             ( SELECT subvbfa~vbelv
               FROM vbfa AS subvbfa
               WHERE subvbfavbelv = vbfavbelv
               AND   subvbfa~vbtyp_n = 'V' )           "Purchase Order
          AND vbfa~vbelv NOT IN
             ( SELECT DelList~vbeln
               FROM vbfa AS DelList
               WHERE DelListvbeln = vbfavbelv
               AND   DelList~vbtyp_v = 'C'             "Order Document Type
               AND   DelList~vbelv IN                  "Delivery Doc
                  ( SELECT OrderList~vbelv
                    FROM vbfa AS OrderList
                    WHERE OrderList~vbtyp_n = 'H' )    "Return Ord
          APPEND WA_Transfers TO ITAB_Transfers.
        ENDSELECT.
    Cheers,
    Chris

    I am sending u some of the performance isuues that are to be kept in mind while coding.
    1.Donot use Select *...... instead use Select <required list>......
    2.Donot fetch data from CLUSTER tables.
    3.Donot use Nested Select statements as. U have used nested select which reduces performance to a greater extent.
      Instead  use  views/join .
    Also keep in mind that not use join condition for more for more than three tables unless otherwise required.
    So split select statements into three or four and use Select ......for all entries....
    4.Extract  the data from the database  atonce consolidated upfront into table.
      i.e. use INTO TABLE <ITAB> clause instead of using
    Select----
    End Select.
    5.Never use order by clause in Select ..... statement. instead use SORT<itab>.
    6.When  ever u need to calculate max,min,avg,sum,count use AGGREGATE FUNCTIONS and GROUP BY clause insted of calculating by userself..
    7.Donot use the same table once for Validation and another time for data extraction.select data  only once.
    8.When the intention is for validation use Select single ....../Select.......up to one rows ......statements.
    9.If possible always use array operations to update the database tables.
    10.Order of the fields in the where clause select statement  must be in the same order in the index of table.
    11.Never release the object unless throughly checked by st05/se30/slin.
    12.Avoid using identical select statements.

  • How to find the number of fetched lines from select statement

    Hi Experts,
    Can you tell me how to find the number of fetched lines from select statements..
    and one more thing is can you tell me how to check the written select statement or written statement is correct or not????
    Thanks in advance
    santosh

    Hi,
    Look for the system field SY_TABIX. That will contain the number of records which have been put into an internal table through a select statement.
    For ex:
    data: itab type mara occurs 0 with header line.
    Select * from mara into table itab.
    Write: Sy-tabix.
    This will give you the number of entries that has been selected.
    I am not sure what you mean by the second question. If you can let me know what you need then we might have a solution.
    Hope this helps,
    Sudhi
    Message was edited by:
            Sudhindra Chandrashekar

  • What is the use of additon in up to 1 rows in SELECT statement

    Hi All,
             What is the use of up to 1 rows in select statement.
    for example
    SELECT kostl
          FROM pa0001
          INTO y_lv_kostl UP TO 1 ROWS
          WHERE pernr EQ pernr
          AND endda GE sy-datum.
        ENDSELECT.
    I'm unable to get in wat situations we hav to add up to 1 rows
    please help me out...
    Thanks,
    santosh.

    Hi,
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Regards,
    Bhaskar

  • REG:- SELECT STATEMENT IN IF CONDITION.

    HI FRIENDS,
    CAN V USE SELECT STATEMENT IN IF CONDITION LIKE....
    IF (SELECT COUNT(EMPID) FROM EMPLOPYEE) > 1 THEN
    UPDATE STATEMENT;
    END IF;
    PLEASE HELP.
    --RAJNISH                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi,
    1. Hit the Caps Lock key hard in your key board.
    2. Put your code between tags for better readability.
    3. When you have a where clause, why do you want to go for if clause? as in
    [code]
    update <your_table> set <your_col> = <your_new_val>
               where (select count(empid) from employee) > 1
    [/code]
    is logically equivalent to your
    [code]
    if (select count(empid) from employee) > 1 then
    update statement;
    end if;
    [/code]
    -Arun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Using Select statement in IF condition?

    hi all,
    Can i use select statement in IF COndition in pl sql ?
    eg like- if( select 1 from ASD) then
    end if;

    There is no way to do any kind of select statement inside if conditions.
    Why don't test simple cases like this first?
    An example to show it.
    SQL> begin
      2   if exists (select 1 from dual) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if exists (select 1 from dual) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 5:
    PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL
    statement only
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignored
    SQL> begin
      2   if ( (select count(*) from dual) > 0 ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( (select count(*) from dual) > 0 ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 8:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternativ
    ORA-06550: line 2, column 33:
    PLS-00103: Encountered the symbol ")" when expecting one of the following:
    . , @ ; for <an identifier>
    <a double-quoted delimited-identifier> group having intersect
    minus order partition start subpartition union where connect
    SQL> begin
      2   if ( 0 in (select count(*) from dual) ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( 0 in (select count(*) from dual) ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 12:
    PLS-00405: subquery not allowed in this context
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignoredBye Alessandro

  • Select statement in if/else condition

    Hi i need to write a select statement in the if condition in pl/sql how can i write this
    example :
    if field_name not in (select statement) then
    Is this type of if condition is possible in pl/sql?
    thanks in advance for help.

    Qwerty wrote:
    here pick a job example salesman for ename ward, now i want to compare this job that is "salesman" with all the jobs which are before it. that is clerk in line 1 and salesman in line 2Define "before it". There is no order in relational tables. Only ORDER BY means ordered sets. Therefore there is no before/after without ORDER BY. Assuming ORDER BY empno, job count of same job title before empno:
    select  ename,
            job,
            count(*) over(partition by job order by empno) - 1 same_job_count_before_empno
      from  emp
    ENAME      JOB       SAME_JOB_COUNT_BEFORE_EMPNO
    SCOTT      ANALYST                             0
    FORD       ANALYST                             1
    SMITH      CLERK                               0
    ADAMS      CLERK                               1
    JAMES      CLERK                               2
    MILLER     CLERK                               3
    JONES      MANAGER                             0
    BLAKE      MANAGER                             1
    CLARK      MANAGER                             2
    KING       PRESIDENT                           0
    ALLEN      SALESMAN                            0
    ENAME      JOB       SAME_JOB_COUNT_BEFORE_EMPNO
    WARD       SALESMAN                            1
    MARTIN     SALESMAN                            2
    TURNER     SALESMAN                            3
    14 rows selected.To find job count of same job title as Ward has before Ward (by empno):
    SELECT  same_job_count_before_empno
      FROM  (
             select  ename,
                     count(*) over(partition by job order by empno) - 1 same_job_count_before_empno
               from  emp
      WHERE ename = 'WARD'
    SAME_JOB_COUNT_BEFORE_EMPNO
                              1SY.

Maybe you are looking for

  • Stock Aging Analysis Report by Serial Number

    Hi Experts, Is it right to create a Stock Analysis Report for all materials based on Serial Numbers? Because I have now developed a Stock Aging Report which will display the values of stock aging based on Goods Receipt created however, when I base it

  • Signature problem - adding symbols to some messages

    I have a user who will sometimes have a > in front of each line in her signature. I've been able to determines it only happens when replying to Plain Text messages - other formats are fine. Any suggestions?

  • AirPort Express DHCP Server for distribution of IP-addresses?

    Does the AirPort Express have an DHCP server that distribute local IP-addresses like other Wi-FI router does? If so, how do I set it up in the AirPort Utillity?

  • Weblogic 6.0 sp2: War deployment not working !!

    Hi, I'm using weblogic 6.0 sp2, and it seems as though the war deployment is not working. My war consists of jsps, images, and under the WEB-INF/classes directory, Struts classes (i.e. Form and Action classes). When I try to run a jsp, i get the foll

  • Dynamic vi loading - Error code 7

    Being a novice, I've been cracking my head over getting a VI I've created to run dynamically. All I get is Error code 7. Does anyone know what that means, and where i can find the interpretations for these error codes in the future? Thank you very mu