Need to write with single select statement

NAME
SAL
GENDER
X    10000    M
X    9000    F
Y    8000    M
Y    7000    M
Z    6000    F
Z    5000    F
A    4000    M
A    4000    F
1) How to write a query that displays the name that exist in both male and female gender. using single select statement
I tried this one
SELECT NAME FROM EMPL WHERE NAME IN (SELECT NAME FROM EMPL WHERE GENDER='F') AND GENDER='M';
It worked fine
But when i converted to single select statement it didn't work . You can find the query below. can i rewrite in any possible ways(using single select statement).
Select name from table_name where gender='M' and gender='F'
thanks in advance

If a Name does not exist with same gender
i.e
Name     Gender
X              M
X              M    
if above sceniorio not exist in ur data than following query will work
select name from table_name
group by name
having count(name) > 1

Similar Messages

  • HOW CAN I  USE MULTIPLE INNERJOINS IN A SINGLE SELECT STATEMENT?

    HI,
    I AM SHABEER AHMED,
    I AM GETTING AN ERROR WHILE I ATTEMPT TO EXECUTE A SELECT STATEMENT WITH MULTIPLE INNER JOINS . BECOZ I WANT TO FETCH ITEM DATA, PARTNER DATA  BASED ON HEADER DATA .
    THEN OF COURSE I HAVE FETCH DATA FROM VBAK VBAP VBKD SO LZ SEND ME THE SOLUTION.
    BYE

    Hi,
    1.Just see this:
    SELECT * INTO CORRESPONDING FIELD OF TABLE itab
    FROM t1 INNER JOIN t2 ON t1f4 EQ t2f4
    INNER JOIN t3 ON t2f5 EQ t3f5 AND
    t2f6 EQ t3f6 AND
    t2f7 EQ t3f7.
    2.But better to use for all entries.It increases the performance.
    FOR ALL ENTRIES
    Tabular Conditions
    The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
    SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
    <cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
    The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
    You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
    Example for ALL ENTRIES
    DATA: TAB_SPFLI TYPE TABLE OF SPFLI,
    TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT
    WITH UNIQUE KEY TABLE LINE,
    WA LIKE LINE OF TAB_SFLIGHT.
    SELECT CARRID CONNID
    INTO CORRESPONDING FIELDS OF TABLE TAB_SPFLI
    FROM SPFLI
    WHERE CITYFROM = 'NEW YORK'.
    SELECT CARRID CONNID FLDATE
    INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT
    FROM SFLIGHT
    FOR ALL ENTRIES IN TAB_SPFLI
    WHERE CARRID = TAB_SPFLI-CARRID AND
    CONNID = TAB_SPFLI-CONNID.
    LOOP AT TAB_SFLIGHT INTO WA.
    AT NEW CONNID.
    WRITE: / WA-CARRID, WA-CONNID.
    ENDAT.
    WRITE: / WA-FLDATE.
    ENDLOOP.
    INNER JOINS
    In a relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single SELECT statement, such that the data in the tables all has to meet the same conditions, using the following join expression:
    SELECT...
    FROM <tab> INNER JOIN <dbtab> AS <alias> ON <cond> <options>
    where <dbtab> is a single database table and <tab> is either a table or another join expression. The database tables can be specified statically or dynamically as described above. You may also use aliases. You can enclose each join expression in parentheses. The INNER addition is optional.
    A join expression links each line of <tab> with the lines in <dbtab> that meet the condition <cond>. This means that there is always one or more lines from the right-hand table that is linked to each line from the left-hand table by the join. If <dbtab> does not contain any lines that meet the condition <cond>, the line from <tab> is not included in the selection.
    The syntax of the <cond> condition is like that of the WHERE clause, although individual comparisons can only be linked using AND. Furthermore, each comparison must contain a column from the right-hand table <dbtab>. It does not matter on which side of the comparison it occurs. For the column names in the comparison, you can use the same names that occur in the SELECT clause, to differentiate columns from different database tables that have the same names.
    The comparisons in the condition <cond> can appear in the WHERE clause instead of the ON clause, since both clauses are applied equally to the temporary table containing all of the lines resulting from the join. However, each join must contain at least one comparison in the condition <cond>.
    Example for INNER JOINS
    REPORT demo_select_inner_join.
    DATA: BEGIN OF wa,
    carrid TYPE spfli-carrid,
    connid TYPE spfli-connid,
    fldate TYPE sflight-fldate,
    bookid TYPE sbook-bookid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY carrid connid fldate bookid.
    SELECT pcarrid pconnid ffldate bbookid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( spfli AS p
    INNER JOIN sflight AS f ON pcarrid = fcarrid AND
    pconnid = fconnid )
    INNER JOIN sbook AS b ON bcarrid = fcarrid AND
    bconnid = fconnid AND
    bfldate = ffldate )
    WHERE p~cityfrom = 'FRANKFURT' AND
    p~cityto = 'NEW YORK' AND
    fseatsmax > fseatsocc.
    LOOP AT itab INTO wa.
    AT NEW fldate.
    WRITE: / wa-carrid, wa-connid, wa-fldate.
    ENDAT.
    WRITE / wa-bookid.
    ENDLOOP.
    Regards,
    Shiva Kumar(Reward if helpful).

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • Update with a select statement

    hi experts,
    I need some help again.. :)
    I have an insert query here with a select statement.. Juz wondering how to do it in update?
    insert into newsmail_recipient
            (IP_RECIPIENTID,NF_LISTID,NF_STATUSID,D_CREATED,D_MODIFIED,C_NAME,C_EMAIL,USER_ID,NEWSMAIL_ID)
            select newsmail_recipientid_seq.nextval
              , liste
              , 1
              , sysdate
              , sysdate
              , null
              , null
              , ru.nf_userid
              , null
            from roleuser ru, unit u, userinfo ui
            where u.ip_unitid = ru.nf_unitid
            and u.ip_unitid = unit_id
            and ui.ip_userid = ru.nf_userid
            and ui.nf_statusid = 1
            and n_internal = 0
            and ui.ip_userid not in (select user_id
                                       from newsmail_recipient
                                      where user_id = ui.ip_userid
                                        and nf_listid = liste
                                        and nf_statusid = 1);let me know your thoughts.
    Regards,
    jp

    Hi,
    924864 wrote:
    ... I have an insert query here with a select statement.. Juz wondering how to do it in update?How to do what, exactly?
    MERGE can UPDATE existing rows, and INSERT new rows at the same time. In a MERGE statement, you give a table or a sub-query in the USING clause, and define how rows from that result set match rows in your destination table. If rows match, then you can UPDATE the matching row with values from the sub-query.
    Very often, MERGE is easier to use, and perhaps more efficient, than UPDATE just for changing existing rows. That is, while MERGE can do both INSERT and UPDATE, it doesn't have to . You can tell MERGE just to do one or the other if you wish.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Since you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • "Dynamic List Box with Single Selection" Survey Suite in CRM 6.0

    Hi
    I am using CRM 6.0. There in Survey Suite there are 2 answering options "Dynamic List Box with Single Selection" & "Dynamic List Box with Multiple Selection". I am able to make out, how we can assign values to this. I have seen example "Example_Dynamic_survey" also.
    I believe we have to use programming for populating this. But how do we have to carry that out.
    Thanx and Regards
    Hitesh

    Hi Hitesh,
    There is no need of programming for populating values for Answer category 'List Box with Single Selection' or 'List Box with Multiple Selection'. You have to follow the following steps to populate values for those:
    - In the Answer Category select List Box with Single Selection from drop down list
    - Then on left hand side tree, right click on Answer and select Insert Answer Option (Answer->Insert Answer Option)
    - Then on right side, provide Text for the answer (value)
    - To add more values, repeat the process Answer->Insert Answer Option and providing text for those answers in the right side.
    Similarly you can populate values for 'List Box with Multiple Selection' also.
    This has to be done in the transaction CRM_SURVEY_SUITE.
    Hope this is clear to you
    regards
    Srikantan

  • Update multiple columns with single update statement..

    HI all,
    i am reading the columns value from different table but i want to update it with signle update statement..
    such as how to update multiple columns (50 columns) of table with single update statement .. is there any sql statement available i know it how to do with pl/sql..

    As I understood, may be this. Here i am updating ename,sal, comm columns all at once.
    SQL> select * from emp where empno=7369;
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17/12/1980 12:00:00        800                    20
    SQL> UPDATE emp
      2     SET ename = lower (ename),
      3         sal = sal + 1000,
      4         comm = 100
      5   WHERE empno = 7369;
    1 row updated.
    SQL> select * from emp where empno=7369;
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 smith      CLERK           7902 17/12/1980 12:00:00       1800        100         20
    SQL> UPDATE emp
      2     SET ename = (SELECT 'ABCD' FROM DUAL),
      3         sal = (SELECT 1000 FROM DUAL),
      4         comm = (SELECT 100 FROM DUAL)
      5   WHERE empno = 7369;
    1 row updated.

  • Smart scan not working with Insert Select statements

    We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
    Can you please help us to explain this behavior?

    There is a specific exadata forum - you would do better to post the question there: Exadata
    I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
    Regards
    Jonathan Lewis

  • Copy Function with Single selection of row

    I want to copy necessary Planning items in my Input ready query from period 1 to remaining periods based on variable entries.  To achieve this I have created a copy planning function to copy amount entered in period 1 (variable) to range of posting period variable entries (e.g. 2 -12 or 6-12).
    I have created structure for GL accounts and I want to copy from period 1 to 2 - 12 for one row at a time.
    I have created WAD template, I selected in behavior section of Analysis item, single with command option and assigned Planning sequence (consisting of copy function) as command.
    On execution of WAD, I select single row in my input ready query and instead of one row getting copied over to the range of posting period, all rows consisting of Planning Items with amount are getting copied over, which I am not expecting with single selection option.
    How can I have only one row getting copied over?
    Am I am missing something?
    Your suggestions are highly appreciated.
    Regards,
    Sachin

    Hello Gregor,
    Thanks for your response.  I tried what you have suggested and also followed the documentation, not sure why it is not working as expected
    In my variable I have characterictis such as:
    Version
    Fiscal Year
    Fiscal Year Variant
    Profit Center
    In my rows:
    Planning Item
    Columns:
    Period
    Amount
    In behavior I have selected Row Selection Single.  I am using Button group and assigned following:
    Command: Execute a Planning Function -> In Data Binding -> Selection Binding -> Characteristic -> Planning Item -> Binding Type -> Item Characteristic -> Web Item Selection -> Item Binding -> Query (Analysis Item) -> Characteristic -> Planning item.
    For Variable I have defined nothing.
    Do you think my settings are correct?
    Regards,
    Sachin

  • Help needed with a SELECT statement. How can I make it run faster?

    Hi,
    not sure if my brain is just too tired but I can't seem to crack this problem today.
    Here is my scenario.
    I have 2 tables
    TABLE1 (searchId INTEGER, routeId INTEGER);
    TABLE2 (routeId INTEGER, cityId INTEGER);
    There are indexes on all 4 columns.
    (routeId on TABLE1 is a primary key).
    In the data I am using, a given search has more than 500 routes, each route has between 10 and 300 cities among more than 4000 possible different cities.
    Now, what I want to create is the list of route couple, within a certain search, that do not have a single city in common.
    That list should populate a table with the following structure
    TABLE3 (searchId INTEGER, routeId1 INTEGER, routeId2 INTEGER)
    Here is the fastest select statement I have found so far.
    SELECT :searchId, t1.routeId, t2.routeId FROM table1 t1, table1 t2
    WHERE t1.searchId=:searchId AND t2.searchId=:searchId
    AND t1.routeId>t2.routeId
    AND NOT EXISTS (
    SELECT cityId FROM table2
    WHERE routeId=t1.routeId
    INTERSECT
    SELECT cityId FROM table2
    WHERE routeId=t2.routeId);
    But it still seem really slow to me.
    Any suggestion for an improved version is welcome.
    Thanks,
    Martin.
    Title was edited by:
    user453358

    I originaly posted this thread because I tought I was missing something "obvious" that would perform better that would make my SELECT statement perform better.
    So I did not want to go as deep as using TKPROOF yet.
    Here is the statistics I gets on my statement.
      1   SELECT t1.searchId,t1.routeId, t2.routeId id2
      2      FROM table1 t1, table1 t2
      3     WHERE t1.searchid=t2.searchid
      4      AND t1.searchId=91
      5      AND t1.routeId>t2.routeId
      6      AND NOT EXISTS (
      7             SELECT cityId FROM table2
      8              WHERE routeId=t1.routeId
      9             INTERSECT
    10             SELECT cityId FROM table2
    11*            WHERE routeId=t2.routeId)
    SQL> /
    43302 rows.
    Tidsåtgång: 00:01:55.02
    Körschema
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=1 Bytes=14)         
       1    0   FILTER                                                             
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=1 Card=1 Bytes=7)                                                
       3    2       NESTED LOOPS (Cost=3 Card=1 Bytes=14)                          
       4    3         TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=2 Card=1 Bytes=7)
       5    4           INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=1 Card=1)                                                    
       6    3         INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=0 Card=1)                                                      
       7    1     INTERSECTION                                                     
       8    7       SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)                      
       9    8         TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)                                 
      10    9           INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)                                               
      11    7       SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)                      
      12   11         TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)                                 
      13   12           INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)                                               
    Statistik
              1  recursive calls                                                   
              0  db block gets                                                     
        2872765  consistent gets                                                   
              0  physical reads                                                    
            812  redo size                                                         
         964172  bytes sent via SQL*Net to client                                  
          32245  bytes received via SQL*Net from client                            
           2888  SQL*Net roundtrips to/from client                                 
         860256  sorts (memory)                                                    
              0  sorts (disk)                                                      
          43302  rows processed  Looks like a big number of consistent gets! Any idea how to improve on that?
    Martin.

  • Unable to boot normally - Always need to boot with Single User Mode

    Hi Community,
    Since last few days, I am unable to boot my Macbook Pro normally, running latest version of OS X Yosemite. When I boot, it goes to grey screen with Apple logo and progress bar, once the progress completes to 100% (after 5-10 minutes which is very longer than usual), it asks me to 'Select  language' which seems like fresh installation of OS X. In that case, when I click next and it doesn't detect my SSD (blank list of select installation disk/drive).
    After reading some threads, I found work-around and always need to boot into Single user mode (by pressing Command+S during power on) and then need to run following commands...
    /sbin/fsck -fy
    /sbin/mount -uw /
    "device is write protected" numerous times
    reboot
    and then only it loads OS X and displays login screen. This happens all the times and I need to follow above steps always to get login screen.
    How can I fix this?

    Please help me out here. I tried booting it off a USB flash drive with ATV flash but that gave me some errors and prompted me to login with username [email protected] with password frontrow
    But I am not sure how to get to login using a suitable input. I tried to telnet it using my PC over network but I dont think it has initialized anything (like wifi or network) at the prompt. Would it take USB keyboard input? All I can do is remove the power and restart it with the usb flash out and get into then get into the recovery loop. I am not sure replacing the hard-drive would help. Any help would be greatly appreciated.
    Thanks
    Sinu

  • Quick help with a select statement...

    Hello all,
    I will try to lay this out as simply as possible.  I have the following table in my code:
    TYPES: BEGIN OF ty_table,
        vbeln TYPE likp-vbeln,
        lfdat TYPE likp-lfdat,
        lfart TYPE likp-lfart,
        wadat_ist TYPE likp-wadat_ist,
        vstel TYPE likp-vstel,
        route TYPE likp-route,
        vsbed TYPE likp-vsbed,
        inco1 TYPE likp-inco1,
        inco2 TYPE likp-inco2,
        kunnr TYPE likp-kunnr,
        kunag TYPE likp-kunag,
        brgew TYPE lips-brgew,
        matnr TYPE lips-matnr,
        arktx TYPE lips-arktx,
        meins TYPE lips-meins,
        lgmng TYPE lips-lgmng,
        vgbel TYPE lips-vgbel,
        name2 TYPE adrc-name2,
        street TYPE adrc-street,
        city1 TYPE adrc-city1,
        region TYPE adrc-region,
        post_code1 TYPE adrc-post_code1,
        lifnr  TYPE lfa1-lifnr,
        name1 TYPE adrc-name1,
        so_vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
      END OF ty_table.
    DATA: it_table TYPE TABLE OF ty_table.
    I then run through a select statement as follows:
    * Get data from LIKP and LIPS.
      SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
               b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
               FROM likp AS a
                INNER JOIN lips AS b ON b~vbeln = a~vbeln
                WHERE a~vstel IN so_vstel
                AND a~wadat_ist IN so_wadat
                AND b~mtart IN so_mtart.
    That works fine.  The next statement, in the report, is the following select.  When this next select runs it clears all of the fields except for vbeln and erdat.  I want c~vbeln to go into it_table-so_vbeln.  Now it is going into it_table-vbeln.
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
          FROM lips AS a
            INNER JOIN vbap AS b ON b~vbeln = a~vgbel
            AND b~posnr = a~vgpos
              INNER JOIN vbak AS c ON c~vbeln = b~vbeln
              FOR ALL ENTRIES IN it_table
                WHERE a~vgbel = it_table-vgbel.
    I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
        FROM lips AS a
          INNER JOIN vbap AS b ON b~vbeln = a~vgbel
          AND b~posnr = a~vgpos
            INNER JOIN vbak AS c ON c~vbeln = b~vbeln
            FOR ALL ENTRIES IN it_table
              WHERE a~vgbel = it_table-vgbel.
    Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table?  Also, is there a way to combine the two selects into one join? 
    Regards,
    Davis

    Following is the entire report, if that makes it easier:
    *& Report  Z_TRANS_EVAL
    REPORT  z_trans_eval.
    TABLES: likp, lips, adrc, vbpa.
    TYPE-POOLS: truxs.
    TYPES: BEGIN OF ty_table,
        vbeln TYPE likp-vbeln,
        lfdat TYPE likp-lfdat,
        lfart TYPE likp-lfart,
        wadat_ist TYPE likp-wadat_ist,
        vstel TYPE likp-vstel,
        route TYPE likp-route,
        vsbed TYPE likp-vsbed,
        inco1 TYPE likp-inco1,
        inco2 TYPE likp-inco2,
        kunnr TYPE likp-kunnr,
        kunag TYPE likp-kunag,
        brgew TYPE lips-brgew,
        matnr TYPE lips-matnr,
        arktx TYPE lips-arktx,
        meins TYPE lips-meins,
        lgmng TYPE lips-lgmng,
        vgbel TYPE lips-vgbel,
        name2 TYPE adrc-name2,
        street TYPE adrc-street,
        city1 TYPE adrc-city1,
        region TYPE adrc-region,
        post_code1 TYPE adrc-post_code1,
        lifnr  TYPE lfa1-lifnr,
        name1 TYPE adrc-name1,
        so_vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
      END OF ty_table.
    DATA: it_table TYPE TABLE OF ty_table,
          wa_table LIKE LINE OF it_table,
          it_table_csv TYPE truxs_t_text_data.
    DATA : lv_tabix LIKE sy-tabix.
    DATA temp_string TYPE string.
    DATA w_adrnr TYPE vbpa-adrnr.
    DATA: w_adrnr_sp TYPE vbpa-adrnr.
    * Selction criteria
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
    SELECT-OPTIONS: so_vstel FOR likp-vstel,
                    so_wadat FOR likp-wadat_ist,
                    so_mtart FOR lips-mtart.
    SELECTION-SCREEN END OF BLOCK b2.
    * CSV output filename
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (16) text-002 FOR FIELD p_file.
    PARAMETERS: p_file(30) TYPE c.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b3.
    START-OF-SELECTION.
    * Get data from LIKP and LIPS.
      SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
               b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
               FROM likp AS a
                INNER JOIN lips AS b ON b~vbeln = a~vbeln
                WHERE a~vstel IN so_vstel
                AND a~wadat_ist IN so_wadat
                AND b~mtart IN so_mtart.
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
          FROM lips AS a
            INNER JOIN vbap AS b ON b~vbeln = a~vgbel
            AND b~posnr = a~vgpos
              INNER JOIN vbak AS c ON c~vbeln = b~vbeln
              FOR ALL ENTRIES IN it_table
                WHERE a~vgbel = it_table-vgbel.
    * Get internal address number for ship to party
      LOOP AT it_table INTO wa_table.
        lv_tabix = sy-tabix.    "update counter.
        SELECT SINGLE adrnr FROM vbpa INTO w_adrnr WHERE
        vbeln = wa_table-vgbel
        AND parvw = 'WE'.
        SELECT SINGLE lifnr FROM vbpa INTO wa_table-lifnr WHERE
          vbeln = wa_table-vbeln
          AND parvw = 'SP'
          AND  posnr = '000000'.
        SELECT SINGLE name1 FROM lfa1 INTO wa_table-name1 WHERE
          lifnr = wa_table-lifnr.
    * Get address data from VBPA
        SELECT city1 region post_code1 INTO CORRESPONDING FIELDS OF wa_table
        FROM adrc WHERE
        addrnumber = w_adrnr.
        ENDSELECT.
    * Update the internal table
        MODIFY  it_table INDEX lv_tabix FROM wa_table.
      ENDLOOP.
    END-OF-SELECTION.
    * Call correct display procedure(s).
      IF p_file <> ''.
    * Save a CSV file
        PERFORM display_csv.
      ELSE.
    *Display in ALV
        PERFORM display_alv.
      ENDIF.
    *&      Form  display_alv
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_alv .
      DATA: gr_alv TYPE REF TO cl_salv_table,
            gr_func TYPE REF TO cl_salv_functions,
            gr_columns TYPE REF TO cl_salv_columns_table,
            gr_column TYPE REF TO cl_salv_column_table,
            gr_error TYPE REF TO cx_salv_error.
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = gr_alv
            CHANGING
              t_table      = it_table.
        CATCH cx_salv_msg INTO gr_error.
      ENDTRY.
      gr_func = gr_alv->get_functions( ).
      gr_func->set_all( abap_true ).
      gr_alv->display( ).
    ENDFORM.                    " display_alv
    *&      Form  display_csv
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_csv .
      DATA: w_filename TYPE string.
      CONCATENATE p_file temp_string INTO w_filename.
      CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
        EXPORTING
          i_field_seperator    = ';'
        TABLES
          i_tab_sap_data       = it_table
        CHANGING
          i_tab_converted_data = it_table_csv
        EXCEPTIONS
          conversion_failed    = 1
          OTHERS               = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename = w_filename
        TABLES
          data_tab = it_table_csv
        EXCEPTIONS
          OTHERS   = 1.
      PERFORM display_alv.
    ENDFORM.                    " display_csv

  • Short dump with a select statement

    I have the following select statement (I have also inluded my data statement(s)) and I get a short dump.  The error is as follows:
    <b>What happened?                                                                 
        Error in ABAP application program.                                                                               
    The current ABAP program "ZPARTNER" had to be terminated because one of the
        statements could not be executed.                                                                               
    This is probably due to an error in the ABAP program.                                                                               
    Following a SELECT statement, the data read could not be placed in AN      
        the output area.                                                           
        A conversion may have been intended that is not supported by the           
        system, or the output area may be too small.                                                                               
    Error analysis                                                                 
        An exception occurred. This exception will be dealt with in more detail    
        below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not   
         caught, which                                                             
         led to a runtime error. The reason for this exception is:                 
        The data read during a SELECT access could not be inserted into the        
        target field.                                                              
        Either conversion is not supported for the target field's type or the      
        target field is too short to accept the value or the data are not in a     
        form that the target field can accept          </b>                            
    it_adrc TYPE TABLE OF adrc,
          wa_adrc LIKE LINE OF it_adrc,
    SELECT addrnumber name1 street city1 region post_code1 tel_number
      FROM adrc INTO TABLE it_adrc
      FOR ALL ENTRIES IN it_detail
      WHERE addrnumber = it_detail-adrnr.
    Regards,
    Davis

    If you only need the fields mentioned in the select query, then follow this:
    TYPES: BEGIN OF ADRC_TYPE,
         ADDRNUMBER LIKE ADRC-ADDRNUMBER,
         NAME1        LIKE ADRC-NAME1,
         STREET        LIKE ADRC-STREET,
         CITY        LIKE ADRC-CITY,
         REGION        LIKE ADRC-REGION,
         POST_CODE1 LIKE ADRC-POST_CODE1,
         TEL_NUMBER LIKE ADRC-TEL_NUMBER,
           END OF ADRC_TYPE,
           ADRC_T_TYPE TYPE TABLE OF ADRC_TYPE.
    DATA: IT_ADRC TYPE ADRC_T_TYPE WITH HEADER LINE.
    IF NOT IT_DETAIL[] IS INITIAL.
    SELECT addrnumber name1 street city1 region post_code1 tel_number
      FROM adrc INTO TABLE it_adrc
      FOR ALL ENTRIES IN it_detail
      WHERE addrnumber = it_detail-adrnr.
    ENDIF.
    Thanks,
    SKJ

  • How to increment variable value in single select statement

    Hi guys
    in this select statement i have hard coded date value but i need to put variable instead of hard coded date and then i want to increment that variable value till sysdate.. i have tried using curser , type tables but they are very very slow .. any experiance guys can give me good hint what should i use.
    my query
    select
    start_dt,
    end_dt,
    hi_start_dt,
    hi_end_dt,
    ph_start_dt,
    ph_end_dt,
    h_start_date,
    h_end_date,
    g_code,
    emp_det.ref,
    u_code,
    costing,
    emp_nm,
    emp_no
    from
    emp_det,
    emp_ph_det,
    emp_hi_det,
    emp_h_det
    where
    emp_det.ref(+) = emp_ph_det.ref
    and emp_hi_det.p_ref(+) = emp_ph_det.p_ref
    and emp_h_det.ph_ref = emp_ph_det.ph_ref
    and emp_h_det.ph_st_dt(+) = emp_hi_det.st_date;
    and to_date('01-MAR-2008') between i.start_dt and nvl(i.end_dt, to_date('01-MAR-2008') +1)
    and to_date('01-MAR-2008') between i.hi_start_dt and nvl(i.hi_end_dt, to_date('01-MAR-2008') + 1)
    and to_date('01-MAR-2008') between i.ph_start_dt and nvl(i.ph_end_dt, to_date('01-MAR-2008') + 1)
    and to_date('01-MAR-2008') between i.h_start_date and nvl(i.h_end_date, to_date('01-MAR-2008') + 1)
    or
    (----emp has left this month
    i.start_dt < i.emp_end_dt
    and i.end_dt between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
    and i.hi_start_dt < i.hi_end_dt
    and i.hi between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
    and i.ph_start_dt < i.ph_end_dt
    and i.ph_end_dt between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
    and i.h_start_date < i.h_end_date
    and i.h_end_date between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')

    Hi Anurag
    Thanks for the reply.please find my sample data below . below i am only showing data for one employee only.. i want to write a query where i will query for a month like march 2008 and then i need to find out the record for employe where this month march 2008 is between all the start and end dates like it should be between start_dt and end_dt and h_start_date and h_end_date and hi_strt_dt and hi_end_dt and ph_start_dt and ph_end_dt and where all the combination are true show me that record only .. i don't want any other record.
    h_start h_end_
    start_dt      end_dt     date        date          histrt_dt hi_end_dt ph_start_dt ph_end_dt
    1-Sep-07     31-Dec-08     8-Feb-08     31-Aug-08     1-Sep-07     31-Dec-07     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     1-Sep-07     31-Dec-07     1-Sep-07     31-Dec-07     1-Sep-07     31-Dec-07
    1-Sep-07     31-Dec-08     1-Sep-08     31-Dec-08     1-Sep-07     31-Dec-07     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     8-Feb-08     31-Aug-08     1-Aug-08     31-Aug-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     1-Sep-07     31-Dec-07     1-Aug-08     31-Aug-08     1-Sep-07     31-Dec-07
    1-Sep-07     31-Dec-08     1-Sep-08     31-Dec-08     1-Aug-08     31-Aug-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     8-Feb-08     31-Aug-08     1-Oct-08     31-Dec-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     1-Sep-07     31-Dec-07     1-Oct-08     31-Dec-08     1-Sep-07     31-Dec-07
    1-Sep-07     31-Dec-08     1-Sep-08     31-Dec-08     1-Oct-08     31-Dec-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     8-Feb-08     31-Aug-08     1-Sep-08     30-Sep-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     1-Sep-07     31-Dec-07     1-Sep-08     30-Sep-08     1-Sep-07     31-Dec-07
    1-Sep-07     31-Dec-08     1-Sep-08     31-Dec-08     1-Sep-08     30-Sep-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     8-Feb-08     31-Aug-08     8-Feb-08     31-Jul-08     8-Feb-08     31-Dec-08
    1-Sep-07     31-Dec-08     1-Sep-07     31-Dec-07     8-Feb-08     31-Jul-08     1-Sep-07     31-Dec-07
    1-Sep-07     31-Dec-08     1-Sep-08     31-Dec-08     8-Feb-08     31-Jul-08     8-Feb-08     31-Dec-08

  • Need to fetch only the select statement

    Hi ,
    I am able to fetch all the select statements from my program if program name as my input.
    I want only the select statement where we fetch the field entries like
    select single from mara
    select * from mara
    select count(*)
    select matnr from mara
    like this i want to fetch i dont want to display the select-options or start-of-selection .

    Hello Shwetha
    If the function module <b>RS_PROGRAM_TABLES</b> (function group <b>SEA1</b>) is available on your system you can run this fm with the following parameters:
    - OBJECT_TYPE = 'TRAN'   " transaction
    - OBJECT_NAME = 'VA03'  " example
    - OBJECT_TYPE = 'PROG'   " report
    - OBJECT_NAME = 'SAPMV45A'  " example: report executed by VA03
    The fm returns you a list of tables that are accessed.
    Regards,
      Uwe

  • Where all we not needed  ENDSELECT ... in select statements.

    explain the scenarios...

    Hi,
    It is always advised to avoid using ENDSELECT statment and it can be avoided also.
    For example:
    when you want to get data into internel table with a SELECT query, use <b>TABLE</b> keyword before internal table name.
    OR if you want to get data into a work area then,
    Use <b>SELECT SINGLE</b> statment.
    Regards,
    Amit

Maybe you are looking for

  • Download ISO for windows 8.1 pro ?

    I am setting up a new computer and I have the key to Windows 8.1 Pro. And I will be needing an ISO file for installation because it is a new PC with nothing installed on it. Cannot find a legal link or option to download with a key. Kindly help.

  • How do you connect iMovie to a projector?

    I have no problem with keynote, it connects easily to a projector, but I do not find a way for iMovie Help please

  • Ipad and Laptop yearly service

    Who do I talk to at Apple. When I bought my ipad and laptop nobody asked me if I wanted to join the Apple training system yearly. I understand you can only sign up when you buy them but was not aware of that and was not asked.

  • IMovie 5.0.2 Cannot See Canon DV Camera

    Running iMovie HD 5.0.2. Previous version of iMovie 4 worked fine with my Canon ZR300 DV camera. Now, iMovie says no camera attached. Connected vi USB. Have tried every combination of powering on and plugging. in. Thoughts anybody?

  • Remote Service - Configuring Destination - Scope attribute

    I want to clarify my understanding that destination of Remoting Service if configured as "request" scope is safe to use in load balancer (having no session stickiness) with multiple web servers. Pls. note that there is no state maintained at server s