Вы находитесь на странице: 1из 4

METHOD get_contract_details.

TYPES: BEGIN OF lty_serv_req,


guid TYPE crmt_object_guid,
object_id TYPE crmt_object_id_db,
END OF lty_serv_req.

DATA: c_sitetype TYPE smw1stid VALUE 'SMOF_ERPSITE',


ls_smof_erpsh TYPE smof_erpsh.

DATA: lt_serv_req TYPE TABLE OF lty_serv_req,


ls_serv_req LIKE LINE OF lt_serv_req,
lt_serv_req_temp TYPE TABLE OF lty_serv_req,
ls_serv_req_temp LIKE LINE OF lt_serv_req,
lt_guid TYPE crmt_object_guid_tab,
lt_requested_objects TYPE crmt_object_name_tab,
ls_requested_objects LIKE LINE OF lt_requested_objects,
lt_ref_obj TYPE crmt_refobj_wrkt,
ls_ref_obj LIKE LINE OF lt_ref_obj.

DATA: lv_destination TYPE char40,


lv_contractid TYPE vbeln_va,
lv_start_date TYPE dats,
lv_end_date TYPE dats,
lv_free_callouts TYPE c LENGTH 4,
lv_amc_options TYPE c LENGTH 50,
lv_callouts TYPE i,
lv_count TYPE i,
lv_days_diff TYPE i,
lv_diff TYPE string.

* Get the RFC destination attached to the SITEID Type ERP


CALL FUNCTION 'SMOF_READ_SMOFERPSH'
EXPORTING
i_sitetypeid = c_sitetype
i_mandt = sy-mandt
IMPORTING
e_smof_erpsh = ls_smof_erpsh.

* Check for the RFC existence


CALL FUNCTION 'RFC_CHECK_DESTINATION'
EXPORTING
mydest = ls_smof_erpsh-rfcdest
mytype = '3'
EXCEPTIONS
empty_destination = 1
invalid_logical_destination = 2
destination_with_special_char = 3
internal_destination_id = 4
empty_rfctype = 5
OTHERS = 6.

lv_destination = ls_smof_erpsh-rfcdest.

CALL FUNCTION 'ZCRM_GET_DATA_FOR_CONTRACT'


DESTINATION lv_destination
EXPORTING
tplnr = ip_objectid
IMPORTING
valid_cont = lv_contractid
start_date = lv_start_date
end_date = lv_end_date
free_callout = lv_free_callouts
amc_options = lv_amc_options.

IF lv_contractid IS NOT INITIAL.


SHIFT lv_contractid LEFT DELETING LEADING '0'.

CONCATENATE 'Contract No: ' lv_contractid


' Validity: ' lv_start_date+6(2) '.' lv_start_date+4(
2) '.' lv_start_date+0(4)
' to ' lv_end_date+6(2) '.' lv_end_date+4(2) '.' lv_e
nd_date+0(4)
INTO ep_contractdet.

IF lv_free_callouts EQ '*'.
* Begin of changes by Abid : 10th April 2018 TR : CMDK901014.
* Below lines Commented by Abid. No need to show pending free callo
uts if free callout is unlimited
* CONCATENATE 'Pending free callouts: Unlimited,' lv_amc_options
* INTO ep_callout
* SEPARATED BY space.
* End of changes by Abid TR : CMDK901014.
ELSEIF lv_free_callouts IS INITIAL.
* Begin of changes by Abid : 10th April 2018 TR : CMDK901014.
* Below lines Commented by Abid. No need to show pending free callo
uts if free callout is unlimited
* CONCATENATE 'Pending free callouts: Unlimited,' lv_amc_options
* INTO ep_callout
* SEPARATED BY space.
* End of changes by Abid TR : CMDK901014.
ELSE.
* Begin of changes by Abid : 10th April 2018 TR : CMDK901014.
* To resolve AMC details not showing up on CRM ISSUE.
* logic : lv_free_callouts is of type Char, when free call outs is u
nlimited :
* the statement "MOVE lv_free_callouts TO lv_callouts" is throwing e
rror because :
* lv_callouts is of type I so type mismatch happens.
* So excluding the assignments when free callout is unlimited.
IF NOT ( lv_free_callouts cs 'UNLI').
* End of changes by Abid TR : CMDK901014.
MOVE lv_free_callouts TO lv_callouts.
* Begin of changes by Abid : 10th April 2018 TR : CMDK901014.
ENDIF.
* End of changes by Abid TR : CMDK901014.

SELECT guid
object_id
FROM crmd_orderadm_h
INTO CORRESPONDING FIELDS OF TABLE lt_serv_re
q_temp
WHERE process_type = 'YSVR'
AND zzfld00000j = '003' " AMC Free Callout
-- 002 Old value.
AND posting_date BETWEEN lv_start_date AND
lv_end_date.
IF lt_serv_req_temp[] IS NOT INITIAL.
LOOP AT lt_serv_req_temp INTO ls_serv_req_temp.
INSERT ls_serv_req_temp-guid INTO TABLE lt_guid.
ENDLOOP.

ls_requested_objects = 'REFOBJ'.
INSERT ls_requested_objects INTO TABLE lt_requested_objects.
CLEAR ls_requested_objects.

CALL FUNCTION 'CRM_ORDER_READ'


EXPORTING
it_header_guid = lt_guid[]
it_requested_objects = lt_requested_objects[]
IMPORTING
et_refobj = lt_ref_obj[]
EXCEPTIONS
document_not_found = 1
error_occurred = 2
document_locked = 3
no_change_authority = 4
no_display_authority = 5
no_change_allowed = 6
OTHERS = 7.
IF sy-subrc <> 0.
ENDIF.

lt_serv_req[] = lt_serv_req_temp[].

LOOP AT lt_serv_req_temp INTO ls_serv_req_temp.


READ TABLE lt_ref_obj INTO ls_ref_obj WITH KEY ref_guid =
ls_serv_req_temp-guid
ref_kind =
'A'.
IF sy-subrc = 0.
IF ls_ref_obj-product_id NE ip_objectid.
DELETE lt_serv_req WHERE guid = ls_serv_req_temp-guid.
ENDIF.
ENDIF.
ENDLOOP.

DESCRIBE TABLE lt_serv_req LINES lv_count.


* Begin of changes by Abid : 10th April 2018 TR : CMDK901014.
* No need to determine and show pending free lookout if free lookout
is unlimited.
IF NOT ( ( lv_free_callouts cs 'UNLI') or
( lv_free_callouts is INITIAL ) or
( lv_free_callouts eq '*') ). """"-----------
--ABID
* End of changes by Abid TR : CMDK901014.
lv_callouts = lv_callouts - lv_count.

lv_free_callouts = lv_callouts.

CONCATENATE 'Pending free callouts:' lv_free_callouts ',' lv_


amc_options
INTO ep_callout
SEPARATED BY space.
* Begin of changes by Abid : 10th April 2018 TR : CMDK901014.
ENDIF.
* End of changes by Abid TR : CMDK901014.

ENDIF.
ENDIF.

lv_days_diff = lv_end_date - sy-datum.

IF lv_days_diff LE 30.
lv_diff = lv_days_diff.

CONCATENATE 'Contract expiring in' lv_diff 'days'


INTO ep_contractexp
SEPARATED BY space.
ENDIF.
ELSE.
CONCATENATE 'No Valid Contract' 'determined.'
INTO ep_callout
SEPARATED BY space.
ENDIF.
ENDMETHOD.

Вам также может понравиться