Code: Alles auswählen.
SORT lt_data BY date+4 DESCENDING.
DELETE lt_data WHERE date+4 GE sy-datum+4. "Datum
* oder
SORT lt_data BY date DESCENDING.
DELETE lt_data WHERE date GE sy-datum+4. "Monat + Tag
READ TABLE lt_data INDEX 1 ASSIGNING FIELD-SYMBOL(<ls_data>).
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
PeterPaletti
Code: Alles auswählen.
METHOD if_oo_adt_classrun~main.
DATA: itab TYPE TABLE OF zbirthdays,
item TYPE zbirthdays,
today TYPE d,
dayDiff TYPE i,
prev TYPE zbirthdays,
prevDiff TYPE i,
current_year TYPE string,
dob TYPE d.
SELECT * FROM zbirthdays INTO TABLE itab.
today = sy-datum.
today = '20241015'.
DATA: formatDate TYPE string.
formatDate = |{ today+6(2) }.{ today+4(2) }.{ today+0(4) }|.
out->write( formatDate ).
out->write( | Today: { today } | ).
current_year = sy-datum(4).
" Lowest positive Diff-Value = nearst Date before Today in actual Year
LOOP AT itab INTO item.
dob = item-dob.
dob = current_year && dob+4(4).
dayDiff = today - dob.
IF dayDiff >= 0.
IF ( prevDiff IS INITIAL ) OR dayDiff < prevDiff.
prev = item.
prevDiff = dayDiff.
ENDIF.
ENDIF.
ENDLOOP.
IF ( prevDiff IS INITIAL ).
" Nothing found, no one had birthday this year
" Lowest negative diff Value = Nearest Birthdate to Dec. 31 past year
LOOP AT itab INTO item.
dob = item-dob.
dob = current_year && dob+4(4).
dayDiff = today - dob.
IF dayDiff < 0.
IF ( prevDiff IS INITIAL ) OR dayDiff < prevDiff.
prev = item.
prevDiff = dayDiff.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
out->write( | Geburtstag von { prev-name } am { prev-dob } | ).
ENDMETHOD.
Code: Alles auswählen.
define table zbirthdays {
key client : abap.clnt not null;
key id : sysuuid_x16 not null;
name : abap.char(100);
dob : abap.dats;
}
Code: Alles auswählen.
itab = VALUE #(
(
dob = '19830721'
id = cl_system_uuid=>create_uuid_x16_static( )
name = 'Hugo'
)
(
dob = '19871013'
id = cl_system_uuid=>create_uuid_x16_static( )
name = 'Peter'
)
(
dob = '19910501'
id = cl_system_uuid=>create_uuid_x16_static( )
name = 'Marie'
)
(
dob = '19731201'
id = cl_system_uuid=>create_uuid_x16_static( )
name = 'Birgit'
)
).