Select fields from Table PA0001 where condition in PA0000 EQ X.

I'm quite new here at SDN an to ABAP as my code below will show.  =)
I have two tables PA0001 and PA0000 and I want to show the PERNR from Table PA0001 WHERE PA0000-stat2 EQ '3'.
SELECT PERNR STAT2 FROM pa0000 INTO CORRESPONDING FIELDS OF TABLE it_act WHERE stat2 EQ '3'.    "this works fine
SELECT * FROM pa0001 INTO TABLE it_pos.
LOOP AT it_pos INTO wa_pos WHERE It_pos-pernr EQ it_act-pernr.                
WRITE......
ENDLOOP.
Isn't it possible to put the conditions in the LOOP statement? Should i somehow do i join in the select instead?
If you dont understand what I mean just ask and I will try to explain.
Best Regards Claes.

Hi Claes Widestadh ,
I have total Code for you, to solve your Problem, I have written the code for you & tested it, and it was Working Very Fine.
Please find the Below Code.
TABLES : PA0000, PA0001.
DATA : IT_PA0000 LIKE PA0000 OCCURS 0 WITH HEADER LINE,
       IT_PA0001 LIKE PA0001 OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF IT_FINAL OCCURS 0,
       PERNR LIKE PA0001-PERNR,
       END OF IT_FINAL.
SELECT PERNR STAT2 INTO CORRESPONDING FIELDS OF TABLE IT_PA0000 FROM
PA0000 WHERE STAT2 = '3'.
SELECT * FROM PA0001 INTO TABLE IT_PA0001.
SORT IT_PA0001.
LOOP AT IT_PA0000.
  READ TABLE IT_PA0001 WITH KEY PERNR = IT_PA0000-PERNR.
  IF SY-SUBRC = 0.
    IT_FINAL-PERNR = IT_PA0001-PERNR.
    APPEND IT_FINAL.
    CLEAR IT_FINAL.
  ENDIF.
ENDLOOP.
LOOP AT IT_FINAL.
  WRITE :/ IT_FINAL.
ENDLOOP.
Note: If you find this Answer is very Helpful Please allot me the Points.
Please do let me know any isssues at your end.
Thanks,
Satya Krishna.M

Similar Messages

  • Selecting records from table A where A.date = max of date from table B

    Hi,
    I am new to OBIEE, How can I build the following Oracle query in OBIEE....
    select a.F1, a.F2, a.F3, a.date
    from Table1 a
    where a.date in
    (select max(b.date) from Table2 b where
    b.F1 = a.F1
    GROUP BY by b.F1)
    I tried Rank, Top, Aggregate however did not get the desired result.
    Thanks, Rohit

    You can create another request and use the results of that request as a Subquery in the filtering of the master request.

  • Probel while selecting data from table

    Hi,
      As per my below code i want to select data from table AFKO  where  PLNBEZ = it_mat-matnr, and  GETRI  IS BLANK , but data is not comingin IT_AFKO
    **********************CODE
    select AUFNR RSNUM GAMNG PLNBEZ From AFKO into table it_afko for all entries in it_mat
                                                              where PLNBEZ = it_mat-matnr
                                                                and GETRI =  '  '.
    regards,
    zafar

    Hi,
    Try below code
    select AUFNR RSNUM GAMNG PLNBEZ From AFKO into table it_afko for all entries in it_mat
    where PLNBEZ = it_mat-matnr
    and GETRI = '00000000'.
    Hope you need the records for which GETRI is not updated.
    Regards
    Vinod

  • Update PRODH field from table T179T

    hi,
    i want to update PRODH field from table T179T into table VBRP. for this we
    need to take selection option also.
    selection option will be :
    ·             Sales Organization (field VBRK-VKORG)
    ·       Billing Date Range (VBRK-FKDAT)
    ·       Distribution Channel (Vbrk-vtweg
    while i have done this for one field by using hard code but like:
    TABLES: VBRP.
    CLEAR VBRP.
    UPDATE VBRP SET PRODH = 'PLC01' WHERE VBELN = '0008300051'.
    SELECT SINGLE * FROM VBRP WHERE VBELN = '0008300051'.
    WRITE: VBRP-VBELN,VBRP-PRODH.
    but this is not the right way. please guide me how to solve this.

    TABLES: VBRP.
    CLEAR VBRP.
    UPDATE VBRP SET PRODH = 'PLC01' WHERE VBELN = '0008300051'.
    <b>commit work.</b>
    SELECT SINGLE * FROM VBRP WHERE VBELN = '0008300051'.
    WRITE: VBRP-VBELN,VBRP-PRODH.
    use commit work after update statement.
    But this code would make vbrp-vbeln as plc01 only.
    If you want to get the prodh value from t179t, then write a sleect on t179t and then update.
    TABLES: VBRP.
    CLEAR VBRP.
    select single prodh
      from t179t
    where......
    UPDATE VBRP SET PRODH = t179-prodh WHERE VBELN = '0008300051'.
    commit work.
    SELECT SINGLE * FROM VBRP WHERE VBELN = '0008300051'.
    WRITE: VBRP-VBELN,VBRP-PRODH.

  • Select data from table not in another table

    Hi,
    I want to select data from table A which is not in table B.
    Currently I am doing:
    select
    snoA,
    nameA,
    dobA
    from A
    where snoA not in
    (select snoB from A, B
    where snoA = snoB
    and nameA = nameB)
    But above is very slow.
    Can I do something like:
    select
    snoA,
    nameA,
    dobA
    from A, B
    where
    EXCLUDE ( snoA = snoB and nameA = nameB)
    Please note that I need the where condition on both the columns.
    any help will be appreciated.
    -- Harvey

    What are the approximate data volumes in A and B?
    What is "very slow"?
    What version of Oracle?
    What is the query plan?
    Without knowing anything about your system, my first thought would be to see if a NOT EXISTS happened to be faster for your data
    SELECT snoA,
           nameA,
           dobA
      FROM a
    WHERE NOT EXISTS (
        SELECT 1
          FROM b
         WHERE a.snoA = b.snoB
           AND a.nameA = b.nameB )Of course, I'm not sure why you are joining A & B in your NOT IN subquery. It would seem like you would just need a correlated subquery, i.e.
    SELECT snoA,
           nameA,
           dobA
      FROM a
    WHERE snoA NOT IN (
        SELECT snoB
          FROM b
         WHERE a.snoA = b.snoB
           AND a.nameA = b.nameB )That should be more efficient than the original query. The NOT EXISTS version may or may not be more efficient than the NOT IN depending on data volumes.
    Justin

  • Add Fields from table ADRC (Fields Name 1 to 4) for Open Item Processing

    Hi SAP Expert:
    Our client requires vendor/customer name to be displayed in the open item processing line layout for transaction code f-58, so they can double check if the vendor name is complete as intended. 
    We intend to add fields from table ADRC instead of REGUH since the characters in maintaining vendor/customer name is 40 characters and REGUH - ZNME1s are only 35 characters. 
    We have managed to add fields from ADRC and change the SAPDF05X program and were able to display the names in open item layout, except that the program seems to "automatically" create a generic table which only carries 30 characters of the vendor/customer name.  The source table should be RFOPS_DK but the program automatically looks up from table RFOPS_GEN for the particular fields - Name 1 to 4.  Is there a way to "instruct" the program to use RFOPS_DK instead of RFOPS_GEN?
    Hope this will merit somebody's attention... Thanks !!!

    Thanks,  i have assigned the layout via o7v3,  it is the program that i have a problem with,  actually another program that we change is the program MF05BFPO where it generates data to be displayed in the FBZ4 screen,  though we add a field with 40 characters (ADRC Name 1 to 4)  what the program dispalys is a 30 character Name1 to 4 from structure RFOPS_GEN. 
    My question is can i extend/change the structure RFOP_GEN to 40 characters,  is there any SAP standard program that will aftected if i do so?  thank very much...
    Lorena

  • Select values from table%ROWTYPE variable into a cursor

    I have a stored procedure which has an OUT parameter of table1%ROWTYPE.
    In future we might have to add more OUT parameters of table2%ROWTYPE etc. But at any point of time only one will have values.
    So instead of having table%ROWTYPE as OUT parameter, can I send these single row ( with variable values) in a cursor, so that declaration part atleast will not change.
    Is it possible to select values from table%ROWTYPE variable into a cursor.
    cursorOUT IS
    SELECT * FROM varREC;
    where varREC is table.ROWTYPE variable.
    Or which is the better solution in this situation.
    Thanks.

    SQL> var a refcursor
    SQL> declare
      2   bb emp%ROWTYPE;
      3  begin
      4   select * into bb from emp where rownum = 1;
      5   open :a for select bb.ename ename, bb.empno empno from dual;
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> print a
    ENAME                                 EMPNO
    SMITH                                  7369Rgds.

  • How to hide a field from table maintenance view?

    Hi,
    How to hide a field from table maintenance view? 
    The field is used for data created date. I need to hide it from display.
    Thanks

    Chk this link.
    http://help.sap.com/saphelp_nw04/helpdata/en/66/33f52010dd11d6999300508b5d5211/frameset.htm
    Maintenance Attributes
    You can assign a maintenance attribute P to individual fields in the maintenance view definition in the Dictionary (SE11). It can be  H (hidden)
    H (hidden)
    A field flagged H is not displayed on the screen. This field must also be filled in the background by a routine at an event.
    The system writes R and H fields to the database like all other fields when a new data record is saved.

  • Select count(*) from table in oracle 11g with direct path read takes time

    select count(*) from table takes long time, even more than couple of hours..
    direct path read is the wait event which is almost is at 99%..
    can u someone provide some info on this.. on solution.. thankx

    knowledgespring wrote:
    table has millions of records... 130 millions..
    select count(*) from BIG_SIZE_TABLE; --- executed in sql plus command prompt.
    Rows     Execution Plan
    0  SELECT STATEMENT   MODE: ALL_ROWS
    0   SORT (AGGREGATE)
    0    TABLE ACCESS   MODE: ANALYZED (FULL) OF 'BIG_SIZE_TABLE' (TABLE)
    Elapsed times include waiting on following events:
    Event waited on                             Times   Max. Wait  Total Waited
    ----------------------------------------   Waited  ----------  ------------
    SQL*Net message to client                       1        0.00          0.00
    enq: KO - fast object checkpoint                1        0.01          0.01
    Disk file operations I/O                       18        0.00          0.00
    direct path read                            58921        0.34        418.54direct path read time waited is : 58921 total time waited: 418.54
    That 418 seconds - not the hours you reported earlier. Is it possible that your connection to the database broke ?
    On a typical system, by the way, you can usually turn one direct read for tablescan into 1MB, so your scan seems to have covered about 59 GB, which seems to be in the right sort of ballpark for 130M rows.
    we have another query and when we test the query execution using v$sql, is_bind_sensitive =N, how to make is_bind_sensitive=Y all the time.. There is a hint /*+ bind_aware */ - I'd have to check whether or not it's documented at present. It might help.
    I would be interested in hearing why you think the hint should be bind sensitive when the optimizer doesn't.
    Regards
    Jonathan Lewis

  • How do I execute "Select count(*) from table " in OCI

    Hi,
    I am new to OCI and so this question may seem stupid. I would like to know how to execute the query "select count(*) from <table>" using OCI V8 functionality? Also after how do I get the result into a integer datatype? I have gone through most of the demo programs but is is of little help to me.
    Thanks in advance...
    Regards,
    Shubhayan.

    Hi,
    Here is sample code to give you some idea how to do it. If you want some more info let me know.
    Pankaj
    ub4 count;
    // Prepare the statement.
    char szQry = "SELECT count() FROM T1";
    if(OCI_ERROR == OCIStmtPrepare(pStmthp, pErrhp, (unsigned char*)szQry, strlen(szQry), OCI_NTV_SYNTAX , OCI_DEFAULT) )
         cout << "Error in OCIStmtPrepare" << endl;
         exit(1);
    // Bind the output parameter.
    OCIDefine *pDefnpp;
    if(OCI_ERROR == OCIDefineByPos ( pStmthp, &pDefnpp, pErrhp, 1,
    &count, sizeof(ub4), SQLT_INT,
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
                        OCI_DEFAULT) )
         cout << "Error in OCIDefineByPos" << endl;
         exit(1);
    if(OCI_ERROR == OCIStmtExecute(pSvchp, pStmthp, pErrhp, 1, 0, NULL, NULL, OCI_DEFAULT) )
         cout << "Error in OCIStmtExecute" << endl;
         exit(1);

  • Can a procedure select data from tables on other schemas?

    Can a procedure select data from tables on other schemas?
    If it is posible, which syntax should I use to identify the tables and schemas on the SELECT query?

    Yes , it is possible..unless the current user has the right privileges on others' db objects schema.
    Now , as regards the syntax....
    1) The more descriptive way is to use the format ... <owner_schema>.<obj_name>.
    2) If you have declared public synonyms of other schema's objects then you can refer to them as just <obj.name>.... but the <owner_schema>.<obj_name> is not wrong.
    3) If the db objects reside on another database you must have declared a db link.... then the syntax is <owner_schema>.<obj_name>@<db_link_name>.
    Regards,
    Simon

  • Select aentries from table Z-Table for all sales order line items

    Hi friends,
    can anyone please explain me about the "Select entries from table Z-Table for all sales order line items".
    Thanks.

    Moderator message - Welcome to SCN.
    But
    Moderator message - Please search before asking. Press F1 on SELECT and look at the FOR ALL ENTRIES addition. - post locked             
    Rob

  • Select data from table where field is initial

    I have table that has 10 million records.
    I want to select data from this table where certain date field is blank.
    *SELECT * FROM table*
    INTO TABLE internal table
    WHERE PSTNG_DATE = BLANK.
    Does anybody know how to select data from data base table when certain field is blank.
    I cont select all data once and delete which i dont want, the table is big, it will blow up app server.
    thanks in advance,
    Sachin
    Moderator: Pls do not lock the posting instead provide me the link, its disrespecting.

    Respect the forum rules and common sense, and you will be respected.
    "how to select data from a database table when the field is blank" is very basic, and basic questions will be locked, because they have been asked many times and you can find the answer yourself with a little effort. There is nothing disrespectful about it.
    Thread locked.
    Thomas

  • To fetch selective fields from DATABASETABLE into Internal TABLE

    Hi Friends,
    I have declared an internal table with fields for e.g. A , B , C , D.
    This does not have any records as of now.
    I have to fetch data from a DATABASE TABLE with fields A , B , X , Y , Z having records .
    I only need records for fields A B fron DB table.Can any one pls tell how can I do that with performance issues in mind as lots of records are there.
    I had written a query where:
    SELECT A B from dbtab
                        into CORRESPONDING FIELDS of table it_table.
    It_table i had defined with only two fields A B.
    Is this correct?
    Please tell wats the way to do it as I am new to ABAP.
    THANKS in ADVANCE..

    Hi.....
    What mentioned in all above answers is very helpful for ur requirement...
    and...
       Here some Steps to increase the performence of your programs...
    >Use Select Single when only one row is expected
    >Use Select Where rather than Selectu2026Check
    >Use Select with aggregate functions (SUM, MAX, MINu2026)
    >Use a View instead of nested Selects
    >Use Select column specific instead of select * for few fields
    >Use Selectu2026Into Table rather than Select...Move Corru2026Apend
    >Use Join extension with Select if possible
    >Use special operators (CO, CA, CS) rather than code your own
    >Use Delete Adjacent Duplicates rather than manual processing
    >Specify key fields for Readu2026Binary Search
    >Use Loop At Where rather than Loop Atu2026Check
    >Copy Internal Tables with TAB_DEST() = TAB_SRC()
    >Specify the sort key as restrictively as possible
    >Use Append To, Insert Into, Collect Into rather than Move
    >Compare tables with If Tab1() = Tab2()u2026
    >Use Delete ITAB Whereu2026 instead of Loop At ITAB Whereu2026Delete..
    >Use Case statements instead of If-constructions
    >Use Call Functions wisely, Performs use less memory
    >Use While instead of Do Exit
    >Use Type I for Indices
    >Keep Occurs clause realistic or use 0
    >Use COMMIT WORK as appropriate to free the Data Base and preserve work
    >
    >Avoid:
    >Using Shift inside a While-loop
    >Leaving unneeded declarations in your program
    >Using Move-corresponding for just a few fields
    >Excessive nested includes within function calls
    >Using DB field names if the value will be changed
    >Using Occurs clause if only the header is needed
    Thanks,
    Naveen.I

  • Selecting text field from table ignoring capitalization

    Hi,
    i'm doing a read on a table using select.....where text in s_text . if i want to ignore the capitalization; how to perform the read.
    for eg : if the text is saved as 'Name' and in my select criteria if i specify the selection text as 'name' it should pick up even if 'N' is not in CAPS in DB.
    Thanks,
    GV.

    Hi,
    The Function Module, STRING_UPPER_LOWER_CASE will convert your string to lower case except the first letter
    So if user input as name, after passing it to FM you will get the value as 'Name' and then you can able to check your condition
    May this will help you
    Rani

Maybe you are looking for