2013 Jul 01 5:31 AM
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.
2013 Jul 01 7:41 AM
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
2013 Jul 01 7:55 AM
Hi,
Share the code that you tried and where it is going wrong. We will correct it.
Regards,
Swarna
2013 Jul 01 8:17 AM
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.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |