Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sql problem in select clause...

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

FredericGirod
Active Contributor
0 Kudos

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

5 REPLIES 5

FredericGirod
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Martin,

You can not subtract like this in SQL.

Use Functions like SUM, Count in SQL statement.

Regards,

Amey

Former Member
0 Kudos

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

abdul_hakim
Active Contributor
0 Kudos

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

abdul_hakim
Active Contributor
0 Kudos

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