Quantcast
Channel: Tweaks
Viewing all articles
Browse latest Browse all 66

How to update custom field of PRPS table

$
0
0

Or How to update custom fields of CJ20N t-code?

At the outset, you might feel why is the need of this topic. It is such a common requirement where we need to update custom field of a screen (or table). There should be plenty of FMs and BAPis available to do this work.

In this post, we are talking about custom field in WBS screen (transaction CJ02 or CJ20N).

Recently, when I received this enhancement requirement to add two custom fields in CJ20N screen and then another conversion requirement to populate these custom fields using a batch program. I thought it would be a cake walk. Adding the custom field was easy. I enhanced structure CI_PRPS and SAP Project (t-code SMOD) CNEX0007 ‘PS customer specific fields WBS element’.

Enhance PRPS table

The enhanced project’s detail from t-code CMOD is below:

Bapi function module to update PRPS table

After implement this exit, you see a new tab Cust Enhancement in CJ20N with the custom fields.

User-defined fields are not displayed

In case, you do not see user defined fields in the screen, then you might be missing this step.

Use transaction SE51 to create the user-defined screen SAPLXCN1 0700 and develop the layout. In particular, you can get fields from the ABAP Dictionary (from the table PRPS):
Choose “Goto -> Dict./program fields”.
Maintain the table/field name PRPS and select the fields that are to be displayed on the screen.

Activate and you would see the custom fields.

For more details to implement project CNEX0007, refer SAP Note 522581 – User-defined fields are not displayed.

But my intention to write this post was not to show how to enhance WBS screen. This is well documented and easily available in internet. I wanted to show how to update these custom fields from custom program (batch conversion jobs). You can do the BDC and achieve the functionality, but we did not want to take the BDC route. We wanted to achieve it using standard FM or BAPI (preferably). I found the BAPI ‘BAPI_BUS2054_CHANGE_MULTI‘ which would do the job. But passing the correct parameters to the BAPI was tricky.

Also the internet is flooded with queries regarding how to make BAPI ‘BAPI_BUS2054_CHANGE_MULTI’ update the custom fields using EXTENSIONIN. But all are not answered clearly. Some even suggest to implement a BADI to make this BAPI work. Friends, if you want to just update the custom fields, you do not need to implement the BADI ‘BAPIEXT_BUS2054′ (Enhancement for BAPIs for BO WBSPI). You need the BADI for some other requirements.

Check some of the questions and answers from SCN and other sites.

Bapi function module to update PRPS table.
How to Update Multiple WBS elements. 
How can I pass extensionin for BAPI_BUS2054_CHANGE_MULTI to enhance. 
Bapi function module for updating data into PRPS table.

There is no clear answer/solution and working code provided in the communities (at least I did not find one).

Actual solution:
The tricky part was to pass the Key Field (WBS_ELEMENT) to the EXTENSIONIN structure which would make the custom field entries unique. Please read the BAPI documentation properly. 🙂

*&---------------------------------------------------------------------*
* Very Very Important
ls_te_wbs_element-wbs_element = wa_prps-posid. " Key to identify the custom fields
*&---------------------------------------------------------------------*

Now it looks so obvious. Is n’t it? Trust me, I wasted an evening to figure this out. Our goal at SAPYard is to help our readers know about such small tricks and not to reinvent the wheel.

Please find the working code below to update the custom fields in t-code CJ20N (CJ02) or PRPS table.

*&---------------------------------------------------------------------*
*& Form UPDATE_CUSTOM_WBS_FIELDS
*&---------------------------------------------------------------------*
* Update the Custom WBS Fields
*----------------------------------------------------------------------*
FORM update_custom_wbs_fields.
DATA:
lv_project_def TYPE ps_pspid,
ls_wbs_element_up TYPE bapi_bus2054_upd,
ls_wbs_element TYPE bapi_bus2054_chg,
lt_wbs_element TYPE STANDARD TABLE OF bapi_bus2054_chg,
lt_wbs_element_up TYPE STANDARD TABLE OF bapi_bus2054_upd,
lt_te_wbs_element TYPE STANDARD TABLE OF bapi_te_wbs_element,
ls_te_wbs_element TYPE bapi_te_wbs_element,
lt_pre_return TYPE STANDARD TABLE OF bapiret2,
ls_return TYPE bapiret2,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_extensionin TYPE bapiparex,
lt_extensionin TYPE STANDARD TABLE OF bapiparex,
lwa_report TYPE ty_report.

* Project
CALL FUNCTION 'CONVERSION_EXIT_KONPD_OUTPUT'
EXPORTING
input = wa_prps-psphi
IMPORTING
output = lv_project_def.
*--------------------------------------------------------------------*
ls_wbs_element-wbs_element = wa_prps-posid.
APPEND ls_wbs_element TO lt_wbs_element.

*--------------------------------------------------------------------*
ls_wbs_element_up-wbs_element = wa_prps-posid.
APPEND ls_wbs_element_up TO lt_wbs_element_up.

*--------------------------------------------------------------------*
CLEAR ls_extensionin.
ls_extensionin-structure = 'BAPI_TE_WBS_ELEMENT'. " Extension Structure

* Pass the Key.. Important
ls_te_wbs_element-wbs_element = wa_prps-posid. " Key to identify the custom fields

* These are the custom fields. You will have your own logic to get the data
* to be populated
ls_te_wbs_element-zswbsref = wa_prps-poski.
ls_te_wbs_element-zaufnr = wa_cobrb-aufnr.

ls_extensionin-valuepart1 = ls_te_wbs_element.

APPEND ls_extensionin TO lt_extensionin.
*--------------------------------------------------------------------*
* Initialization of the Current Processing Unit
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

* BAPI to update Custom WBS Elements
CALL FUNCTION 'BAPI_BUS2054_CHANGE_MULTI'
EXPORTING
i_project_definition = lv_project_def
TABLES
it_wbs_element = lt_wbs_element
it_update_wbs_element = lt_wbs_element_up
et_return = lt_return
extensionin = lt_extensionin. " Here we have custom field

* Pre Commit Check
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = lt_pre_return.

* Looking for error
READ TABLE lt_pre_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.

* Add your ERROR message as per requirement

* Rollback
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.
* Add your SUCCESS message as per requirement

* Do the commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

ENDIF.

ENDFORM.

If you want to get such practical issues and resolutions straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.

If you liked this post, please hit the share buttons.

Thank you very much for your time!!


Viewing all articles
Browse latest Browse all 66

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>