Need to create an ABAP query on 2 tables BSIK and BSAK

Hi,
  I need to create an ABAP query which has the fields document no, doc date, amount in doc currency and some other fields from 2 tables BSIK and BSAK. Is it possible to write a single abap query to fetch the data from both the tables.
The selection screen fields are doc number, date and doc type.
  I need to display invoices for open items and cleared items together.
  Please let me know if this is possible.
Thanks and Regards,
Ajith

See if this is anything like what you need:
REPORT ztest MESSAGE-ID 00.
TABLES: bkpf, bseg.
SELECT-OPTIONS: s_bukrs FOR bkpf-bukrs,
                s_belnr FOR bkpf-belnr,
                s_gjahr FOR bkpf-gjahr,
                s_blart FOR bkpf-blart,
                s_budat FOR bkpf-budat.
DATA: BEGIN OF bkpf_int OCCURS 0.
        INCLUDE STRUCTURE bkpf.
DATA: END   OF bkpf_int.
DATA: BEGIN OF bseg_int OCCURS 0.
        INCLUDE STRUCTURE bseg.
DATA: END   OF bseg_int.
DATA: BEGIN OF bsik_int OCCURS 0.
        INCLUDE STRUCTURE bsik.
DATA: END   OF bsik_int.
SELECT  *
  FROM  bkpf
  INTO  TABLE bkpf_int
  WHERE bukrs  IN s_bukrs
    AND belnr  IN s_belnr
    AND gjahr  IN s_gjahr
    AND blart  IN s_blart
    AND bldat  IN s_budat.
SORT bkpf_int BY bukrs belnr gjahr.
SELECT  *
  FROM  bseg
  INTO  TABLE bseg_int
  FOR ALL ENTRIES IN bkpf_int
  WHERE bukrs = bkpf_int-bukrs
    AND belnr = bkpf_int-belnr
    AND gjahr = bkpf_int-gjahr
    AND koart = 'K'.
SORT bseg_int BY bukrs belnr gjahr buzei.
LOOP AT bseg_int.
  MOVE-CORRESPONDING bseg_int TO bsik_int.
  READ TABLE bkpf_int WITH KEY
    bukrs = bseg_int-bukrs
    belnr = bseg_int-belnr
    gjahr = bseg_int-gjahr
    BINARY SEARCH.
  IF sy-subrc = 0.
    MOVE-CORRESPONDING bkpf_int TO bsik_int.
    APPEND bsik_int.
  ELSE.
    MESSAGE e001 WITH 'Error during read'.
  ENDIF.
ENDLOOP.
Rob

Similar Messages

  • How to create an ABAP Query with OR logical expression in the select-where

    Hi,
    In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
    Please help me on this.. Points will be rewarded.
    Thanks a lot.
    Regards,
    Question Man

    Hi Bhupal, Shanthi, and Saipriya,
    Thanks for your replies. But that didn't answer my question.
    Bhupal,
    You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
    Shanthi,
    Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
    Saipriya,
    Like what I have said, this is a standard SAP code so we can't do your suggestion.
    I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
    Thanks a lot.
    Points will be rewarded.
    Regards,
    Question Man

  • Need to create at BEX Query to get last 30 days data.

    Hi,
    I need to create a bex query based on input date need to calculate last 30 days outstanding and 31-60 days outstanding 61-90 days outstanding 91-180 days outstanding and greater than 180 days outstanding. Please find the format of the report.Kindly help me.
                                                                                                                          Thanks & Regards,

    Based on those documents you can easily create.
    1. First create variable (Mandatory) user input
    2. Posting date is avaialble as char you will get
    3. need to calcualte difference b/w those 2 dates  you can refer below  By using replacement path we can convert both dates into get difference.
    http://www.sd-solutions.com/SAP-HCM-BW-Replacement-Path-Variables.html
    4. now need to create  Bucketing logic  formula  as per requirement above documents will give idea.

  • Need Help! Ad Hoc Query in HR Tables

    Dear Friends,
    I need to create a adhoc query for the following tables.
    PA*
    HRP1000
    HRP1001
    But I could select only PNPCE LDB... I do not know how to define one and get the information out from PA* and HRP1000 and HRP1001 info types....
    Please help.
    Thanks,
    Joy

    Hi Joydip,
    Go to transaction SQ02, from the Edit menu go to "Change Infotype Selection" step. Go to the end of the tree structure. From "Infotypes of related objects" select the respective organizational object (e.g. org unit, position) & respective relationship. When you click on these items & confirm your selection, they all apeear in the infotype tree structure at the left part of the SQ02 screen. You can use them just like other info types of PNPCE logical DB.
    Regards,
    Dilek

  • Gross Salary Report Need to develop in ABAP Query -sap-hr

    Dear Experts,
    i need to create salary report through ABAP-query.
    i have following below stops.
    1)Create user group thorugh SQ03.
    2) Having problem in creating Infosets,as i need to use PNPCE as ldb and p9001,p9002,p9008,p9000,p90402.but when i am created infoset it is showing in order p9000,p9001,p9002,p9008,p90402.and i am not finding any where join condition,how will i join these.
    Didnt find any tutorials..for HR abap-query
    please advice.
    Thanks & Regards
    Anwar

    Dear Experts,
    i need to create salary report through ABAP-query.
    i have following below stops.
    1)Create user group thorugh SQ03.
    2) Having problem in creating Infosets,as i need to use PNPCE as ldb and p9001,p9002,p9008,p9000,p90402.but when i am created infoset it is showing in order p9000,p9001,p9002,p9008,p90402.and i am not finding any where join condition,how will i join these.
    Didnt find any tutorials..for HR abap-query
    please advice.
    Thanks & Regards
    Anwar

  • Help needed on creating a SAP query

    Hi All,
    Can somebody give me the step by step procedures of creating a SAP query and Infoset.
    My requirement is to display asset master details with Asset number or Asset class as input.
    Any pointers or links to create an infoset and query will br highly helpful.
    Thanks,
    Arun

    Here are couple of fields you might be needed :
    AGKO     Cleared Accounts
    ANAR     Asset Types
    ANAT     Asset type text
    ANEK     Document Header Asset Posting
    ANEP     Asset Line Items
    ANEV     Asset downpymt settlement
    ANKT     Asset classes- Description
    ANLA     Asset Master Record Segment
    ANLB     Depreciation terms
    ANLC     Asset Value Fields
    ANLH     Main asset number
    AT02T     Transaction Activity Category- Description
    AT02A     Transaction Code for Menu TIMN
    AT10     Transaction type
    AT10T     Name of Transaction Type
    BKDF     Document Header Supplement for Recurring Entry
    BKORM     Accounting Correspondence Requests
    BKPF     Accounting Document Header
    BLPK     Document log header
    BLPP     Document log item
    BLPR     Document Log Index and Planned Order (Backflush)
    BNKA     Bank master record
    BP000     Business Partner Master (General Data)
    BPBK     Doc.Header Controlling Obj.
    BPEG     Line Item Total Values Controlling Obj.
    BPEJ     Line Item Annual Values Controlling Obj.
    BPEP     Line Item Period Values Controlling Obj.
    BPGE     Totals Record for Total Value Controlling obj.
    BPJA     Totals Record for Annual Total Controlling Obj.
    BSAD     Accounting- Secondary Index for Customers (Cleared Items)
    BSAK     Accounting- Secondary Index for Vendors (Cleared Items)
    BSAS     Accounting- Secondary Index for G/L Accounts (Cleared Items)
    BSEC     One-Time Account Data Document Segment
    BSEG     Accounting Document Segment
    BSID     Accounting- Secondary Index for Customers
    BSIK     Accounting- Secondary Index for Vendors
    BSIM     Secondary Index, Documents for Material
    BSIS     Accounting- Secondary Index for G/L Accounts
    CEPC     Profit Center Master Data Table
    CEPCT     Texts for Profit Center Master Data
    COBRA     Settlement Rule for Order Settlement
    COBRB     Distribution Rules Settlement Rule Order Settlement
    COKA     CO Object- Control Data for Cost Elements
    COSP     CO Object- Cost Totals for External Postings
    COSS     CO Object- Cost Totals for Internal Postings
    CRCO     Assignment of Work Center to Cost Center
    CSKA     Cost Elements (Data Dependent on Chart of Accounts)
    CSKB     Cost Elements (Data Dependent on Controlling Area)
    CSLA     Activity master
    FEBEP     Electronic Bank Statement Line Items
    FPLA     Billing Plan
    FPLT     Billing Plan- Dates
    GLPCT     EC-PCA- Totals Table
    KNA1     General Data in Customer Master
    KOMK     Pricing Communication Header
    MAHNV     Management Records for the Dunning Program
    REGUT     TemSe - Administration Data
    SKA1     G/L Account Master (Chart of Accounts)
    SKAT     G/L Account Master Record (Chart of Accounts- Description)
    SKB1     G/L account master (company code)
    T003T     Document Type Texts
    T007S     Tax Code Names
    T087J     Text
    TAPRFT     Text tab. for investment profile
    TKA01     Controlling Areas
    TKA09     Basic Settings for Versions
    TKVS     CO Versions
    TZB0T     Flow types text table
    TZPAT     Financial Assets Management product type texts
    VBSEGS     Document Segment for G/L Accounts Document Parking
    VTBFHA     Transaction
    VTBFHAPO     Transaction Flow
    VTBFHAZU     Transaction Activity
    VTBFINKO     Transaction Condition
    VTIDERI     Master Data Listed Options and Futures
    VTIFHA     Underlying transaction
    VTIFHAPO     Underlying transaction flows
    VTIFHAZU     Underlying transaction status table
    VTIOF     Options Additional Data
    VWPANLA     Asset master for securities

  • Need to Create delivery on the basis of sales order and schedule line

    Hi,
    I need to create delivery on for sales order which is splitted in schedule line number (ETENR).
    I am using FM RV_DELIVERY_CREATE and passing sales order number with single line item at a time for different (schedule line) VBEP-ETENR. but it is creating the delivery for all schedule line  items in first time only and in second loop it is not returing any thing even error. can any one please suggest me  urgently what can I do for it.

    Hi Ankit,
    You will have to create your own program to do this.
    There is no standard way todo this.
    Best regards,
    Ramki

  • Need to create a vertical view from horizontal table w/delimited column

    I would like to create a vertical view frm a table that has a colon delimited column.
    I can get a single row to work. I need the level to reset to 1 when the row changes.
    any Ideas? the key to the table is: sos,nr,prgm_cd,mth
    here is my select for a single row w/where clause removed:
    SELECT SOS,NR,PRGM_CD,trunc(sysdate-(30*LEVEL) , 'mm') MTH,
    ADD_MONTHS(trunc(sysdate,'q'),-3*LEVEL) QTR,
    SUBSTR(qty,
    INSTR(qty,':',1,LEVEL) +1,
    INSTR(qty,':',1,LEVEL+1) - INSTR(qty,':',1,LEVEL)-1) QTTY
    FROM (SELECT SRC_SUPL_CD SOS,APPL_PRGM_DESIG_NR,TYP_PRGM_CD,':'||PAST_PRGM_QY||':' qty from
    rssp_api_master )
    CONNECT BY LEVEL < LENGTH(qty) - LENGTH(REPLACE(qty,':'))
    ex. data
    sos nr prgm_cd qty
    aaa 3 xx 1:2:3:4:5:5
    bbb 3 xx 9:10:11:12:13
    need to look like this
    aaa 3 xx 1
    aaa 3 xx 2
    bbb 3 xx 9
    bbb 3 xx 10
    bbb 3 xx 11

    See this thread
    Re: rows into column
    Nicolas.

  • Get a summary of items by a query with 2 tables (INV1 and RIN1)

    Hi!
    I have a question about SQL-queries.
    When a customer pay an item (sum 100.- Euro), this is written in table INV1.
    SELECT T0.DocEntry, T0.ObjType, T0.DocDate, T0.ItemCode, T0.Dscription, T0.LineTotal,T0.SlpCode FROM INV1 T0
    show me all entries about all sold items. Thats fine!
    When the same customer give back some of this sold item (sum 50.- Euro), this is written in RIN1.
    SELECT T0.DocEntry, T0.ObjType, T0.DocDate, T0.ItemCode, T0.Dscription, T0.LineTotal,T0.SlpCode FROM RIN1 T0
    shows me the sum of all items that get back.
    For a statistc i want evaluate a sum of real sold items (sum of money).
    Now, i want create a query that evaluate a sum of the table INV1 and RIN1 and want show the result.
    Example for a result:
    DocEntry       ObjType       DocDate       ItemCode       Descriton       LineToal
    1       13       01.01.06       11111       ItemOne       100.- Euro
    2       14       05.01.06       11111       ItemOne       - 50.- Euro
                                              total sum:               50.- Euro
    is there a way that show me this result (query, form, etc.)?
    How can i realize it?
    Thanks a lot!
    Juergen

    I'm a SQLServer newbie from the Oracle world, so there may be a simpler way to do this, but the following will return all the data that you need, although it may not be pretty:
    SELECT 'Detail' LineType, T0.DocEntry, T0.ObjType, T0.DocDate, T0.ItemCode, T0.Dscription, T0.LineTotal,T0.SlpCode FROM INV1 T0
    union all
    SELECT 'Detail' LineType, T0.DocEntry, T0.ObjType, T0.DocDate, T0.ItemCode, T0.Dscription, T0.LineTotal,T0.SlpCode FROM RIN1 T0
    union all
    select 'Total' LineType, null DocEntry, null ObjType, null DocDate, null ItemCode, null Dscription, sum(LineTotal) LineTotal, null SlpCode from
    (SELECT T0.DocEntry, T0.ObjType, T0.DocDate, T0.ItemCode, T0.Dscription, T0.LineTotal,T0.SlpCode FROM INV1 T0
    union all
    SELECT T0.DocEntry, T0.ObjType, T0.DocDate, T0.ItemCode, T0.Dscription, T0.LineTotal,T0.SlpCode FROM RIN1 T0 ) x
    order by 1,2

  • Abap MDM API - get table fields and types

    Hi gurus,
    dealing with a simple task for my development... I need to retrieve, for a given MDM table name, a list of field's names with their data types in Value_pair format.
    Basically, this is what RETRIEVE method does; but:
    - I don't need any value; I just need to know which fields build up the table (in order to create entries for that)... Let's say that I'm interested in the CODE and the TYPE  fields of an MDM_NAME_VALUE_PAIR structure describing each field of my MDM table.
    - I can't workaround extracting a certain index (say, the first) from the table using a RETRIEVE, as the target table could also be empty.
    How to do that?
    Thanks in advance

    Hello Binori,
    Thanks a lot for the immediate reply!
    I have connected MS SQL server mgmt studio to MAP tool, as you have already mentioned!
    How do I get access to MAP's db, since I need data from MAP's db in our application db, and our application is purely java based.
    For ex: I need data of all Operating Systems, Performance metrics, Server name, Hardware Configurations etc.
    Thanks in advance,
    Sheetal 

  • Query between two tables : COAS and BPGE

    Hi,
    I want to create a Query between tables : COAS and BPGE but when i generate the Info-set the system had a problem of jointure. (the field OBJNR exist in the both)
    By this query i want to display the Order and the value of Budget
    Please Advise
    Regards

    hi..
    you can go with following type of code....
    select  coas~field1
               coas~field2
               bpge~field5
               bpeg~field6
    from    coas inner/outer join bpge
      on     coasobjnr = bpgeobjnr
    into      table t_table
    where condition
    hope this one will solve the issue
    regards

  • Assistance Needed With Creating a Dynamic Query

    I am attempting to rename several of my primary key/foreign key constraints from the default "SYS" names to something actually meaningful. I have several "semi-dynamic" queries that look something like this:
    SELECT 'ALTER TABLE L_ROLE RENAME CONSTRAINT ' || CONSTRAINT_NAME || ' TO NN_ROLE_ID; ' FROM USER_CONSTRAINTS WHERE CONSTRAINT_TYPE ='C' AND TABLE_NAME='L_ROLE' AND search_cond(constraint_name)='"ID" IS NOT NULL';
    Unfortunately, I have to capture the output of this script and run THOSE statements to get anything done.
    I would like to convert this to simply use EXECUTE IMMEDIATE or if necessary a stored procedure. Unfortunately, I'm a bit confused on what the end result would look like. Any assistance would be appreciated.
    Jason
    p.s."search_cond" is a custom function defined as follows:
    create function search_cond( p_cons_name in varchar2 ) return varchar2
    as
    l_search_condition varchar2(4000);
    begin
         select SEARCH_CONDITION into l_search_condition
         from user_constraints
         where constraint_name = p_cons_name;
    return l_search_condition;
    end;
    For some reason, just running the query outside the function doesn't work.

    OK, try this. Please note that I commented out the actual exec immediate line and instead just dbms_output the commands that will get executed. This way you can try this first to make sure it produces what you expect. Then just put the exec immediate back in when you are ready.
    DECLARE
        TYPE cur_typ IS REF CURSOR;
        v_cursor cur_typ;
        v_query VARCHAR2(1000);
        v_exec VARCHAR2(1000);
    BEGIN
        v_query := 'SELECT ''ALTER TABLE ''||uc.table_name||''  RENAME CONSTRAINT '' || uc.constraint_name ||
                          '' TO NN_''||ucc.column_name||'' '' thequery
                    FROM  user_constraints uc,
                          user_cons_columns ucc
                    WHERE uc.constraint_name = ucc.constraint_name
                    AND   uc.constraint_type =''C''
                    AND   search_cond(uc.constraint_name)=''"ID" IS NOT NULL''
                    AND   uc.constraint_name LIKE ''SYS%'' ';
        DBMS_OUTPUT.PUT_LINE(v_query);
        OPEN v_cursor FOR v_query;
        LOOP
            FETCH v_cursor INTO v_exec;
            EXIT WHEN v_cursor%NOTFOUND;
            --EXECUTE IMMEDIATE (v_exec);
            dbms_output.put_line(v_exec);
        END LOOP;
        CLOSE v_cursor;   
    END;
    /Greg

  • Need help creating large SQL query

    I am trying collect the sum of records that have a cancelled event prior to the Arrive event. The solution needs to be within the Sum function. Any ideas would be helpful
    The structure of the table is as follows
    1. Record_Num(primary): varchar
    2. Event_Type: varchar
    3. Time: timestamp
    Each record number can contain multiple events, hence the issue with specifiying the time for an event of 'Arrive' and an event of 'Canceled'
    This is part of a much bigger query, here's what that looks like:
    Select
    Sum(Case when di.calltype = 'Missed' then 1 else null end) as "Canceled Prior To Liftoff",
    Sum(Case
    when dt.eventtype = 'Canceled' Then 1
    when
    (select to_char(dt.datetimestamp, 'HH:MI:SS')
    from progpennstar.dispatchtime dt
    where Lower(dt.eventtype) in 'aborted')
    < any (select to_char(dt.datetimestamp, 'HH:MI:SS')
    from progpennstar.dispatchtime dt
    where dt.eventtype in 'Arrive Locale')
    Then 1
    Else null end) as "Canceled Enroute to Call"
    From progpennstar.dispatch di, progpennstar.dispatchtime dt
    where di.dateoftransport >= to_date('07/01/2008', 'MM/DD/YYYY') and
    di.dateoftransport <= to_date('09/30/2008', 'MM/DD/YYYY') and
    di.dispatch_id = dt.dispatch_id

    to the op: I think SomeoneElse already got the solution, I just want to add a few minor points. You can replace the ANY construct (which is rarely used) with a simple comparison. In general ANY constructs are more difficult to understand. Check if the correct logic is applied.
    SELECT SUM(CASE
                   WHEN di.calltype = 'Missed' THEN 1
                   ELSE NULL
               END) AS "Canceled Prior To Liftoff"
          ,SUM(CASE
                   WHEN dt.eventtype = 'Canceled' THEN 1
                   WHEN dt.eventtype = 'Aborted'
                   AND  exists (SELECT null
                                        FROM dispatchtime dt2
                                        WHERE dt2.eventtype IN 'Arrive Locale'
                                        AND dt2.dispatch_id = di.dispatch_id
                                        AND dt.datetimestamp < dt2.datetimestamp /* this is the new comparison */
                         THEN   1
                   ELSE  NULL
               END) AS "Canceled Enroute to Call"
    FROM   dispatch di,
           dispatchtime dt
    WHERE  di.dateoftransport >= to_date('07/01/2008', 'MM/DD/YYYY')
    AND    di.dateoftransport < to_date('09/30/2008', 'MM/DD/YYYY') /* Carefull! I changed <= to <. Do you want to include the full last day or only midnight?  */
    AND    di.dispatch_id = dt.dispatch_id;I also changed the alias of the remaining subquery so that different aliases are used.
    Edited by: Sven W. on Dec 11, 2008 1:01 PM

  • Creating a dynamic query by choosing the field and getting the report

    Hi,
    Is there a way to create a report by allowing the user to choose a field from the table and design a query based on that field.
    Ex In a table students with fields
    (StudentNo, StudentName,Age,Qualification,Hobbies, PlaceofBirth)
    Is it possible to generate a query
    select * from students where Hobbies=programming;
    where the user can be given the option of selecting the field and the value (Hobbies, programming), the query is generated for that, then the report is designed for that query. How could the query be generated?
    Regards,
    Reshma

    You sure can ;)
    Here's an example.
    You can create a JComboBox and have the different categories of hobbies in there and then use ActionListener on the JcomboBox.
    The code will be something like this
    public void actionPerformed(ActionEvent ae)
      if(ae.getSource()==combo)    //assuming the JComboBox object is combo
        String query=new String("");
        String st = combo.getSelectedItem().toString();
        Connection connection=DriverManager.getConnection("jdbc:odbc:DSN","user","password");
        Statement stmt=connection.createStatement();
        String qry="SELECT * FROM tablename WHERE hobby=";
        String query=qry+st;
        ResultSet rs=stmt.execute(query);     //Then do whatever you want with the ResultSet object
    }

  • Creating a tree query on multiple tables

    I have been reading the following article:
    http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/gennick_connectby.html#f1
    The diagram 1b that the above links to shows a local government hierrachy structure stored in multiple tables. I am having a little difficulty understanding how you would write a query (using start with connect by syntax) to get the data displayed in a tree format??
    ie: (spaces are being removed so replaced them with --)
    state1
    --county1
    --county2
    ----township1
    ----township2
    --county3
    state2
    state3
    --county3
    --county4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    hi, please post a sample data it would help us to further analyze. thanks.
    here is some example that might help
    NODE_DATA                                NODE_PAREN
    CAR                                      TRANSPORT
    PLANE                                    TRANSPORT
    BIKE                                     TRANSPORT
    TRANSPORT
    HONDA                                    CAR
    747-400                                  PLANE
    MAZDA                                    CAR
    FOOD
    FRUIT                                    FOOD
    VEGETABLE                                FOOD
    SPINACH                                  VEGETABLE
    CARROT                                   VEGETABLE
    12 rows selected.
    SQL> select substr(rpad(' ',decode(level,1,0,2,2,4),' ')||node_data,1,20) node_data
      2    from myTreeData
      3  start with node_parent is null
      4  connect by node_parent = prior node_data;
    NODE_DATA
    TRANSPORT
      CAR
        HONDA
        MAZDA
      PLANE
        747-400
      BIKE
    FOOD
      FRUIT
      VEGETABLE
        SPINACH
        CARROT
    12 rows selected.
    SQL>

Maybe you are looking for