SAP ABAP里unicode转中文的一个解决方案的完整代码

class CL_SOC_UTIL definition
  public
  final
  create public .

public section.

  types:
    tt_post_attributes TYPE STANDARD TABLE OF crmt_soc_post_attr .
  types:
    tt_post_uuid TYPE STANDARD TABLE OF crmt_soc_data_uuid .
  types:
    tt_socialuserinfo type standard table of socialuserinfo .

  class-methods READ_POST_ATTRIBUTES
    importing
      !IT_POST_UUID type TT_POST_UUID
    exporting
      !ET_POST_ATTRIBUTES type TT_POST_ATTRIBUTES .
  class-methods GET_SQL_STATEMENT_FOR_STATUS
    importing
      !IT_STATUS type STRING_TABLE
    returning
      value(RV_STATEMENT) type STRING .
  class-methods GET_SQL_STATEMENT
    importing
      !IV_FIELD_NAME type STRING
      !IV_FIELD_VALUE type ANY
    returning
      value(RV_STATEMENT) type STRING .
  class-methods GET_SQL_STATEMENT_FOR_DATE
    importing
      !IV_FROM type CRMT_AUI_FROM
      !IV_TO type CRMT_AUI_TO
    returning
      value(RV_STATEMENT) type STRING .
  class-methods GET_MAIN_CATEGORIES
    importing
      !IV_MAP_ITEM_TYPE type CRMT_AUI_MAP_ITEM_TYPE optional
    returning
      value(ET_MAINCATEGORY_LIST) type CRMTT_AUI_KEY_VALUE_PAIRS .
  class-methods GET_SOCIAL_USER_INFO
    importing
      !IV_SOCIALMEDIACHANNEL type SMI_SOCIALMEDIACHANNEL
      !IV_SOCIALUSER type SMI_SOCIALUSER
    exporting
      value(ES_SOCIALUSERINFO) type SOCIALUSERINFO .
  class-methods CONVERT_SCID_TO_BPID
    importing
      !IV_SOCIALMEDIACHANNEL type SMI_SOCIALMEDIACHANNEL
      !IV_SOCIALUSER type SMI_SOCIALUSER
    exporting
      !EV_PARTNER_GUID type BU_PARTNER_GUID .
  class-methods GET_POST_TYPE_DESC
    importing
      !IV_TYPE_CODE type CHAR10
    returning
      value(RV_TYPE_TEXT) type CHAR60 .
  class-methods GET_CHNL_DESC
    importing
      !IV_CHNL_CODE type CHAR4
    returning
      value(RV_CHANL_DESC) type CHAR100 .
  class-methods GET_SENTI_DESC
    importing
      !IV_SENTI_CODE type CHAR10
    returning
      value(RV_SENTI_DESC) type CHAR60 .
  type-pools ABAP .
  class-methods CHECK_POST_DEPENDENT_OBJ
    importing
      !IV_OBJ_GUID type CRMT_GENIL_OBJECT_GUID
    exporting
      !EV_DEP_OBJ_FLAG type ABAP_BOOL .
  class-methods REMOVE_POST_DEPENDENT_LINKS
    importing
      !IV_OBJ_GUID type CRMT_GENIL_OBJECT_GUID
    exporting
      !EV_DEP_OBJ_REMOVED type ABAP_BOOL .
  class-methods GENERATE_POST_INTERNAL_ID
    returning
      value(RV_ID) type CRMT_SOC_POST_INTERNAL_ID .
  class-methods GET_SMI_USER_AND_BP
    importing
      !IV_CHNL_CODE type SMI_SOCIALMEDIACHANNEL
      !IV_SOCIAL_USER type SMI_SOCIALUSER
    exporting
      !EV_BUPA_NUMBER type BU_PARTNER
      !EV_BUPA_NAME type BU_DESCRIP
      !ES_SMI_USER type CRMT_BUPA_SOCIAL_USER_DATA .
  class-methods CLASS_CONSTRUCTOR .
  class-methods CONVERT_ISOGENDER_TO_INTERNAL
    importing
      !IV_GENDER_CODE type SMI_GENDERCODE
    returning
      value(RV_VALUE) type SMI_GENDERCODE .
  class-methods GET_FORMATTED_STRING
    importing
      !IV_FLAG type CRMT_SOC_UNICODE_FLAG optional
      !IV_STRING type STRING
    returning
      value(RV_STRING) type STRING .
  class-methods RESERVE_CURRENT_POST
    importing
      !IO_BOL_ENTITY type ref to CL_CRM_BOL_ENTITY
    exporting
      !EV_PROCESSOR type XUBNAME
      !EV_MESSAGE type CRMST_AUI_MESSAGE .
  class-methods CHECK_IN_DB
    importing
      !IV_POST_UUID type CRMT_GENIL_OBJECT_GUID
    exporting
      !EV_FLAG type ABAP_BOOL .
protected section.
private section.

  types:
    tt_sentit TYPE STANDARD TABLE OF crmc_soc_senti_t .

  constants C_EMPLOYEE_FIELD_NAME type NAME_KOMP value 'PROCESSOR'. "#EC NOTEXT
  constants CO_SWITCH_ID type SFW_SWITCH_ID value 'CRM_SOC_SFWS_SMI_1'. "#EC NOTEXT
  constants GC_REL_INTO type BINRELTYP value 'INTO'. "#EC NOTEXT
  class-data ST_SENTIT type TT_SENTIT .
  class-data SV_CURRENT_YEAR type CHAR4 .
  class-data SV_UNICODE_FLAG type CRMT_SOC_UNICODE_FLAG value '\u'. "#EC NOTEXT .  .  .  . " .
  class-data ST_INVALID type STRING_TABLE .
  constants C_COOKIE_ID type CHAR20 value 'CRM_SOC_COOKIE'. "#EC NOTEXT
  constants C_APPLICATION_NAME type CHAR20 value 'CRM_SOCIAL_MEDIA'. "#EC NOTEXT
  constants C_APPLICATION_NAMESPACE type CHAR10 value 'CRM_SOC'. "#EC NOTEXT
  constants C_USER_NAME type CHAR10 value 'PUBLIC'. "#EC NOTEXT
  constants C_SESSION_ID type CHAR10 value '000'. "#EC NOTEXT
  class-data ST_CONTROL_FLAGS type STRING_TABLE .

  type-pools ABAP .
  class-methods IS_HEXDECIMAL
    importing
      !IV_STRING type CHAR4
    returning
      value(IS_HEXDECIMAL) type ABAP_BOOL .
  class-methods IS_VALID_UNICODE_FLAG
    importing
      !IV_FLAG type CRMT_SOC_UNICODE_FLAG
    returning
      value(RV_VALID) type ABAP_BOOL .
ENDCLASS.



CLASS CL_SOC_UTIL IMPLEMENTATION.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>CHECK_IN_DB
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_POST_UUID                   TYPE        CRMT_GENIL_OBJECT_GUID
* | [<---] EV_FLAG                        TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD check_in_db.
    DATA lv_uuid TYPE crmt_soc_data_uuid.

    SELECT SINGLE uuid FROM crmd_soc_post INTO lv_uuid WHERE uuid = iv_post_uuid.
    IF lv_uuid IS INITIAL.
      ev_flag = abap_false.
    ELSE.
      ev_flag = abap_true.
    ENDIF.
  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>CHECK_POST_DEPENDENT_OBJ
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_OBJ_GUID                    TYPE        CRMT_GENIL_OBJECT_GUID
* | [<---] EV_DEP_OBJ_FLAG                TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD check_post_dependent_obj.

    DATA: lt_bor       TYPE        crmt_ic_irec_links,
          lv_objtype   TYPE        swo_objtyp,
          lv_objkey    TYPE        swo_typeid,
          ls_root      TYPE        borident,
          lv_inst      TYPE        crmt_genil_obj_instance.


    FIELD-SYMBOLS: <bor>   TYPE relgraphlk.
    INCLUDE: crm_object_types_con.

    ls_root-objkey = iv_obj_guid.
    ls_root-objtype = 'CRMSOCPOST'.

* Get the Relations (Interaction Records)
    CALL FUNCTION 'SREL_GET_NEXT_RELATIONS'
      EXPORTING
        object         = ls_root
        max_hops       = 1
      TABLES
        links          = lt_bor
      EXCEPTIONS
        internal_error = 1
        no_logsys      = 2
        OTHERS         = 3.

*1569923
    SORT lt_bor BY utctime DESCENDING.

* Analyse them
    CLEAR ev_dep_obj_flag.
    LOOP AT lt_bor ASSIGNING <bor>.
      IF <bor>-objkey_a = iv_obj_guid.
        lv_objtype = <bor>-objtype_b.
        lv_objkey  = <bor>-objkey_b.
      ELSE.
        lv_objtype = <bor>-objtype_a.
        lv_objkey  = <bor>-objkey_a.
      ENDIF.

*   Get dependent objects
      lv_inst-object_name = cl_crm_aui_service=>get_genilname_from_bustype( lv_objtype ).
      IF lv_inst-object_name IS NOT INITIAL.
          ev_dep_obj_flag = 'X'.
          RETURN.
      ENDIF.
    ENDLOOP.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>CLASS_CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method CLASS_CONSTRUCTOR.
     sv_current_year = sy-datum.
     APPEND cl_abap_conv_in_ce=>uccp( 'p2d3' ) to st_invalid. "#EC NOTEXT
     APPEND cl_abap_conv_in_ce=>uccp( '1234' ) to st_invalid. "#EC NOTEXT
     DATA: it_taba TYPE STANDARD TABLE OF dd07v,
           it_tabb TYPE STANDARD TABLE OF dd07v.

     FIELD-SYMBOLS: <item> TYPE dd07v.

   CALL FUNCTION 'DD_DOMA_GET'
      EXPORTING
        domain_name   = 'CRM_SOC_UNICODE_FLAG'
        langu         = sy-langu
        withtext      = 'X'
      TABLES
        dd07v_tab_a   = it_taba
        dd07v_tab_n   = it_tabb
      EXCEPTIONS
        illegal_value = 1
        op_failure    = 2
        OTHERS        = 3.

   LOOP AT it_taba ASSIGNING <item>.
      APPEND <item>-domvalue_l TO st_control_flags.
   ENDLOOP.


  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>CONVERT_ISOGENDER_TO_INTERNAL
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_GENDER_CODE                 TYPE        SMI_GENDERCODE
* | [<-()] RV_VALUE                       TYPE        SMI_GENDERCODE
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD convert_isogender_to_internal.
    DATA: lv_gender_code TYPE string.

    lv_gender_code = iv_gender_code.
    TRANSLATE lv_gender_code TO LOWER CASE.

    IF lv_gender_code EQ 'm'. "#EC_NOTEXT
      rv_value = 1. "#EC_NOTEXT
    ELSEIF lv_gender_code EQ 'f'. "#EC_NOTEXT
      rv_value = 2. "#EC_NOTEXT
    ELSE.
      rv_value = iv_gender_code.
    ENDIF.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>CONVERT_SCID_TO_BPID
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_SOCIALMEDIACHANNEL          TYPE        SMI_SOCIALMEDIACHANNEL
* | [--->] IV_SOCIALUSER                  TYPE        SMI_SOCIALUSER
* | [<---] EV_PARTNER_GUID                TYPE        BU_PARTNER_GUID
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method CONVERT_SCID_TO_BPID.
     call function 'CRM_BUPA_SMI_USER_GET'
      exporting
        iv_socialmediachannel = IV_SOCIALMEDIACHANNEL
        iv_socialuser         = IV_SOCIALUSER
      importing
        ev_partner_guid = EV_PARTNER_GUID.
  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GENERATE_POST_INTERNAL_ID
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_ID                          TYPE        CRMT_SOC_POST_INTERNAL_ID
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method GENERATE_POST_INTERNAL_ID.

  DATA: rc type INRI-RETURNCODE,
        number TYPE char8.

  CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
      nr_range_nr             = '01'
      object                  = 'SOCPOSTNR'
    IMPORTING
      number                  = number
      returncode              = rc
    EXCEPTIONS
      interval_not_found      = 1
      number_range_not_intern = 2
      object_not_found        = 3
      quantity_is_0           = 4
      quantity_is_not_1       = 5
      interval_overflow       = 6
      buffer_overflow         = 7
      OTHERS                  = 8.

  CHECK sy-subrc = 0.
  CONCATENATE sv_current_year number INTO rv_id.

  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_CHNL_DESC
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_CHNL_CODE                   TYPE        CHAR4
* | [<-()] RV_CHANL_DESC                  TYPE        CHAR100
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_chnl_desc.
    DATA:
          ls_chnl_def TYPE smi_s_socialmediachanneldef.

    CALL METHOD cl_smi_chnldef=>get_social_media_channel
      EXPORTING
        iv_channel_id  = iv_chnl_code
      IMPORTING
        es_smi_chnldef = ls_chnl_def.

**Tempory use here. Once the ATC check error fixed, we may migrate to BS_FDN API.
*    SELECT socialmediachanneldesc FROM smi_chnldef_t INTO rv_chanl_desc WHERE socialmediachannel = iv_chnl_code AND spras = sy-langu.
*    ENDSELECT.

    rv_chanl_desc = ls_chnl_def-socialmediachanneldesc.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_FORMATTED_STRING
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FLAG                        TYPE        CRMT_SOC_UNICODE_FLAG(optional)
* | [--->] IV_STRING                      TYPE        STRING
* | [<-()] RV_STRING                      TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method GET_FORMATTED_STRING.

    CONSTANTS: c_default TYPE CRMT_SOC_UNICODE_FLAG VALUE '\u'.
    TYPES: BEGIN OF ty_pair,
               unicode TYPE char4,
               chinese TYPE char2,
           END OF ty_pair.

    DATA: lv_offset TYPE i,
          lv_start TYPE i,
          lt_match TYPE match_result_tab,
          ls_match LIKE LINE OF lt_match,
          lv_unicode TYPE char4,
          lv_upper TYPE char4,
          lt_chinese TYPE STANDARD TABLE OF ty_pair,
          ls_pair TYPE ty_pair,
          lv_len TYPE i,
          lv_chinese TYPE crmt_soc_unicode_flag,
          lv_replace TYPE char7,
          lv_input TYPE string.

    IF iv_flag IS NOT SUPPLIED.
        sv_unicode_flag = c_default.
    ELSEIF is_valid_unicode_flag( iv_flag ) = abap_false.
        rv_string = iv_string.
        RETURN.
    ELSE.
        sv_unicode_flag = iv_flag.
    ENDIF.

    FIND ALL OCCURRENCES OF sv_unicode_flag IN iv_string RESULTS lt_match.
    IF sy-subrc <> 0.
       rv_string = iv_string.
       RETURN.
    ENDIF.

    lv_input = iv_string.
    lv_len = strlen( lv_input ).

    CLEAR: lt_chinese.

    LOOP AT lt_match INTO ls_match.
       lv_start = ls_match-offset + ls_match-length.
       CHECK lv_len >= lv_start + 4.

       lv_upper = lv_unicode = iv_string+lv_start(4).
       TRANSLATE lv_upper TO UPPER CASE.
       CHECK is_hexdecimal( lv_unicode ) = abap_true.
       lv_chinese = cl_abap_conv_in_ce=>uccp( lv_upper ).
       READ TABLE st_invalid WITH KEY table_line = lv_chinese TRANSPORTING NO FIELDS.
       CHECK sy-subrc <> 0.
       ls_pair-unicode = lv_unicode.
       ls_pair-chinese = lv_chinese.
       APPEND ls_pair TO lt_chinese.
    ENDLOOP.

    LOOP AT lt_chinese INTO ls_pair.
       lv_replace = sv_unicode_flag && ls_pair-unicode.
       REPLACE ALL OCCURRENCES OF lv_replace IN lv_input WITH ls_pair-chinese.
    ENDLOOP.

    rv_string = lv_input.
  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_MAIN_CATEGORIES
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_MAP_ITEM_TYPE               TYPE        CRMT_AUI_MAP_ITEM_TYPE(optional)
* | [<-()] ET_MAINCATEGORY_LIST           TYPE        CRMTT_AUI_KEY_VALUE_PAIRS
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method GET_MAIN_CATEGORIES.
    data: lr_src  type ref to CL_CRM_AUI_SERVICE.
    create object lr_src.
    lr_src->get_main_categories( exporting iv_map_item_type = iv_map_item_type
                                 receiving et_maincategory_list = et_maincategory_list ).
  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_POST_TYPE_DESC
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_TYPE_CODE                   TYPE        CHAR10
* | [<-()] RV_TYPE_TEXT                   TYPE        CHAR60
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_post_type_desc.
    DATA:
          lv_result TYPE dd07v.

    CALL FUNCTION 'DD_DOMVALUE_TEXT_GET'
      EXPORTING
        domname  = 'CRM_SOC_DATA_TYPE'
        value    = iv_type_code
*       LANGU    = ' '
*       BYPASS_BUFFER       = ' '
      IMPORTING
        dd07v_wa = lv_result.

    rv_type_text = lv_result-ddtext.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_SENTI_DESC
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_SENTI_CODE                  TYPE        CHAR10
* | [<-()] RV_SENTI_DESC                  TYPE        CHAR60
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_senti_desc.
    DATA:
          ls_sentit LIKE LINE OF st_sentit.

    IF st_sentit IS INITIAL OR lines( st_sentit ) <= 0.
      SELECT * FROM crmc_soc_senti_t INTO CORRESPONDING FIELDS OF TABLE st_sentit WHERE langu = sy-langu. "#EC CI_NOFIRST
    ENDIF.

    CHECK st_sentit IS NOT INITIAL AND lines( st_sentit ) > 0.

    LOOP AT st_sentit INTO ls_sentit WHERE sentiment = iv_senti_code.
      rv_senti_desc = ls_sentit-sentiment_desc.
      RETURN.
    ENDLOOP.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_SMI_USER_AND_BP
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_CHNL_CODE                   TYPE        SMI_SOCIALMEDIACHANNEL
* | [--->] IV_SOCIAL_USER                 TYPE        SMI_SOCIALUSER
* | [<---] EV_BUPA_NUMBER                 TYPE        BU_PARTNER
* | [<---] EV_BUPA_NAME                   TYPE        BU_DESCRIP
* | [<---] ES_SMI_USER                    TYPE        CRMT_BUPA_SOCIAL_USER_DATA
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_smi_user_and_bp.
    DATA:
          lr_bupa_smi_wrapper TYPE REF TO cl_crm_bupa_smi_user_wrapper,
          lv_bupa_number         TYPE bu_partner.

    lr_bupa_smi_wrapper = cl_crm_bupa_smi_user_wrapper=>get_instance( ).

    CALL METHOD lr_bupa_smi_wrapper->get_smi_user_and_bp
      EXPORTING
        iv_socialmediachannel = iv_chnl_code
        iv_socialuser         = iv_social_user
      IMPORTING
        es_smi_user_data      = es_smi_user
        ev_partner            = ev_bupa_number.

    IF ev_bupa_number IS NOT INITIAL.
      CALL FUNCTION 'CRM_BUPA_DESCRIPTION_READ'
        EXPORTING
          iv_partner          = ev_bupa_number
        IMPORTING
          ev_description_name = ev_bupa_name.
    ENDIF.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_SOCIAL_USER_INFO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_SOCIALMEDIACHANNEL          TYPE        SMI_SOCIALMEDIACHANNEL
* | [--->] IV_SOCIALUSER                  TYPE        SMI_SOCIALUSER
* | [<---] ES_SOCIALUSERINFO              TYPE        SOCIALUSERINFO
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_social_user_info.
    SELECT SINGLE * INTO es_socialuserinfo
                     FROM socialuserinfo  WHERE socialmediachannel = iv_socialmediachannel AND socialuser = iv_socialuser.
  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_SQL_STATEMENT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FIELD_NAME                  TYPE        STRING
* | [--->] IV_FIELD_VALUE                 TYPE        ANY
* | [<-()] RV_STATEMENT                   TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_sql_statement.
    DATA: lv_temp_str TYPE string.

    CHECK iv_field_value IS NOT INITIAL.

    lv_temp_str =  iv_field_value.
    " TODO: it does not make sense for some field to support * like UUID
    " Currently we do not check such case since those fields cannot be consumed
    " directly by end user in UI
    IF lv_temp_str CS '*'.
      REPLACE ALL OCCURRENCES OF '*' IN lv_temp_str WITH '%'.
      CONCATENATE ` AND ` iv_field_name ` LIKE '` lv_temp_str `'`  INTO rv_statement.
    ELSE.
      CONCATENATE ` AND ` iv_field_name ` = '` lv_temp_str `'` INTO rv_statement.
    ENDIF.
  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_SQL_STATEMENT_FOR_DATE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FROM                        TYPE        CRMT_AUI_FROM
* | [--->] IV_TO                          TYPE        CRMT_AUI_TO
* | [<-()] RV_STATEMENT                   TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method GET_SQL_STATEMENT_FOR_DATE.
    data: lv_from type CRMT_SOC_DATA_CREATED,
          lv_to   type CRMT_SOC_DATA_CREATED.

    IF iv_from IS INITIAL AND iv_to IS INITIAL.
       RETURN.
    ELSEIF iv_from IS INITIAL AND iv_to IS NOT INITIAL.
       CONCATENATE ` AND CREATION_DATE_TIME BETWEEN ` `'19700101000000' AND '` iv_to `235959'`
          INTO rv_statement.
    ELSEIF iv_from IS NOT INITIAL AND iv_to IS INITIAL.
       CONCATENATE ` AND CREATION_DATE_TIME BETWEEN '` iv_from `000000' AND '99991231235959'`
          INTO rv_statement.
    ELSE.
       CONCATENATE ` AND CREATION_DATE_TIME BETWEEN '` iv_from `000000' AND '` iv_to `235959'`
          INTO rv_statement.
    ENDIF.

  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>GET_SQL_STATEMENT_FOR_STATUS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_STATUS                      TYPE        STRING_TABLE
* | [<-()] RV_STATEMENT                   TYPE        STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD GET_SQL_STATEMENT_FOR_STATUS.
    DATA: lv_temp_str TYPE string,
          lv_line TYPE i.

    CHECK it_status IS NOT INITIAL.
    lv_line = lines( it_status ).

    IF lv_line = 1.
      READ TABLE it_status INTO lv_temp_str INDEX 1.
      CONCATENATE ` AND STATUS = '` lv_temp_str `'` INTO rv_statement.
    ELSE.
      LOOP AT it_status INTO lv_temp_str.
         IF sy-tabix = 1.
           CONCATENATE ` AND ( STATUS = '` lv_temp_str `'` INTO rv_statement.
         ELSE.
           CONCATENATE rv_statement ` OR STATUS = '` lv_temp_str `' )` INTO rv_statement.
         ENDIF.
      ENDLOOP.
    ENDIF.
  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Private Method CL_SOC_UTIL=>IS_HEXDECIMAL
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_STRING                      TYPE        CHAR4
* | [<-()] IS_HEXDECIMAL                  TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method IS_HEXDECIMAL.
     CONSTANTS: mask TYPE string VALUE '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.

     IF iv_string CO mask.
        is_hexdecimal = abap_true.
     ENDIF.
  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Private Method CL_SOC_UTIL=>IS_VALID_UNICODE_FLAG
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FLAG                        TYPE        CRMT_SOC_UNICODE_FLAG
* | [<-()] RV_VALID                       TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method IS_VALID_UNICODE_FLAG.
     READ TABLE st_control_flags WITH KEY table_line = iv_flag TRANSPORTING NO FIELDS.
     IF sy-subrc = 0.
        rv_valid = abap_true.
     ENDIF.

  endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>READ_POST_ATTRIBUTES
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_POST_UUID                   TYPE        TT_POST_UUID
* | [<---] ET_POST_ATTRIBUTES             TYPE        TT_POST_ATTRIBUTES
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD read_post_attributes.

* Select all the attributes of post from DB.
     SELECT * INTO CORRESPONDING FIELDS OF TABLE et_post_attributes FROM crmd_soc_post
        FOR ALL ENTRIES IN it_post_uuid  WHERE uuid = it_post_uuid-table_line.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>REMOVE_POST_DEPENDENT_LINKS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_OBJ_GUID                    TYPE        CRMT_GENIL_OBJECT_GUID
* | [<---] EV_DEP_OBJ_REMOVED             TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD remove_post_dependent_links.

    DATA:  lt_bor       TYPE        crmt_ic_irec_links,
           lv_objtype   TYPE        swo_objtyp,
           lv_objkey    TYPE        swo_typeid,
           ls_root      TYPE        borident,
           lv_inst      TYPE        crmt_genil_obj_instance.

    DATA: ls_obj   TYPE borident,
          ls_irec    TYPE borident,
          BEGIN OF ls_sofm_key,
             folder_id TYPE soodk,
             object_id TYPE soodk,
          END OF ls_sofm_key.


    FIELD-SYMBOLS: <bor>   TYPE relgraphlk.
    INCLUDE: crm_object_types_con.

    ls_root-objkey = iv_obj_guid.
    ls_root-objtype = 'CRMSOCPOST'.

* Get the Relations (Interaction Records)
    CALL FUNCTION 'SREL_GET_NEXT_RELATIONS'
      EXPORTING
        object         = ls_root
        max_hops       = 1
      TABLES
        links          = lt_bor
      EXCEPTIONS
        internal_error = 1
        no_logsys      = 2
        OTHERS         = 3.
    IF sy-subrc <> 0.
*  To Do
    ENDIF.

* try to delete
    ev_dep_obj_removed = ''.
    LOOP AT lt_bor ASSIGNING <bor>.
      IF <bor>-objkey_b = iv_obj_guid.

        ls_obj-objtype = ls_root-objtype.
        ls_obj-objkey  = ls_root-objkey.

        ls_irec-objtype = <bor>-objtype_a.
        ls_irec-objkey  = <bor>-objkey_a.


        CALL FUNCTION 'BINARY_RELATION_DELETE'
          EXPORTING
            obj_rolea          = ls_irec
            obj_roleb          = ls_obj
            relationtype       = gc_rel_into
            fire_events        = space
          EXCEPTIONS
            entry_not_existing = 1
            internal_error     = 2
            no_relation        = 3
            no_role            = 4
            OTHERS             = 5.

        IF sy-subrc <> 0.
          ev_dep_obj_removed  = ''.
        ELSE.
          ev_dep_obj_removed  = 'X'.
        ENDIF.

* delete new link also
*        IF ls_obj-objtype = 'SOFM'.
*          ls_sofm_key = ls_obj-objkey.
*          CALL FUNCTION 'CRM_IC_EMAIL_LINK' DESTINATION 'NONE'
*            EXPORTING
*              is_bo      = ls_irec
*              is_bci_key = ls_sofm_key-object_id
*              iv_delete  = 'X'.
*        ENDIF.
*         ev_dep_obj_removed  = 'X'.

      ENDIF.
    ENDLOOP.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method CL_SOC_UTIL=>RESERVE_CURRENT_POST
* +-------------------------------------------------------------------------------------------------+
* | [--->] IO_BOL_ENTITY                  TYPE REF TO CL_CRM_BOL_ENTITY
* | [<---] EV_PROCESSOR                   TYPE        XUBNAME
* | [<---] EV_MESSAGE                     TYPE        CRMST_AUI_MESSAGE
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD reserve_current_post.
    DATA:
        lv_bp                 TYPE bu_partner,
        lv_locked             TYPE abap_bool,
        lo_core               TYPE REF TO cl_crm_bol_core,
        lr_ic_bol_tx_handler  TYPE REF TO cl_crm_ic_bol_tx_handler,
        lr_current_uiu_entity TYPE REF TO cl_crm_bol_entity,
        lv_processor          TYPE xubname,
        lr_init_bol_entity    TYPE REF TO cl_crm_bol_entity.

* Check if this user has been asigned to a BP, if no, skip process.
    TRY.
        lv_bp = cl_crm_aui_service=>get_bp_from_username( ).
      CATCH: cx_root.
*     error message - No bo for user found
        ev_message-msg_type       = if_genil_message_container=>mt_error.
        ev_message-msg_id         = 'CRM_IC_AUI'.
        ev_message-msg_number     = '025'.
        ev_message-important_info = abap_true.
        RETURN.
    ENDTRY.

    lo_core = cl_crm_bol_core=>get_instance( ).
    lr_ic_bol_tx_handler = cl_crm_ic_bol_tx_handler=>get_instance( ).
* Remember current uiu entity to restore it at the end
    lr_current_uiu_entity = lr_ic_bol_tx_handler->get_current_uiu_entity( ).

    IF lr_current_uiu_entity IS BOUND.
*   clear current uiu entity set in mr_current_uiu_entity
      CLEAR: lr_init_bol_entity.
      lr_ic_bol_tx_handler->set_current_uiu_entity( ir_entity = lr_init_bol_entity ).
    ENDIF.

*Try to lock current entity
    lv_locked = io_bol_entity->lock( ).
    IF lv_locked = abap_true.
      TRY.
          io_bol_entity->set_property( iv_attr_name = c_employee_field_name iv_value = sy-uname ).
          ev_processor = sy-uname.
          lo_core->modify( ).
        CATCH: cx_sy_ref_is_initial.
*     Error message - can't accept
          ev_message-msg_type       = if_genil_message_container=>mt_error.
          ev_message-msg_id         = 'CRM_IC_AUI'.
          ev_message-msg_number     = '036'.
          RETURN.
      ENDTRY.
    ELSE.
      ev_message-msg_type       = if_genil_message_container=>mt_error.
      ev_message-msg_id         = 'CRM_IC_AUI'.
      ev_message-msg_number     = '018'.
      RETURN.
    ENDIF.

********Jerry: align with Case reserve ************
********Restore current uiu entity, 2nd part of correction done for OSS 228068 2011, Note 1571805
    IF lr_current_uiu_entity IS BOUND.
      lr_ic_bol_tx_handler->set_current_uiu_entity( ir_entity = lr_current_uiu_entity ).
    ENDIF.
********End of 2nd part of correction
  ENDMETHOD.
ENDCLASS.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

展开阅读全文

Git 实用技巧

11-24
这几年越来越多的开发团队使用了Git,掌握Git的使用已经越来越重要,已经是一个开发者必备的一项技能;但很多人在刚开始学习Git的时候会遇到很多疑问,比如之前使用过SVN的开发者想不通Git提交代码为什么需要先commit然后再去push,而不是一条命令一次性搞定; 更多的开发者对Git已经入门,不过在遇到一些代码冲突、需要恢复Git代码时候就不知所措,这个时候哪些对 Git掌握得比较好的少数人,就像团队中的神一样,在队友遇到 Git 相关的问题的时候用各种流利的操作来帮助队友于水火。 我去年刚加入新团队,发现一些同事对Git的常规操作没太大问题,但对Git的理解还是比较生疏,比如说分支和分支之间的关联关系、合并代码时候的冲突解决、提交代码前未拉取新代码导致冲突问题的处理等,我在协助处理这些问题的时候也记录各种问题的解决办法,希望整理后通过教程帮助到更多对Git操作进阶的开发者。 本期教程学习方法分为“掌握基础——稳步进阶——熟悉协作”三个层次。从掌握基础的 Git的推送和拉取开始,以案例进行演示,分析每一个步骤的操作方式和原理,从理解Git 工具的操作到学会代码存储结构、演示不同场景下Git遇到问题的不同处理方案。循序渐进让同学们掌握Git工具在团队协作中的整体协作流程。 在教程中会通过大量案例进行分析,案例会模拟在工作中遇到的问题,从最基础的代码提交和拉取、代码冲突解决、代码仓库的数据维护、Git服务端搭建等。为了让同学们容易理解,对Git简单易懂,文章中详细记录了详细的操作步骤,提供大量演示截图和解析。在教程的最后部分,会从提升团队整体效率的角度对Git工具进行讲解,包括规范操作、Gitlab的搭建、钩子事件的应用等。 为了让同学们可以利用碎片化时间来灵活学习,在教程文章中大程度降低了上下文的依赖,让大家可以在工作之余进行学习与实战,并同时掌握面涉及的Git不常见操作的相关知识,理解Git工具在工作遇到的问题解决思路和方法,相信一定会对大家的前端技能进阶大有帮助。
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值