How to Get Accurate Pricing in SD for Customer and Material?
At the start, you could feel for what reason is the need of this point. It is a particularly normal necessity where we really want to refresh custom field of a screen (or table). There ought to be a lot of FMs and BAPis accessible to accomplish this work.
Here, we are discussing custom field in WBS screen (exchange CJ02 or CJ20N).
As of late, when I got this upgrade necessity to add two custom fields in CJ20N screen and afterward one more transformation prerequisite to populate these custom fields utilizing a group program. I figured it would be a cake walk. It was not difficult to Add the custom field. I upgraded structure CI_PRPS and SAP Venture (t-code SMOD) CNEX0007 ‘PS client explicit fields WBS component’. Ok so Let’s go into on how to Get Accurate Pricing in SD for Customer and Material?
The upgraded venture’s detail from t-code CMOD is underneath:
After execute this leave, you see another tab Cust Improvement in CJ20N with the custom fields.
On the off chance that, you don’t see client characterized fields in the screen, then you may be feeling the loss of this step.
Use exchange SE51 to make the client characterized screen SAPLXCN1 0700 and foster the design. Specifically, you can get fields from the ABAP Word reference (from the table PRPS):
Pick “Goto – > Dict./program fields”.
Keep up with the table/field name PRPS and select the fields that are to be shown on the screen.
Initiate and you would see the custom fields.
For additional subtleties to execute project CNEX0007, allude SAP Note 522581 – Client characterized fields are not shown.
In any case, my aim to compose this post was not to tell the best way to upgrade WBS screen. This is proven and factual and effectively accessible in web. I needed to tell the best way to refresh these custom fields from custom program (bunch change occupations). You can do the BDC and accomplish the usefulness, yet we would have rather not taken the BDC course. We needed to accomplish it utilizing standard FM or BAPI (ideally). I found the BAPI ‘BAPI_BUS2054_CHANGE_MULTI’ which would finish the work. However, passing the right boundaries to the BAPI was interesting.
Likewise the web is overwhelmed with inquiries in regards to how to make BAPI ‘BAPI_BUS2054_CHANGE_MULTI’ update the custom fields utilizing EXTENSIONIN. Yet, all are not addressed obviously. Some even recommend to execute a BADI to make this BAPI work. Companions, if you need to simply refresh the custom fields, you don’t have to carry out the BADI ‘BAPIEXT_BUS2054′ (Improvement for BAPIs for BO WBSPI). You really want the BADI for a few different prerequisites.
There is no clear answer/solution and working code provided in the communities (at least I did not find one).
Actual solution:
The interesting part was to pass the Key Field (WBS_ELEMENT) to the EXTENSIONIN structure which would make the custom field sections remarkable. Kindly read the BAPI documentation appropriately.
*&---------------------------------------------------------------------* * 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 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.
YOU MAY LIKE THIS
Top SAP ABAP Interview Questions (2024)
LUW(Logical Unit of Work) define
ABAP Evolution: From Monolithic Masterpieces to Agile Architects