on 01-26-2015 4:56 PM
Hi all,
I'm trying to learn how to use PDO classes. In this case I'm tryint to create a CTR from a SC.
But I always get the same errors:
Enter at least one item
Enter exactly one partner of type Supplier
I'm creating a new CTR instance using the method /sapsrm/cl_pdo_factory_ctr_adv=>create_new_instance.
Then I'm trying to add the items with the method /sapsrm/if_pdo_bo_ctr~add_item. I've tried also with method /sapsrm/if_pdo_bo_ctr~update_item.
For partners I'm using method add_header_partners.
And finally I'm using /sapsrm/if_pdo_base~save to save and create the document.
But I'm doing something wrong because I get always these messages...
This is my code: (sorry for the text format, I'm trying to paste the code with abap highlighting)
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
REPORT ztest_ric.
TYPE-POOLS: icon.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS:
pa_sc TYPE crmt_object_id_db OBLIGATORY ,
pa_suppl TYPE bu_partner OBLIGATORY ,
pa_start TYPE sy-datum DEFAULT sy-datum OBLIGATORY ,
pa_end TYPE sy-datum DEFAULT sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
CONSTANTS: lc_process_type TYPE crmt_process_type_db VALUE 'WK'.
DATA:
lv_error TYPE xfeld,
lv_guid TYPE bu_partner_guid,
lv_sc_guid TYPE bbp_guid,
lv_object_id TYPE crmt_object_id_db,
ls_sc_header TYPE bbp_pds_sc_header_d,
ls_guid TYPE bbp_guid_tab,
ls_ctr_partner TYPE bbp_pds_partner,
ls_ctr_header TYPE /sapsrm/s_pdoctr_header,
ls_ctr_item TYPE /sapsrm/s_pdoctr_item,
ls_ctr_orgdata TYPE bbp_pds_org,
lt_sc_item TYPE bbpt_pd_sc_item_d,
lt_sc_partner TYPE bbpt_pd_partner,
lt_sc_orgdata TYPE bbpt_pds_org,
lt_guid TYPE bbpt_guid,
lt_item_guid TYPE /sapsrm/t_pdo_hier_guid_list,
lt_ctr_item TYPE /sapsrm/t_pdoctr_item,
lt_ctr_partner TYPE bbpt_pds_partner,
lt_messages TYPE bbpt_pd_messages,
lo_exception TYPE REF TO cx_root,
lo_messages TYPE REF TO /sapsrm/cl_pdo_msg,
lo_sc_instance TYPE REF TO /sapsrm/if_pdo_bo_sc_adv,
lo_ctr_instance TYPE REF TO /sapsrm/if_pdo_bo_ctr_adv,
lo_message_handler TYPE REF TO /sapsrm/if_pdo_msg_consumer.
FIELD-SYMBOLS:
<ls_sc_item> TYPE bbp_pds_sc_item_d,
<ls_sc_orgdata> TYPE bbp_pds_org,
<ls_item_guid> TYPE /sapsrm/s_pdo_hier_guid_list.
* Get SC GUID;
CALL FUNCTION 'BBP_PD_SC_GUID_GET'
EXPORTING
iv_object_id = pa_sc
IMPORTING
ev_guid = lv_sc_guid
TABLES
et_messages = lt_messages.
IF lv_sc_guid IS INITIAL.
MESSAGE 'SC doesnt exist' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* SC Instance;
CALL METHOD /sapsrm/cl_pdo_factory_sc_adv=>get_instance
EXPORTING
iv_header_guid = lv_sc_guid
iv_mode = /sapsrm/if_pdo_constants_gen_c=>gc_mode_display
RECEIVING
ro_instance = lo_sc_instance.
CHECK lo_sc_instance IS BOUND.
* Create new instance for the new Contract;
TRY.
CALL METHOD /sapsrm/cl_pdo_factory_ctr_adv=>create_new_instance
EXPORTING
iv_uname = sy-uname
iv_process_type = lc_process_type
iv_is_template = space
IMPORTING
eo_ctr_instance = lo_ctr_instance
CHANGING
co_message_handler = lo_message_handler.
CATCH /sapsrm/cx_pdo_wf_mode_ban INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_wrong_bus_type INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_pd_read_error INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_lock_failed INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_no_authorizatio INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_parameter_error INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_status_error INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_incons_user INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_error INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* Get SC header details;
TRY.
CALL METHOD lo_sc_instance->/sapsrm/if_pdo_bo_sc~get_header_detail
IMPORTING
es_header = ls_sc_header.
CATCH /sapsrm/cx_pdo_no_authorizatio INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* Fill CTR Header:
MOVE-CORRESPONDING ls_sc_header TO ls_ctr_header.
ls_ctr_header-vper_start = pa_start.
ls_ctr_header-vper_end = pa_end.
ls_ctr_header-process_type = lc_process_type.
ls_ctr_header-pmnttrms = 'Z004'.
CLEAR ls_ctr_header-object_id.
CALL FUNCTION 'BBP_LA_UTILITY_GENERATE_GUID'
IMPORTING
e_guid = ls_ctr_header-guid.
* Get SC items;
ls_guid-guid = lv_sc_guid.
APPEND ls_guid TO lt_guid.
CALL METHOD lo_sc_instance->/sapsrm/if_pdo_base~get_item_list
EXPORTING
it_parent_guid = lt_guid
IMPORTING
et_item_guid = lt_item_guid.
* Get SC item details;
CLEAR: lt_guid.
LOOP AT lt_item_guid
ASSIGNING <ls_item_guid>.
ls_guid-guid = <ls_item_guid>-guid.
APPEND ls_guid TO lt_guid.
ENDLOOP.
TRY.
CALL METHOD lo_sc_instance->/sapsrm/if_pdo_bo_sc~get_item_detail
EXPORTING
it_item_guids = lt_guid
IMPORTING
et_item = lt_sc_item
et_partner = lt_sc_partner
et_orgdata = lt_sc_orgdata.
CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* Fill CTR Items:
LOOP AT lt_sc_item
ASSIGNING <ls_sc_item>.
CHECK <ls_sc_item>-del_ind EQ space.
MOVE-CORRESPONDING <ls_sc_item> TO ls_ctr_item.
ls_ctr_item-parent = ls_ctr_header-guid.
ls_ctr_item-header = ls_ctr_header-guid.
ls_ctr_item-ps_handle_itm = ls_ctr_header-guid.
ls_ctr_item-src_guid = <ls_sc_item>-guid.
ls_ctr_item-src_object_type = /sapsrm/if_pdo_obj_types_c=>gc_pdo_shop_item.
ls_ctr_item-itm_released = abap_true.
CALL FUNCTION 'BBP_LA_UTILITY_GENERATE_GUID'
IMPORTING
e_guid = ls_ctr_item-guid.
IF ls_ctr_header-co_code IS INITIAL.
ls_ctr_header-co_code = <ls_sc_item>-be_co_code.
ENDIF.
* Add the item to the contract;
TRY.
CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_bo_ctr~add_item
CHANGING
cs_item = ls_ctr_item.
CATCH /sapsrm/cx_pdo_incons_user.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_no_authorizatio.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_abort.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* APPEND ls_ctr_item TO lt_ctr_item
ADD ls_ctr_item-value TO ls_ctr_header-total_value.
* Move Org. data from the first SC item;
IF ls_ctr_orgdata IS INITIAL.
READ TABLE lt_sc_orgdata
ASSIGNING <ls_sc_orgdata>
WITH KEY p_guid = <ls_sc_item>-guid
del_ind = space.
IF sy-subrc EQ 0.
ls_ctr_orgdata = <ls_sc_orgdata>.
ENDIF.
ENDIF.
ENDLOOP.
* Update Header;
TRY.
CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_bo_ctr~update_header
EXPORTING
is_header = ls_ctr_header
CHANGING
co_message_handler = lo_message_handler.
CATCH /sapsrm/cx_pdo_no_authorizatio INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_wrong_mode INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_parameter_error INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* Update Items;
* TRY.
* CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_bo_ctr~update_item
* EXPORTING
* it_items = lt_ctr_item
* CHANGING
* co_message_handler = lo_message_handler.
* CATCH /sapsrm/cx_pdo_no_authorizatio INTO lo_exception.
* PERFORM get_exception_text USING lo_exception.
* RETURN.
* CATCH /sapsrm/cx_pdo_wrong_mode INTO lo_exception.
* PERFORM get_exception_text USING lo_exception.
* RETURN.
* CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
* PERFORM get_exception_text USING lo_exception.
* RETURN.
* CATCH /sapsrm/cx_pdo_incons_user INTO lo_exception.
* PERFORM get_exception_text USING lo_exception.
* RETURN.
* CATCH /sapsrm/cx_pdo_parameter_error INTO lo_exception.
* PERFORM get_exception_text USING lo_exception.
* RETURN.
* ENDTRY.
* Add Orgdata:
ls_ctr_orgdata-p_guid = ls_ctr_header-guid.
CALL FUNCTION 'BBP_LA_UTILITY_GENERATE_GUID'
IMPORTING
e_guid = ls_ctr_orgdata-guid.
TRY.
CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_do_orgdata~add_header_orgdata
EXPORTING
is_orgdata = ls_ctr_orgdata
CHANGING
co_message_handler = lo_message_handler.
CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* Add Vendor;
ls_ctr_partner-partner_id = pa_suppl.
ls_ctr_partner-p_guid = ls_ctr_header-guid.
ls_ctr_partner-partner_fct = '00000019'.
CALL FUNCTION 'BBP_LA_UTILITY_GENERATE_GUID'
IMPORTING
e_guid = ls_ctr_partner-partner_guid.
CALL FUNCTION 'BUPA_NUMBERS_GET'
EXPORTING
iv_partner = ls_ctr_partner-partner_id
IMPORTING
ev_partner_guid = lv_guid.
ls_ctr_partner-partner_no = lv_guid.
APPEND ls_ctr_partner TO lt_ctr_partner.
CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_do_partner_base~add_header_partners
EXPORTING
it_partner = lt_ctr_partner
CHANGING
co_message_handler = lo_message_handler.
* Check if there are errors;
PERFORM check_messages USING lo_message_handler
CHANGING lv_error.
CHECK lv_error EQ space.
* TRY.
* CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_base~submit_update
* CHANGING
* co_message_handler = lo_message_handler.
* .
* CATCH /sapsrm/cx_pdo_wrong_mode .
* CATCH /sapsrm/cx_pdo_abort .
* ENDTRY.
* Save the document;
CREATE OBJECT lo_messages.
lo_message_handler ?= lo_messages.
TRY.
CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_base~save
CHANGING
co_message_handler = lo_message_handler.
CATCH /sapsrm/cx_pdo_abort INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
CATCH /sapsrm/cx_pdo_error INTO lo_exception.
PERFORM get_exception_text USING lo_exception.
RETURN.
ENDTRY.
* Check if there are errors;
PERFORM check_messages USING lo_message_handler
CHANGING lv_error.
CHECK lv_error EQ space.
CALL METHOD lo_ctr_instance->/sapsrm/if_pdo_base~get_object_id
RECEIVING
rv_object_id = lv_object_id.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WRITE: / icon_led_green AS ICON, 'Contract created: ', lv_object_id.
*&---------------------------------------------------------------------*
*& Form GET_EXCEPTION_TEXT
*&---------------------------------------------------------------------*
* Get exception text
*----------------------------------------------------------------------*
* -->P_LO_EXCEPTION Exception
*----------------------------------------------------------------------*
FORM get_exception_text USING p_lo_exception TYPE REF TO cx_root.
DATA: lv_text TYPE string.
lv_text = p_lo_exception->get_text( ).
WRITE: / icon_led_red AS ICON, lv_text.
ENDFORM. " GET_EXCEPTION_TEXT
*&---------------------------------------------------------------------*
*& Form CHECK_MESSAGES
*&---------------------------------------------------------------------*
* Check messages
*----------------------------------------------------------------------*
* -->P_LO_MESSAGE_HANDLER messages
* <--P_LV_ERROR There are errors
*----------------------------------------------------------------------*
FORM check_messages USING p_lo_message_handler TYPE REF TO /sapsrm/if_pdo_msg_consumer
CHANGING p_lv_error TYPE xfeld .
DATA:
lt_message TYPE bbpt_pd_messages.
FIELD-SYMBOLS:
<ls_message> TYPE bbp_pds_messages.
IF lo_message_handler IS NOT BOUND.
RETURN.
ENDIF.
CALL METHOD p_lo_message_handler->get_messages
IMPORTING
et_messages = lt_message.
LOOP AT lt_message
ASSIGNING <ls_message>
WHERE msgty EQ 'E'
OR msgty EQ 'A'.
WRITE: / icon_led_red AS ICON, <ls_message>-message.
p_lv_error = 'X'.
ENDLOOP.
ENDFORM. " CHECK_MESSAGES
Thanks in advance,
Regards,
Ricardo.
Hello Ricardo,
I will give this code a try. I want to check specifically on two things.
1. Are you trying to order the contract or only save?
2. Where are you triggering this code from?
I would also like you debug that during the scenario place a breakpoint in FM 'BBP_PROCDOC_UPDATE' (should be called multiple times) and check if data raising errors are still present here. I can see two possible issues here.
1. Data is passed with wrong structure.
2. Data is not passed in the final call.
You could also check if change_badi is influencing here.
Thanks and Regards,
Veera
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Veeraraghavan,
Thanks for answer.
In this case it's ok if I create the CTR saved only, but I would like to create it without errors.
This is a test program only to learn how to use these classes, but I have to create a similar FM to use it in several places in my system.
I think something is missing in my code, may be we need to call another previous method or something to reflect the changes in the document before save it.
I've already check that badis are not influencing here. We have an implementation for badi CHANGE and CHECK, I've put a breakpoint there, the badis are triggered serveral times but the document comes always without items.
I have a similar custom FM created but using the "old" FM PRODOC instead of these classes and it's working fine with the same data. This code is not complete, is missing some parts, like the accounting part or adding the item partners, but I'm trying to create the report step by step, but doesn't work fine... if I can not add the items I can not add the other parts of the report...
Regards,
Ricardo.
--------------------------------------------------
EDIT: When I use the method ADD_ITEM, any badi is triggered, may be I'm passing something wrong or I need to use other method...
EDIT_2: I'm trying also with the classes for PO, in this case I can see after adding the items there is an attribute MT_ITEM in the class which is empty, but there is other attribute MO_PDO_UPDATE_BUFFER where I can see the items. May be we need to use a method to update the attribute MT_ITEM from the buffer table...
EDIT_3: There was a silly mistake in the code, I was generating a new guid for the header... I need to use the method GET_HEADER_DETAIL to get the actual guid. But this didn't solve the problem...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.