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: 

How to change code in SAP Query

Former Member
0 Kudos
4,210

Hi Experts !!

In SAP QUERY I am getting the PO with all delivey dates & deliveried Qty but I have to select only single PO with latest delivery date & qty. If there r more than one record for latest delivery date than deliveried QTY must be sum of all QTY (for the latest delivery date). for example :

this is coming

Po delivery date qty

10001 30.06.2009 4

10001 30.06.2009 5

10001 01.05.2009 4

we want

Po delivery date qty

10001 30.06.2009 9

Thanks in advance.

Thanks & Regards

Navneet Singhal

1 ACCEPTED SOLUTION

Former Member
0 Kudos
593

Open the transaction SQ02, give the infoset name and click on change button.

click on the EXTRAS button, and under the CODE tab select the event and write your logic in the down.

Thanks,

Srinivas

6 REPLIES 6

Former Member
0 Kudos
593

Hi Navneeth,

Selection depends on your where clause,

so please can you post your query to help u out,,

Here is a sample method,


DATA : P_WADAT TYPE LIKP-WADAT.

SELECT MAX(WADAT) INTO P_WADAT FROM LIKP.

SELECT VBELN WADAT LFIMG INTO (VBELN, DATE, QTY) WHERE WADAT EQ P_WADAT AND VBELN EQ VBELN.

IT_FINAL-QTY = IT_FINAL-QTY + QTY .
IT_FINAL-VBELN = VBELN.
IT_FINAL-DATE = DATE.

CLEAR : VBELN, DATE, QTY.
ENDSELECT.

Former Member
0 Kudos
594

Open the transaction SQ02, give the infoset name and click on change button.

click on the EXTRAS button, and under the CODE tab select the event and write your logic in the down.

Thanks,

Srinivas

0 Kudos
593

Thanks Srinivas !

There is an internal table %G00 in query generated program (AQCSZPCWMM======Z_PCW_ORDER_V2) when I use this table in Code section (END-OF-SELECTION ) system thro msg %G00 is not defined . if I define this table in DATA section than run the query , It gives the DUMP with error %G00 is already decleared.

How can I use %G00 internal table in my code section.

Kindly suggest.

Thanks & Regards

Navneet Singhal

0 Kudos
593

hi Navneet,

did you got answer to your question (%g00 defined in query code....), if yes then could you please share with me.

thanks & regards,

Hari Krishna.K

0 Kudos
593

>

> There is an internal table %G00 in query generated program (AQCSZPCWMM======Z_PCW_ORDER_V2) when I use this table in Code section (END-OF-SELECTION ) system thro msg %G00 is not defined . if I define this table in DATA section than run the query , It gives the DUMP with error %G00 is already decleared.

>

> How can I use %G00 internal table in my code section.

I have the same problem as the OP. I need to get rid of the duplicates and have all sumarized in just one row. I was thinking about this same solution, but when I add code to the END-OF-SELECTION event, this doesn't appears anywhere (but if I add code to any calculated field, yes).

And the problem of the quoted message. I tried using field-symbols but I have errors saying that it's nos a valid table, etc...

Any ideas???

Thanks!!!

Former Member
0 Kudos
593

Hi,

The folowing code will help you.

TABLES: EKPO.

DATA : P_WADAT TYPE EKPO-AEDAT ,

P_EBELN TYPE EKPO-EBELN VALUE '3000000004',

X LIKE EKPO-AEDAT,

Y LIKE EKPO-EBELN,

Z LIKE EKPO-MENGE,

M LIKE EKPO-AEDAT.

SELECT MAX( AEDAT ) INTO EKPO-AEDAT FROM EKPO WHERE EBELN = P_EBELN.

M = EKPO-AEDAT.

SELECT SUM( MENGE ) EBELN AEDAT INTO (Z, Y, X) FROM EKPO WHERE AEDAT EQ M AND EBELN EQ P_EBELN GROUP BY MENGE EBELN AEDAT.

ENDSELECT.

Z gives the sum of quantity.

Aswarth