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

how to group data based on date

0 Likes
1,362

In my program the internal table is returning several values based on date.

for example for the first pernr in the image below  there are four records. i need to delete the first record which is between the dates 20 and 30 .

and also i need to get the difference between the dates as the record 23 and 28  i need to get separate dates as 24, 25..28.

In my program the internal table is returning several values based on date.

for example for the first pernr in the image below  there are four records. i need to delete the first record which is between the dates 20 and 30 .

and also i need to get the difference between the dates as the record 23 and 28  i need to get separate dates as 24, 25..28.

3 REPLIES 3
Read only

kaushalya
Active Participant
0 Likes
1,091

Hi Narasimha,

Since the date fields BEGDA and ENDDA are stored in char field of format YYYYMMDD, the month and day can be extracted as sub-strings.

So, modify your internal table structure lt_fields2 and add two new fields to assign the month and day:

lt_fields2-month = BEGDA+4(2) and

lt_fields2-day = BEGDA+6(2).


Now you can put the sorting condition on it as:

SORT lt_fields2 BY month day.


To delete the records between the dates 20 and 30:

DELETE lt_fields2 WHERE day BETWEEN 20 AND 30.

Rgds

~Kaushalya

Read only

former_member217544
Active Contributor
0 Likes
1,091

Hi,

Share the code that you tried and where it is going wrong. We will correct it.

Regards,

Swarna

Read only

Former Member
0 Likes
1,091

I am not sure if I understood your question correctly.

From what I have understood, you can use the following logic.

This logic will move all the records from lt_fields2 to another table lt_fields1 with begda between 20 and 30 of any month, except for the first record. It will also move records for every date between begda and endda of each record.

You can alter the logic based on your exact requirement.

declare another table lt_fields1 like lt_fields2.

data del_flag.

data prev_month(2) type c.

sort lt_fields by pernr begda.

clear del_flag.

loop at lt_fields2 into wa_fields where begda+6(2) GE 20.

* Delete the first record having date greater than 20 in a month for each pernr.

   at new pernr.

        clear del_flag.

   endat.

   if begda+4(2) NE prev_month.

       clear del_flag.

  endif.         

    if del_flag is initial. 

        del_flag = 'X'.

        continue.  " This record will not be moved to the final internal table.

   endif.

* Add records for each date between begda and endda.

   append wa_fields to lt_fields1.

   prev_month = begda+4(2)

   while wa_fields-begda LT wa_fields-endda.

         wa_fields-begda = wa_fields-begda+1.

         append wa_fields to lt_fields1.

   endwhile.

endloop.