SELECT statement (urgent!)

Could you please help me with the following statement?
The FROM clause is incorrect but i don't know what i should write.
Thank you in advance.
Maria.
DECLARE
A NUMBER;
CURSOR C1 IS
SELECT TABLE_NAME, COLUMN_NAME
FROM USER_TAB_COLUMNS
WHERE NULLABLE='N' AND TABLE_NAME LIKE 'P_%';
BEGIN
FOR i IN C1
LOOP
SELECT COUNT(*) INTO A
FROM i.TABLE_NAME
WHERE i.COLUMN_NAME IS NOT NULL;
END LOOP;
END;
/

FOR-LOOP
Whereas the number of iterations through a WHILE loop is unknown until the loop completes, the number of iterations through a FOR loop is known before the loop is entered. FOR loops iterate over a specified range of integers. The range is part of an iteration scheme, which is enclosed by the keywords FOR and LOOP. A double dot (..) serves as the range operator. The syntax follows:
FOR counter IN [REVERSE] lower_bound..higher_bound LOOP
sequence_of_statements
END LOOP;
The range is evaluated when the FOR loop is first entered and is never re-evaluated.
As the next example shows, the sequence of statements is executed once for each integer in the range. After each iteration, the loop counter is incremented.
FOR i IN 1..3 LOOP -- assign the values 1,2,3 to i
sequence_of_statements -- executes three times
END LOOP;
The following example shows that if the lower bound equals the higher bound, the sequence of statements is executed once:
FOR i IN 3..3 LOOP -- assign the value 3 to i
sequence_of_statements -- executes one time
END LOOP;
By default, iteration proceeds upward from the lower bound to the higher bound. However, as the example below shows, if you use the keyword REVERSE, iteration proceeds downward from the higher bound to the lower bound. After each iteration, the loop counter is decremented. Nevertheless, you write the range bounds in ascending (not descending) order.
FOR i IN REVERSE 1..3 LOOP -- assign the values 3,2,1 to i
sequence_of_statements -- executes three times
END LOOP;
Inside a FOR loop, the loop counter can be referenced like a constant but cannot be assigned values, as the following example shows:
FOR ctr IN 1..10 LOOP
IF NOT finished THEN
INSERT INTO ... VALUES (ctr, ...); -- legal
factor := ctr * 2; -- legal
ELSE
ctr := 10; -- not allowed
END IF;
END LOOP;
Iteration Schemes
The bounds of a loop range can be literals, variables, or expressions but must evaluate to numbers. Otherwise, PL/SQL raises the predefined exception VALUE_ERROR. The lower bound need not be 1, as the examples below show. However, the loop counter increment (or decrement) must be 1.
j IN -5..5
k IN REVERSE first..last
step IN 0..TRUNC(high/low) * 2
Internally, PL/SQL assigns the values of the bounds to temporary PLS_INTEGER variables, and, if necessary, rounds the values to the nearest integer. The magnitude range of a PLS_INTEGER is -2**31 .. 2**31. So, if a bound evaluates to a number outside that range, you get a numeric overflow error when PL/SQL attempts the assignment, as the following example shows:
DECLARE
hi NUMBER := 2**32;
BEGIN
FOR j IN 1..hi LOOP -- causes a 'numeric overflow' error
END LOOP;
END;
Some languages provide a STEP clause, which lets you specify a different increment (5 instead of 1 for example). PL/SQL has no such structure, but you can easily build one. Inside the FOR loop, simply multiply each reference to the loop counter by the new increment. In the following example, you assign today's date to elements 5, 10, and 15 of an index-by table:
DECLARE
TYPE DateList IS TABLE OF DATE INDEX BY BINARY_INTEGER;
dates DateList;
k CONSTANT INTEGER := 5; -- set new increment
BEGIN
FOR j IN 1..3 LOOP
dates(j*k) := SYSDATE; -- multiply loop counter by increment
END LOOP;
END;
Dynamic Ranges
PL/SQL lets you determine the loop range dynamically at run time, as the following example shows:
SELECT COUNT(empno) INTO emp_count FROM emp;
FOR i IN 1..emp_count LOOP
END LOOP;
The value of emp_count is unknown at compile time; the SELECT statement returns the value at run time.
What happens if the lower bound of a loop range evaluates to a larger integer than the upper bound? As the next example shows, the sequence of statements within the loop is not executed and control passes to the next statement:
-- limit becomes 1
FOR i IN 2..limit LOOP
sequence_of_statements -- executes zero times
END LOOP;
-- control passes here
Scope Rules
The loop counter is defined only within the loop. You cannot reference it outside the loop. After the loop is exited, the loop counter is undefined, as the following example shows:
FOR ctr IN 1..10 LOOP
END LOOP;
sum := ctr - 1; -- not allowed
You need not explicitly declare the loop counter because it is implicitly declared as a local variable of type INTEGER. The next example shows that the local declaration hides any global declaration:
DECLARE
ctr INTEGER;
BEGIN
FOR ctr IN 1..25 LOOP
IF ctr > 10 THEN ... -- refers to loop counter
END LOOP;
END;
To reference the global variable in this example, you must use a label and dot notation, as follows:
<<main>>
DECLARE
ctr INTEGER;
BEGIN
FOR ctr IN 1..25 LOOP
IF main.ctr > 10 THEN -- refers to global variable
END IF;
END LOOP;
END main;
The same scope rules apply to nested FOR loops. Consider the example below. Both loop counters have the same name. So, to reference the outer loop counter from the inner loop, you must use a label and dot notation, as follows:
<<outer>>
FOR step IN 1..25 LOOP
FOR step IN 1..10 LOOP
IF outer.step > 15 THEN ...
END LOOP;
END LOOP outer;
Using the EXIT Statement
The EXIT statement lets a FOR loop complete prematurely. For example, the following loop normally executes ten times, but as soon as the FETCH statement fails to return a row, the loop completes no matter how many times it has executed:
FOR j IN 1..10 LOOP
FETCH c1 INTO emp_rec;
EXIT WHEN c1%NOTFOUND;
END LOOP;
Suppose you must exit from a nested FOR loop prematurely. You can complete not only the current loop, but any enclosing loop. Simply label the enclosing loop that you want to complete. Then, use the label in an EXIT statement to specify which FOR loop to exit, as follows:
<<outer>>
FOR i IN 1..5 LOOP
FOR j IN 1..10 LOOP
FETCH c1 INTO emp_rec;
EXIT outer WHEN c1%NOTFOUND; -- exit both FOR loops
END LOOP;
END LOOP outer;
-- control passes here
Joel P�rez

Similar Messages

  • Problem in select statement(urgent)

    hi experts,
    my ztable structure is,
    year(key) customer(key) month(key) quan1 quan2 quan3
    2006       britania         01          23   12    13
    2006       britania         06          34   24    15
    2006       britania         09          45   10    22
    i want to select quan1 from the above ztable for the same customer in the same year but the maximum of month.how to do that.
    in the above data i want to select 45 for britania in 2006.
    please give me the solution.
    thanks in advance
    regards,
    Ashok.

    Hi Ashok
      Please try with code similar to this:
      select year customer max( month )
             from <ztable>
             into <itab>
             where <cond>
             group by year customer.
    Kind Regards
    Eswar

  • Urgent, SELECT statement results in error

    hi all, this is very urgent, could you guys have a look at my SELECT statement?
      SELECT vk~kunnr         "customer no
              vk~vbeln         "sales order no
              vk~audat         "date
              vk~vbtyp         "SD DOCUMENT CATEGORY
              vk~knumv         "lwk
              vp~kwmeng        "qty
              vp~matnr         "material no
              vp~posnr         "LINE ITEM
              vd~bstkd         "PURCHASE ORDER NO
    *          kv~kwert         "lwk
              FROM  vbak AS vk
              INNER JOIN vbap AS vp
              ON vk~vbeln = vp~vbeln
              INNER JOIN vbkd AS vd
              ON vk~vbeln = vd~vbeln
    *          INNER JOIN konv AS kv
    *          ON kv~knumv = vk~knumv
              INTO CORRESPONDING FIELDS OF TABLE it_so
              WHERE vk~vkorg IN s_vkorg
              AND vk~audat IN s_date
              AND vk~kunnr IN s_kunnr
              AND vp~matnr IN s_matnr
              AND vd~bstkd IN s_bstkd
              AND vk~vbeln IN s_vbeln
    *          AND kv~kschl = 'ZP00'
              AND vk~vbtyp = 'C'.
    The commented lines are the new additions that i want to add to the SELECT statement. But when i un-comment them, i get an error while activating my program. Error is as follows:
    For pooled tables, cluster tables, and project views, JOIN is not allowed: "KONV".
    Is there a way i can go around it?

    Hi,
    look at this SAP note : 550043
    Symptom
    KEPM: dump 'MESSAGE_TYPE_X' during automatic planning method execution.
    Other terms
    KEPM MESSAGE_TYPE_X transform characteristic value
    Reason and Prerequisites
    This note is related only to cases, if dump 'MESSAGE_TYPE_X' is raising
    during execution of planning method, for which is possible to define
    transformation of characteristics values i.e. Copy, Forecast, Top-Down
    distribution, Ratios and Customer Enhancement.
    Dump is raising in case, if there was defined transformation of char.
    values in parameter set definition for some characteristic. Later on,
    this characteristic was removed from planning level definition but
    characteristic wasn't removed from relevant customizing of transform
    characteristic values before.
    Solution
    Please apply attached program correction.
    Regards,
    GSR.

  • Urgent: regarding sub select statement

    I making a report in which i have to display the STOCK and i want to do the sum in a select statement of the value coming from the field AFRU-GMNGA so that i can do calculation of the value of 1st field to be subtracted from the last value of the same field .
    can anybody provide me example of it as i am currently using dis select statement:-
    SELECT AMATNR ALGORT BGMNGA BVORNR C~MEINS FROM AFPO AS A
      INNER JOIN AFRU AS B ON AAUFNR = BAUFNR
        INNER JOIN MARA AS C ON AMATNR = CMATNR
          INTO TABLE ITAB
          WHERE MTART IN MAT_TYPE AND A~MATNR IN P_MATNR .
    plzz help me out as it is really urgent to me.

    Hi,
    Go thr the below select query.
    select tvkwzwerks a350kschl a350vkorg konpkbetr
           from tvkwz inner join a350 on tvkwzvkorg = a350vkorg inner join konp
           on a350knumh = konpknumh into table itab where  tvkwz~werks = '1003'
           and a350~kschl = 'ZCPA'.
    Regards,
    vijay

  • Select statement issue--urgent

    Hi All,
    i need information regarding below select statement.
    SELECT ebelp
               ebeln
               vgabe
               SUM( menge ) AS menge
               shkzg
          FROM ekbe
          INTO TABLE t_ekbe
         WHERE ebeln EQ t_documents-ebeln
           AND ebelp EQ t_documents-ebelp
           AND ( vgabe EQ c_1
            OR   vgabe EQ c_2 )
         GROUP by ebelp ebeln vgabe shkzg.
    I am working 4.5b version now.All the data declartion is correct.This select statement goes to Dump .when ever data is selected before the select statment.
    let me any other choices to do same.its urgent.
    Thanks,
    Arnald

    Hi...Arnald..
    Try this way... Runtime error may be bcoz of the Order of fields....
    types : begin of st_ekbe,
                 EBELN TYPE EKBE-EBELN,
                 EBELPTYPE EKBE-EBELP,
                 VGABE TYPE EKBE-VGABE,
                 SHKZG TYPE EKBE-SHKZG,
                 MENGE TYPE EKBE-MENGE,
               end of st_ekbe.
    DATA: T_EKBE TYPE TABLE OF ST_EKBE.
    SELECT
    ebeln
    ebelp
    vgabe
    shkzg
    SUM( menge )
    FROM ekbe
    INTO TABLE t_ekbe
    WHERE ebeln EQ t_documents-ebeln
    AND ebelp EQ t_documents-ebelp
    AND ( vgabe EQ c_1
    OR vgabe EQ c_2 )
    GROUP by  ebeln  ebelp vgabe shkzg.
    <b>Reward if Helpful</b>

  • Select statement issue- urgent pls help

    Hi
    The following select statement is always  failed, even LIKP table has data. pls help me
      LOOP AT LT_VBRP.
        IF LV_KEEP_VGBEL <> LT_VBRP-VGBEL.
          LV_KEEP_VGBEL = LT_VBRP-VGBEL.
          CLEAR LIKP.
          SELECT single  VBELN TRAID TRATY VERUR BOLNR LFDAT
          FROM LIKP INTO
          (LIKP-VBELN,LIKP-TRAID,LIKP-TRATY,LIKP-VERUR,LIKP-BOLNR,LIKP-LFDAT)
            WHERE BOLNR = LT_VBRP-VGBEL.
          IF SY-SUBRC = 0.
            LV_ASN_FOUND = 'X'.
          ELSE.
            CLEAR LV_ASN_FOUND.
          ENDIF.
        ENDIF.
        MOVE-CORRESPONDING LT_VBRP TO LT_LIPOV.
        IF LV_ASN_FOUND = 'X'.
          LT_LIPOV-VBELN    = LIKP-VBELN.             "ASN #
          LT_LIPOV-LFDAT    = LIKP-LFDAT.
         lt_lipov-verur    = likp-verur.
          LT_LIPOV-BOLNR    = LIKP-BOLNR.             "DDL#
          LT_LIPOV-KOMAU    = LIKP-VBELN.
    get the ASN line number details.
          SELECT VBELN POSNR MATNR ERDAT LFIMG ERNAM WERKS VGBEL VGPOS FROM LIPS INTO
          TABLE LT_LIPOV
           WHERE VBELN = LIKP-VBELN.
        ELSE.
          CLEAR LT_REP-VBELN.
          CLEAR LT_REP-LFDAT.
          CLEAR LT_REP-VERUR.
          CLEAR LT_REP-BOLNR.
          LT_REP-KOMAU = LT_VBRP-VBELN.             "Inv no
          LV_MESSAGE = TEXT-504.
          PERFORM CREATE_REPORT_RECORD_LIN01.
          LT_REP-LINE_COLOUR = 'C610'.  " red Intensified
        ENDIF.
        APPEND LT_REP.
        APPEND LT_LIPOV.
        CLEAR LT_LIPOV.
        CLEAR LT_REP.
      ENDLOOP.

    Hi Kumar....
    if statement should not be like ..
    if lv_keep_vgbel lt_vbrp-vgbel.
    Should be like this  if lv_keep_vgbel = lt_vbrp-vgbel.
    and try to use work area and table to select and loop the data...
    Have YOu checked whether da data in it_vbrp...
    there few error in way You are writing...
    And one more thing in the table LIKP the field BOLNR is 35 Char and VGBEL of VBRP is 10 char ...and your are equalling that to extract the data which will not happen even..
    So before select statement change VBRP-VGBEL as 35 char varible by using like this
    data : v_vgbel type likp-bolnr.
    loop at lt_vbrp.
    if lv_keep_vgbel lt_vbrp-vgbel. " Why did you right the statement like this
        if lv_keep_vgbel = lt_vbrp-vgbel.
            clear likp.
                call function 'CONVERSION_EXIT_ALPHA_INPUT'
                  exporting
                    input  = lt_vbrp-vgbel
                  importing
                    output = v_vgbel.
                  select single vbeln traid traty verur bolnr lfdat
                                                      from likp into
                                                     (likp-vbeln,likp-traid,likp-traty,likp-verur,likp-bolnr,likp-lfdat)
                                                      where bolnr = v-vgbel.
    regards,
    sg
    Edited by: Suneel Kumar Gopisetty on May 26, 2008 4:41 AM

  • Really urgent: reagrding adding fields select statement in smart forms

    hi,
    i am working on a smart form which was made by someone else and now i have to make changes in it and now i have to add 1 field in that select statement but it is giving error even if i am storing the  variable in it and declaring it in global declarations.
    plzz help me how to overcome dis problem?

    Hi Ric,
    As u have added one more field in the select statement,
    U must modify the internal table as well.
    Now when u pass this internal table to smartform just chk the type reference of this internal table from smartform : Global Settings - Form Interface - Tables tab.
    In most of the cases its a Z-structure.
    Just add the new field in this structure as that of ur internal table in program. ( At same position..)
    For eg:
    In my program I am passing following table to smartform...
    TABLES
        I_ZEKPO                    = IT_FINAL_DATA
        I_ZADRC                    = IT_VENDOR_ADDRESS
    now in smartform form interface i have declared them as:
    I_ZEKPO             LIKE           ZEKPO     
    I_ZADRC             LIKE           ZADRC  
    here ZEKPO and ZADRC are the structures which I have created via SE11...
    So whenever I modify in the program internal table structure I need to modify respective Z-strucure as well...
    Just chk if the same thin has been already implemented by previous guy...and do the changes..
    Edited by: Dhananjay Patil on Mar 11, 2008 12:03 PM

  • Urgent help on difficult programming  required -remove select statement

    loop at zt_wbs.
      clear   zt_cobrb.
      refresh zt_cobrb.
    Select settlement rules
      select distinct anln1 anln2 from cobrb
             into corresponding fields of table zt_cobrb
             where objnr = zt_wbs-objnr and
                   perbz = 'GES'        and
                   konty = 'AN'.
        if sy-subrc = 0.
          describe table zt_cobrb lines i.
          if i = 1.
        unique settlement rule
            read table zt_cobrb index 1.
            zt_changes-equnr = zt_wbs-equnr.
            zt_changes-anln1 = zt_cobrb-anln1.
            zt_changes-anln2 = zt_cobrb-anln2.
            collect zt_changes.
          endif.
        endif.
    endloop.
    hii...i can modify the structure of table zt_cobrb  if required. please tell me a code in which i can carry my select statements outside the loop.and do the same thing.
    remember there is a distinct keyword after select statement and i have to loop at zt_wbs having one of the fields objnr.

    loop at zt_wbs.
      clear   zt_cobrb.
      refresh zt_cobrb.
    Select settlement rules
      select distinct anln1 anln2 from cobrb
             into corresponding fields of table zt_cobrb
             where objnr = zt_wbs-objnr and
                   perbz = 'GES'        and
                   konty = 'AN'.
        if sy-subrc = 0.
          describe table zt_cobrb lines i.
          if i = 1.
        unique settlement rule
            read table zt_cobrb index 1.
            zt_changes-equnr = zt_wbs-equnr.
            zt_changes-anln1 = zt_cobrb-anln1.
            zt_changes-anln2 = zt_cobrb-anln2.
            collect zt_changes.
          endif.
        endif.
    endloop.
    hii...i can modify the structure of table zt_cobrb  if required. please tell me a code in which i can carry my select statements outside the loop.and do the same thing.
    remember there is a distinct keyword after select statement and i have to loop at zt_wbs having one of the fields objnr.

  • A trouble with "LIKE" in a select statement

    Hi!
    I'm having trouble with "LIKE" in a select statement...
    With Access I can make the following and everything works well:
    SELECT name, birthday
    FROM client
    WHERE birthday LIKE '*/02/*';
    but if try to do it in my application (it uses Access), it doesn't work - I just can't understand that!!!
    In my application the "month" is always the currently month taken from the "System". Look what I'm doing...
    String query1 = "SELECT name, birthday " +
              "FROM client " +
              "WHERE birthday " +
              "LIKE '*/" +
              pMonth +
              "/*' " +
              "ORDER BY birthday ASC ";
    ResultSet rs = statement1.executeQuery(consulta1);
    boolean moreRecords = rs.next();
    The variable "moreRecords" is always "false", the query returns nothing although the table "client" has records that attend the query.
    Please, anyone can help me?! It's a little bit urgent.
    Thanks,
    Katia.

    Hi Katia,
    I'll bet the problem lies with the characters you're using to escape the LIKE clause. You're using the ones that Access likes to see, but that's not necessarily what's built into the JDBC-ODBC driver class.
    You can find out what the correct escape wildcard characters are from the java.sql.DatabaseMetaData.getSearchStringEscape() method. It'll tell you what to use in the LIKE clause.
    I'm not 100% sure about your code. It doesn't use query1 anywhere. I'd do this:
    String query = "SELECT name, birthday FROM client WHERE birthday LIKE ? ORDER BY birthday ASC";
    PreparedStatement statement = connection.createStatement(query);
    String escape = connection.getMetaData().getSearchStringEscape();
    String test = escape + '/' + pMonth + '/' + escape;
    statement.setString(1, test);
    ResultSet rs = statement.executeQuery();
    while (rs.hasNext())
    // load your data into a data structure to pass back.
    rs.close();
    statement.close();Let me know if that works. - MOD

  • Select statement in a sub routine(For Sapscript)

    Hi,
    M unable to write select statement for my reqirement in Sap-script in Sub routine.
    My requirement is 1)"Your correspondent for quality" in main window of my form.
    For dis rule is as below
    "Get the 'changed by' value resord in table QCPR field AENDERER.For the same value found in tabe USR21 fiels BNAME,pick up the PERSUNUM value.For dis PERSUNUM value, found in ADRP feild NAME_TEXT the value for "Your Correspondent for Quality".
    2) For this PERSUNUM value found in ADCP-TEL_NUMBER the vakue for "Ph".
    3)For this PERSUNUM value found in ADCP-FAX_NUMBER the vakue for "FAX".
    4For this PERSUNUM value found in ADR6-SMTP_ADDR the vakue for "EMAIL".
    Please help me out it's urgent for me.I wil b waiting 4 ur reply.

    READ TABLE in_par WITH KEY 'QCPR-AENDERER'.
      CHECK sy-subrc = 0.
      MOVE in_par-value TO V_aenderer
    .  READ TABLE in_par WITH KEY 'USR21-BNAME.
      CHECK sy-subrc = 0.
      MOVE in_par-value TO V_bname
      SELECT SINGLE persnumber addrnumber
        INTO wa_usr21-persnumber wa_usr21-addrnumber
        FROM usr21
        WHERE bname = V_bname
    and <b>check field for this</b> = V_aenderer.
      CHECK sy-subrc = 0.
      SELECT SINGLE tel_number fax_number
        INTO adcp-tel_number adcp-fax_number
        FROM adcp
        WHERE addrnumber = usr21-addrnumber
          AND persnumber = usr21-persnumber.
      CHECK sy-subrc = 0.
      READ TABLE out_par WITH KEY 'ADCP-TEL_NUMBER'.
      CHECK sy-subrc = 0.
      out_par-value = adcp-tel_number.
      MODIFY out_par INDEX sy-tabix.
      READ TABLE out_par WITH KEY 'ADCP-FAX_NUMBER'.
      CHECK sy-subrc = 0.
      out_par-value = adcp-fax_number.
      MODIFY out_par INDEX sy-tabix.
      SELECT SINGLE smtp_addr
        INTO adr6-smtp_addr
        FROM adr6
        WHERE addrnumber = usr21-addrnumber
          AND persnumber = usr21-persnumber.
      READ TABLE out_par WITH KEY 'ADR6-SMTP_ADDR'.
      CHECK sy-subrc = 0.
      out_par-value = adr6-smtp_addr.
      MODIFY out_par INDEX sy-tabix.
    Regards

  • Query in SELECT statement!!!!

    Hi all,
              I have a SELECT statement as follows:
      SELECT aguid_hi bpartner_no
      FROM crmd_link AS a
      INNER JOIN crmd_partner AS b ON bguid EQ aguid_set
      INTO TABLE p_partners
      FOR ALL ENTRIES IN i_sub_contracts
      WHERE a~guid_hi     EQ i_sub_contracts-guid
        AND a~objtype_hi  EQ '05'
        AND b~partner_fct EQ p_partner_fct.
    Please tell me if I can create a view for the above.
    Once I create a view for the above will it really boost the performance.
    Kindly reply immediately as this is bit urgent.
    Regards,
    Vijay

    hi,
    As said above view is nothing but an inner join between tables which you are already doing it in your program ... So i don't think there will be any improvement in the performance of the program ...
    Regards,
    Santosh

  • Decode in the select Statement

    Hi All,
    I am using the decode function in the select statement....but as i am using the group by in the select statement....i am not able to run the same query
    How to tackle this problem of handling the decode ....while we have group by also.
    This is bit urgent
    Thanks for your help
    Ramya

    Hi,
    Thanks for the quick reply.
    Here is the code...i have included the decode for the customer carrier code...
    SELECT c.trx_number invoice_number,
    c.trx_date invoice_date,
    ctl.sales_order_date order_date,
    c.ship_date_actual ship_date,
    c.purchase_order,
    ctl.sales_order order_number,
    olv.ordered_item item,
    msi.description item_description,
    olv.ordered_quantity quantity,
    olv.unit_selling_price unit_price,
    olv.unit_selling_price * olv.ordered_quantity amount,
    olv.tax_value,
    rc.customer_number,
    csta.customer_carrier_code,
    (SELECT decode(customer_carrier_code, NULL, 'Shipping & Handling', 'Shipping') sh
    FROM xx_cust_ship_to_addresses_v cstaa,
    ra_addresses ara
    WHERE cstaa.location_id = ad.location_id
    AND ara.location_id = ad.location_id) SH,
    rc.customer_name invoice_to_name,
    rct.name invoice_type,
    olv.sold_to,
    olv.ship_to_location,
    olv.ship_to_address1,
    olv.ship_to_address2,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -2, LENGTH(olv.ship_to_address5)) ship_to_country,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -9, 6) ship_to_postalcode,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -12, 2) ship_to_state,
    SUBSTR(olv.ship_to_address5, 1, LENGTH(olv.ship_to_address5) -15) ship_to_city,
    olv.invoice_to_address1,
    olv.invoice_to_address2,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -2, LENGTH(olv.invoice_to_address5)) invoice_to_country,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -9, 6) invoice_to_postalcode,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -12, 2) invoice_to_state,
    SUBSTR(olv.invoice_to_address5, 1, LENGTH(olv.invoice_to_address5) -15) invoice_to_city,
    olv.flow_status_code,
    olv.terms net_terms,
    olv.freight_terms_code freight_terms,
    olv.fob_point_code fob
    FROM ra_customer_trx_all c,
    ra_customer_trx_lines_all ctl,
    ra_cust_trx_types rct,
    jtf_rs_salesreps rs,
    ra_customers rc,
    ra_addresses ad,
    ra_site_uses su,
    mtl_system_items msi,
    oe_order_headers_v ohv,
    oe_order_lines_v olv,
    rcv_lot_transactions tl,
    rcv_shipment_lines sl,
    rcv_shipment_headers rsh,
    rcv_transactions rt,
    wsh_delivery_details wdd,
    xx_cust_ship_to_addresses_v csta
    WHERE to_char(ohv.order_number) = ctl.sales_order
    AND ctl.customer_trx_id = c.customer_trx_id
    AND c.cust_trx_type_id = rct.cust_trx_type_id
    AND c.org_id = rs.org_id
    AND c.primary_salesrep_id = rs.salesrep_id
    AND c.ship_to_site_use_id = su.site_use_id
    AND su.address_id = ad.address_id
    AND ad.customer_id = rc.customer_id
    AND ctl.inventory_item_id = msi.inventory_item_id
    AND ohv.header_id = olv.header_id
    AND olv.line_id = wdd.source_line_id(+)
    AND to_char(olv.line_id) = ctl.interface_line_attribute6
    AND tl.shipment_line_id = sl.shipment_line_id
    AND sl.shipment_header_id = rsh.shipment_header_id
    AND tl.transaction_id = rt.transaction_id
    AND csta.location_id = ad.location_id;
    GROUP BY c.trx_number,
    csta.customer_carrier_code,
    c.trx_date,
    c.creation_date,
    c.ship_date_actual,
    c.sold_to_customer_id,
    c.bill_to_customer_id,
    c.bill_to_site_use_id,
    c.ship_to_customer_id,
    c.ship_to_site_use_id,
    c.purchase_order,
    (SELECT decode(customer_carrier_code, NULL, 'Shipping & Handling', 'Shipping') sh
    FROM xx_cust_ship_to_addresses_v cstaa,
    ra_addresses ara
    WHERE cstaa.location_id = ara.location_id
    AND ara.location_id = ad.location_id),
    ctl.sales_order,
    ctl.sales_order_date,
    ctl.tax_rate,
    ctl.customer_trx_id,
    ctl.taxable_amount,
    rc.customer_number,
    olv.ordered_item,
    olv.unit_selling_price,
    olv.unit_list_price,
    olv.tax_value,
    olv.unit_cost,
    olv.ordered_quantity,
    rs.name,
    rc.customer_name,
    rc.customer_id,
    rc.party_id,
    rc.party_number,
    ad.address_id,
    rct.name,
    msi.description,
    olv.unit_selling_price * olv.ordered_quantity,
    c.org_id,
    ohv.header_id,
    olv.sold_to,
    olv.ship_from,
    olv.ship_to_location,
    olv.ship_to_address1,
    olv.ship_to_address2,
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -2, LENGTH(olv.ship_to_address5)),
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -9, 6),
    SUBSTR(olv.ship_to_address5, LENGTH(olv.ship_to_address5) -12, 2),
    SUBSTR(olv.ship_to_address5, 1, LENGTH(olv.ship_to_address5) -15),
    olv.invoice_to_location,
    olv.invoice_to_address1,
    olv.invoice_to_address2,
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -2, LENGTH(olv.invoice_to_address5)),
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -9, 6),
    SUBSTR(olv.invoice_to_address5, LENGTH(olv.invoice_to_address5) -12, 2),
    SUBSTR(olv.invoice_to_address5, 1, LENGTH(olv.invoice_to_address5) -15),
    olv.flow_status_code,
    olv.terms,
    olv.freight_terms_code,
    olv.shipping_method_code,
    olv.fob_point_code,
    olv.line_id,
    rsh.attribute1,
    rsh.attribute2,
    su.tax_code,
    su.ship_via,
    wdd.tracking_number
    ORDER BY invoice_number;

  • Clarification on Select statement

    Hello all,
    can u please any one tell me the solution.
    In one condition.
    i am getting the data from marc mkpf and mseg
    my requirement is
    get the material number from marc based on plant on selection screen
    get some data from mkpf table based on posting date(budat) on selection screen entered .
    then
    get the material data from mseg table based on matnr = equal to point1
                                                   mblnr = equal to point2
                                                   mjahr = equal to point2.
                                here some fields is there that equal to selection screen fields.
    for that i have written the code like this
    one way:
    select matnr
           werks
      from marc
      into table out_it_marc
    where werks in s_werks.
    sort out_it_marc by matnr werks.
    delete adjacent duplicates from out_it_marc
                        comparing matnr werks.
    loop at out_it_marc into lfl_marc.
    vr_matnr-low = lfl_marc-matnr.
    vr_matnr-sign = c_in.
    vr_matnr-option = c_eq.
    append vr_matnr.
    clear : lfl_marc.
    endloop.
    FORM get_mseg_data
                   tables i_r_matnr  structure vr_matnr
                    USING  in_it_mkpf  type t_it_mkpf
                  changing out_it_mseg type t_it_mseg.
    if not in_it_mkpf[] is initial.
    select
            MBLNR    "Number of Material Document
            MJAHR   "Material Document Year
            BWART    "Movement Type (Inventory Management)
            MATNR    "Material Number
            WERKS    "Plant
            LGORT   "Storage location
            SOBKZ    "Special Stock Indicator
            LIFNR   "Vendor's account number
            KUNNR    "Account number of customer
            DMBTR    "Amount in local currency
            MENGE    "Quantity
            MEINS    "Base Unit of Measure
            EBELN    "Purchase order number
            KOSTL    "Cost Center
            AUFNR    "Order Number
            BUKRS    "company code
            PS_PSP_PNR  "Work Breakdown Structure Element (WBS Element)
            SAKTO  "G/L account number
         from mseg
          into table out_it_mseg
        for all entries in in_it_mkpf
      where mblnr eq in_it_mkpf-mblnr
        and mjahr eq in_it_mkpf-mjahr
        and bwart in s_bwart
        and matnr in vr_matnr
        and werks in s_werks
        and kostl in s_kostl
        and ps_psp_pnr in s_pspnr.
    endif.
    but its getting dump because of so many records
    so that i have written again like this.
    FORM get_mkpf_mseg_data  USING  in_it_marc type t_it_marc
                             changing out_it_mkpf_mseg type t_it_mkpf_mseg.
    if not in_it_marc[] is not initial.
    select A~mblnr
           A~mjahr
           A~budat
           A~cpudt
           A~cputm
           A~usnam
           A~xblnr
           B~BWART    "Movement Type (Inventory Management)
           B~MATNR    "Material Number
           B~WERKS    "Plant
           B~LGORT   "Storage location
           B~SOBKZ    "Special Stock Indicator
           B~LIFNR   "Vendor's account number
           B~KUNNR    "Account number of customer
           B~DMBTR    "Amount in local currency
           B~MENGE    "Quantity
           B~MEINS    "Base Unit of Measure
           B~EBELN    "Purchase order number
           B~KOSTL    "Cost Center
           B~AUFNR    "Order Number
           B~BUKRS    "company code
           B~PS_PSP_PNR  "Work Breakdown Structure Element (WBS Element)
           B~SAKTO  "G/L account number
      INTO TABLE out_it_mkpf_mseg
      from mkpf AS A INNER JOIN MSEG AS B
      ON AMBLNR = BMBLNR
      AND AMJAHR = BMJAHR
      FOR ALL ENTRIES IN IN_IT_MARC
      WHERE B~MATNR  = IN_IT_MARC-MATNR
        AND B~WERKS  = IN_IT_MARC-WERKS
        AND A~BUDAT IN S_BUDAT
        AND B~BWART IN S_BWART
       AND MATNR  = IN_IT_MSEG-MATNR
       AND WERKS  = IN_IT_MSEG-WERKS
        AND B~KOSTL IN S_KOSTL
        AND B~PS_PSP_PNR IN S_PSPNR.
      ENDIF.
    BREAK-POINT.
    ENDFORM.                    " get_mkpf_mseg_data
    but this select statement is not working properly
    is there anyway to solve it.
    please give me the solution ASAP, its urgent.
    Thanks in advance....

    Hi bs,
    you dont\'t have to build a range table vr_matnr for the selection, you just can use for all entries. See help on WHERE-clause:
    Suppose FTAB is filled as follows:
    CARRID  CONNID
    LH      2415
    SQ      0026
    LH      0400
    SELECT * FROM sflight INTO wa_sflight
        FOR ALL ENTRIES IN ftab
        WHERE CARRID = ftab-carrid AND
              CONNID = ftab-connid AND
              fldate = '20010228'.
      free = wa_sflight-seatsocc - wa_sflight-seatsmax.
      WRITE: / wa_sflight-carrid, wa_sflight-connid, free.
    ENDSELECT.
    Cheers,
    Stefan

  • Passing of internal table values to the select statement as SETS

    Hi All,
    Is there any way that i can restrict the values of a internal table to be passed to a select statement set by set..
    say for eg: if a itab has 1000 entries i want the first 500 to be going out in a select statement as a comparision for all entries and then the next set of 500 to go out..
    Please let me know.. this is very urgent..

    <b>Appending Several Lines</b>
    You can also append internal tables to index tables using the following statement:
    APPEND LINES OF <itab1> TO <itab2>.
    This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
    When you append an index table to another index table, you can specify the lines to be appended as follows:
    APPEND LINES OF <itab1> [FROM <n1>] [TO <n 2>] TO <itab2>.
    <n 1 > and <n 2 > specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
    This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX contains the index of the last line appended. When you append several lines to a sorted table, you  must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
    Then u can use <b> FOR ALL ENTRIES</b> in select query.
    regards
    vinod

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

Maybe you are looking for

  • Report Painter - Display two characteristics on one line in lead column

    I have a requirement to produce a Report Painter report to display values by Cost Centre and Cost Element. The requesting user wants to see the Cost Centre AND Cost Element keys displayed on each row of the report, to allow for manipulation in Excel.

  • Mail Package, Mail Body with CSV Mail Attachment

    Hello Experts, I have scenario where I need to email in case XI is not able to send data to ECC system I need to send CSV file as an attachment in the email. To mail address depens on the Warehuse Number Also i need to send some data in Email body an

  • Production Planning at Moving Average Price

    We do very little manufacting, in fact, I would call it "re-packaging".  All our compnay does is take products from one package size and convert them to another package size, for example, we take bulk gallons and repackage it to 5 gallon pails.  The

  • Restore database that has mirroring enabled

    I apologize, as I'm the default SQL person now and my skill level is pretty much limited to running queries. SQL 2008 R2 We have a Test database that is mirrored and has severely outdated data. I'd like to copy the data in from a recent back up of ou

  • Soundblaster X-Fi Xtreme Microphone Buzzing Issues

    Hi there, I have just built a brand new PC with a Soundblaster X-Fi Xtreme Soundcard. Basicly the issue I have is whenever I enter a 3D program (game) the microphone I have plugged in starts giving buzzing feedback and i can hear a very faint buzzing