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

Former Member
0 Likes
616

hi,

i need to extract the highest number for vbeln.

example 12000012, 12000014, 12000018, then i will retrieve 12000018.

1)may i know below can return accurately? do i need to have group by?

2)also can have order by for select single? for this select statement i do not have max( ) but i got error.

SELECT SINGLE max( vbeln ) INTO wa_report-inv FROM vbfa

WHERE vbelv = wa_report-vgbel AND

posnv = wa_report-vgpos AND

vbtyp_n = 'U'.

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
593

Hi

Declare an ITAB with required fields

if not wa_report-vgbel [] is initial.

SELECT vbeln INTO table Itab FROM vbfa

WHERE vbelv = wa_report-vgbel AND

posnv = wa_report-vgpos AND

vbtyp_n = 'U'.

endif.

Sort ITAB by vbeln decending .

read table itab index 1.

if sy-subrc = 0.

<b>required VBELN (highest) = itab-vbeln.</b>

endif.

Reward points if useful

Regards

Anji

6 REPLIES 6
Read only

Former Member
0 Likes
593

hi,

i hope aggregate objects will not work single statement.so better remove single from select statement.

reward points if it is helpful

regards,

sangeetha.a

Read only

Former Member
0 Likes
594

Hi

Declare an ITAB with required fields

if not wa_report-vgbel [] is initial.

SELECT vbeln INTO table Itab FROM vbfa

WHERE vbelv = wa_report-vgbel AND

posnv = wa_report-vgpos AND

vbtyp_n = 'U'.

endif.

Sort ITAB by vbeln decending .

read table itab index 1.

if sy-subrc = 0.

<b>required VBELN (highest) = itab-vbeln.</b>

endif.

Reward points if useful

Regards

Anji

Read only

Former Member
0 Likes
593

Hi Eliana,

SINGLE is not required for MAX( VBELN ) as MAX( VBELN ) will itself picks highest vbeln from the table.

Check this code.

<b>SELECT max( vbeln )</b> INTO wa_report-inv FROM vbfa

WHERE vbelv = wa_report-vgbel AND

posnv = wa_report-vgpos AND

vbtyp_n = 'U'.

Thanks,

Vinay

Read only

Former Member
0 Likes
593

Hi elina,

this will work fine..

check this one

TABLES: sflight.

DATA wa_report LIKE sflight.

SELECT SINGLE MAX( seatsocc ) INTO wa_report-seatsocc

FROM sflight

WHERE carrid = 'AA'.

Regards

Sarath

Read only

S0025444845
Active Participant
0 Likes
593

Hi,

You can do like this,

SELECT vbeln INTO it_report FROM vbfa

WHERE vbelv = wa_report-vgbel AND

posnv = wa_report-vgpos AND

vbtyp_n = 'U'.

sort it_report by inv descending.

read table it_report index1.

regards,

sudha.

Read only

Former Member
0 Likes
593

put them in an internal table.

sort itab by vbeln.

loop at itab.

endloop.

now the last entry is that you want.

reward with points if its helpful.