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

Finding Min value in an table using SY-TABIX variable.

praveen_kumar334
Participant
0 Likes
1,022

Hi Team,

I have a requirement where i want to find the min value( combination of both date and time) based on a transaction number using sy-tabix variable. Any input will be greatly appreciated. Below is the pseudo code, i am using to get the max value.

current output

Expected output for Min value :

lv_tabix_temp  = 1.
SORT RESULT_PACKAGE BY /bic/tnr       ASCENDING
                       /bic/zerdat    ASCENDING
                       /bic/zerzetims ASCENDING.
 LOOP AT RESULT_PACKAGE ASSIGNING <result_fields>. 
 lv_tabix = sy-tabix.
     LOOP AT RESULT_PACKAGE INTO wa_result_package FROM
                lv_tabix_temp WHERE /bic/zrpa_tnr = <result_fields>-/bic/zrpa_tnr.               
                lv_tabix_temp = sy-tabix.
    ENDLOOP.
        IF lv_tabix = lv_tabix_temp.
            <result_fields>-/bic/flag = 'X'.        
        ENDIF.
ENDLOOP.
3 REPLIES 3
Read only

FredericGirod
Active Contributor
952

If you make a Sort by TNR & ZERDAT & ZERZETIMS ascending, the first row of new TNR will be the lower values of ZERDAT & ZERZETIMS

So you don't need to play with SY-TABIX or do several LOOP on the same internal table.

Read only

praveen_kumar334
Participant
0 Likes
952

Hi Girod,

Yes, we can do that with sort. But I want to achieve that with SY-TABIX because of some other dependency. Any input on SY-TABIX will be of great help.

Read only

FredericGirod
Active Contributor
952

You have proposed a code with a SORT

Otherwise you could also add a new sorted key on the internal table.

If it is a lesson exercise and you have to follow stupid rules, just say it