Problem in the select query

Hi.
here i have to make the code in exit_saplv56u_004 in include zxv56u11.
there are tables defined in itself.
i have written like this,but not sure about the table updation and the declaration part:
here i am writing this code in exit_sap
  TABLES:VTTP,VTTK,LIKP,KNA1.
  TABLES:ZOTC_SHPMNT_RTE.
  DATA:x_vttp type vttpvb,
       x_vttk type vttkvb,
       X_LIKP TYPE LIKP,
       X_KNA1 TYPE KNA1,
       X_ZOTC_SHPMNT_RTE TYPE ZOTC_SHPMNT_RTE,
       t_temp type vttk,       feels that declaration iswrong
       x_temp type vttk.      this table andwork area will be used to finally update vttk table feilds
  READ TABLE I_XVTTK INTO X_VTTK INDEX 1.
  READ TABLE I_XVTTP INTO X_VTTP INDEX 1.
CLEAR X_LIKP.
  SELECT SINGLE *     FROM LIKP
                      INTO X_LIKP
                      WHERE VBELN = X_VTTP-VBELN.
    IF SY-SUBRC = 0.
      CLEAR X_KNA1.
  SELECT SINGLE * FROM KNA1              i jus need 2-3 feilds so howcan i avoid the performance prob
       INTO X_KNA1
    WHERE KUNNR = X_LIKP-KUNNR.
IF SY-SUBRC = 0.
  CLEAR X_TEMP.
     SELECT SINGLE * FROM ZOTC_SHPMNT_RTE INTO table t_TEMP
     WHERE SHTYP = X_VTTK-SHTYP
     AND   LAND1 = X_KNA1-LAND1
     AND   BLAND = X_KNA1-REGIO
     AND   ZONE1 = X_KNA1-LZONE.
     IF SY-SUBRC = 0.
       IF T_TEMP[] IS INITIAL.
       READ TABLE T_TEMP INTO X_TEMP.     i want to create a temp internal table
       ELSE.
       SELECT SINGLE * FROM ZOTC_SHPMNT_RTE INTO TABLE t_TEMP
     WHERE SHTYP = X_VTTK-SHTYP
     AND   LAND1 = X_KNA1-LAND1
     AND   BLAND = X_KNA1-REGIO.
       IF SY-SUBRC = 0.
          READ TABLE T_TEMP INTO X_TEMP.
          IF SY-SUBRC = 0.
         MODIFY vttk FROM t_TEMP.       here i want to modify the feilds like vttk-route and vttk-tdlnr
         ENDIF.
         ENDIF.
         ENDIF.
endif.
endif.

First declare a types structure with this 3 variables u want...
now declare a work area(X_KNA1) of this types structure.
And
SELECT SINGLE LAND1 REGIO LZONE FROM KNA1
INTO X_KNA1
WHERE KUNNR = X_LIKP-KUNNR.

Similar Messages

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • Problem in the "select" query....Just check out and help me

    Hi there !!
    I am getting the following errors while trying to execute the "select" query from JSP page:
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
    My code is :
    String reg_no=(String)session.getAttribute("reg_no");
    ResultSet rs=stmt.executeQuery("SELECT * FROM reg WHERE regno = "+reg_no);
    (Note: the "regno" in the database is of numeric datatype)
    Try to help me...
    Thanx,
    Ram.

    Just so everyone knows:
    Ram Mohan joined the forum on 7-Sep-2003 and received
    his 25 Dukes for joining.
    Since then, he's posted three questions, each one
    promising 5-10 Dukes, and never once awarded them.
    His strategy seems to be to wave Dukes, ask his
    hit-and-run question, and then bolt.
    Answer his questions if you wish, but don't do it
    expecting Dukes. - MODDuffy, you're getting just as cranky as I have. See what hanging around these forums does to oneself? :)

  • Problem in my Select query

    Hi Experts,
    I need a clarification in my Select query.
    Have created a custom search help and my requirement is I have Request ID, Last and First Name as my search parameters. I need to fetch the values from my Ztable on search with the above said search parameters, where its workflow status = 30.
       * Get Request ID
      lv_pattern = <ls_query_params>-request_id.
      IF lv_pattern CA '*'.
        REPLACE ALL OCCURRENCES OF '*' IN lv_pattern WITH '%'.
      ENDIF. " IF lv_pattern CA '*'
      IF lv_pattern IS INITIAL.
        lv_pattern = '%'.
      ENDIF. " IF lv_pattern IS INITIAL
    ** Get NACHN - Lastname
        lv_last_name = <ls_query_params>-nachn.
        IF lv_last_name CA '*'.
          REPLACE ALL OCCURRENCES OF '*' IN lv_last_name WITH '%'.
        ENDIF. " IF lv_pattern CA '*'
        IF lv_last_name IS INITIAL.
          lv_last_name = '%'.
        ENDIF. " IF lv_pattern IS INITIAL
    ** Get VORNA - First Name
        lv_first_name = <ls_query_params>-vorna.
        IF lv_first_name CA '*'.
          REPLACE ALL OCCURRENCES OF '*' IN lv_first_name WITH '%'.
        ENDIF. " IF lv_pattern CA '*'
        IF lv_first_name IS INITIAL.
          lv_first_name = '%'.
        ENDIF. " IF lv_pattern IS INITIAL
    *Selecting the RequestID/Last and First Name values with workflow status as 30.
    SELECT zzreq_id " Internal number for appropriation request
                nachn
               vorna
      INTO TABLE lt_select_list
      FROM ZTABLE
      WHERE (  ( zzreq_id LIKE lv_pattern ) and
                     ( nachn like lv_last_name ) or
                      ( vorna LIKE lv_first_name ) )
           AND zzstatus = lv_workflow_status.
    My problem is, ofcourse this query is selecting all the records where status = 30 and even it works correctly, If I searches with Request ID(* or *3*).
    But am not able to select the records, if I searches with Last or First Name. Guess I did some thing wrong in select query.
    Please advice me.
    With Regards,
    Ram.

    Re: Problem in my Select query
    Krishna kumar Jun 9, 2014 7:52 AM (in response to Ramakrishnan Murugan)
    Hi Ramakrishnan,
                         Can you just try the below Select Query,
    SELECT zzreq_id
                nachn
               vorna
      INTO TABLE lt_select_list
      FROM ZTABLE
      WHERE ( zzreq_id     LIKE    lv_pattern                and
                         nachn         LIKE    lv_last_name         and
                         vorna          LIKE     lv_first_name )    and
                          zzstatus = lv_workflow_status.
    Cheers,
    Krishnakumar B.
    I think the above suggested query is same as your solution.

  • Problem in standard select query in fagll03

    Good Morning frndz,
    I m facing a problem while runnin fagll03. when executed it gives timeout error.
    When I debug it  , it gets stuck in a select query
    SELECT SINGLE * FROM t800m INTO CORRESPONDING FIELDS OF ls_b
    WHERE totable = ls_t800a-ntable
    AND fromtable = 'ACCIT_GLX'
    AND tofield = id_glflex_fieldname
    AND seqnr = space.
    The content in variable ls_t800a-ntable was FAGLFLEXA  and in id_glflex_fieldname was USNAM.
    When I cheked in table t800m, the entry could not be found. But in the report instead of setting
    sy-subrc = 0 , it is stuck in the select query itself....kindly suggest y it is happening so
    Regards,
    Vincy

    Re: Problem in my Select query
    Krishna kumar Jun 9, 2014 7:52 AM (in response to Ramakrishnan Murugan)
    Hi Ramakrishnan,
                         Can you just try the below Select Query,
    SELECT zzreq_id
                nachn
               vorna
      INTO TABLE lt_select_list
      FROM ZTABLE
      WHERE ( zzreq_id     LIKE    lv_pattern                and
                         nachn         LIKE    lv_last_name         and
                         vorna          LIKE     lv_first_name )    and
                          zzstatus = lv_workflow_status.
    Cheers,
    Krishnakumar B.
    I think the above suggested query is same as your solution.

  • Problem in the select

    Hi.
    i am having problem during execution in the select query and its taking time.what is to be done and do  i need to add line of code.
    plz reply
    sort i_aufk by aufnr.
    delete adjacent duplicates from i_aufk comparing aufnr.
    IF NOT i_aufk[] is INITIAL.
        SELECT  aufnr      "Order number
                budat      "Posting date
        INTO TABLE i_afru
        FROM afru         "Order Confirmations
        FOR ALL ENTRIES IN i_aufk
        WHERE aufnr = i_aufk-aufnr.
        IF sy-subrc EQ 0.
        SORT i_aufk BY aufnr.

    Hi,
    Table AFRU is not indexed on AUFNR (as standard) so it will be performing multiple full table scans.
    Create a secondary index on the table including MANDT & AUFNR and the performance will improve.
    Regards,
    Darren

  • Using case when statement in the select query to create physical table

    Hello,
    I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
    I have a physical table based on a select table with one column.
    SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
    I also have a customer table.
    In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
    In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
    EXECUTION
    When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
    everything works as expected. YE!!
    Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
    SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
    FROM DUAL
    Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
    surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
    SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
    If anyone has any explanation to this error and how we can achieve the same, please help.
    Thanks.

    Hello,
    Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
    I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
    Here is what I am trying to do. the select query of the physical table is as follows.
    SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
    The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
    Thanks.

  • How to optimize the select query that is executed in a cursor for loop?

    Hi Friends,
    I have executed the code below and clocked the times for every line of the code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table
                                                         WHERE division = rec.division)));
       END LOOP;
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;The SELECT query inside the cursor FOR LOOP took 773 seconds.
    I have tried using BULK COLLECT instead of cursor for loop but it did not help.
    When I took out the select query separately and executed with a sample value then it gave the results in a flash of second.
    All the tables have primary key indexes.
    Any ideas what can be done to make this code perform better?
    Thanks,
    Raj.

    As suggested I'd try merging the queries into a single SQL. You could also rewrite your IN clauses as JOINs and see if that helps, e.g.
    SELECT DISTINCT ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
               INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
               FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
              WHERE ai.item_id_edw = aix.item_id_edw
                AND aix.item_code_cust = rec.item_code_cust
                AND aix.facility_num = acdf.facility_code
                AND acdf.chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                AND acdf.div_id = ad.div_id
                AND ad.division = rec.division;ALSO: You are calling ah_internal_data_pkg.get_chain_id (p_file_id) every time. Why not do it outside the loop and just use a variable in the inner query? That will prevent context switching and improve speed.
    Edited by: Dave Hemming on Dec 3, 2008 9:34 AM

  • Need some help with the Select query.

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

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

  • Restricting record in the select query

    Is there any way to restrict the number of search (e.g 10) records in the SELECT query ?

    Hi,
    You can use as below:
    select <fieldname> up to 10 rows from <tablename> into itab.
    Thanks,
    Sriram Ponna.

  • Problem with the selection screen in submit program

    Hi Friends,
    i am facing the problem wih the selection screen in submit program. in my Module pool program i am using the submit program statement, When i execute the program , The module program display the submit program selections creen.
    I have implemented the code same as below.
    submit ztest with tknum =p_tknum and  return.
    Can you pleaes help me how to avoid the submit program selection screen.
    Thanks,
    Charan

    Hi Charan,
    You have to give the selection screen values when you submit a job.
    Press F1 on submit and you will see more details.
    Here is an example from ABAP Documentation.
    Program accessed
    REPORT report1.
    DATA text(10) TYPE c.
    SELECTION-SCREEN BEGIN OF SCREEN 1100.
      SELECT-OPTIONS: selcrit1 FOR text,
                      selcrit2 FOR text.
    SELECTION-SCREEN END OF SCREEN 1100.
    Calling program
    REPORT report2.
         DATA: text(10)   TYPE c,
          rspar_tab  TYPE TABLE OF rsparams,
          rspar_line LIKE LINE OF rspar_tab,
          range_tab  LIKE RANGE OF text,
          range_line LIKE LINE OF range_tab.
    rspar_line-selname = 'SELCRIT1'.
    rspar_line-kind    = 'S'.
    rspar_line-sign    = 'I'.
    rspar_line-option  = 'EQ'.
    rspar_line-low     = 'ABAP'.
    APPEND rspar_line TO rspar_tab.
    range_line-sign   = 'E'.
    range_line-option = 'EQ'.
    range_line-low    = 'H'.
    APPEND range_line TO range_tab.
    range_line-sign   = 'E'.
    range_line-option = 'EQ'.
    range_line-low    = 'K'.
    APPEND range_line TO range_tab.
    SUBMIT report1 USING SELECTION-SCREEN '1100'
                   WITH SELECTION-TABLE rspar_tab
                   WITH selcrit2 BETWEEN 'H' AND 'K'
                   WITH selcrit2 IN range_tab
                   AND RETURN.
    Regards,
    Jovito.

  • Performance of the select query

    i want to know wheter the conversion of  the select query
    SELECT  * FROM mchb                        
            WHERE matnr EQ mch1-matnr
            AND   charg EQ mch1-charg
            AND   werks EQ plant-werks.
            itab-lgort = mchb-lgort.
            itab-clabs = mchb-clabs.
            APPEND itab.
          ENDSELECT.
    into following pattern
    select lgort clabs
           from mchb
           into corresponding fields of itab
           WHERE matnr EQ mch1-matnr
           AND   charg EQ mch1-charg
           AND   werks EQ plant-werks.
           ENDSELECT.
    will give  the same results ?

    Hi,
    It will results in performance issue because of end select statement.
    select lgort clabs
         from mchb
            into table itab
            WHERE matnr EQ mch1-matnr
                  AND charg EQ mch1-charg
                  AND werks EQ plant-werks.
    Use like this you will get the values of lgort and clabs in the internal table itab.
    Then use loop statement to use that values further.
    Dont use end select it will be a performance issue.
    In this code there is no need to use of ENDSELECT and use corresponding fields of table itab.
    select lgort clabs
    from mchb
    into corresponding fields of itab
    WHERE matnr EQ mch1-matnr
    AND charg EQ mch1-charg
    AND werks EQ plant-werks.
    ENDSELECT.
    Thanks,
    Sakthi

  • How to insert the select query result into table?

    How to insert the select query result into table?
    SELECT  top 20 creation_time  
            ,last_execution_time 
            ,total_physical_reads
            ,total_logical_reads  
            ,total_logical_writes
            , execution_count 
            , total_worker_time
            , total_elapsed_time 
            , total_elapsed_time / execution_count avg_elapsed_time
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset 
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END 
                - qs.statement_start_offset)/2) + 1) AS statement_text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    ORDER BY total_elapsed_time / execution_count DESC;
    Thanks,
    Tirumala

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • Issue with the select query

    Hi,
    DATA: BEGIN OF IT_MATERIAL OCCURS 0,
          IDNRK  LIKE  STPO-IDNRK,
          MATNR  LIKE  MAST-MATNR,
          END OF IT_MATERIAL.
    FORM CHECK_SALESDATA_EXISTENCE .
      IF NOT IT_MATERIAL[] IS INITIAL.
        LOOP AT IT_MATERIAL.
          CLEAR VBAP.
          SELECT SINGLE * FROM VBAP WHERE MATNR EQ IT_MATERIAL-MATNR.
          IF SY-SUBRC NE 0.
            DELETE IT_MATERIAL WHERE IDNRK EQ IT_MATERIAL-IDNRK
                                 AND MATNR EQ IT_MATERIAL-MATNR.
          ENDIF.
          CLEAR IT_MATERIAL.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " CHECK_SALESDATA_EXISTENCE
    The above is the subroutine in the program which check whether sales data exists for a material or not. But the problem is the select statement which is written in the loop is taking so much of time because of this the program is going into short dump "Time Exceed Limit".
    Please suggest how can i modifiy the above statemnt so that the performance of the program increases.
    <REMOVED BY MODERATOR>
    Thanks.
    Edited by: Alvaro Tejada Galindo on Mar 4, 2008 10:37 AM

    The program deletes multiple records inside a loop. This isn't good practice. The following should work:
    REPORT ztest LINE-SIZE 80 MESSAGE-ID 00.
    TABLES: vapma.
    DATA: BEGIN OF it_material OCCURS 0,
      matnr LIKE mast-matnr,
      idnrk LIKE stpo-idnrk,
    END OF it_material.
    PERFORM check_salesdata_existence.
    *&      Form  CHECK_SALESDATA_EXISTENCE
    *       text
    FORM check_salesdata_existence .
      DATA: delete.
      SORT it_material BY matnr.
      LOOP AT it_material.
        AT NEW matnr.
          SELECT SINGLE * FROM vapma
            WHERE matnr EQ it_material-matnr.
          IF sy-subrc <> 0.
            delete = 'X'.
          ELSE.
            CLEAR delete.
          ENDIF.
        ENDAT.
        IF delete = 'X'.
          DELETE it_material.
        ENDIF.
      ENDLOOP.
    ENDFORM. " CHECK_SALESDATA_EXISTENCE
    Note that I have changed the filed order in it_material so that AT NEW will work correctly.
    Rob

  • Code order in sq02, Problem in the selection fields in sq01

    Hi all,
    I'm writing a query with sq01 and sq02.
    In sq02 I have some joined tables, and 2 extras fields named: "TIME" and "LEFT_ER".
    in this fields I wrote a code to calculate something from fields in the tables.
    The problem is:
    1. When I write the code in the coding section "Additional field/structure" for each field, If I want to use this fields in the selection fields (in sq01) the query can't find any record.
    But if I run this query without any selection in this fields, I get all the records, with my calculated fields.
    2. I tried to write this code in the coding section "Record processing", and it seems that I can use this fields in the selection fields (in sq01), and get all the records I wanted.
    But in the sq02 I get a Warning messages:
    "Access error in code for additional field *GET******
    *GET****** has sequence number 00
    Access to LEFT_ER with sequence number 00"
    In this case my field LEFT_ER has no code.
    And when I change the order of the sequence number, I didn't get the Warning message, but I could not use my fields in the selection fields (in sq01), like at the beginning.
    HELP ME PLEASE.
    Itzhak.
    Message was edited by: Itzhak Tanami

    Hi,
    i've an idea .
    pls define your help-fields :
    1) as sel-option : s_f1 for bseg-dmbtr
    and
    2) as calculate-field  : c_f1 for bseg-dmbtr
    so for event e.g. GET BSEG .
    you <b>1st</b> calculate your field .
    e.g.
    if bseg-shkzg = 'H'.
       c_f1 = Bseg-wrbtr * -1.
      else.
       c_f1 = Bseg-wrbtr.
    endif.
    and 2nd  your restriction from sel-screen:
    <b>check c_f1 in s_f1.</b>
    good luck
    Andreas

Maybe you are looking for