on 11-26-2012 4:11 PM
HI Experts,
I have added new category and group for capacity planning.
I want to create this new category or group ( Capacity planning ) from portfolio item screen for old item ( Report /RPM/PLAN_INT_PREP is available to do that but we want to do only for those items for which user is interested ).
So for this purpose I have implemented BadI : RPM_PROJ_CUST_FIELDS .and called this code from Method: CUST_PROJ_ON_COMMIT_CHANGES
called below code to create new groups and category in case it doesn't exist , same works in case of report program but in my case
DATA lit_capcat_config TYPE TABLE OF /rpm/port_capgrp.
DATA lwa_capcat_config TYPE /rpm/port_capgrp.
DATA lit_cap_category_t TYPE /rpm/tt_cap_catg_t.
DATA lwa_cap_category_t TYPE /rpm/ts_cap_catg_t.
DATA lit_cap_group_t TYPE /rpm/tt_cap_groups_t.
DATA lwa_cap_group_t TYPE /rpm/ts_cap_groups_t.
DATA lit_cap_plan TYPE /rpm/tt_cap_plan_breakdown.
DATA lwa_cap_grp_int TYPE /rpm/ts_cap_group_attr.
DATA lwa_cap_group TYPE /rpm/cap_group.
DATA lwa_cap_cat TYPE /rpm/cap_cat.
DATA lwa_cap_category_api TYPE /rpm/ts_cap_cat_api.
DATA lv_laiso TYPE laiso.
DATA lv_created TYPE boolean.
DATA lv_subrc TYPE sy-subrc.
DATA lv_rc TYPE i.
DATA lv_error TYPE i.
DATA lr_cap_category_api TYPE REF TO /rpm/cl_cap_category_api.
DATA lr_cap_category TYPE REF TO cl_rpm_cap_category.
IF i_v_guid IS NOT INITIAL.
SELECT * FROM /rpm/port_capgrp INTO TABLE lit_capcat_config WHERE portfolio_type = 'CG' ."i_v_port_type.
CREATE OBJECT lr_cap_category_api.
CALL METHOD /rpm/cl_configuration=>get_capacity_category_t
EXPORTING
iv_langu = lv_laiso
IMPORTING
et_cap_category_t = lit_cap_category_t.
LOOP AT lit_capcat_config INTO lwa_capcat_config.
" check if the category guid exists for the item
SELECT SINGLE * FROM /rpm/cap_cat INTO lwa_cap_cat
WHERE parent_guid = i_v_guid AND category = lwa_capcat_config-category.
lv_subrc = sy-subrc.
CASE lv_subrc .
WHEN '0'. " the category exists. No need to create the category. Check whether the groups exists.
CALL METHOD /rpm/cl_configuration=>get_cap_groups_t
EXPORTING
iv_langu = lv_laiso
iv_cap_category = lwa_capcat_config-category
IMPORTING
et_cap_groups_t = lit_cap_group_t.
LOOP AT lit_cap_group_t INTO lwa_cap_group_t .
SELECT SINGLE * FROM /rpm/cap_group INTO lwa_cap_group
WHERE parent_guid = lwa_cap_cat-guid
AND group_id = lwa_cap_group_t-group_id.
IF sy-subrc IS NOT INITIAL. " The group does not exist, so create the group.
CLEAR lwa_cap_grp_int.
lwa_cap_grp_int-description = lwa_cap_group_t-group_t.
lwa_cap_grp_int-external_id = lwa_cap_group_t-group_id.
lwa_cap_grp_int-parent_guid = lwa_cap_cat-guid.
lwa_cap_grp_int-active = 'X'.
lwa_cap_grp_int-original = 'X'.
lwa_cap_grp_int-plan_data = lit_cap_plan.
" Create group.
CALL METHOD lr_cap_category_api->create_group
EXPORTING
iv_item_guid = i_v_guid
is_group_int = lwa_cap_grp_int
iv_language = lv_laiso
iv_simulation = 'X'
IMPORTING
ev_rc = lv_rc.
lv_created = 'X'.
lv_error = lv_rc.
ENDIF.
ENDLOOP.
WHEN OTHERS. " The Category does not exist . Create the Category and the corresponding groups
" create category
READ TABLE lit_cap_category_t INTO lwa_cap_category_t
WITH KEY category = lwa_capcat_config-category.
lwa_cap_category_api-description = lwa_cap_category_t-category_t.
lwa_cap_category_api-external_id = lwa_capcat_config-category.
lwa_cap_category_api-parent_guid = i_v_guid.
lwa_cap_category_api-active = 'X'.
lwa_cap_category_api-original = 'X'.
CALL METHOD lr_cap_category_api->create_category
EXPORTING
is_category_api = lwa_cap_category_api
iv_language = lv_laiso
iv_simulation = 'X'
IMPORTING
er_category = lr_cap_category
ev_rc = lv_rc.
lv_created = 'X'.
lv_error = lv_rc.
CALL METHOD /rpm/cl_configuration=>get_cap_groups_t
EXPORTING
iv_langu = lv_laiso
iv_cap_category = lwa_capcat_config-category
IMPORTING
et_cap_groups_t = lit_cap_group_t.
LOOP AT lit_cap_group_t INTO lwa_cap_group_t.
" create group.
CLEAR lwa_cap_grp_int.
lwa_cap_grp_int-description = lwa_cap_group_t-group_t.
lwa_cap_grp_int-external_id = lwa_cap_group_t-group_id .
lwa_cap_grp_int-parent_guid = lr_cap_category->if_rpm_common~get_guid( ).
lwa_cap_grp_int-active = 'X'.
lwa_cap_grp_int-original = 'X'.
lwa_cap_grp_int-plan_data = lit_cap_plan.
" Create group.
CALL METHOD lr_cap_category_api->create_group
EXPORTING
iv_item_guid = i_v_guid
is_group_int = lwa_cap_grp_int
iv_language = lv_laiso
iv_simulation = 'X'
IMPORTING
ev_rc = lv_rc.
lv_created = 'X'.
lv_error = lv_rc.
ENDLOOP.
ENDCASE.
ENDLOOP.
IF lv_error IS INITIAL AND lv_created = 'X'.
CALL FUNCTION '/RPM/SAVE_CHANGES' .
CLEAR: lv_created, lv_error.
ENDIF.
ENDIF.
The same code works if I call from report program
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
6 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.