Application Development and Automation 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: 
Read only

abap help needed (select)

Former Member
0 Likes
984

Hi,

I would like to read from table where more than one entry for each material is. I would like to get just the higher one. How to maintain the code?

Example:

***

SELECT SINGLE * FROM AUSP WHERE ( OBJEK = MVKE-MATNR ) AND

( ATWRT IN ATWRT ) AND

( ATZHL ?????????????? ).

In the field ATZHL are numbers from 1-4. How can I write the code, that the program will give to me the higher entry?

BR

Saso

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
922

try this

SELECT * FROM AUSP

into wa_ausp

up to 1 rows

WHERE ( OBJEK = MVKE-MATNR ) AND

( ATWRT IN ATWRT )

order descending by atzhl.

endselect.

    • reward if solved**

6 REPLIES 6
Read only

Former Member
0 Likes
922

Hi

There will be multiple characteristics(ATINN) for a same single material

and the characteristic values (ATWRT) are stored in this table.

So which characteristci value you need

decide and use this table

So pass Material number and as well as ATINN field also to take a particular value.

you can use the BAPI or fun module

BAPI_OBJCL_GETDETAIL

or use the fun module:

CLAF_CLASSIFICATION_OF_OBJECTS.

for this purpose.

Regards

Anji

Message was edited by:

Anji Reddy Vangala

Read only

Former Member
0 Likes
922

Use aggregate functions , in below format

select MAX(x)

y

z

from tab1

where....

Read only

0 Likes
922

Uf , sorry I don't understand ) Can you change my select ?

SELECT SINGLE * FROM AUSP WHERE ( OBJEK = MVKE-MATNR ) AND

( ATWRT IN ATWRT ) AND

( ATZHL = MAX *******).

thanks a lot

saso

Read only

Former Member
0 Likes
923

try this

SELECT * FROM AUSP

into wa_ausp

up to 1 rows

WHERE ( OBJEK = MVKE-MATNR ) AND

( ATWRT IN ATWRT )

order descending by atzhl.

endselect.

    • reward if solved**

Read only

Former Member
0 Likes
922

Hi Saso, depending on the use of the program you are planning to write and your level of comfort with the values of ATZHL you could always try a while loop. It may be faster than reading the BAPI. Using a temporary value for ATZHL you could use the following code.



data: t_atzhl type ausp-atzhl.

t_atzhl = 4.

while t_atzhl > 0.

SELECT SINGLE * FROM AUSP WHERE ( OBJEK = MVKE-MATNR ) AND
( ATWRT IN ATWRT ) AND
( ATZHL = t_atzhl ).

  if sy-subrc = 0.

    t_atzhl = 0.

  else.

    t_atzhl = t_atzhl - 1.

  endif.


endwhile.

Kevin

Read only

Former Member
0 Likes
922

Hi Saso,

Check the query below, this should give you the total idea

how to get the desired result...


tables : ausp.

select  * from ausp into ausp up to 1 rows
where OBJEK = '000000000000000001'
order BY ATINN DESCENDING.
endselect.

Hope this worked for u..

Happy coding .......

Regards,

SJ