1. ACL ( Acess Control List Integration ) for PS module.
PSACL_TAB - Table for PS ACL Integration
report zps_add_acl_role.
types :begin of ty_final,
guid type string,
objnr type proj-objnr,
usename type string,
acl_type type psacl_tab-act_type,
init type char1,
end of ty_final.
data:lt_final type table of ty_final,
ls_final type ty_final,
lt_final1 type table of ty_final,
ls_final1 type ty_final,
lt_proj type table of proj,
ls_proj type proj,
lt_prps type table of prps,
ls_prps type prps,
lt_temp type table of psacl_tab,
ls_temp type psacl_tab,
lv_guid type char16.
data : ty_raw type truxs_t_text_data .
*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
selection-screen : begin of block b1 with frame title text-001.
parameters : p_path type rlgrap-filename obligatory.
selection-screen : end of block b1.
*----------------------------------------------------------------------*
* Selection Screen Validations *
*----------------------------------------------------------------------*
at selection-screen on value-request for p_path.
call function 'F4_FILENAME'
exporting
field_name = 'FILE'
importing
file_name = p_path.
start-of-selection.
perform xls.
if lt_final is not initial.
perform get_data.
else.
message 'No data is avaiable' type 'S'.
endif.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form XLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form xls .
* **********Convert Excel file to SAP*
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = ty_raw
i_filename = p_path
tables
i_tab_converted_data = lt_final
exceptions
conversion_failed = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
**Project Details*****
select * from proj into table lt_proj for all entries in lt_final where objnr = lt_final-objnr.
if sy-subrc = 0.
sort lt_proj.
endif.
if lt_proj is not initial .
**WBS Elements details*
select * from prps into table lt_prps for all entries in lt_proj where psphi = lt_proj-pspnr.
if sy-subrc = 0.
sort lt_prps.
endif.
endif.
loop at lt_final into ls_final.
call function 'GUID_CREATE'
importing
ev_guid_16 = ls_temp-guid. ""Guid
ls_temp-objnr = ls_final-objnr. ""Project ID
ls_temp-act_type = ls_final-acl_type. ""Act Type
ls_temp-auth_user = ls_final-usename. ""user name
ls_temp-inhrt = ls_final-init.""Inhertitance
append ls_temp to lt_temp.
clear :ls_final,ls_temp.
endloop.
insert psacl_tab from table lt_temp.
delete lt_final where init ne 'X'.
lt_final1[] = lt_final[].
refresh lt_temp.
loop at lt_final1 into ls_final1.
read table lt_proj into ls_proj with key objnr = ls_final1-objnr.
if sy-subrc = 0.
loop at lt_prps into ls_prps where psphi = ls_proj-pspnr.
call function 'GUID_CREATE'
importing
ev_guid_16 = ls_temp-guid. ""Guid
ls_temp-objnr = ls_prps-objnr. ""Project ID
ls_temp-act_type = ls_final1-acl_type. ""Act Type
ls_temp-auth_user = ls_final1-usename. ""user name
ls_temp-inhrt = ''."ls_final1-init.""Inhertitance
ls_temp-inhr_from = ls_final1-objnr.""Project Id
append ls_temp to lt_temp.
clear:ls_temp.
endloop.
endif.
clear:ls_final1.
endloop.
insert psacl_tab from table lt_temp.
if sy-subrc = 0.
message 'Data is saved successfuly' type 'S'.
endif.
endform.
*&---------------------------------------------------------------------*
*& Form BDCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
**************************************************************
2.Modified costsheet and overheadkey for all Wbs Element of Project (remove CSLD,TECO).
tables:proj,prps.
types :begin of ty_msg,
projdef type string,
msg type string,
end of ty_msg.
data: gt_msg type table of ty_msg,
gs_msg type ty_msg,
gv_no(2) type c,
gt_fieldcat type slis_t_fieldcat_alv,
gs_fieldcat type slis_fieldcat_alv.
data:lt_prps type table of prps,
ls_prps type prps.
data:lv_project type bapi_bus2001_new-project_definition.
* lv_wbs_element type char24.
data:it_wbs_element type table of bapi_bus2054_chg,
wa_wbs_element type bapi_bus2054_chg.
data:it_update_wbs_element type table of bapi_bus2054_upd,
wa_update_wbs_element type bapi_bus2054_upd.
data:lt_return type table of bapiret2,
ls_return type bapiret2.
selection-screen : begin of block b1 with frame title text-001 .
select-options : so_elem for prps-posid matchcode object prp.
selection-screen : end of block b1 .
start-of-selection.
perform data_modified.
perform logs.
end-of-SELECTION.
CLEAR:gv_no.
REFRESH :so_elem,lt_return,it_wbs_element,it_update_wbs_element.
*&---------------------------------------------------------------------*
*& Form DATA_MODIFIED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form data_modified .
***** To Get all WBS Elemenst Details
select * from prps into table lt_prps where posid in so_elem.
if sy-subrc = 0.
sort lt_prps .
endif.
loop at lt_prps into ls_prps.
* if ls_prps-pspnr is not initial .
* call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
* exporting
* input = ls_prps-pspnr
* importing
* output = ls_header-wbs_element.
* endif.
if ls_prps-psphi is not initial .
call function 'CONVERSION_EXIT_KONPD_OUTPUT'
exporting
input = ls_prps-psphi
importing
output = lv_project.
endif.
* loop at lt_elements into ls_elements.
case ls_prps-prctr.
when 'SS9000' or 'SSIN10' or 'SSIN11' or 'SSIN12' or 'SSIN13' or 'SSIN20' or 'SSIN21'.
wa_wbs_element-overhead_key = 'SS'.
when 'IM2000' or 'IMIN10' or 'IMIN11' or 'IMIN12'
or 'IMIN13' or 'IMIN20' or 'IMIN21' or 'IMIN30'.
wa_wbs_element-overhead_key = 'IM'.
when 'ETJ5000' or 'ETJIN10' or 'ETJIN11' or 'ETJIN12' or 'ETJIN13' or 'ETJIN20' or 'ETJIN21' or 'ETJIN30'.
wa_wbs_element-overhead_key = 'ETJ'.
when 'ET5000' or 'ETIN10' or 'ETIN11' or 'ETIN12' or 'ETIN13' or 'ETIN20' or 'ETIN21' or 'ETIN30'.
wa_wbs_element-overhead_key = 'ET'.
when 'CS3000' or 'CSIN10' or 'CSIN11' or 'CSIN12' or 'CSIN13' or 'CSIN20' or 'CSIN21' or 'CSIN30'.
wa_wbs_element-overhead_key = 'CS'.
when 'CT4000' or 'CTIN10' or 'CTIN11' or 'CTIN12' or 'CTIN13' or 'CTIN20' or 'CTIN21' or 'CTIN30'.
wa_wbs_element-overhead_key = 'CT'.
when 'ASN1000' or 'ASNIN10' or 'ASNIN11' or 'ASNIN12' or 'ASNIN13' or 'ASNIN20' or 'ASNIN21' or 'ASNIN30'.
wa_wbs_element-overhead_key = 'ASN'.
when 'ASP1000' or 'ASPIN10' or 'ASPIN11' or 'ASPIN12' or 'ASPIN13' or 'ASPIN20' or 'ASPIN21' or 'ASPIN30'.
wa_wbs_element-overhead_key = 'ASP'.
endcase.
wa_wbs_element-wbs_element = ls_prps-posid.""Wbs Element
* wa_wbs_element-description = ls_prps-p.
wa_wbs_element-cstg_sheet = ls_prps-pbukr.""Company
wa_update_wbs_element-wbs_element = ls_prps-posid.
wa_update_wbs_element-cstg_sheet = 'X'.
* wa_update_wbs_element-description = 'X'.
wa_update_wbs_element-overhead_key = 'X'.
append wa_update_wbs_element to it_update_wbs_element.
clear :wa_update_wbs_element.
append wa_wbs_element to it_wbs_element.
clear:wa_wbs_element.
call function 'BAPI_PS_INITIALIZATION'.
******** Changes WBS Elements
refresh:lt_return.
call function 'BAPI_BUS2054_CHANGE_MULTI'
exporting
i_project_definition = lv_project
tables
it_wbs_element = it_wbs_element
it_update_wbs_element = it_update_wbs_element
et_return = lt_return.
read table lt_return into ls_return with key type = 'E'.
if sy-subrc eq 0.
loop at lt_return into ls_return.
gs_msg-projdef = ls_prps-posid.
gs_msg-msg = ls_return-message.
append gs_msg to gt_msg.
clear gs_msg.
endloop.
else.
call function 'BAPI_PS_PRECOMMIT'
tables
et_return = lt_return.
read table lt_return into ls_return with key type = 'E'.
if sy-subrc eq 0.
loop at lt_return into ls_return.
gs_msg-projdef = ls_prps-posid.
gs_msg-msg = ls_return-message.
append gs_msg to gt_msg.
clear gs_msg.
endloop.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
gs_msg-projdef = ls_prps-posid.
gs_msg-msg = 'Successfully Modified'.
append gs_msg to gt_msg.
clear gs_msg.
endif.
endif.
clear:ls_prps,lv_project,ls_return.
REFRESH :it_update_wbs_element,it_wbs_element.
endloop.
endform.
*&---------------------------------------------------------------------*
*& Form LOGS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form logs .
gv_no = gv_no + 1.
perform fieldcat using gv_no 'PROJDEF' 'GT_MSG' text-002.
gv_no = gv_no + 1.
perform fieldcat using gv_no 'MSG' 'GT_MSG' text-003.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
* IS_LAYOUT =
it_fieldcat = gt_fieldcat
i_save = 'A'
tables
t_outtab = gt_msg.
endform.
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GV_NO text
* -->P_0299 text
* -->P_0300 text
* -->P_TEXT_002 text
*----------------------------------------------------------------------*
form fieldcat using p_gv_no
value(p_0299)
value(p_0300)
p_text_002.
clear gs_fieldcat.
gs_fieldcat-col_pos = p_gv_no.
gs_fieldcat-fieldname = p_0299.
gs_fieldcat-tabname = p_0300.
gs_fieldcat-reptext_ddic = p_text_002.
append gs_fieldcat to gt_fieldcat.
endform.
*endform.
**************************************************************************
3. New WBS ELEMENT UPLOAD
*&---------------------------------------------------------------------*
*& Include ZPS_R_WBS_UPLOAD_BAPI_TOP
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Types Declarations *
*----------------------------------------------------------------------*
types : begin of ty_final,
projdef type ps_pspid, " Project Definition
wbselement type ps_posid , " WBS Element
descr type ps_post1, " Description
wbsbillel TYPE ps_fakkz, "WBS Billing Element
* resanakey TYPE abgr_schl, "Result Analysis Key
compcod type ps_pbukr, " Company Code
plant type werks_d, " Plant
profitcen type prctr, " Profit Center
wbs_up type string,
wbs_left type string,
* leve TYPE string,
* startdt TYPE ps_pstrt, " Start Date
* finishdt TYPE ps_pende, " End Date
end of ty_final,
begin of ty_msg,
projdef type ps_pspid,
msg type string,
end of ty_msg,
begin of ty_proj,
projdef type ps_pspid, " Project Definition
new_wbs TYPE string,
end of ty_proj.
*----------------------------------------------------------------------*
* Internal Tables and Workarea Declarations *
*----------------------------------------------------------------------*
data : gt_final type table of ty_final,
gs_final type ty_final,
gt_xls type table of alsmex_tabline,
gs_xls type alsmex_tabline,
gv_flag type c,
gt_wbs type table of bapi_bus2054_new,
gs_wbs type bapi_bus2054_new,
gt_return type table of bapiret2,
gs_return type bapiret2,
gt_msg type table of ty_msg,
gs_msg type ty_msg,
gv_no(2) type c,
gt_fieldcat type slis_t_fieldcat_alv,
gs_fieldcat type slis_fieldcat_alv,
gt_proj type table of ty_proj,
gs_proj type ty_proj.
data : ty_raw type truxs_t_text_data .
*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
selection-screen : begin of block b1 with frame title text-000.
parameters : p_path type rlgrap-filename obligatory.
selection-screen : end of block b1.
*----------------------------------------------------------------------*
* Selection Screen Validations *
*----------------------------------------------------------------------*
at selection-screen on value-request for p_path.
call function 'F4_FILENAME'
exporting
field_name = 'FILE'
importing
file_name = p_path.
*&---------------------------------------------------------------------*
*& Include ZPS_R_WBS_UPLOAD_BAPI_F01
*&---------------------------------------------------------------------*
start-of-selection.
perform xls_to_sap.
perform fill_final.
perform log_display.
*&---------------------------------------------------------------------*
*& Form XLS_TO_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form xls_to_sap .
* **********Convert Excel file to SAP*
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = ty_raw
i_filename = p_path
tables
i_tab_converted_data = gt_final
exceptions
conversion_failed = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
*&---------------------------------------------------------------------*
*& Form FILL_FINAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fill_final .
*gt_final[] = gt_xls[].
loop at gt_final into gs_final.
gs_proj-projdef = gs_final-projdef.
gs_proj-new_wbs = gs_final-wbselement.
collect gs_proj into gt_proj.
clear gs_proj.
endloop.
loop at gt_proj into gs_proj.
loop at gt_final into gs_final where projdef eq gs_proj-projdef and wbselement = gs_proj-new_wbs.
gs_wbs-wbs_element = gs_final-wbselement.
gs_wbs-description = gs_final-descr.
gs_wbs-company_code = gs_final-compcod.
gs_wbs-profit_ctr = gs_final-profitcen.
gs_wbs-wbs_billing_element = 'X'.
gs_wbs-res_anal_key = ''.
gs_wbs-plant = gs_final-plant.
gs_wbs-wbs_left = gs_final-wbs_left.
gs_wbs-wbs_up = gs_final-wbs_up.
* gs_wbs-wbs_basic_start_date = gs_final-startdt.
* gs_wbs-wbs_basic_finish_date = gs_final-finishdt.
* gs_wbs-wbs_forecast_start_date = gs_final-startdt.
* gs_wbs-wbs_forecast_finish_date = gs_final-finishdt.
* gs_wbs-wbs_actual_start_date = gs_final-startdt.
append gs_wbs to gt_wbs.
clear gs_wbs.
endloop.
call function 'BAPI_PS_INITIALIZATION'.
call function 'BAPI_BUS2054_CREATE_MULTI'
exporting
i_project_definition = gs_proj-projdef
tables
it_wbs_element = gt_wbs
et_return = gt_return.
read table gt_return into gs_return with key type = 'E'.
if sy-subrc eq 0.
loop at gt_return into gs_return.
gs_msg-projdef = gs_final-projdef.
gs_msg-msg = gs_return-message.
append gs_msg to gt_msg.
clear gs_msg.
endloop.
else.
call function 'BAPI_PS_PRECOMMIT'
tables
et_return = gt_return.
read table gt_return into gs_return with key type = 'E'.
if sy-subrc eq 0.
loop at gt_return into gs_return.
gs_msg-projdef = gs_final-projdef.
gs_msg-msg = gs_return-message.
append gs_msg to gt_msg.
clear gs_msg.
endloop.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
gs_msg-projdef = gs_final-projdef.
gs_msg-msg = 'Successfully Created'.
append gs_msg to gt_msg.
clear gs_msg.
endif.
endif.
clear :gs_proj, gs_msg,gs_final.
refresh:gt_return,gt_wbs.
endloop.
endform.
*&---------------------------------------------------------------------*
*& Form LOG_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form log_display .
gv_no = gv_no + 1.
perform fieldcat using gv_no 'PROJDEF' 'GT_MSG' text-002.
gv_no = gv_no + 1.
perform fieldcat using gv_no 'MSG' 'GT_MSG' text-003.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
* IS_LAYOUT =
it_fieldcat = gt_fieldcat
i_save = 'A'
tables
t_outtab = gt_msg.
endform.
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GV_NO text
* -->P_0299 text
* -->P_0300 text
* -->P_TEXT_002 text
*----------------------------------------------------------------------*
form fieldcat using p_gv_no
value(p_0299)
value(p_0300)
p_text_002.
clear gs_fieldcat.
gs_fieldcat-col_pos = p_gv_no.
gs_fieldcat-fieldname = p_0299.
gs_fieldcat-tabname = p_0300.
gs_fieldcat-reptext_ddic = p_text_002.
append gs_fieldcat to gt_fieldcat.
endform.
No comments:
Post a Comment