2012 Apr 23 9:54 AM
I am trying to update one custom field ZREFNO in RKPF table using standard bapi "BAPI_RESERVATION_CREATE1" with the structure of ZREFNO located in BAPI_TE_REQUISITION_ACCOUNT. I want to use the extensionin parameter to update the custom field. I tried many ways to define the structure but still the values are not populating in the extensionin table structure of bapi_reservation_create1 call. Hence I guess the value is not being updated in the resultant RKPF table. Kindly help where I went wrong.
Below is the code:
FUNCTION zmm_sts_create_resv.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IS_RESB) TYPE ZMM_STS_RESB_HEAD
*" REFERENCE(IT_RESBITEM) TYPE ZMM_STS_RESB_ITEM_TT
*" EXPORTING
*" REFERENCE(E_RSNUM) TYPE RSNUM
*" REFERENCE(ET_RETURN) TYPE BAPIRET2_T
*"----------------------------------------------------------------------
* Description : This function create SI Reservation using
* BAPI_RESERVATION_CREATE1.
*"----------------------------------------------------------------------
* MODIFICATION LOG :
* Date Modified by Changes
*"----------------------------------------------------------------------
DATA : lt_item TYPE TABLE OF bapi2093_res_item,
ls_item LIKE LINE OF lt_item,
ls_resbitem LIKE LINE OF it_resbitem.
DATA : ls_resb LIKE bapi2093_res_head.
DATA : lt_segment TYPE TABLE OF bapi_profitability_segment,
ls_segment TYPE bapi_profitability_segment.
DATA l_glacct TYPE saknr.
DATA : lt_mard TYPE TABLE OF mard,
ls_mard TYPE mard.
DATA: ls_mara TYPE mara.
DATA: lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2.
DATA: ls_prps TYPE prps.
* DATA extensionin TYPE TABLE OF bapiparex WITH HEADER LINE.
DATA : wa_extensionin TYPE bapiparex,
it_extensionin TYPE TABLE OF bapiparex.
DATA: WA_BAPI_TE_REQUISITION_ACCOUNT LIKE BAPI_TE_REQUISITION_ACCOUNT.
l_glacct = '7001000010'.
*Build Reservation Header
UNPACK is_resb-kostl TO ls_resb-costcenter .
WRITE is_resb-posid TO ls_resb-wbs_element .
MOVE sy-datum TO ls_resb-res_date.
MOVE sy-uname TO ls_resb-created_by.
MOVE '221' TO ls_resb-move_type.
*Build Items Table
LOOP AT it_resbitem INTO ls_resbitem.
CLEAR ls_item.
ls_item-material = ls_resbitem-matnr.
ls_item-stge_loc = ls_resbitem-lgort.
ls_item-entry_qnt = ls_resbitem-menge.
ls_item-unload_pt = ls_resbitem-ablad.
ls_item-entry_uom = ls_resbitem-meins.
ls_item-plant = 'SSPL'.
ls_item-req_date = sy-datum.
ls_item-movement = 'X'.
ls_item-gl_account = l_glacct.
ls_item-acct_man = 'X'.
ls_item-item_text = ls_resbitem-sgtxt.
ls_item-gr_rcpt = ls_resbitem-wempf.
APPEND ls_item TO lt_item.
CLEAR ls_segment.
ls_segment-fieldname = ''.
ls_segment-value = ''.
APPEND ls_segment TO lt_segment.
*Check Material UOM
SELECT SINGLE * FROM mara INTO ls_mara
WHERE matnr = ls_item-material.
IF sy-subrc NE 0.
ls_return-type = 'E'.
CONCATENATE 'Material' ls_item-material `doesn't exists`
INTO ls_return-message SEPARATED BY space.
APPEND ls_return TO et_return.
ELSEIF ls_mara-lvorm EQ 'X'.
ls_return-type = 'E'.
CONCATENATE 'Material' ls_item-material `marked for deletion`
INTO ls_return-message SEPARATED BY space.
APPEND ls_return TO et_return.
ELSE.
SELECT SINGLE * FROM mara INTO ls_mara
WHERE matnr = ls_item-material
AND lvorm NE 'X'
AND meins = ls_item-entry_uom.
IF sy-subrc NE 0.
ls_return-type = 'E'.
CONCATENATE `UOM '` ls_item-entry_uom `' ` 'of the material' ls_item-material
'is not matched with SAP.' INTO ls_return-message SEPARATED BY space.
APPEND ls_return TO et_return.
ENDIF.
ENDIF.
*Check Material in Storage Location
SELECT SINGLE * FROM mard INTO ls_mard
WHERE matnr = ls_item-material
AND werks = ls_item-plant
AND lgort = ls_item-stge_loc
AND lvorm NE 'X'.
IF sy-subrc NE 0.
ls_return-type = 'E'.
CONCATENATE 'Material' ls_item-material 'does not exist in the storage location'
ls_item-stge_loc INTO ls_return-message SEPARATED BY space.
APPEND ls_return TO et_return.
ENDIF.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM et_return[].
*Check for Errors
READ TABLE et_return WITH KEY type = 'E' TRANSPORTING NO FIELDS .
CHECK sy-subrc NE 0.
CLEAR wa_extensionin.
wa_extensionin-structure = 'BAPI_TE_REQUISITION_ACCOUNT'.
WA_BAPI_TE_REQUISITION_ACCOUNT-PREQ_ITEM = 1234.
WA_BAPI_TE_REQUISITION_ACCOUNT-SERIAL_NO = 12.
WA_BAPI_TE_REQUISITION_ACCOUNT-ZREFNO = ls_resbitem-saprefno.
* WA_BAPI_TE_REQUISITION_ACCOUNT+7(40) = ls_resbitem-saprefno.
wa_extensionin-valuepart1 = WA_BAPI_TE_REQUISITION_ACCOUNT.
APPEND wa_extensionin TO it_extensionin.
*Call BAPI
CHECK ls_resb IS NOT INITIAL AND lt_item IS NOT INITIAL.
* LOOP AT it_resbitem INTO WA_BAPI_TE_REQUISITION_ACCOUNT.
* ENDLOOP.
CALL FUNCTION 'BAPI_RESERVATION_CREATE1'
EXPORTING
reservationheader = ls_resb
IMPORTING
reservation = e_rsnum
TABLES
reservationitems = lt_item
profitabilitysegment = lt_segment
extensionin = it_extensionin
return = lt_return.
APPEND LINES OF lt_return TO et_return.
IF e_rsnum IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = ' '
IMPORTING
return = ls_return.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFUNCTION.
2012 Apr 23 10:28 AM
You have badi and user eixts available for the purpose. But rest assured they are for RESB and not for RKPF. You need to change the global data of FM for that. Follow the steps below and let me know if you are stuck at anypoint. The BAPI_TE structure the you extended is not the correct one but whithout introducing major change in your design I suggest the below point
Do let me know if it solves the problem
1) Create an impliementation of badi MB_RES_BAPI_CREATE.
2) inside the method EXTENSIONIN_TO_RESB put the code something like below
field-symbol : <rkpf> type rkpf,
<fs_extensionin> type bapiparex.
data : wa_REQUISITION_ACCOUNT type BAPI_TE_REQUISITION_ACCOUNT.
assign ('(SAPLMB_BUS2093)S_RKPF') to <rkpf>.
CHECK EXTENSION_IN[] IS NOT INITIAL.
READ TABLE EXTENSION_IN ASSIGNING <FS_EXTENSIONIN> INDEX 1.
CHECK SY-SUBRC = 0.
IF <FS_EXTENSIONIN>-structure = 'BAPI_TE_REQUISITION_ACCOUNT'.
wa_REQUISITION_ACCOUNT = <FS_EXTENSIONIN>-valuepart1.
<rkpf>-ZREFNO = wa_REQUISITION_ACCOUNT-zrefno.
endif.
2012 Apr 23 10:17 AM
Are you using User EXIT "EXIT_SAPLMB_BUS2093_001" to take care of the extension fields and population of the same in the STD SAP structure??
I think just passing the fields will not populate the values. You need to pass the values to appropriate fields in the above mentioned use exit.
2012 Apr 24 1:21 AM
Thank you for the reply Harshad. Can you please tell me what exactly need to be done as part of EXIT_SAPLMB_BUS2093_001 user exit.
2012 Apr 23 10:28 AM
You have badi and user eixts available for the purpose. But rest assured they are for RESB and not for RKPF. You need to change the global data of FM for that. Follow the steps below and let me know if you are stuck at anypoint. The BAPI_TE structure the you extended is not the correct one but whithout introducing major change in your design I suggest the below point
Do let me know if it solves the problem
1) Create an impliementation of badi MB_RES_BAPI_CREATE.
2) inside the method EXTENSIONIN_TO_RESB put the code something like below
field-symbol : <rkpf> type rkpf,
<fs_extensionin> type bapiparex.
data : wa_REQUISITION_ACCOUNT type BAPI_TE_REQUISITION_ACCOUNT.
assign ('(SAPLMB_BUS2093)S_RKPF') to <rkpf>.
CHECK EXTENSION_IN[] IS NOT INITIAL.
READ TABLE EXTENSION_IN ASSIGNING <FS_EXTENSIONIN> INDEX 1.
CHECK SY-SUBRC = 0.
IF <FS_EXTENSIONIN>-structure = 'BAPI_TE_REQUISITION_ACCOUNT'.
wa_REQUISITION_ACCOUNT = <FS_EXTENSIONIN>-valuepart1.
<rkpf>-ZREFNO = wa_REQUISITION_ACCOUNT-zrefno.
endif.
2012 Apr 24 1:16 AM
I appreciate your reply Gaurav.
Can I use the customer exit(EXIT_SAPLMB_BUS2093_001) provided in BAPI_RESERVATION_CREATE1.
If so please tell me what is to be done in EXIT_SAPLMB_BUS2093_001.
Thank you.
2012 Apr 24 2:55 AM
Please let me know if we can acheive this without changing the standard code of SAP. Thank you.
2012 Apr 24 3:21 AM
Both exit and the badi does the same thing. they are for the same purpose but with different name for the same variable. But when both exit and badi are available I would always prefer BADI. I suggest you go for badi too though you can use the function exit also equally well.
And we are not changing any standard code. We are using the enhancement and it is not a modification. here if perfectly find the get the global data and change this way provided you have no other option(which is this case.. you have a custom field and you need to update it using bapi )
2012 Apr 24 4:35 AM
Thank you for the support Gaurav. I have tried doing the below steps:
It is asking for access key. Does this mean we are trying to edit standard SAP? Kindly help as I am new to this.
2012 Apr 24 5:27 AM
Hi Arvind,
I think kumar suggestion should work, i have done similar thing which worked before using field-symbols.
Goto se19 and create a new badi implementation or check whether already implementation is done for the particular badi. Implementation of badi will create a ZCL_ class, in that z class go to the method extensionin_to_resb and change that code accordingly as kumar suggested. if you struck, let forum knows it.
2012 Apr 24 5:56 AM
Hi Arvind , you can vind the steps to implement any badi here
For your case follow the following steps
FIELD-SYMBOLS : <rkpf> TYPE rkpf,
<fs_extensionin> TYPE bapiparex.
DATA : wa_requisition_account TYPE bapi_te_requisition_account.
ASSIGN ('(SAPLMB_BUS2093)S_RKPF') TO <rkpf>.
CHECK extension_in IS NOT INITIAL.
IF <fs_extensionin>-structure = 'BAPI_TE_REQUISITION_ACCOUNT'.
wa_requisition_account = <fs_extensionin>-valuepart1.
<rkpf>-zrefno = wa_requisition_account-zrefno.
ENDIF.
2012 Apr 24 7:32 AM
I have made same changes as mentioned. But still the RKPF table is not showing up the updated value in ZREFNO. Do I need to something else in the code written in ZIM_MB_RES_BAPI_CREA.
method IF_EX_MB_RES_BAPI_CREATE1~EXTENSIONIN_TO_RESB.
FIELD-SYMBOLS : <rkpf> TYPE rkpf,
<fs_extensionin> TYPE bapiparex.
DATA : wa_requisition_account TYPE bapi_te_requisition_account.
ASSIGN ('(SAPLMB_BUS2093)S_RKPF') TO <rkpf>.
CHECK extension_in IS NOT INITIAL.
IF <fs_extensionin>-structure = 'BAPI_TE_REQUISITION_ACCOUNT'.
wa_requisition_account = <fs_extensionin>-valuepart1.
<rkpf>-zrefno = wa_requisition_account-zrefno.
ENDIF.
endmethod.
This method is getting activated but still says there are some warnings.
Thank you.
2012 Apr 24 7:39 AM
Few things
1) have you activated the badi implimentation?
2) After ASSIGN ('(SAPLMB_BUS2093)S_RKPF') TO <rkpf>. CHECK <rkpf> is assigned.
3) Debug and let me know if a) method is getting trigger b) You are getting the line you append in extension_in structure.
Ironically I found it unusual but the badi is just passing the header line of extensionin.
Let me knwo the above accordingly we will have to check in the exit if it it doesn't work.
2012 Apr 24 8:09 AM
BADI is not activated due to this warning at Line10 in the code:
wa_requisition_account = <fs_extensionin>-valuepart1.
After a structure enhancement, assignment or comparison may no longer be permitted.
2012 Apr 24 8:21 AM
Warning shouldn't stop you from activating the badi.
Anywyas if you want to get rid fo that message do this
CHECK extension_in IS NOT INITIAL.
IF extension_in-structure = 'BAPI_TE_REQUISITION_ACCOUNT'.
<rkpf>-zrefno = extension_in-valuepart1+7(40). " Assuming leght is 40.
ENDIF.
2012 Apr 24 8:36 AM
I debugged the code and found that it is coming out of the method at this line:
CHECK extension_in IS NOT INITIAL.
I have checked that extension_in is not holding any values passed. Whereas I can see the values getting populated in the calling FM
CALL FUNCTION 'BAPI_RESERVATION_CREATE1'
EXPORTING
reservationheader = ls_resb
IMPORTING
reservation = e_rsnum
TABLES
reservationitems = lt_item
profitabilitysegment = lt_segment
extensionin = it_extensionin
return = lt_return.
2012 Apr 24 9:23 AM