on 10-17-2008 12:04 PM
Hello,
I'm trying to make a custom description for an crm transaction(activitiy). Can anyone give me some sample code or help for the <<change_before_save>> method.
I can read the data from the memory but I need some help on changing it.
method IF_EX_ORDER_SAVE~CHANGE_BEFORE_UPDATE.
INCLUDE crm_object_names_con.
DATA : lt_act_guid TYPE crmt_object_guid_tab,
x_guid TYPE BALLOGHNDL,
lt_orderadm_h TYPE crmt_orderadm_h_wrkt,
ls_orderadm_h TYPE crmt_orderadm_h_wrk,
ls_activity_h TYPE crmt_activity_h_wrkt,
importob TYPE crmt_object_name_tab.
DATA : ls_changes TYPE CRMT_INPUT_FIELD_NAMES,
lt_changes TYPE CRMT_INPUT_FIELD_NAMES_TAB,
ls_header TYPE CRMT_ORDERADM_H_COM.
REFRESH lt_act_guid.
APPEND iv_guid to lt_act_guid.
CALL FUNCTION 'CRM_ORDER_READ_OW'
EXPORTING
IT_HEADER_GUID = lt_act_guid
IMPORTING
ET_ORDERADM_H = lt_orderadm_h
ET_ACTIVITY_H = ls_activity_h
CHANGING
CV_LOG_HANDLE = x_GUID
.
ls_changes-fieldname = 'a new description'.
ls_changes-CHANGEABLE = ' '.
append ls_changes to lt_changes.
LOOP at lt_orderadm_h INTO ls_orderadm_h.
MOVE-CORRESPONDING ls_orderadm_h to ls_header.
ls_header-description = 'DESCRIPTION'.
ENDLOOP.
I think i need FUNCTION 'CRM_ORDERADM_H_MAINTAIN_OW but I can't get it working and
what about FUNCTION 'CRM_ORDERADM_H_CHANGE_OW'?
Kind regards,
Frederik
Hi,
Use FM CRM_ORDER_MAINTAIN.. The best way to do this change description in GUI manually and before saving put a breakpoint(/H) and press save button. Now in the debugger put breakpoint on FM CRM_ORDER_MAINTAIN and the check the values in the importing structures CT_INPUT_FIELDS & CT_ORDERADM_H. Now you can give the same values in ur Badi implementation..
Hope it works
Thanks
RR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for the response. I implemented the result but no succes. It does not save. Adding the save_order function does not resolve it either because then you come in a endless loop. Nor adding the badi_commit_work.
Any suggestions?
Kind regards,
DATA : lt_act_guid TYPE crmt_object_guid_tab,
x_guid TYPE BALLOGHNDL,
lt_orderadm_h TYPE crmt_orderadm_h_wrkt,
ls_orderadm_h TYPE crmt_orderadm_h_wrk,
ls_activity_h TYPE crmt_activity_h_wrkt,
importob TYPE crmt_object_name_tab.
DATA : ls_changes TYPE CRMT_INPUT_FIELD,
lt_changes TYPE CRMT_INPUT_FIELD_TAB,
ls_header TYPE CRMT_ORDERADM_H_COM,
lt_header TYPE CRMT_ORDERADM_H_COMT,
lt_fields TYPE CRMT_INPUT_FIELD_NAMES_TAB,
ls_fields TYPE CRMT_INPUT_FIELD_NAMES,
lt_activity TYPE CRMT_ACTIVITY_H_COMT,
ls_activity TYPE CRMT_ACTIVITY_H_COM.
REFRESH lt_act_guid.
APPEND iv_guid to lt_act_guid.
CALL FUNCTION 'CRM_ORDER_READ_OW'
EXPORTING
IT_HEADER_GUID = lt_act_guid
IMPORTING
ET_ORDERADM_H = lt_orderadm_h
ET_ACTIVITY_H = ls_activity_h
CHANGING
CV_LOG_HANDLE = x_GUID
EXCEPTIONS
DOCUMENT_NOT_FOUND = 1
ERROR_OCCURRED = 2
DOCUMENT_LOCKED = 3
NO_CHANGE_AUTHORITY = 4
NO_DISPLAY_AUTHORITY = 5
NO_CHANGE_ALLOWED = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
ENDIF.
LOOP at lt_orderadm_h INTO ls_orderadm_h.
MOVE-CORRESPONDING ls_orderadm_h to ls_header.
ls_header-description = 'My New Description'.
APPEND ls_header to lt_header.
ENDLOOP.
CLEAR ls_fields. REFRESH lt_fields.
ls_fields-FIELDNAME = 'DESCRIPTION'.
ls_fields-CHANGEABLE = ' '.
APPEND ls_fields to lt_fields.
ls_changes-ref_guid = ls_header-guid.
ls_changes-objectname = 'ORDERADM_H'.
ls_changes-FIELD_NAMES = lt_fields.
APPEND ls_changes to lt_changes.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
CHANGING
CT_ORDERADM_H = lt_header
CT_INPUT_FIELDS = lt_changes
EXCEPTIONS
ERROR_OCCURRED = 1
DOCUMENT_LOCKED = 2
NO_CHANGE_ALLOWED = 3
NO_AUTHORITY = 4
OTHERS = 5
.
IF SY-SUBRC <> 0.
ENDIF.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
Thanks for response Ram,
I double checked the fields structure and it is all the same as when you go into debugging after you made a manual save.
No succes however. What do you mean by lt_order. There is no such table or structure.
Maybe you can give me your code sample.
Any one else maybe? Check SE18 - ORDER_SAVE and check for Z implementations. I can not imagine that I am the first to change something on header level if an order is changed.
Kind regards,
Frederik Defour
Edited by: Frederik Defour on Oct 17, 2008 4:02 PM
Hi
Iam Giving you the sample code which i implemented to change the status of the order.....
here in sample code i populated the GUID value of the order id and populated the it_status table and the ct_input fields.....
so in your case please populate the internal table which is populating when u changed manually that field.
and ct_inputfields...
data:llt_inputfields type crmt_input_field_names_tab,
lls_inputfieldnames like line of llt_inputfields.
data: lt_partner type crmt_partner_external_wrkt.
data:lt_status type crmt_status_comt,
ls_status like line of lt_status.
data:lt_inputfields type crmt_input_field_tab,
ls_inputfields like line of lt_inputfields.
data: l_tck type crmt_erms_service_id,
ls_guid type string.
parameters: p_tck type crmt_erms_service_id.
l_tck = p_tck.
call function 'CRM_ERMS_GET_GUID_FOR_TICKET'
exporting
ticket_number = l_tck
importing
ticket_guid = ls_guid
.
iv_guid = ls_guid.
lv_guid = iv_guid.
append lv_guid to lt_guids.
ls_status-ref_guid = iv_guid.
ls_status-ref_kind = 'A'.
ls_status-status = 'E0002'.
ls_status-user_stat_proc = 'YCC_ST'.
ls_status-activate = 'X'.
append ls_status to lt_status.
clear ls_status.
lls_inputfieldnames-fieldname = 'ACTIVATE'.
append lls_inputfieldnames to llt_inputfields.
ls_inputfields-ref_guid = iv_guid.
ls_inputfields-ref_kind = 'A'.
ls_inputfields-objectname = 'STATUS'.
ls_inputfields-logical_key = 'E0002YCC_ST' .
ls_inputfields-field_names = llt_inputfields.
append ls_inputfields to lt_inputfields.
clear ls_inputfields.
call function 'CRM_ORDER_MAINTAIN'
exporting
it_status = lt_status
changing
ct_input_fields = lt_inputfields
exceptions
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
others = 5
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
call function 'CRM_ORDER_SAVE'
exporting
it_objects_to_save = lt_guids
IV_UPDATE_TASK_LOCAL = FALSE
IV_SAVE_FRAME_LOG = FALSE
IV_NO_BDOC_SEND = FALSE
IMPORTING
ET_SAVED_OBJECTS =
ET_EXCEPTION =
ET_OBJECTS_NOT_SAVED =
CHANGING
CV_LOG_HANDLE =
exceptions
document_not_saved = 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.
commit work.
at end save and commit work must and let me know which field u want to change so that i ll give u exact code..
any one have doubts on crm2007 concepts let me know i ll try to findout the solution.
Thanks all for your assistance,
I finally cracked the code.
My mistake was that I didn't provide the original GUI in the change structure of de crm_order_maintain function.
For others who tumble on this answer.
-> You can change header data of an transaction by creating an implementation in SE18 of the order_save.
Method save_prepare.
-> by using the CRM_ORDER_MAINTAIN I can update the header data before it is actually saved.
This code is called every time a user changes a transaction
The code provide above with the 'CRM_ORDER_SAVE' is for a standalone program to change orders. Do not use it in the order_save implementation since this is a part of the crm_order_save.
Otherwise you have an endless loop.
*----------------------------------------------------------------------*
* Change description *
*----------------------------------------------------------------------*
DATA : lt_act_guid TYPE crmt_object_guid_tab,
x_guid TYPE BALLOGHNDL,
* lt_orderadm_h TYPE crmt_orderadm_h_wrkt,
* ls_orderadm_h TYPE crmt_orderadm_h_wrk,
ls_activity_h TYPE crmt_activity_h_wrkt,
importob TYPE crmt_object_name_tab.
DATA : ls_changes TYPE CRMT_INPUT_FIELD,
lt_changes TYPE CRMT_INPUT_FIELD_TAB,
ls_headerdes TYPE CRMT_ORDERADM_H_COM,
lt_headerdes TYPE CRMT_ORDERADM_H_COMT,
lt_fields TYPE CRMT_INPUT_FIELD_NAMES_TAB,
ls_fields TYPE CRMT_INPUT_FIELD_NAMES.
REFRESH lt_act_guid.
APPEND iv_guid to lt_act_guid.
REFRESH lt_orderadm_h.
REFRESH ls_activity_h.
CLEAR x_GUID.
CALL FUNCTION 'CRM_ORDER_READ_OW'
EXPORTING
IT_HEADER_GUID = lt_act_guid
IMPORTING
ET_ORDERADM_H = lt_orderadm_h
ET_ACTIVITY_H = ls_activity_h
CHANGING
CV_LOG_HANDLE = x_GUID
EXCEPTIONS
DOCUMENT_NOT_FOUND = 1
ERROR_OCCURRED = 2
DOCUMENT_LOCKED = 3
NO_CHANGE_AUTHORITY = 4
NO_DISPLAY_AUTHORITY = 5
NO_CHANGE_ALLOWED = 6
OTHERS = 7
.
IF SY-SUBRC = 0.
ENDIF.
REFRESH lt_headerdes. CLEAR ls_headerdes.
LOOP at lt_orderadm_h INTO ls_orderadm_h.
MOVE-CORRESPONDING ls_orderadm_h to ls_headerdes.
IF ls_headerdes-description is initial.
* select new description
ls_headerdes-description = 'My New Description'.
APPEND ls_headerdes to lt_headerdes.
ENDIF.
ENDLOOP.
IF ls_headerdes-description is not initial.
* fill structure with fields to change - ORDERADM_H " header structure change
* Tip to see how this structure is filled place a break a crm_order_maintain and
* change the field you want to change
CLEAR ls_fields. REFRESH lt_fields.
ls_fields-FIELDNAME = 'DESCRIPTION'.
ls_fields-CHANGEABLE = ' '.
APPEND ls_fields to lt_fields.
ls_changes-ref_guid = ls_orderadm_h-guid.
ls_changes-objectname = 'ORDERADM_H'.
ls_changes-FIELD_NAMES = lt_fields.
APPEND ls_changes to lt_changes.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
CHANGING
CT_ORDERADM_H = lt_headerdes
CT_INPUT_FIELDS = lt_changes
EXCEPTIONS
ERROR_OCCURRED = 1
DOCUMENT_LOCKED = 2
NO_CHANGE_ALLOWED = 3
NO_AUTHORITY = 4
OTHERS = 5
.
IF SY-SUBRC = 0.
ENDIF.
ENDIF.
Hope this help some else in the sap world.
Greetz
Frederik
Thanks all for you input
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
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.