Skip to Content
author's profile photo Former Member
Former Member

Sql problem in select clause...

Hi,

I need some help with my sql-statement.

I need to substract MENGE from DABMG.

It gives me an error below...

Any pointers ?

  • Get PO data Schedule

select

X_EKKO~EBELN as EBELN

X_EKKO~LIFNR as LIFNR

X_EKKO~BEDAT as BEDAT

X_EKKO~EKGRP as EKGRP

X_EKPO~WERKS as WERKS

X_EKPO~EBELP as EBELP

X_EKPO~MATNR as MATNR

(X_EKETMENGE-X_EKETDABMG) as MENGE " PROBLEM!!

X_EKET~EINDT as EINDT

from EKKO as X_EKKO

inner join EKPO as X_EKPO on X_EKPOEBELN = X_EKKOEBELN

inner join EKET as X_EKET on X_EKETEBELN = X_EKPOEBELN AND X_EKETEBELP = X_EKPOEBELP

into corresponding fields of table i_zopenpo_schedule

where

(i_where_clause).

//Martin

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Nov 25, 2005 at 09:43 AM

    Hi Martin,

    SAP is not a very good tool to play with SQL, maybe you have to be careful when you write a SQL command. The best way to play with ABAP is: get the data from the database and after play with this data.

    The cost time to get the data is really important, so stop to add inner join, group by or anything to strong for the SAP kernel. And inner join works well when you have a relation 1:n (with the key).

    My answer will be, substract outside from the SELECT.

    Rgd

    Frédéric

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 25, 2005 at 09:43 AM

    Hi Martin,

    You can not subtract like this in SQL.

    Use Functions like SUM, Count in SQL statement.

    Regards,

    Amey

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 25, 2005 at 09:46 AM

    Hi,

    Its not possible to substract in select statement itslef.

    Make it outside.

    And one more thing you r substracting DABMG from MENGE.

    But you mentioned that MENGE from DABMG in second line.

    Check & try again.

    (X_EKETMENGE-X_EKETDABMG) as MENGE " PROBLEM!!

    Regards

    KER

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 25, 2005 at 09:47 AM

    Hi Martin,

    You cannot subtract like this in SQL statement.

    Get the values from the DBtable and do your validation in your program(outside the SELECT).I would also advice you to avoid joins in this situation which may again end up with performance issue..

    Regards,

    Abdul

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 25, 2005 at 09:57 AM

    Hi Martin,

    Also replace your query with the following query.

    It will give good performance...

    SELECT ebeln

    lifnr

    bedat

    ekgrp

    FROM ekko INTO TABLE int_ekko.

    SELECT ebeln

    werks

    ebelp

    matnr

    FROM ekpo INTO TABLE int_ekpo

    FOR ALL ENTRIES IN int_ekko

    WHERE ebeln EQ int_ekko-ebeln.

    SELECT ebeln

    ebelp

    menge

    dabmg

    FROM eket INTO TABLE int_eket

    FOR ALL ENTRIES IN int_ekpo

    WHERE ebeln EQ int_ekpo-ebeln AND

    ebelp EQ int_ekpo-ebelp.

    LOOP AT int_eket INTO wa_eket.

    <Do your subtraction here>

    ENDLOOP.

    Regards,

    Abdul

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.