hie guys
i have done my program to send mail to sapmail inbox to users and its working well, however i want to resrtict the number of times it should send an email out about a particular lease out about to expire. my line of thot was that i extract all lease out from sap standard table where the lease out expires in within the next 6 months and modify my ztable. after that i want to extract from my ztable into an internal table where i will loop at, calculate the actual number of days left b4 expiry if the number is within a certain range and and a status is filled it shud skip that notice otherwise it shud populate email body table and modify the ztable entry with the status.
this is how im thinking because i want to limit the number of notifications that are sent out for a lease out to max 6 (ie 1st in sixth month, 2nd in fifth month, 3rd in fourth month etc)
please help me fine tune my code.
*----
P R O G R A M H E A D E R
*----
Program ID : Z_LEASE_NOTIFICATION
Version : 1.0
SAP Version : ECC 5.0
Program Name : Z_LEASE_NOTIFICATION
Created by : IPCHIKOVORE
Created on : 18.07.2008
Program Type : Report
Message Class : ZPRIN
Description : Lease Expiry Notification
*----
*----
C H A N G E H I S T O R Y
*----
Change Id :
Author :
Changed On :
Description : Lease Expiry Notification
*----
*&----
*& Report Z_LEASE_NOTIFICATION
*&----
REPORT z_lease_notification LINE-SIZE 200 NO STANDARD PAGE HEADING
MESSAGE-ID zpri.
*----
*TABLES DECLARATIONS
*----
TABLES: vimimv,
zzvimimv,
zreceiver,
zlease_receiver.
*----
VARIABLES DECLARATIONS, INTERNAL TABLES & WORK AREAS
*----
DATA: itab_zvimimv TYPE TABLE OF zzvimimv WITH HEADER LINE,
itab2_zvimimv TYPE TABLE OF zzvimimv WITH HEADER LINE.
DATA: edays TYPE i,
emonths TYPE i,
eyears TYPE i.
DATA: notification_msg(80),
subject LIKE sodocchgi1,
msg_body LIKE solisti1 OCCURS 0 WITH HEADER LINE,
receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA: status TYPE char1,
xp_date TYPE char10,
subject_obj_descr TYPE so_obj_des,
msg_body_line TYPE so_text255.
DATA: itab_zlease_receiver TYPE TABLE OF zlease_receiver WITH HEADER LINE.
*----
*SELECTION
*----
SELECT * FROM vimimv
INTO CORRESPONDING FIELDS OF zzvimimv
WHERE dmiend > sy-datum
AND smive <> 0.
IF sy-subrc = 0.
APPEND itab_zvimimv.
ENDIF.
ENDSELECT.
DESCRIBE TABLE itab_zvimimv.
IF sy-tfill = 0.
EXIT.
ELSE.
MODIFY zzvimimv FROM itab_zvimimv.
ENDIF.
REFRESH itab_zvimimv.
CLEAR: itab_zvimimv,
edays.
*----
*SELECTION ALL DATA INTO INTERNAL TABLE FROM ZTABLE
*----
SELECT * FROM zzvimimv INTO TABLE itab_zvimimv WHERE smive <> 0.
*----
*LOOP AT INTERNAL TABLE AND COMPUTE NUM OF DAYS LEFT FOR LEASE EXPIRY
*SORT INTERNAL TABLE BY STATUS
*----
LOOP AT itab_zvimimv.
CONCATENATE itab_zvimimv-dmiend6(2) '.' itab_zvimimv-dmiend4(2) '.' itab_zvimimv-dmiend(4) INTO xp_date.
CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
i_date_from = sy-datum "current sy-datum
i_date_to = itab_zvimimv-dmiend "day of lease termination
IMPORTING
e_days = edays
e_months = emonths
e_years = eyears.
IF ( ( edays > 150 ) AND ( edays <= 183 ) ).
IF itab_zvimimv-status <> 6.
itab_zvimimv-status = 6.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the first notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 120 ) AND ( edays <= 150 ) ) .
IF itab_zvimimv-status <> 5.
itab_zvimimv-status = 5.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the second notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 90 ) AND ( edays <= 120 ) ) .
IF itab_zvimimv-status <> 4.
itab_zvimimv-status = 4.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the third notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 60 ) AND ( edays <= 90 ) ) .
IF itab_zvimimv-status <> 3.
itab_zvimimv-status = 3.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the fourth notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 30 ) AND ( edays <= 60 ) ) .
IF itab_zvimimv-status <> 2.
itab_zvimimv-status = 2.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the fifth notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 15 ) AND ( edays <= 30 ) ) .
IF itab_zvimimv-status <> 1.
itab_zvimimv-status = 1.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the sixth notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 7 ) AND ( edays <= 14 ) ) .
IF itab_zvimimv-status <> 1.
itab_zvimimv-status = 1.
CONCATENATE: 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the fort-night notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF ( ( edays > 2 ) AND ( edays <= 7 ) ) .
IF itab_zvimimv-status <> 1.
itab_zvimimv-status = 1.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' this is the last week"s notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ELSEIF edays = 1.
IF itab_zvimimv-status <> 1.
itab_zvimimv-status = 1.
CONCATENATE 'Lease Out: ' itab_zvimimv-smive ' for customer: ' itab_zvimimv-kunnr ' expires on ' xp_date ' tomorrow, this is the final notification.'
INTO msg_body_line.
APPEND msg_body_line TO msg_body.
MODIFY itab_zvimimv.
ENDIF.
ENDIF.
ENDLOOP.
SORT itab_zvimimv BY status.
MODIFY zzvimimv FROM itab_zvimimv.
*----
*MAINTAIN MAIL RECEIVERS
*----
SELECT * FROM zlease_receiver
INTO TABLE itab_zlease_receiver
WHERE valid_to >= sy-datum.
LOOP AT itab_zlease_receiver.
receivers-receiver = itab_zlease_receiver-officer.
receivers-express = 'X'.
APPEND receivers.
ENDLOOP.
receivers-receiver = 'IPCHIKOVORE'.
receivers-express = 'X'.
APPEND receivers.
receivers-receiver = 'NNWAOGU'.
receivers-express = 'X'.
APPEND receivers.
receivers-receiver = 'AOMUYA'.
receivers-express = 'X'.
APPEND receivers.
receivers-receiver = 'AAJOLOPO'.
receivers-express = 'X'.
APPEND receivers.
receivers-receiver = 'OAMEZE'.
receivers-express = 'X'.
APPEND receivers.
receivers-receiver = 'MOJO'.
receivers-express = 'X'.
APPEND receivers.
receivers-receiver = 'AADENUSI'.
receivers-express = 'X'.
APPEND receivers.
*----
*MAIL HEADER
*----
CONCATENATE 'Lease Out Expiry Notification as at: ' sy-datum INTO subject_obj_descr.
subject-obj_descr = subject_obj_descr.
*----
*SEND MAIL
*----
DESCRIBE TABLE msg_body.
IF sy-tfill = 0.
EXIT.
ELSE.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = subject
put_in_outbox = 'X'
TABLES
object_content = msg_body
receivers = receivers.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.