SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Fix CRM_ORDER019 (Document is being distributed)



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> CRM
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Fri Apr 22, 2016 11:33 am    Post subject: Fix CRM_ORDER019 (Document is being distributed) Reply with quote

Fix CRM_ORDER019 'Document is being distributed; changes are not possible' error
Code:
FUNCTION zlru_order_save.
*"----------------------------------------------------------------------
*"*"Локальный интерфейс:
*"  IMPORTING
*"     REFERENCE(IR_ORDER) TYPE REF TO  CL_CRM_BOL_ENTITY OPTIONAL
*"     REFERENCE(IR_ADMINH) TYPE REF TO  CL_CRM_BOL_ENTITY OPTIONAL
*"     REFERENCE(IV_NOSAVE) TYPE  CRMT_BOOLEAN OPTIONAL
*"  EXPORTING
*"     REFERENCE(EV_SUCCESS) TYPE  ABAP_BOOL
*"----------------------------------------------------------------------

  DATA: lv_header_guid            TYPE crmt_object_guid,
        lv_lock                   TYPE abap_bool,
        lr_adminh                 TYPE REF TO cl_crm_bol_entity.

  ev_success = abap_false.
  CHECK ir_order IS BOUND OR ir_adminh IS BOUND.

  TRY.
      IF ir_adminh IS BOUND.
        lr_adminh = ir_adminh.
      ENDIF.

      IF lr_adminh IS NOT BOUND AND ir_order IS BOUND.
        lr_adminh ?= ir_order->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
      ENDIF.
      IF lr_adminh IS BOUND.
        lr_adminh->get_property_as_value(
        EXPORTING
          iv_attr_name = 'GUID'
        IMPORTING
          ev_result    = lv_header_guid ).
      ENDIF.
    CATCH cx_crm_genil_duplicate_rel.
    CATCH cx_crm_genil_model_error.
  ENDTRY.

  CALL FUNCTION 'ZLRU_LOCK'
    EXPORTING
      ir_adminh  = lr_adminh
    IMPORTING
      ev_success = lv_lock.

  IF lv_lock = if_genil_boolean=>true.

    DATA: lr_tx   TYPE REF TO if_bol_transaction_context,
          lr_core TYPE REF TO cl_crm_bol_core.

    lr_core = cl_crm_bol_core=>get_instance( ).
    lr_core->modify( ).
    IF iv_nosave IS INITIAL.
      IF ir_order IS BOUND.
        lr_tx = ir_order->get_transaction( ).
      ELSE.
        lr_tx = lr_core->get_transaction( ).
      ENDIF.
      IF lr_tx->save( ) = abap_true.
        lr_tx->commit( ).
      ELSE.
        lr_tx->rollback( ).
      ENDIF.
    ENDIF.
  ENDIF.

  IF ir_adminh IS BOUND.
    ev_success = lr_adminh->is_locked( ).
  ELSEIF ir_order IS BOUND.
    ev_success = ir_order->is_locked( ).
  ENDIF.

  IF ev_success = abap_false.
    PERFORM check_lock USING lv_header_guid.
  ENDIF.

  PERFORM check_status USING lv_header_guid.

ENDFUNCTION.


Code:

FUNCTION zlru_lock.
*"----------------------------------------------------------------------
*"*"Локальный интерфейс:
*"  IMPORTING
*"     REFERENCE(IR_ORDER) TYPE REF TO  CL_CRM_BOL_ENTITY OPTIONAL
*"     REFERENCE(IR_ADMINH) TYPE REF TO  CL_CRM_BOL_ENTITY OPTIONAL
*"  EXPORTING
*"     REFERENCE(EV_SUCCESS) TYPE  ABAP_BOOL
*"----------------------------------------------------------------------
* it is need to IV_REFRESH_BUFFER = 'X' if previous was done save without order buffer initial
  DATA: lv_header_guid TYPE crmt_object_guid,
        lr_order       TYPE REF TO cl_crm_bol_entity,
        lr_adminh      TYPE REF TO cl_crm_bol_entity.

  ev_success = abap_false.
  CHECK ir_order IS BOUND OR ir_adminh IS BOUND.

  TRY.
      IF ir_adminh IS BOUND.
        lr_adminh = ir_adminh.
      ENDIF.
      IF ir_order IS BOUND.
        lr_order = ir_order.
      ENDIF.

      IF lr_adminh IS NOT BOUND AND lr_order IS BOUND.
        lr_adminh ?= ir_order->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
      ENDIF.
      IF lr_adminh IS BOUND AND lr_order IS NOT BOUND.
        lr_order ?= lr_adminh->get_parent( ).
      ENDIF.

      IF lr_adminh IS BOUND.
        lr_adminh->get_property_as_value(
        EXPORTING
          iv_attr_name = 'GUID'
        IMPORTING
          ev_result    = lv_header_guid ).
      ENDIF.
    CATCH cx_crm_genil_duplicate_rel.
    CATCH cx_crm_genil_model_error.
  ENDTRY.

  IF ir_adminh IS BOUND.
    ev_success = lr_adminh->is_locked( ).
  ELSEIF lr_order IS BOUND.
    ev_success = lr_order->is_locked( ).
  ENDIF.

  IF ev_success = abap_false.
    PERFORM check_lock USING lv_header_guid.
  ENDIF.

  PERFORM check_status USING lv_header_guid.

  IF lr_adminh IS BOUND.
    ev_success = lr_adminh->lock( ).
  ELSEIF lr_order IS BOUND.
    ev_success = lr_order->lock( ).
  ENDIF.

ENDFUNCTION.


Code:

*----------------------------------------------------------------------*
***INCLUDE LZLRU_CRM_UTILSF01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CHECK_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_HEADER_GUID  text
*----------------------------------------------------------------------*
FORM check_status  USING p_header_guid TYPE crmt_object_guid.
  DATA: lt_jest                   TYPE TABLE OF jest,
        ls_jest                   TYPE jest,
        lv_status_transferring    TYPE crmt_boolean,
        lv_status_transfer_failed TYPE crmt_boolean.

  IF NOT p_header_guid IS INITIAL.

    DO 20 TIMES.
      REFRESH lt_jest.
      CLEAR: lv_status_transferring, lv_status_transfer_failed.

      SELECT stat INTO CORRESPONDING FIELDS OF TABLE lt_jest
        FROM crm_jest
        WHERE objnr EQ p_header_guid
          AND inact EQ ''.
      LOOP AT lt_jest INTO ls_jest.
        CASE ls_jest-stat.
          WHEN 'I1054'.  "TRANSFERRING
            lv_status_transferring  = abap_true.
          WHEN 'I1056'.  "TRANSFER_FAILED
            lv_status_transfer_failed = abap_true.
          WHEN  'I1111'.
            lv_status_transferring = abap_true.
            lv_status_transfer_failed = abap_false.
        ENDCASE.
      ENDLOOP.
      IF  lv_status_transferring    EQ abap_true
      AND lv_status_transfer_failed EQ abap_false.
        WAIT UP TO 2 SECONDS.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  CHECK_LOCK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_HEADER_GUID  text
*----------------------------------------------------------------------*
FORM check_lock  USING pv_header_guid TYPE crmt_object_guid.

  DATA: lv_garg       TYPE seqg3-garg,
        lv_str        TYPE seqg3-garg,
        lt_enq        TYPE TABLE OF seqg3,
        ls_enq        TYPE seqg3,
        lv_lock       TYPE as4flag,
        lv_was_locked TYPE as4flag.

  IF pv_header_guid IS INITIAL.
    EXIT.
  ENDIF.

  lv_str = pv_header_guid.
  CONCATENATE sy-mandt lv_str INTO lv_garg.

  DO 20 TIMES.
    CLEAR lv_lock.
    REFRESH lt_enq.
    CALL FUNCTION 'ENQUEUE_READ'
      EXPORTING
        gclient               = sy-mandt
        gname                 = 'CRMD_ORDERADM_H'
        garg                  = lv_garg
        guname                = '*'
      TABLES
        enq                   = lt_enq
      EXCEPTIONS
        communication_failure = 1
        system_failure        = 2
        OTHERS                = 3.
    IF sy-subrc IS INITIAL.
      LOOP AT lt_enq INTO ls_enq WHERE gmode = 'E'.
        lv_lock = 'X'.
        lv_was_locked = 'X'.
        EXIT.
      ENDLOOP.
    ENDIF.
    IF NOT lv_lock IS INITIAL.
      WAIT UP TO 1 SECONDS.
    ELSE.
      IF NOT lv_was_locked IS INITIAL.
        WAIT UP TO 2 SECONDS.
      ENDIF.
      EXIT.
    ENDIF.
  ENDDO.

ENDFORM.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> CRM All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.