Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
suryag
Explorer
0 Kudos
Introduction:

The development of this interface will facilitate the entry of delegation values into the standard SAP table HRUS_D2. 3PL system will provide a file that will be sent to SAP nightly utilizing PI for processing. The file will be tab delimited in format and will be placed in be placed in a SAPIN folder: \\saptest\\sapin\erp\\folder

Overview:-

1) 3PL system will provide a file.

2) The file will be tab delimited in format and will be placed in be placed in a SAPIN folder.

3) Path \\saptest\\sapin\\erp\\folder

4) Check conditions. If yes, based on conditions data will be created or updated or modified         in HRUS_D2 table. Send log information through email.

5) If no, continue business process.

 

Step By Step Procedure for Creating Proxy

1.The Proxy Service Interface has to be created by PI consultant from PI side. This will further reflect in ABAP side in T-Code “SPROXY”.

2.Create the Proxy from T-Code “SPROXY”.

3.The Proxy created from PI side will be reflected with following details in SPROXY.
Software Component: Service_1.0_of_erp.com
Namespace:                http://erp.com//3PLtoSAPService
Service Interfaces:      Service_Async_Out

4. Proxy Name will be available once we generate the Proxy.

To generate proxy we need to right click on Service Interface “Service_Async_Out” for Outbound and     click on “Create Proxy”.

5.We need to give the “Package” and “Transport Request” to which the Proxy needs to be saved.

6.Once the proxy is created for a service interface then that Interface will be marked as Green.

7. we can find the Proxy Name when we double click on the generated Service Interface. In this case since the Outbound Proxy was already generated we can find the Proxy name of that.

8 .The objects created when we generate a Proxy is as follows
I. Data Type
ii. Message Type
iii. Proxy Class.

 

Implement proxy class method

Switch to the Properties tab. Double-click the implementing class. and then double-click the method.

Maintain the implementation of the method.

Purpose: Upload data into HRUS_D2 table(Substituted by User).using below function modules in our interface.

SAP_WAPI_SUBSTITUTE_DELETE
SAP_WAPI_SUBSTITUTE_MAINTAIN
RH_UPDATE_SUBST_LIST_SERVER

Total 3 scenarios are there

Once the file triggers proxy then checking the conditions. Based on conditions data will be created or updated or modified.

Scenario1: If file data not in a table, then it inserts a new record same as in file.

Scenario2: If file data in a table, then it updates existing record same as in file.

Scenario3: Table data not in a file then need to update end date and active with ‘space’.

After file execution sent an email with log information (which email is maintained in ZEMAIL table).

 

METHOD zclii_service_async_in~service_async_in.

*/ Structure declarations
TYPES: BEGIN OF ty_input,
us_name TYPE xubname,
rep_name TYPE xubname,
begda TYPE begdatum,
endda TYPE enddatum,
reppr TYPE hr_rep_prf,
active TYPE hs_rep_act,
END OF ty_input.
TYPES: BEGIN OF ty_final,
us_name TYPE xubname,
rep_name TYPE xubname,
begda TYPE begdatum,
endda TYPE enddatum,
reppr TYPE hr_rep_prf,
active TYPE hs_rep_act,
message(100) TYPE c,
END OF ty_final.

DATA: substituted_obj TYPE swragent,
substitute TYPE swragent,
sub_beg TYPE swr_substbegin,
sub_end TYPE swr_substend,
sub_pfile TYPE swr_substprof,
sub_act TYPE swr_substactive,
lang TYPE sylangu,
ext_badi TYPE xfeld,
ret_code TYPE sysubrc,
msg_lines TYPE TABLE OF swr_messag,
msg_str TYPE TABLE OF swr_mstruc,
subs_tab TYPE TABLE OF swragent,
date(2) TYPE c,
month(2) TYPE c,
year(4) TYPE c,
lv_datum(8) TYPE c,
lv_dat(8) TYPE c.

*/ Data declarations
DATA:
*/ Internal Tables
lt_input TYPE TABLE OF ty_input,
lt_output TYPE TABLE OF ty_input,
lt_modify TYPE TABLE OF ty_input,
lt_temp TYPE TABLE OF ty_input,
lt_insert TYPE TABLE OF ty_input,
lt_update TYPE TABLE OF ty_input,
lt_updatex TYPE TABLE OF ty_input,
lt_deletex TYPE TABLE OF ty_input,
lt_email_address TYPE ifp_tab_address,
lt_binary_content TYPE solix_tab,
lt_email_body TYPE TABLE OF tline,

*/ Local Reference
lo_email TYPE REF TO zcl_gen_utilities,

*/ Local Structures
ls_output TYPE ty_input,
ls_insert TYPE ty_input,
ls_update TYPE ty_input,
ls_updatex TYPE ty_input,
ls_deletex TYPE ty_input,
ls_email_body TYPE tline,
ls_email_address TYPE ifp_str_address,

*/ Local Variables
lv_string TYPE string,
lv_size TYPE so_obj_len,
lv_subject(50),
lv_enddate TYPE sy-datum,
lv_err TYPE c,
lc_tab TYPE c VALUE cl_bcs_convert=>lc_tab,
lc_crlf TYPE c VALUE cl_bcs_convert=>lc_crlf.

DATA:
subst_tab TYPE STANDARD TABLE OF hrus_d2, "TABLES PARAM
wa_subst_tab LIKE LINE OF subst_tab,
err_tab TYPE STANDARD TABLE OF hrscmperr, "TABLES PARAM
wa_err_tab LIKE LINE OF err_tab.

DATA: lt_final TYPE TABLE OF ty_final,
ls_final TYPE ty_final,
lt_hrus TYPE TABLE OF hrus_d2,
lt_temp TYPE TABLE OF hrus_d2.

*/ Constants Declarations

CONSTANTS: lc_eamt_parameters TYPE string VALUE 'ZEMAIL', "
lc_ricefid_1234 TYPE zparam_name VALUE 'EMAIL1234', "
lc_param_name TYPE zmaptype1 VALUE 'Z1234_EMAIL'. "
"lc_eamt_parameters TYPE string VALUE 'ZEAMT_PARAMETERS', "

REFRESH: lt_input, lt_output, lt_update, gt_insert, lt_updatex,
lt_final, lt_hrus, lt_temp, lt_temp, subst_tab, err_tab, gt_deletex.
CLEAR: ls_final, ls_output, ls_insert, gs_update, ls_updatex, ls_deletex.

IF input-delegation_update_sap IS NOT INITIAL.
MOVE-CORRESPONDING input-delegation_update_sap-record TO lt_input.

LOOP AT lt_input INTO DATA(ls_input).
ls_output-us_name = ls_input-us_name.
ls_output-rep_name = ls_input-rep_name.
ls_output-begda = ls_input-begda.
ls_output-endda = ls_input-endda.
ls_output-reppr = ls_input-reppr.
ls_output-active = ls_input-active.
APPEND ls_output TO lt_output.
CLEAR:ls_output,
ls_input.
ENDLOOP.

LOOP AT lt_output INTO DATA(ls_output) WHERE reppr = '0003'.
month = ls_output-begda+0(2).
date = ls_output-begda+2(2).
year = ls_output-begda+4(4).
CONCATENATE year month date INTO ls_output-begda.

month = ls_output-endda+0(2).
date = ls_output-endda+2(2).
year = ls_output-endda+4(4).
CONCATENATE year month date INTO ls_output-endda.

SELECT SINGLE * FROM hrus_d2 INTO @DATA(ls_hrus) WHERE us_name = @ls_output-us_name
AND rep_name = @ls_output-rep_name
AND begda = @ls_output-begda.
"Case1 File data not in a table then insert a record
IF sy-subrc <> 0 AND ls_hrus IS INITIAL.
MOVE-CORRESPONDING ls_output TO ls_insert.
APPEND ls_insert TO gt_insert.
"Case2 File data in a table then update a record
ELSEIF ls_hrus IS NOT INITIAL.

IF ls_output-endda = ls_hrus-endda. "It triggers Maintain Function module
MOVE-CORRESPONDING ls_output TO gs_update.
APPEND ls_update TO lt_update.
ELSEIF ls_output-endda <> ls_hrus-endda.. "It triggers delete FM and insert a record
MOVE-CORRESPONDING ls_output TO ls_updatex.
APPEND ls_updatex TO lt_updatex.

MOVE-CORRESPONDING ls_output TO ls_deletex.
ls_deletex-endda = ls_hrus-endda. "need
APPEND ls_deletex TO gt_deletex.
ENDIF.

ENDIF.
CLEAR: ls_insert, ls_output, ls_hrus, gs_update, ls_updatex, ls_deletex.
ENDLOOP.

"Case3 Table data not in a file then need to update enddate and active
LOOP AT lt_output INTO DATA(gs_modify).
month = gs_modify-begda+0(2).
date = gs_modify-begda+2(2).
year = gs_modify-begda+4(4).
CONCATENATE year month date INTO gs_modify-begda.

month = gs_modify-endda+0(2).
date = gs_modify-endda+2(2).
year = gs_modify-endda+4(4).
CONCATENATE year month date INTO gs_modify-endda.

APPEND gs_modify TO lt_temp.
CLEAR: gs_modify.
ENDLOOP.

IF lt_temp IS NOT INITIAL.
SELECT * FROM hrus_d2 INTO TABLE lt_temp WHERE reppr = '0003'.

LOOP AT lt_temp INTO DATA(gs_temp).
DELETE lt_temp WHERE us_name = gs_temp-us_name
AND rep_name = gs_temp-rep_name
AND begda = gs_temp-begda.
CLEAR: gs_temp.
ENDLOOP.
lt_hrus = lt_temp.

"Delete the records
LOOP AT lt_temp INTO DATA(ls_temp) WHERE active = 'X'.
substituted_obj-otype = 'US'.
substituted_obj-objid = ls_temp-us_name.

substitute-otype = 'US'.
substitute-objid = ls_temp-rep_name.
APPEND substitute TO subs_tab.

sub_beg = ls_temp-begda.
sub_end = ls_temp-endda.

CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_DELETE'
EXPORTING
substituted_obj = substituted_obj
start_date = sub_beg
end_date = sub_end
delete_without_date = 'X'
lang = sy-langu
ext_badi = ' '
IMPORTING
ret_code = ret_code
TABLES
substitutes = subs_tab
msg_lines = msg_lines
msg_str = msg_str.
CLEAR: ls_temp.
REFRESH: subs_tab.
ENDLOOP.

"Change end date and active with space
LOOP AT lt_hrus INTO ls_hrus.
IF ls_hrus-active = 'X'.
gs_modify-us_name = ls_hrus-us_name.
gs_modify-rep_name = ls_hrus-rep_name.
gs_modify-begda = ls_hrus-begda.
lv_datum = sy-datum.
lv_dat = lv_datum - 1.
year = lv_dat+0(4).
month = lv_dat+4(2).
date = lv_dat+6(2).
CONCATENATE year month date INTO gs_modify-endda. "need to modify
gs_modify-reppr = ls_hrus-reppr.
gs_modify-active = ls_hrus-active.
APPEND gs_modify TO lt_modify.
CLEAR: gs_modify, ls_hrus, lv_dat.
ELSE.
MOVE-CORRESPONDING ls_hrus TO gs_modify.
APPEND gs_modify TO lt_modify.
CLEAR: gs_modify, ls_hrus.
ENDIF.
ENDLOOP.
ENDIF.

LOOP AT lt_deletex INTO ls_deletex.
substituted_obj-otype = 'US'.
substituted_obj-objid = ls_deletex-us_name.
substitute-otype = 'US'.
substitute-objid = ls_deletex-rep_name.
APPEND substitute TO subs_tab.
sub_beg = ls_deletex-begda.
sub_end = ls_deletex-endda.

CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_DELETE'
EXPORTING
substituted_obj = substituted_obj
start_date = sub_beg
end_date = sub_end
delete_without_date = 'X'
lang = sy-langu
ext_badi = ' '
IMPORTING
ret_code = ret_code
TABLES
substitutes = subs_tab
msg_lines = msg_lines
msg_str = msg_str.
CLEAR: ls_deletex.
REFRESH: subs_tab.
ENDLOOP.

"Case1 Create a new record
IF lt_insert IS NOT INITIAL.

LOOP AT lt_insert INTO ls_insert.
substituted_obj-otype = 'US'.
substituted_obj-objid = ls_insert-us_name.
substitute-otype = 'US'.
substitute-objid = ls_insert-rep_name.
sub_beg = ls_insert-begda.
sub_end = ls_insert-endda.
sub_pfile = ls_insert-reppr.
sub_act = ls_insert-active.

CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_MAINTAIN'
EXPORTING
substituted_obj = substituted_obj
substitute = substitute
sub_beg = sub_beg
sub_end = sub_end
sub_pfile = sub_pfile
sub_act = sub_act
lang = sy-langu
ext_badi = ' '
IMPORTING
ret_code = ret_code
TABLES
msg_lines = msg_lines
msg_str = msg_str.

IF ret_code = 0.
ls_final-us_name = ls_insert-us_name.
ls_final-rep_name = ls_insert-rep_name.
ls_final-begda = ls_insert-begda.
ls_final-endda = ls_insert-endda.
ls_final-reppr = ls_insert-reppr.
ls_final-active = ls_insert-active.
ls_final-message = 'Create a new record'.
APPEND ls_final TO lt_final.
ELSE.
ls_final-us_name = ls_insert-us_name.
ls_final-rep_name = ls_insert-rep_name.
ls_final-begda = ls_insert-begda.
ls_final-endda = ls_insert-endda.
ls_final-reppr = ls_insert-reppr.
ls_final-active = ls_insert-active.
ls_final-message = 'Record is already existed'.
APPEND ls_final TO lt_final.
ENDIF.

CLEAR: ls_insert, ls_final.
ENDLOOP.
ENDIF.
"Case2 Update a existing record
IF lt_update IS NOT INITIAL. "It triggers update a existing record
LOOP AT lt_update INTO gs_update.
substituted_obj-otype = 'US'.
substituted_obj-objid = gs_update-us_name.
substitute-otype = 'US'.
substitute-objid = gs_update-rep_name.
sub_beg = gs_update-begda.
sub_end = gs_update-endda.
sub_pfile = gs_update-reppr.
sub_act = gs_update-active.

CALL FUNCTION 'SAP_WAPI_SUBSTITUTE_MAINTAIN'
EXPORTING
substituted_obj = substituted_obj
substitute = substitute
sub_beg = sub_beg
sub_end = sub_end
sub_pfile = sub_pfile
sub_act = sub_act
lang = sy-langu
ext_badi = ' '
IMPORTING
ret_code = ret_code
TABLES
msg_lines = msg_lines
msg_str = msg_str.

IF ret_code = 0.
ls_final-us_name = gs_update-us_name.
ls_final-rep_name = gs_update-rep_name.
ls_final-begda = gs_update-begda.
ls_final-endda = gs_update-endda.
ls_final-reppr = gs_update-reppr.
ls_final-active = gs_update-active.
ls_final-message = 'Modified Existing Record'.
APPEND ls_final TO lt_final.
ELSE.
ls_final-us_name = gs_update-us_name.
ls_final-rep_name = gs_update-rep_name.
ls_final-begda = gs_update-begda.
ls_final-endda = gs_update-endda.
ls_final-reppr = gs_update-reppr.
ls_final-active = gs_update-active.
ls_final-message = 'Record is already existed'.
APPEND ls_final TO lt_final.
ENDIF.

CLEAR: gs_update, ls_final.
ENDLOOP.
ENDIF.

IF lt_updatex IS NOT INITIAL. "It triggers delete FM and insert a new record

LOOP AT lt_updatex INTO ls_updatex.
wa_subst_tab-us_name = ls_updatex-us_name.
wa_subst_tab-rep_name = ls_updatex-rep_name.
wa_subst_tab-begda = ls_updatex-begda.
wa_subst_tab-endda = ls_updatex-endda.
wa_subst_tab-reppr = ls_updatex-reppr.
wa_subst_tab-active = ls_updatex-active.
APPEND wa_subst_tab TO subst_tab.

CALL FUNCTION 'RH_UPDATE_SUBST_LIST_SERVER'
TABLES
subst_tab = subst_tab
err_tab = err_tab
EXCEPTIONS
no_wf_plvar = 1
. " RH_UPDATE_SUBST_LIST_SERVER

IF sy-subrc EQ 0.
"All OK
ELSEIF sy-subrc EQ 1. "Exception
"Add code for exception here
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = '1'
* IMPORTING
* RETURN =
.
WAIT UP TO 1 SECONDS.
IF sy-subrc = 0.
ls_final-us_name = ls_updatex-us_name.
ls_final-rep_name = ls_updatex-rep_name.
ls_final-begda = ls_updatex-begda.
ls_final-endda = ls_updatex-endda.
ls_final-reppr = ls_updatex-reppr.
ls_final-active = ls_updatex-active.
ls_final-message = 'Modified Existing Record'.
APPEND ls_final TO lt_final.
ELSE.
ls_final-us_name = ls_updatex-us_name.
ls_final-rep_name = ls_updatex-rep_name.
ls_final-begda = ls_updatex-begda.
ls_final-endda = ls_updatex-endda.
ls_final-reppr = ls_updatex-reppr.
ls_final-active = ls_updatex-active.
ls_final-message = 'Record is already existed'.
APPEND ls_final TO lt_final.
ENDIF.
CLEAR: ls_final, ls_updatex, wa_subst_tab.
REFRESH: subst_tab.
ENDLOOP.

ENDIF.
"Case3 modify a existing record
IF lt_modify IS NOT INITIAL.
LOOP AT lt_modify INTO gs_modify WHERE active = 'X'.
wa_subst_tab-us_name = gs_modify-us_name.
wa_subst_tab-rep_name = gs_modify-rep_name.
wa_subst_tab-begda = gs_modify-begda.
wa_subst_tab-endda = gs_modify-endda.
wa_subst_tab-reppr = gs_modify-reppr.
wa_subst_tab-active = ''.
APPEND wa_subst_tab TO subst_tab.
CALL FUNCTION 'RH_UPDATE_SUBST_LIST_SERVER'
TABLES
subst_tab = subst_tab
err_tab = err_tab
EXCEPTIONS
no_wf_plvar = 1
. " RH_UPDATE_SUBST_LIST_SERVER

IF sy-subrc EQ 0.
"All OK
ELSEIF sy-subrc EQ 1. "Exception
"Add code for exception here
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = '1'
* IMPORTING
* RETURN =
.
WAIT UP TO 1 SECONDS.
IF sy-subrc = 0.
ls_final-us_name = gs_modify-us_name.
ls_final-rep_name = gs_modify-rep_name.
ls_final-begda = gs_modify-begda.
ls_final-endda = gs_modify-endda.
ls_final-reppr = gs_modify-reppr.
ls_final-active = ''.
ls_final-message = 'Modified Existing Record'.
APPEND ls_final TO lt_final.
ELSE.
ls_final-us_name = gs_modify-us_name.
ls_final-rep_name = gs_modify-rep_name.
ls_final-begda = gs_modify-begda.
ls_final-endda = gs_modify-endda.
ls_final-reppr = gs_modify-reppr.
ls_final-active = ''.
ls_final-message = 'Record is already existed'.
APPEND ls_final TO lt_final.
ENDIF.

CLEAR: gs_modify, ls_final, wa_subst_tab.
REFRESH: subst_tab.
ENDLOOP.
"table data not in a file then need to update end date and active with ‘space’.
LOOP AT lt_modify INTO gs_modify WHERE active = ''.
ls_final-us_name = gs_modify-us_name.
ls_final-rep_name = gs_modify-rep_name.
ls_final-begda = gs_modify-begda.
ls_final-endda = gs_modify-endda.
ls_final-reppr = gs_modify-reppr.
ls_final-active = ''.
ls_final-message = 'Activate with set to space'.
APPEND ls_final TO lt_final.
CLEAR: gs_modify, ls_final.
ENDLOOP.

ENDIF.

*/Sending email notification

IF lt_final IS NOT INITIAL. "Email

CREATE OBJECT lo_email.

lv_string = lv_string &&
'User Name'(012) && lc_tab &&
'User Name'(013) && lc_tab &&
'Start Date'(014) && lc_tab &&
'End Date'(015) && lc_tab &&
'Substitute Profile'(016) && lc_tab &&
'Substitution Active'(017) && lc_tab &&
'Message'(018) && lc_crlf.

LOOP AT lt_final ASSIGNING FIELD-SYMBOL(<fs_output>).

lv_string = lv_string &&
<fs_output>-us_name && lc_tab &&
<fs_output>-rep_name && lc_tab &&
<fs_output>-begda && lc_tab &&
<fs_output>-endda && lc_tab &&
<fs_output>-reppr && lc_tab &&
<fs_output>-active && lc_tab &&
<fs_output>-message && lc_crlf .

ENDLOOP.

ls_email_body-tdline = 'Hi'.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = ''.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = ''.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = 'Pleae see the attached file for the 3PL Substitution to S4'.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = 'Can you please check the records'.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = ''.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = ''.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

ls_email_body-tdline = 'Thank you'.
APPEND ls_email_body TO lt_email_body.
CLEAR ls_email_body.

* Convert the inernal table data into binary format.
IF lv_string IS NOT INITIAL.
lo_email->create_excel_content( EXPORTING
email_data = lv_string
IMPORTING
binary_content = lt_binary_content
size = lv_size ).
ENDIF.

* Append all the emails
DATA(l_util) = NEW zcl_gen_utilities( ).
l_util->read_parameters_table( EXPORTING table = lc_eamt_parameters
name = lc_ricefid_1234
maptype1 = lc_param_name
IMPORTING data = DATA(lt_param_tab) ).

CLEAR lt_email_address.

LOOP AT lt_param_tab INTO DATA(lw_param_tab).
CLEAR ls_email_address.
ls_email_address-address = lw_param_tab-param1.
APPEND ls_email_address TO lt_email_address.
CLEAR ls_email_address.
ENDLOOP.

CLEAR lv_subject.
lv_subject = '3PL Substitution to S4'.

IF lt_email_address IS NOT INITIAL.

lo_email->send_email_with_xls_attachment( EXPORTING
subject = lv_subject
email_address = lt_email_address
binary_content = lt_binary_content
size = lv_size
email_body_tab = lt_email_body ).

ENDIF.
ENDIF. "Email

ENDIF.

ENDMETHOD.