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 statement problem

Former Member
0 Likes
1,408

Hello all,

I am facing a problem in finding maximum number by using a select stmt.

I had a table contain fields in this seq .

z_doc table:

1.PERNR type pernr

2. Doc_type type C

3.Doc_ID type NUMC

I want to find large number in DOC_ID .

I used select statement as

Select max (doc_id) from Z_doc into wa.

But i am not getting the large number in that .

Pls help me in this issue ..Thanking you.

URS ,

Suman

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
986

Hi Suman,

Alternative way :

1.select all the records into a table.

2.sort the table by docid descending.

3.read the table at index 1.

regards,

Dinesh

8 REPLIES 8
Read only

Former Member
0 Likes
986

Hi Suman,

Try this:



data: l_doc_id type numc.
..
..
Select max (doc_id) from z_doc into l_doc_id.

george

Read only

Former Member
0 Likes
987

Hi Suman,

Alternative way :

1.select all the records into a table.

2.sort the table by docid descending.

3.read the table at index 1.

regards,

Dinesh

Read only

Former Member
0 Likes
986

Hi Suman,

You cannot get that value to a Work Area or a structure,,..

It should be retrieve to a field,,, make sure that in

Select max (doc_id) from Z_doc into wa , WA is a field of doc_id type.

Thanks & regards,

Dileep .C

Read only

venkat_o
Active Contributor
0 Likes
986

Hi Suman,

Try below one, your query is right but you need to give INTO <fieldname> not <work area>.

TABLES ztest_pernr.
SELECT SINGLE MAX( doc_id ) FROM ztest_pernr INTO ztest_pernr-doc_id .
WRITE ztest_pernr-doc_id.

Thanks

Venkat

Read only

Former Member
0 Likes
986

Hello all,

I am facing a problem in finding maximum number by using a select stmt.

I had a table contain fields in this seq .

z_doc table:

1.PERNR type pernr

2. Doc_type type C

3.Doc_ID type NUMC

I want to find large number in DOC_ID .

I used select statement as

Select max (doc_id) from Z_doc into wa.

But i am not getting the large number in that .

Here the problem is Table is a DB table and it is sorting depends on PERNR.

So the value corresponding to highest perner getting as large doc_id.

We want to retried it by select stmt only becoz there are 50lacs data in that doc id.

Pls help me in this issue ..Thanking you.

URS ,

Suman

Read only

venkat_o
Active Contributor
0 Likes
986

Hi Suman, Try below one, your query is right but you need to give INTO <fieldname> not <work area>.


TABLES ztest_pernr.
SELECT SINGLE MAX( doc_id ) FROM ztest_pernr INTO ztest_pernr-doc_id .
WRITE ztest_pernr-doc_id.
Thanks Venkat.O

Read only

Former Member
0 Likes
986

Hi,

SELECT MAX( FIELDNAME ) INTO TABLENAME-FIELDNAME FROM TABLE NAME

WHERE FIELDNAME = <VARIABLE> OR <PARAMETER>.

If you use more than one field in select statement then use group by cause.

SELECT MAX( FIELDNAME ) fieldname2 fieldname 3 INTO ( TABLENAME-FIELDNAME, TABLENAME-FIELDNAME2, TABLENAME-FIELDNAME3 ) FROM TABLE NAME

WHERE FIELDNAME = <VARIABLE> OR <PARAMETER>

group by fieldname filedname2 fieldname3.

Aswarth

Read only

Former Member
0 Likes
986

thanks all