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

Select Statment

Former Member
0 Likes
588

Hello,

I am trying to select field name ETENR with the highest value. with respect to VBELN table name vbep. so in VBEP there is one vbeln with more that one ETENR. I want to select the Highest ETENR for that Specific Vbeln. can anyone please help. I am new to ABAP.

Thanks.

4 REPLIES 4
Read only

Former Member
0 Likes
551

Hi,

Use order by descending..

DATA: V_ETENR LIKE VBEP-ETENR.

SELECT ETENR UP TO 1 ROWS

INTO V_ETENR

FROM VBEP

WHERE VBELN = '121212'

ORDER BY ETENR DESCENDING.

ENDSELECT.

IF SY-SUBRC = 0.

WRITE: / 'Last number - ', V_ETENR.

ENDIF.

Thanks,

Naren

Read only

Former Member
0 Likes
551

Please find the query here

SELECT MAX(ETENR)

INTO V_ETENR

FROM VBEP

WHERE VBELN = '100034'

ORDER BY ETENR DESCENDING.

ENDSELECT.

Regards

Kathirvel

Read only

0 Likes
551

SELECT MAX( ETENR ) as etenr

INTO Vbep-ETENR

FROM VBEP

WHERE VBELN = '100034'

.

Read only

venkata_ramisetti
Active Contributor
0 Likes
551

Hi heba,

Since ETENR is a numeric field, you can also write code like below.

DATA: V_ETENR TYPE VBEP-ETENR.

SELECT MAX( ETENR ) INTO V_ETENR

FROM VBEP

WHERE VBELN = V_VBELN.

I think this more efficient one.

Thanks

Ramakrishna