Temporary Table In SAP Query - Does not Work?

DECLARE @date DATE
DECLARE @delrows INT
DECLARE @delquan INT
DECLARE @a INT
DECLARE @recrows INT
DECLARE @recquan INT
SET @a=0
IF OBJECT_ID('tempdb..##tab) IS NOT NULL DROP TABLE ##tab
CREATE TABLE ##tab
[Date] date,
[Delivery Rows] varchar(40),
[Delivery Total Units] varchar(40),
[Receipts Rows] varchar(40),
[Receipts Total Units] varchar(40),
WHILE @a!=7
     BEGIN
     SET @date=DATEADD(day,-@a, getdate())
     SELECT @delrows=ISNULL(COUNT(DLN1.[LineNum]),0), @delquan=ISNULL(SUM(DLN1.[Quantity]),0)
     FROM ODLN
     INNER JOIN DLN1 ON ODLN.[DocEntry]=DLN1.[DocEntry]
     WHERE ODLN.[CreateDate] = @date
     SELECT @recrows=ISNULL(COUNT(PCH1.[LineNum]),0) , @recquan=ISNULL(SUM(PCH1.[Quantity]),0)
     FROM OPCH
     INNER JOIN PCH1 ON OPCH.[DocEntry]=PCH1.[DocEntry]
     WHERE OPCH.[DocDate]=@date
     SET @a=@a+1
          INSERT INTO ##tab VALUES(@date,@delrows,@delquan,@recrows,@recquan)
END
SELECT * FROM ##tab
{/code}
Can anyone explain why this query does not work in SAP? It works fine on SQL but gives me this message in SAP:
1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near ')'.
2). [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.
Edited by: Chris Candido on Feb 2, 2011 8:38 PM

Chris,
There are several areas in your code which needed changes. 
1. On the field name for your temp table you had spaces.
2. The SAP table name ODLN, OPCH, PCH1 had to be fully referenced like
[dbo].[ODLN]
3. You really need not have ## in front of your temp table, it could just be #
The select at the end is actually what causes the most problem as for some reason from within SAP it does not produce the result.  I would suggest you put the whole code into a Stored Procedure and call the SP from SAP.  Corrected SQL below.  If you remove the Select line at the end the query would work with in SAP, but keep it give give you an error. SP is the best option for this.
DECLARE @date DATE
DECLARE @delrows INT
DECLARE @delquan INT
DECLARE @a INT
DECLARE @recrows INT
DECLARE @recquan INT
SET @a=0
IF object_id('tempdb..#tab') IS NOT NULL
BEGIN
   DROP TABLE #tab
END
CREATE TABLE #tab
[Date] date,
DeliveryRows varchar(40),
DeliveryTotalUnits varchar(40),
ReceiptsRows varchar(40),
ReceiptsTotalUnits varchar(40),
WHILE @a!=7
BEGIN
SET @date=DATEADD(day,-@a, getdate())
SELECT @delrows=ISNULL(COUNT(DLN1.LineNum),0), @delquan=ISNULL(SUM(DLN1.Quantity),0)
FROM [dbo].[ODLN]
INNER JOIN DLN1 ON [dbo].[ODLN].DocEntry=DLN1.DocEntry
WHERE [dbo].[ODLN].CreateDate = @date
SELECT @recrows=ISNULL(COUNT([dbo].[PCH1].LineNum),0) , @recquan=ISNULL(SUM([dbo].[PCH1].Quantity),0)
FROM [dbo].[OPCH]
INNER JOIN [dbo].[PCH1] ON [dbo].[OPCH].DocEntry=[dbo].[PCH1].DocEntry
WHERE [dbo].[OPCH].DocDate=@date
SET @a=@a+1
INSERT INTO #tab VALUES(@date,@delrows,@delquan,@recrows,@recquan)
END
SELECT * FROM #tab
Suda Sampath

Similar Messages

  • ALTER TABLE command with owner does not work

    I performed the following statement in a SQLplus script where the variables were filled some lines before:
    alter table '&ownername||'.'||&tablename' move online tablespace '&tablespacename';
    However this does not work. I am getting:
    ERROR at line 1:
    ORA-00903: invalid table name
    The variables are replace correctly by SQLplus and everything owner, table, tablespace exist.
    Can I (as SYSDBA) not alter the table of another user?
    Peter

    Solomon Yakobson wrote:
    EdStevens wrote:
    Ok, you removed the mis-placed quotes, but why the double "." ??
    If you wish to append characters immediately after a substitution variable, use a <font color=red size=3>period</font> to separate the variable from the character.
    SY.Ah, I had simply never done it that way nor seen it done that way.

  • SAP QUERY does not execute in other client

    Hi,
    I am working on SAP QUERY on the Quality Assurance and Cust & Dev Client and i am facing a strange thing when i tried to execute the Query from SQ01 ,there i found itis not able to get executed but when i generated the report ,after that it get s executed.
    I want to know what are the reasons behind it,please provide me guidelines for solving it.

    See, SQ01 can not alone be used.
    It is linked with the SQ02 - Funectional Area, where the joins handeled and codes implemented.
    Also SQ03 - User Groups.
    User Group you can ignore, but Functional Area is must to run a query through SQ01.
    When you generate the Functional Area using SQ02, it activates all the objects associated with the Query.
    So even if you need same query to some other client sayu in quality or production, you need to import export Functional area first before query or simultaneously.
    Regds,
    ANil

  • Media query does not work on my iPad (Was: media query question)

    I am coding a site for mobile/tablet/desktop and while my desktop and iphone respond to the CSS, my ipad does not. The changes I make to the tablet in dreamweaver take, but when they go live the ipad does not respond. Obviously my media query must be incorrect but I cannot figure out the issue. Any help is much appreciated.
    http://gbetza.mydomain.com/webservice2/test/KathrynFee/2014/profile.html
    Thank you.

    Yes.  That's inevitable because smart phones are getting bigger while tablets are getting smaller & bigger.  There is always going to be some crossover.   Think of it this way, when a tablet behaves like a mobile device, it takes on the mobile layout.  When tablet behaves more like a desktop, it takes the desktop layout.
    Similarly, a wide smartphone in landscape mode is apt to look like your tablet layout.
    See FluidGrid Example below:
    http://alt-web.com/FluidGrid/Fluid2.html
    Desktop = 4-col layout
    Tablet = 2-col layout
    Mobile = 1-col layout
    For illustration purposes, I added a thick gold border to the Tablet layout only.
    /* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */
    @media only screen and (min-width: 481px) and (max-width:768px) {
    .gridContainer {width: 92%; border: 16px solid gold}
    Nancy O.

  • Frame 9 solution for table column + side head does not work in Frame 10 and 11

    In Frame 9 structured (DITA) we could force Frame to record the actual widths of table columns in the DITA XML.  Frame 9 would respect the widths when opening the file.  This was particularly useful for forcing tables to be wide -- to go across the column and the side head -- and for the columns to never resize. 
    In Frame 9 this was done by commenting out the line
    "writer use proportional widths;" 
    like this
    "/* writer use proportional widths; */"
    in the topic.rules.text" file located in
    "...\FrameMaker9\Structure\xml\DITA\app\DITA-Topic-FM"
    This no longer works in Frame10 and Frame 11.  Even though the same line is commented out in all the "NAME.rules.txt" files in all the subdirectories of
        "...\AdobeFrameMaker11\Structure\xml\DITA_1.2\app"
    and
        "...\AdobeFrameMaker11\Structure\xml\DITA\app"  
    and
        "...\AdobeFrameMaker10\Structure\xml\DITA_1.2\app"
    and
        "...\AdobeFrameMaker10\Structure\xml\DITA\app"  .
    Commenting out the line does force Frame 10 and 11 to record  the absolute column width (2.357" etc.) in the DITA XML.
    However, on Open,  Frame 10 and 11 force the table to fit in the column, not the column and sidehead. That is they behave as though they were still using proportional column widths.  It seems the original values (as inserted by Frame 10 and 11 before closing!) are recalculated on Open, thereby mimicking the default proportional width behavior.  
    For example, this on Save then Close from Frame 10 or 11
    <table frame = "topbot" colsep = "0" rowsep = "1">
    <tgroup cols = "4" colsep = "0" rowsep = "1" outputclass = "FormatB">
    <colspec colnum = "1" colname = "1" colwidth = "1.796in" colsep = "0"/>
    <colspec colnum = "2" colname = "2" colwidth = "1.852in" colsep = "0"/>
    <colspec colnum = "3" colname = "3" colwidth = "1.179in" colsep = "0"/>
    <colspec colnum = "4" colname = "4" colwidth = "2.152in" colsep = "0"/>
    goes to this on Open then Save: 
    <table frame = "topbot" colsep = "0" rowsep = "1">
    <tgroup cols = "4" colsep = "0" rowsep = "1" outputclass = "FormatB">
    <colspec colnum = "1" colname = "1" colwidth = "1.351in" colsep = "0"/>
    <colspec colnum = "2" colname = "2" colwidth = "1.393in" colsep = "0"/>
    <colspec colnum = "3" colname = "3" colwidth = "0.887in" colsep = "0"/>
    <colspec colnum = "4" colname = "4" colwidth = "1.618in" colsep = "0"/>
    Any help at all would be appreciated!  
    We have 8,000 to 10,000 pages to PDF in the next few days and about 33% of those pages are messed up tables!
    Message was edited by: borealforest

    Hi...
    Unfortunately, I don't have any insight into the default DITA table handling in FM10 or FM11 .. so can't give you the answer you're looking for. Since both FM10 and FM11 offer ExtendScript, you could write a script (or have one written) that processes all of your files to reset the table widths. Or, perhaps the best short term solution may be to reinstall FM9 to get the job done, then spend more time later to figure out a better solution.
    One alternative would be for you to use DITA-FMx, which supports the table/@pgwide attribute for controlling which tables span the page and which don't. Since your tables probably don't make use of this attribute, it won't help in the near term, but might make sense going forward.
    Cheers,
    Scott Prentice
    Leximation, Inc.
    www.leximation.com

  • Interactively changing values to table problem: indicator and control table, and why it does not work after a while...?

    I have been producing a VI that loads a set of data and displays it in a table: A table control is initialised with an empty variable, the loaded data takes the place of the variable and fills the table, while some headers are added. That table feeds an intensity graph to give a pictorial impression of the data.
    With this scheme, a user can change any value of the table, and the changes are interactively reflected on the graph.
    Problem: after few saving of the VI, the access to the table doesn't work anymore. It is the same with all my numerical controls in the VI where it should be possible to enter a value.
    If anybody has an idea on the potential
    causes of these problem, I would be really grateful as it is very useful...when it works !
    Regards,
    Elie Allouis

    I can not image what is causing the error. Would you be willing to post some code to see if we can reproduce the problem?
    Jeremy7

  • Media Query does not work from GoDaddy redirect?

    Website is set up and all looks good, except when the page is loaded from the redirect host name setup in Godaddy, the mobile media queries don't work. I'm not sure why?? The page loads ok, but will not apply the phone.css on a mobile device. However, if I use the local host url all works great. Thank you if you have any recommendations!

    Thank you again for taking time to look at this. I failed to mention I had adjusted the media query to 360px. Although, both urls above call up the same web page it seems the first url is wrapping the source into a frame.
    Source code from Firefox:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
      <title>O'Krent </title>
    </head>
    <frameset rows="100%,*" border="0">
      <frame src="http://www.accu-print.org/okrentgolf" frameborder="0" />
      <frame frameborder="0" noresize />
    </frameset>
    <!-- pageok -->
    <!-- 02 -->
    <!-- -->
    </html>

  • ReadObject query by idfr does not work first call

    I am running Toplink 10.1.3.0.0 inside the oc4j container. A basic example is that I have an object Employee that has a String attribute id. This class goes to the employee table. I have set an Expression in the Toplink Workbench to do Read Object and it just checks that id = the idfr passed in as an argument. When running the query by the idfr in the container, the idfr is set as the argument and the data exists in the database. With Toplink logging turned onto FINE I see the query being run "select xyz from employee where idfr = x". But the return value from the query is null. But if I run the query through a second time it returns with the correct object. I have tried changing this to a Read All query, and then just accessing the 0th element from the List returned, and this seems to work fine. I am still concerned, though, as to why the Read Object query does not work on the first go around as is expected?

    Any reason you set the Read Object query? The Expression you've provided is the same as what TopLink generates.
    Out of interest, does the problem occur if your primary key attribute is an int/long, or some other numeric type. Does your String attribute value or query id value have trailing or leading spaces? Oracle database will trim leading and trailing blanks on INSERT/UPDATE which can lead to confusion.
    Turn the logging up to FINEST and look for log messages relating to registration of existing objects. If you can post the test code and log that would help.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SELECT DISTINCT does not work - Another Problem!

    Dear All
    Previous Post
    I just posted a thread, which has been answered by an expert. It's here:
    SELECT DISTINCT does not work. Why?
    My original problem was that the Query returned duplicate records, and SELECT DISTINCT did not work.
    The solution was to change this select:
    T0.[U_SupInv]      AS 'Link'
    ... to this:
    CAST(T0.[U_SupInv] as nvarchar(100))      AS 'Link'
    The amended Query worked.
    New Problem
    I just discovered that resolving the problem created a new one.
    The field U_SupInv (Link) is in fact a UDF.
    I created it so that all Suppliers' Invoices could be Scanned to pdf files, and these pdf could be linked
    to the respective AP Invoice.
    Originally, when I clicked 'Link' in my Query results, the pdf scan pops up.
    When the Query is amended by adding CAST, the link becomes dead.
    Help
    Could anyone tell me how I can make SELECT DISTINCT work, as well keeping the LINKS live?
    The main purpose of my Query is to help users view the pdf scans by clicking on the links.
    Thanks
    Leon Lai
    Here's my Original Query
    SELECT
    T0.[UpdateDate] AS 'Update Dt',
    T0.[TaxDate] AS 'Doc Dt',
    CASE T5.[TransType]
         WHEN '18' THEN 'PU ' + CONVERT(VARCHAR(6), T0.[DocNum])
         WHEN '19' THEN 'PC ' + CONVERT(VARCHAR(6), T0.[DocNum])
    END 'SAP Ref.',
    T1.[ImportLog]     AS 'Ship #',
    T0.[CardCode] + '' AS 'Supplier #',
    T0.[CardName]      AS 'Supplier Name',
    T0.[DocTotal]      AS 'Rs',
    T1.[BlockNum]      AS 'Reqn #',
    T0.[DocNum]        AS 'Doc No',
    T0.[U_SupInv]      AS 'Link'
    FROM klship.[dbo].[OPCH] T0
    INNER JOIN klship.[dbo].[PCH1] T1 ON T0.[DocEntry] = T1.[DocEntry]
    INNER JOIN klship.[dbo].[OJDT] T5 ON T0.[TransID] = T5.[TransID]
    WHERE
    (T0.[UpdateDate] >= '[%2]' AND
    T0.[UpdateDate]  <= '[%3]' AND
    T0.[U_SupInv] IS NULL)
    OR
    (T0.[UpdateDate] >= '[%4]' AND
    T0.[UpdateDate]  <= '[%5]' AND
    T0.[U_SupInv] IS NOT NULL)
    FOR BROWSE

    Dear István Korös,
    Thanks a lot for your answer.
    I will test your suggestion tomorrow, as it's night and I am returning home now.
    However, I do not think it will suit my requirements for the foll reasons:
    - I worked hard to get rid of the need to enter anything in the @Scan2 field.
    - This UDF was created solely as a text of instruction for my staff.
       Unfortunately I had to fill in something to make the Query work.
    - The problem is that if the user forgets to click the drop-down arrow and leaves @Scan2
       blank, the query does not work.
    - With the help of another expert, I succeeded in ignoring @Scan2 altogether.
    - I posted only a simplified version of my Query on the forum, without the codes relating to eliminating the
      need to enter something in @Scan2, so you may not be aware of my requirement.
    - I hope you understand my reluctance. But I will try your suggestion nevertheless.
    My Suggestion
    I think using PCH1.VISORDER may be the solution.
    If we select only those rows where visorder = 0, then
       - there will be no duplication
       - I need not use SELECT DISTINCT
       - All my LINKS to pdf files will be live because I need not use CAST
       - I may retain that part of my Query which permits ignoring @Scan2 altogether.
    - A Dream!-
    The problem is that I don't know how and where  to place that VISORDER.
    If you think I may be right, could you help me along that line?
    Best Regards
    Leon Lai

  • UNION for Columns of CLOB data type does not work

    Hi,
    I have two tables Encounter & Encounter_History. They have same columns. One column is of type CLOB. My requirement is to retrieve all the distinct records from both the tables with order by a date column. But problem is, UNION does not work in case of CLOB data type.
    I know it will work if I use UNION ALL, but it returns duplicate records.
    Please give me suggestion, how to solve this problem.
    For example: The following query does not work since column1 is a CLOB data type
    select column1 from table1
    union
    select column1 from table2
    Thanks

    But for sufficiently small clobs you can try:
    michaels>  SELECT TO_CLOB ('abc') cl
      FROM DUAL
    UNION
    SELECT TO_CLOB ('abc')
      FROM DUAL
    Error at line 1
    ORA-00932: inconsistent datatypes: expected - got CLOB
    michaels>  SELECT TO_CHAR (TO_CLOB ('abc')) cl
      FROM DUAL
    UNION
    SELECT TO_CHAR (TO_CLOB ('abc'))
      FROM DUAL
    CL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    abc                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    1 row selected.

  • Lead Selection does not work after setting filter for ALV.

    Hi, Can you please suggest on below scenario :
    I have a Node with a sub node in it .
    I am using the supply function on Sub Node to retrieve the date based on Parent Node.
    There are two ALV's to display parent and item data. The issue is when a filter(user defined filter) is done on Parent table, the supply function does not work. The value is that of the selected row before setting the filter. Even after removing the filter, the item data is stuck and does not change on Lead Selection.
    One thing I noticed is if the child table is a table UI, there is no issue. The only problem is when the second table is ALV
    Thanks In Advance

    Hi Prashanthi,
    Your issue can be resolved as below
    Create an event handler method 'set_alv_data'  for the event 'ON_LEAD_SELECT' of parent alv
    Write the below code inside the event handler method
    METHOD set_alv_data.
      DATA lo_node TYPE REF TO if_wd_context_node.
      DATA lv_path TYPE string.
      DATA lv_index TYPE string.
      lv_index = r_param->index.
      CONDENSE lv_index.
      CONCATENATE wd_this->wdctx_my_parent_node
      lv_index
      wd_this->wdctx_my_child_node
      INTO lv_path SEPARATED BY '.'.
      lo_node = wd_context->path_get_node(
          path                          = lv_path
      DATA lo_interface TYPE REF TO iwci_salv_wd_table.
      lo_interface = wd_this->wd_cpifc_alv_child( ). "get the ref of alv comp of child
      lo_interface->set_data(
        EXPORTING
    *    only_if_new_descr =
          r_node_data       = lo_node
    ENDMETHOD.
    The above code sets the data node of child alv based on lead selection of parent alv data.
    Note: Replace 'parent_node', 'child_node'  with your nodes & 'alv_child' with your alv component name of child alv.
    If you want to control the data of child alv on filter function, you can use the event ON_STD_FUNCTION_AFTE and once you define the filter you get the r_param->id = 'SALV_WD_FILTER_DEFINE'  & now you can clear data of child alv.
    Hope this helps you.
    Regards,
    Rama

  • Defaulting query to SAP LIST VIWER not working! Please help!

    Hello everyone:
            I have some query's created in old version (4.6C) and we upgraded to ECC6.0. When you go to "SQ01"-Display you will see query properties and display is defaulted to "SAP list viewer". This works fine in older version but in newer version the query returns blank report!!! When I go to paramters selection page it does not show the options to select different outputs!! When I change it to ABAP LIST VIEWER in the properties and run the query, it works fine and also on the parameters selection page it shows th options for other displays! If I select "SAP LIST VIEWER" here it works fine!! Only when it is defaulted to "SAP LIST VIEWER" the query does not return anything! Did anyone face this problem before in newer version (ECC6.0)? Please give me any information you have. I will reward all the answers.
    Thanks.
    Mithun

    Hi Mithun,
    This is happening because SAP has changed the approach of creating the standard program based on the selection of output type.
    Now SAP calls a FM when you select SAP list viewer in the query.
    If you see the code generated when you choose different output type you will understand why it is happening.
    So it is better to select the output type as ABAP LIST VIEWER and then only change the output at the time of execution if required.
    Reward points if useful.
    Regards,
    Atish

  • Why UDO does not work more  in SAP B1 P16?

    Someone of you has tried to use UDO in SAP B1 Patch 16?
    It does not work more what worked in patch 14 created by code.
    I have also created master and detail tables (from menu Options…)
    and the object by hand but I do not succeed to make to work it!
    Can you help me?
    Message was edited by:
            Andrea Scavazza
    Message was edited by:
            Andrea Scavazza
    Message was edited by:
            Andrea Scavazza

    Hi everybody,
    I am using SBO SP1 PL16 and I have problems with Update in Default Form.
    1. I create a Master Data Table and a Lines Master Data Table
    2. I create an UDO using Default Form
    3. When I test it I get the following behavior:
    a) When I add master data an lines at the same time, there is no problem.
    b) When I update any data in master or lines, I press Update Button and the message "successfully" is displayed but automatically it gets the old information
    c) I tried to find the right information in the table but it was not saved.
    Anyone has the same problem?

  • Expert Mode ViewObject: default 'query by example' mechanism does not work

    In JDeveloper 11G 1.1.1
    I have created an Expert Mode view object(VO) which I'm trying to filter in an ADF Swing Panel
    The Panel contains a Swing Table created by dropping a VO data control on the panel as an ADF bound Swing Table.
    TEST
    Run the panel.
    Set the Query Mode on (from the Database menu)
    Enter a relevant view criterion
    Execute the Query
    TEST FAILS
    Table is refreshed but it still displays the entire VO collection (non-filtered).
    Repeating the same experiment with a default, entity object generated VO works as expected.
    Question
    Can the default 'query-by-example' mechanism as provided by the JUTestFrame and the JUNavigationBar be used with Expert Mode view Objects?
    If yes are there any tricks to making this work?

    Hello Frank;
    Additional TEST RESULTS
    In JDev11G
    The default 'query by example mechanism' does not work if you create a new View Object using the <Select data source...> option <Read-only access through SQL query>.
    However, IT DOES WORK if you create a new ViewObject selecting <Updatable access through entity objects> and in the Query step you select <Expert Mode>
    Could you please check and confirm.
    Thanks!
    Ioannis
    Edited by: imouts on Dec 5, 2008 1:38 PM

  • Select All in a table does not work for Drag and Drop

    Hi. I am using Jdeveloper 11.1.1.2 but have also reproduced in 11.1.1.3.
    I am trying to implement drag and drop rows from one table to another. Everything works fine except when I do a Select All (ctrl-A) in a table, the table visually looks like all rows are selected, but when I try to click on one of the selected rows to drag to the other table, only the row I click on is dragged.
    I tried setting Range Size -1, fetch mode to FETCH_ALL, content delivery to "immediate" but nothing works.
    I even have reproduced not using a view object but just a List of beans with only 5 or 10 beans showing in the table.
    Does anyone know how to get Select All to work for a Drag Source?
    Thanks.
    -Ed

    Frank-
    OK, thanks for looking into that. I also submitted this service request, which includes a simple sample app to demonstrate the problem:
    SR #3-2387481211: ADF Drag and Drop does not work for rows in table using Select All
    Thanks again for the reply.
    -Ed

Maybe you are looking for