Select statement (new to ABAP)

Hi, I just get to know ABAP and have been studying about it. I'm practising an exercise in which i use select statement to retrieve data from many tables with the same field. The tables i use are COSS, AFVC, PRPS and IMZO with the same field OBJNR. The data i need to retrieve is POSNR from table IMZO. This is the code that i've just written. Howvever, when i execute it, it said 'Unable to interpret t_imobj-posnr'. I think the code is not right somehow. Very appreciate any guides.
REPORT  Z_IMPOS_TEST.
TABLES: coss,       "CO Object: Cost Totals for Internal Postings
        afvc,       "Operation within an order
        prps,       "WBS (Work Breakdown Structure) Element Master Data
        imzo.       "Table: CO Object - Capital Investment Prog.Pos.
TYPES: BEGIN OF st_impos,
  objnr       TYPE coss-objnr,
  gjahr       TYPE coss-gjahr,
  pspnr       TYPE prps-pspnr,
  posnr       TYPE imzo-posnr,
END OF st_impos.
DATA : st_imobj    TYPE st_impos,
       t_imobj     TYPE STANDARD TABLE OF st_impos.
*PARAMETERS: p_year TYPE coss-gjahr OBLIGATORY.
SELECT objnr gjahr
      INTO CORRESPONDING FIELDS OF st_imobj
      FROM  coss
      WHERE objnr = st_imobj-objnr
      AND  gjahr = '2007'.
   SELECT objnr
      INTO st_imobj-objnr
      FROM afvc
      WHERE projn = st_imobj-pspnr.
         SELECT objnr
         INTO st_imobj-objnr
         FROM imzo
         WHERE posnr = st_imobj-posnr.
         st_imobj-posnr = st_imobj-posnr.
         st_imobj-gjahr = '2007'.
         APPEND st_imobj TO t_imobj.
         ENDSELECT.
    ENDSELECT.
  ENDSELECT.
  WRITE: 'InvProgPosition is : '  t_imobj-posnr.

thank you everyone. I fixed most of the lines in the code. The syntac is correct now, but since i used nested select statements, it takes like FOREVER to give the output when i execute it!. Are there any other ways to make the code more effecient?
REPORT  z_impos_test.
TABLES: coss,       "CO Object: Cost Totals for Internal Postings
        afvc,       "Operation within an order
        prps,       "WBS (Work Breakdown Structure) Element Master Data
        imzo.       "Table: CO Object - Capital Investment Prog.Pos.
TYPES: BEGIN OF st_impos,
  objnr       TYPE coss-objnr,
  gjahr       TYPE coss-gjahr,
  kstar       type coss-kstar,
  projn       type afvc-projn,
  pspnr       type prps-pspnr,
  posnr       type imzo-posnr,
END OF st_impos.
data: year TYPE coss-gjahr value '2007'.
DATA: t_output  TYPE STANDARD TABLE OF st_impos WITH HEADER LINE,
      st_output TYPE st_impos,
      t_output2 TYPE STANDARD TABLE OF st_impos WITH HEADER LINE,
      st_output2 TYPE st_impos.
SELECT objnr gjahr kstar FROM coss
INTO CORRESPONDING FIELDS OF st_output
WHERE ( objnr LIKE 'NV%' OR
      objnr LIKE 'PR%' ) AND
       gjahr = year.
   SELECT SINGLE projn from afvc into CORRESPONDING FIELDS OF st_output
       WHERE objnr = st_output-objnr.
APPEND st_output to t_output.
ENDSELECT.
SORT t_output BY objnr.
DELETE ADJACENT DUPLICATES FROM t_output.
LOOP AT t_output into st_output.
SELECT objnr pspnr
       INTO CORRESPONDING FIELDS OF st_output2
       FROM prps
       WHERE objnr = st_output-objnr
       AND   pspnr = st_output-pspnr.
  SELECT SINGLE posnr from imzo into CORRESPONDING FIELDS OF st_output2
       WHERE objnr = st_output2-objnr.
APPEND st_output2 to t_output2.
ENDSELECT.
ENDLOOP.
LOOP AT t_output2 to st_output2.
WRITE:   st_output2-posnr.
ENDLOOP.

Similar Messages

  • 11gR2 SELECT statement: new syntax for specifying partition key

    I have an Oracle 11gR2 table which is interval partitioned on a single NUMBER column.
    I am trying to query a single partition using the new SELECT ... FOR ( < partition key> ) syntax.
    I keep getting an ORA-00905 error as follows, any ideas what I am doing wrong?
    SQL*Plus: Release 11.2.0.2.0 Production on Wed Dec 12 10:34:36 2012
    Copyright (c) 1982, 2010, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select * from rpt_dif_daily_instance_fact for ( 41215 )
    2 /
    select * from rpt_dif_daily_instance_fact for ( 41215 )
    ERROR at line 1:
    ORA-00905: missing keyword
    SQL> show sqlpluscompatibility
    sqlpluscompatibility 11.2.0

    Welcome to the forum!
    Thanks for providing your 4 digit Oracle version. You should always do that when you post since functionality may be different between versions.
    >
    I have an Oracle 11gR2 table which is interval partitioned on a single NUMBER column.
    I am trying to query a single partition using the new SELECT ... FOR ( < partition key> ) syntax.
    I keep getting an ORA-00905 error as follows, any ideas what I am doing wrong?
    SQL*Plus: Release 11.2.0.2.0 Production on Wed Dec 12 10:34:36 2012
    Copyright (c) 1982, 2010, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select * from rpt_dif_daily_instance_fact for ( 41215 )
    2 /
    select * from rpt_dif_daily_instance_fact for ( 41215 )
    ERROR at line 1:
    ORA-00905: missing keyword
    >
    As bencol said you are not using the new syntax. See the SQL Language doc 'partition_extension_clause' for the syntax diagram that shows the syntax options.
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm
    If you provide the partition name then the syntax is
    . . .PARTITION (partition)If you provide a partition key value the syntax is
    . . .PARTITION FOR (partition_key_value)

  • Can we use is null in our select statement in ABAP program

    hi,
    I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data. Can anyone resolve this.

    Hi,
    I think you've posted your question on the wrong forum. This is the SAP Business One development forum which is not part of ERP and doesn't include any ABAP or Netweaver programming.
    For a list of forums please see here:
    http://forums.sdn.sap.com/index.jspa
    Kind Regards,
    Owen

  • How to use  'is null' in select statement of ABAP program

    hi,
    I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data.
    SELECT * FROM mara INTO TABLE it_mara
          WHERE volum IS NULL .
    Can anyone resolve this.

    Hi PKB,
    Check the below thread for NULL and Space value in ABAP . It will help you
    NULL and Space value in ABAP
    Regards,
    Pawan

  • Code please(select statements)

    Can somebody please help me out in writing an ABAP program for the following requirement?
    Use "select" statement in your ABAP program to select the database table contents depending upon the query that user has entered at the selection screen.
    Display the selected records of database table (point 3) on the output report.
    Selection screen:
    Below are the selection screen parameters/options that you need to provide
    for the user
    1. Employee ID
    2. Employee Name (either Emp ID or name should be mandatory).
    3. Employee Dept/ Designation / joining date
    4. Another parameter should be "Age". Thus, if user enters 27 on Age field, every employee under 27 age should be displayed on the report.
    Output report:
    Employee ID with name / dept / designation / joining date and age should be displayed as details.

    This short sample program should get you started.
    report zrich_0002.
    * declare the internal table
    data: ipa0001 type table of pa0001 with header line.
    * define the selection screen
    select-options: s_pernr for ipa0001-pernr,
                    s_SNAME for ipa0001-SNAME.
    start-of-selection.
    * Select the data from database
    select * into corresponding fields of table ipa0001
                from pa0001
                        where pernr in s_pernr
                          and sname in s_sname
                          and ENDDA = '99991231'.
    * Write out the data in a list
    loop at ipa0001.
      write:/ ipa0001-pernr, ipa0001-sname.
    endloop.
    Regards,
    Rich Heilman

  • ABAP select statements takes too long

    Hi,
    I have a select statement as shown below.
    SELECT * FROM BSEG INTO TABLE ITAB_BSEG
                         WHERE  BUKRS = CO_CODE
                         AND    BELNR IN W_DOCNO
                         AND    GJAHR = THISYEAR
                         AND    AUGBL NE SPACE.
    This select statement runs fine in all of R/3 systems except for 1. The problem that is shown with this particular system is that the query takes very long ( up to an hour for if W_DOCNO consists of 5 entries). Sometimes, before the query can complete, an ABAP runtime error is encountered as shown below:
    <b>Database error text........: "ORA-01555: snapshot too old: rollback segment   
    number 7 with name "PRS_5" too small?"                                       
    Internal call code.........: "[RSQL/FTCH/BSEG ]"                              
    Please check the entries in the system log (Transaction SM21).  </b> 
    Please help me on this issue. However, do not give me suggestions about selecting from a smaller table (bsik, bsak) as my situation does not permit it.
    I will reward points.

    dont use select * ....
    instead u declare ur itab with the required fields and then in select refer to the fields in the select .
    data : begin of itab,
             f1
             f2
             f3
             f4
             end of itab.
    select f1 f2 f3 f4 ..
         into table itab
    from bseg where ...
    . this improves the performance .
    select * is not advised .
    regards,
    vijay

  • ABAP Joins or Separate select statements?

    Hi,
       I am working on a simulation of an implementation project as part of my in-house training programme. I am a rookie to ABAP and am now doing a print program that requires master data selection from tables ANLZ, LFA1, MSEG and CSKT, and also related line items from ANLA.
      As a former Java/.NET programmer I used to play with database joins. Now since ABAP joins are much simpler to use, I take the best advantage of them. For instance, in this particular program, I fetched related data from ANLZ, ANLA, LFA1 and CSKT into one internal table using a single select statement with ABAP joins.
      Now I happen to hear (in bits and pieces) that one should limit the use of nested joins to a certain extend. Instead, for the above program, I was advised to use 4 internal tables and to select data separately using FOR ALL ENTRIES. But in this case, we need to use 4 select statements, which means 4 database operations in place of just one.
      From ABAP documentation, I read that we can link upto 24 tables in a single select statement using ABAP joins.
    Can anyone clarify more about this? Which is high on performance?
    Using a single select statement using joins
    or
    Using multiple selects -- FOR ALL ENTRIES?
    Thanks and regards,
    Arun

    Hi Arun,
    you keep reading in these forums that FOR ALL ENTRIES is more performant, but this is simply not true.
    In your example, joining four tables for one DB operation is better than storing a lot of redundant data in internal tables just to perform four separate DB operations using FOR ALL ENTRIES.
    Make sure you join the tables correctly, i.e. link dependent tables giving their full primary key.
    FOR ALL ENTRIES can be used where effective join statements are not possible, e.g. when cluster tables are involved (like BSEG).
    Cheers
    Thomas
    Edit: check this out too: Inner Join or For All Entries

  • Select statement in ABAP

    Hi,
       I have a table with couple of GUID fields. Primary key is the main GUID. I have another field by name temp_guid which can have the normal guid values or 00000000000000000000000000000000. I want to write a select statement as follows:
    My table name : X
    Field required   : temp_guid
    Select temp_guid FROM X where del_ind = gc_no AND temp_guid is NOT (??)
    I dont want to select those rows where temp_guid has the value 00000000000000000000000000000000.
    I tried with IS NOT NULL. It doesnt seem to be working. Any help would be appreciated.
    thanks,
    Ashwin

    Hi,
    Declare a range.
    range r_xx for x_temp_guid.
    *population.
    r_xx-sign = 'E'.     "Exclude
    r_xx-option = 'EQ'.
    r_xx-low = '00000000000000000000000000000000'.
    append r_xx.
    *select statement
    Select temp_guid FROM X where del_ind = gc_no AND temp_guid in r_xx.
    You will get it.
    regards,
    Subbu

  • Issue with Select options in select statement - ABAP Question

    Hi
    I am facing an issue with select options. Select statement is returning sy-subrc as 4.
    I wrote the program as below:
    SELECT-OPTIONS:
    s_kunnr FOR bsad-kunnr,
    s_lifnr FOR bsak-lifnr,
    s_gjahr FOR bsad-gjahr,
    s_bukrs FOR bsad-bukrs,
    s_saknr FOR bsad-saknr,
    s_budat FOR bsak-budat.
    In start of selection I have written the select statement as
    SELECT * FROM bsak INTO TABLE lt_bsak
    WHERE bukrs IN s_bukrs AND lifnr = s_lifnr AND gjahr IN s_gjahr AND budat IN s_budat AND saknr IN s_saknr.
    In selection screen I have not entered any values and executed the program. I am not getting any result. When I debug that, sy-subrc is 4 at above select statement. But table has records.
    If am removing the "lifnr = s_lifnr " condition in select then select is returning values.
    I am not getting where I made the mistake. Please suggest.
    Thank you
    Hanu

    Hi,
    The problem here with where condition select option lifnr = s_lifnr.
    Use below select query.
    SELECT * FROM bsak INTO TABLE lt_bsak
    WHERE bukrs IN s_bukrs
        AND lifnr     IN s_lifnr
        AND gjahr   IN s_gjahr
        AND budat  IN s_budat
        AND saknr  IN s_saknr.
    s_lifnr is a select option and you are passing it as parameter lifnr = s_lifnr.
    if you want to pass this s_lifnr as single vale then pass in below mentioned way.
    lifnr = s_lifnr-low
    BR,
    Vijay

  • Problems with Hints in abap code to use an index in a Select statement

    Hi,
    I want to use an especific index in a select statement but I can´t get it. I use de next statement:
    SELECT ltaklgnum ltaktanum ltakvbeln ltaptapos ltapnltyp ltappvqui
           FROM ltak AS ltak INNER JOIN ltap AS ltap
                            ON  ltaktanum = ltaptanum
                            AND ltaklgnum = ltaplgnum
           INTO TABLE l_t_tanum_silo
           WHERE ltap~lgnum EQ ip_lgnum
             AND ltap~pquit EQ ' '
             AND ltak~lgnum EQ ip_lgnum
             AND ltak~kquit EQ ' '
             AND ltak~queue EQ ip_queue
             %_HINTS DB2 ''.
    We have DB2 for Linux Unix and Windows 9.5 as DB system.
    How can I fix this?
    Thanks a lot.
    Regards

    The DB2 for Linux Unix and Windows is coded DB6 for SAP and not DB2
    Look at the following OSS notes
    - [Note 129385 - Database hints in Open SQL|https://service.sap.com/sap/support/notes/129385]
    - [Note 150037 - Database hints in Open SQL for DB6 (DB2 for LUW)|https://service.sap.com/sap/support/notes/150037]
    - [Note 1270314 - DB6: DB2 9.5 Perf. degrad. for queries with INLIST clause|https://service.sap.com/sap/support/notes/1270314]
    - [Note 868888 - DB6: Optimization Guidelines|https://service.sap.com/sap/support/notes/868888]
    You should use a
    SELECT ltak~lgnum ltak~tanum ltak~vbeln ltap~tapos ltap~nltyp ltap~pvqui
      FROM ltak AS ltak INNER JOIN ltap AS ltap
      ON ltak~tanum = ltap~tanum
        AND ltak~lgnum = ltap~lgnum
      INTO TABLE l_t_tanum_silo
      WHERE ltap~lgnum EQ ip_lgnum
        AND ltap~pquit EQ ' '
        AND ltak~lgnum EQ ip_lgnum
        AND ltak~kquit EQ ' '
        AND ltak~queue EQ ip_queue
      %_HINTS DB6 '<IXSCAN TABLE=''LTAP'' INDEX=''"LTAP~M"'' />'.
    In note 868888 there is a sample for a join.
    SELECT A~TABSPACE
    FROM TADB6 AS A
    JOIN IADB6 AS B ON A~TABART = B~TABART
    %_HINTS DB6 '<NLJOIN><IXSCAN TABLE=''IADB6'' />'
            DB6 '<IXSCAN TABLE=''TADB6'' /></NLJOIN>'.
    Regards

  • 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.

  • SELECT statement help_HR ABAP

    Hello experts.
    i have browsed the forum about the how to solve my current issue.
    i am creating an FM where i have to update an infotype.
    here is my code:
    IF sy-ucomm EQ lc_route.
        gwa_p0490-zzeval = zneweval.                  <<<<this already has a value
    SELECT <what should i select here?>
          CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
            EXPORTING
              number             = pa0490-pernr
          IF sy-subrc EQ 0.
          CALL FUNCTION 'HR_INFOTYPE_OPERATION'
            EXPORTING
              infty                  = ???
              number                 = ???
              SUBTYPE                = ???
              record                 = ???
              operation              = ???
                IF sy-subrc EQ 0.
             ENDIF.
          ENDIF.
          CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
            EXPORTING
              number        = gwa_pa0490-pernr
          IF sy-subrc EQ 0.
          ENDIF.
        ENDLOOP.
        LEAVE TO SCREEN 0.
    ENDif.
    here's what i wanted to do:
    i have a push button with a function code: 'ROUTE', and when i clicked that one,
    infotype pa490-zzeval should be updated with the value of ZNEWEVAL.
    questions:
    1. how can i update it? whats the select statement should i use?
    2. ZNEWEVAL value is obtained and stored in P0494. how can i link these two infotypes together in order to update the other infotype?
    thanks for future responses.
    Mark

    Hi
    before that HR_INFOTYPE_OPERATION .loop at P0490.
    and give operation as mod.

  • Consolidating the SELECT Statement --- ABAP

    Hi
    I have following query & calculation in part-1. I want to change part-1 so that i could achieve the same by Part-2. I know Part-2 is not syntactically good, but any suggestion how to make Part-1 as Part-2. Thanks...
    Part-1)
    SELECT Creation_Date
                 Rcvd_Date     
        FROM ZPURCHASE
        INTO CORRESPONDING FIELDS OF TABLE ITAB
        UP TO 3 ROWS
        WHERE Customer  = '3000'
        ORDER BY Rcvd_Date DESCENDING.
        LOOP AT ITAB INTO WA.
          WRITE:/ WA-Creation_Date,
                  WA-Rcvd_Date.
        ENDLOOP.
       v_sumDays = 0.
       v_counter = 0.
       LOOP AT ITAB INTO WA.
          v_noOfDays = WA-Rcvd_Date - WA-Creation_Date.
          v_sumDays = v_sumDays + v_noOfDays.
          v_counter = v_counter + 1.
       ENDLOOP.
       v_leadTime = v_sumDays / v_counter.
    Part-2)
    SELECT SUM ( Creation_Date - Rcvd_Date     ) / COUNT(*)
        FROM ZPURCHASE
        INTO CORRESPONDING FIELDS OF TABLE ITAB
        UP TO 3 ROWS
        WHERE Customer  = '3000'
        ORDER BY Rcvd_Date DESCENDING.

    Hi
    select creation_date Rcvd_date from ZPURCHASE into table itab up to 3 rows where Customer = 3000.
    v_sumDays = 0.
    v_counter = 0.
    loop at itab into wa sort by Rcvd_date descending.
    v_noOfDays = WA-Rcvd_Date - WA-Creation_Date.
    v_sumDays = v_sumDays + v_noOfDays.
    v_counter = v_counter + 1.
    ENDLOOP.
    I think you cannot do calculations in Select statement as you have declared in PART2.
    Aggregate functions can be performed on one field or cannot do calculation other than their own functionality.
    to achieve your requirement you need to do your own calculations, As you have done in your part1.
    Please check the above code its almost dimilar to your code
    But do not use move corresponding.
    hope it make you clear.
    Thanks
    Lalit Gupta

  • Regarding Logical database and  select statement..

    Hi
    Experts.
    i would  like to  know the  diff b/w logical data base & select statement  while using report.
    wt is the use of logical databases in R/3. is there   any   advantage  used in the  reports.
    Thanks & Regards..
    Spandana.

    Dear Spandana,
      Go through the below description of LDB. I hope you wil get a fair amount of idea.
    SAP comes loaded with all the extras. Among the extras that are most helpful to IT managers are all the access routines needed to pull any business object that managers can think of out of SAP databases. However, SAP has not thought of everything where your particular applications are concerned. SAP organizes its standard database tables to service business units based on conventional business applications. Itu2019s likely your business requires something new, perhaps even something exotic. In that case, you will need to create a new database, using information from different places. Basically, you need a logical database. You need to create a virtual business data object repository consisting of a new kind of record or table that suits your purposes. In addition, the repository should be composed of information that is actually stored in a number of different locations, none of them necessarily logically associated with one another. Letu2019s take a closer look at creating logical databases.
    A case for a logical database
    Suppose my company manufactures widgets of the most obscure variety, and they are components of other widgets. I sell my widgets as raw material for the more sophisticated widgets built by others, but in some cases I actually partner with other manufacturers in creating yet another class of widget. Now, in my world, I consequently have customers who are also partners. I sell to them and I partner with them in manufacturing and distribution. Also, I need an application that uses both of these dual-use relationships.
    Essentially, I have a customer database and a partner database. Neither contains records that are structured to contain the identifying particulars of the other. Thus, I need a hybrid database that gives me tables detailing these hybrid relationships. What can I do? I can go the long way around and write a new database, pulling information from both and creating new objects with a customized program that I write by hand. However, this process is cumbersome and contains maintenance issues. On the other hand, I can use SAPu2019s logical database facility, create my logical database in a couple of minutes, and have no maintenance issues at all.
    Logical database structures
    There are three defining entities in an SAP logical database. You must be clear on all three in order to create and use one.
    u2022     Table structure: Your logical database includes data from specified tables in SAP. There is a hierarchy among these tables defined by their foreign keys (all known to SAP), and you are going to define a customized relationship between select tables. This structure is unique and must be defined and saved.
    u2022     Data selection: You may not want or need every item in the referenced tables that contributes to your customized database. There is a selection screen that permits you to pick and choose.
    u2022     Database access programming: Once youu2019ve defined your logical database, SAP will generate the access subroutines needed to pull the data in the way you want it pulled.
    Creating your own logical database
    ABAP/4 (Advanced Business Application Programming language, version 4) is the language created by SAP for implementation and customization of its R/3 system. ABAP/4 comes loaded with many predefined logical databases that can construct and table just about any conventional business objects you might need in any canned SAP application. However, you can also create your own logical databases to construct any custom objects you care to define, as your application requires in ABAP/4. Hereu2019s a step-by-step guide:
    1.     Call up transaction SLDB (or transaction SE36). The path you want is Tools | ABAP Workbench | Development | Programming Environment | Logical Databases. This screen is called Logical Database Builder.
    2.     Enter an appropriate name in the logical database name field. You have three options on this screen: Create, Display, and Change. Choose Create.
    3.     Youu2019ll be prompted for a short text description of your new logical database. Enter one. Youu2019ll then be prompted to specify a development class.
    4.     Now comes the fun part! You must specify a root node, or a parent table, as the basis of your logical database structure. You can now place subsequent tables under the root table as needed to assemble the data object you want. You can access this tree from this point forward, to add additional tables, by selecting that root node and following the path Edit | Node | Create. Once youu2019ve saved the structure you define in this step, the system will generate the programming necessary to access your logical database. The best part is you donu2019t have to write a single line of code.
    Watch out!
    The use of very large tables will degrade the performance of a logical database, so be aware of that trade-off. Remember that some tables in SAP are very complex, so they will be problematic in any user-defined logical database.
    Declaring a logical database
    Hereu2019s another surprising feature of logical databases: You do not assign them in your ABAP/4 Code. Instead, the system requires that you specify logical databases as attributes. So when you are creating a report, have your logical database identifier (the name you gave it) on hand when you are defining its attributes on the Program Attributes screen. The Attributes section of the screen (the lower half) will include a Logical database field, where you can declare your logical database.
    Logical databases for increasing efficiency
    Why else would you want to create a logical database? Consider that the logical databases already available to you begin with a root node and proceed downward from there. If the data object you wish to construct consists of items that are all below the root node, you can use an existing logical database program to extract the data, then trim away what you donu2019t want using SELECT statementsu2014or you can increase the speed of the logical database program considerably by redefining the logical database for your object and starting with a table down in the chain. Either way, youu2019ll eliminate a great deal of overhead.
    Regards
    Arindam

  • SELECT statement in FROM clause - syntax help

    Hi,
    I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.
    I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):
    *I leave the INTO itab clause out, since I only want to demonstrate the functionality
    I am trying to get.
    <b>SELECT</b> tableOne~someField
    <b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField
                                         <b>FROM</b> tab
                                         <b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo
    <b>WHERE</b> tableOnesomeField > tableTwosomeField
    like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?
    thanks and regards
    Baran

    sorry i am not enough familiar with sub queries but some error i can see which i will state here.
    1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.
    like this
    SELECT * FROM SFLIGHT
        INTO WA
        WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
    2> you cannot specify field name without into clause either you have to use
    select *  or select f1 into tab-f1  like this...
    but if you are using select * without into you have to define
    tables : dbtab.
    selec * from dbtab. like that.
    regards
    shiba dutta

Maybe you are looking for