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

simple abap query doubt

Former Member
0 Likes
734

Hello all,

i have one simple doubt plz help.

data:begin of itab1 occurs 0,

psnfh like plfh-psnfh,

end of itab1.

select psnfh into table itab1

from plfh

where plnty = 'N'

AND plnNR = group_number

AND plnfl = W_PRT_ASSIGN-SEQUENCE_NO

and loekz ne 'X'

and plnkn = t_plnkn.

this query is working fine.

now i have 3 psnfh entires(0010 0020 0030) ..my requirement is that i have choose maximum of these that is 0030 and wanna add 0010 to it everytime.....and may be it will be better if i can save it in a variable.......

plz help in this syntax......i know we can use MAX function but it will be better if u can give that exact 2-3 lines of code.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
708

Hi Abhijeet,

Do you always want to add "0010" to the maximum value from that internal table?

If yes, then you can follow the steps mentioned below.

1. Declare temporary internal table and transfer al values from your main internal table to the temporary.

ITAB_TEMP[] = ITAB[].

2. Now Sort the temp table as follows.

SORT ITAB_TEMP BY fieldname DESCENDING.

3. Now if you READ this temp table with INDEX 1, you wil get the maximum value to which you can add the value.

READ TABLE ITAB_TEMP INTO W_ITAB INDEX 1.

IF SY-SUBRC EQ 0.

V_MAX = W_ITAB-field + 0010.

ENDIF.

Best Regards,

Ram.

5 REPLIES 5
Read only

Former Member
0 Likes
708

Hi,

do it in this way.

in a loop first compare the values and assign max value to a variable.

then again in a loop increase the value as per your requirment.

hope it will help you.

Thanks

Rajesh Kumar

Read only

Former Member
0 Likes
708

Hi Abhijeet.

Let all the entries come into your internal table first. After you got all the entries :

sort itab by psnfh descending.

read table itab from wa index 1.

if sy-subrc eq 0.
   add 10 to wa_psnfh.
endif.

and delete rest of the records if unnecessary.

Regards,

Swapna.

Read only

Former Member
0 Likes
708

Hi,

Sort the internal table entries in descending order.

And delete all the remaining entries except the first entry,

Read only

Former Member
0 Likes
709

Hi Abhijeet,

Do you always want to add "0010" to the maximum value from that internal table?

If yes, then you can follow the steps mentioned below.

1. Declare temporary internal table and transfer al values from your main internal table to the temporary.

ITAB_TEMP[] = ITAB[].

2. Now Sort the temp table as follows.

SORT ITAB_TEMP BY fieldname DESCENDING.

3. Now if you READ this temp table with INDEX 1, you wil get the maximum value to which you can add the value.

READ TABLE ITAB_TEMP INTO W_ITAB INDEX 1.

IF SY-SUBRC EQ 0.

V_MAX = W_ITAB-field + 0010.

ENDIF.

Best Regards,

Ram.

Read only

Former Member
0 Likes
708

thnks