One order text browser tool

Created by Jerry Wang on Dec 24, 2014

执行report:
One order text browser tool_第1张图片
该report以XML的方式输出该one order instance拥有的所有text:
One order text browser tool_第2张图片
上图的A002和Note对应SPRO里的如下customizing:
One order text browser tool_第3张图片
source code:

REPORT tool_text_browse_one_order.
 
PARAMETERS: id   TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '1656',
 
            type TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'ASOP'.
 
 
TYPES: text_line(cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength)  TYPE c.
 
TYPES: BEGIN OF ty_text_detail,
 
         tdid    TYPE stxh-tdid,
 
         tdspras TYPE stxh-tdspras,
 
         tdfuser TYPE stxh-tdfuser,
 
         tdfdate TYPE stxh-tdfdate,
 
         tdftime TYPE stxh-tdftime,
 
         tdluser TYPE stxh-tdluser,
 
         tdldate TYPE stxh-tdldate,
 
         tdltime TYPE stxh-tdltime,
 
         tdtext  TYPE ttxit-tdtext,
 
         content TYPE string,
 
       END OF ty_text_detail.
 
DATA: lv_char32   TYPE char32, " CRMD_ORDERADM_H-guid,
 
      lv_textname TYPE string,
 
      lv_id       LIKE id,
 
      lv_guid     TYPE crmd_orderadm_h-guid,
 
      lt_stxh     TYPE STANDARD TABLE OF stxh,
 
      ls_stxh     LIKE LINE OF lt_stxh,
 
      ls_notes    TYPE crmt_odata_oppt_notes.
 
DATA: ls_thead                TYPE thead.
 
DATA: lt_text_table           TYPE TABLE OF text_line.
 
 
DATA: ls_bupa_addr            TYPE bapiaddr3.
 
DATA: ls_return               TYPE STANDARD TABLE OF bapiret2.
 
DATA: lt_lines                TYPE STANDARD TABLE OF tline.
 
DATA: et_notes TYPE crmt_odata_oppt_notest.
 
DATA: ls_text_detail TYPE ty_text_detail,
 
      lt_text_detail TYPE STANDARD TABLE OF ty_text_detail.
 
DATA: lt_text_object TYPE STANDARD TABLE OF ttxit,
 
      ls_text_object LIKE LINE OF lt_text_object,
 
      lv_xml         TYPE string.
 
 
lv_id = id.
 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 
  EXPORTING
 
    input  = lv_id
 
  IMPORTING
 
    output = lv_id.
 
 
SELECT SINGLE guid FROM crmd_orderadm_h INTO lv_guid WHERE object_id = id AND process_type = type.
 
IF sy-subrc <> 0.
 
  WRITE: / 'No opportunity found' COLOR COL_GROUP.
 
  RETURN.
 
ENDIF.
 
 
lv_char32 = lv_guid.
 
 
CONCATENATE lv_char32 '%' INTO lv_textname.
 
 
SELECT * FROM stxh INTO TABLE lt_stxh
 
                   WHERE  tdobject  EQ   'CRM_ORDERH'
 
                     AND  tdname    LIKE lv_textname.
 
 
SELECT tdid tdtext FROM ttxit INTO CORRESPONDING FIELDS OF TABLE lt_text_object
 
   WHERE tdspras = sy-langu
 
     AND tdobject  = cl_crm_odata_oppt_constant=>gc_oppt_notes_tdobject.
 
 
LOOP AT lt_stxh INTO ls_stxh.
 
  ls_notes-header_guid = lv_char32.
 
  MOVE-CORRESPONDING ls_stxh TO ls_text_detail.
 
  READ TABLE lt_text_object INTO ls_text_object WITH KEY tdid = ls_stxh-tdid.
 
  IF sy-subrc = 0.
 
    ls_text_detail-tdtext = ls_text_object-tdtext.
 
  ENDIF.
 
 
  CALL FUNCTION 'BAPI_USER_GET_DETAIL'
 
    EXPORTING
 
      username = ls_stxh-tdfuser
 
    IMPORTING
 
      address  = ls_bupa_addr
 
    TABLES
 
      return   = ls_return.
 
 
  ls_notes-creator = ls_bupa_addr-fullname.
 
 
  CONVERT DATE ls_stxh-tdfdate TIME ls_stxh-tdftime INTO TIME STAMP ls_notes-created_at TIME ZONE 'UTC'.
 
 
  CLEAR lt_lines.
 
  CALL FUNCTION 'READ_TEXT'
 
    EXPORTING
 
      id       = ls_stxh-tdid
 
      language = ls_stxh-tdspras
 
      name     = ls_stxh-tdname
 
      object   = ls_stxh-tdobject
 
    IMPORTING
 
      header   = ls_thead
 
    TABLES
 
      lines    = lt_lines
 
    EXCEPTIONS
 
      OTHERS   = 1.
 
  CHECK sy-subrc EQ 0.
 
  CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
 
    TABLES
 
      itf_text    = lt_lines
 
      text_stream = lt_text_table.
 
  CONCATENATE LINES OF lt_text_table INTO ls_notes-content RESPECTING BLANKS.
 
  ls_text_detail-content = ls_notes-content.
 
  APPEND ls_text_detail TO lt_text_detail.
 
 
  CLEAR: ls_notes, ls_stxh, lt_lines, lt_text_table, ls_thead, ls_bupa_addr, ls_text_detail.
 
ENDLOOP.
 
 
CALL TRANSFORMATION id SOURCE data = lt_text_detail RESULT XML lv_xml.
 
CALL METHOD cl_demo_output=>display_xml( lv_xml ).

 

One order text change tool

Created by Jerry Wang, last modified on Jan 01, 2015

使用report 修改之前:
One order text browser tool_第4张图片

执行report,
One order text browser tool_第5张图片
report执行成功:
clipboard3
UI上check:
One order text browser tool_第6张图片
enable overwrite后再执行:

One order text browser tool_第7张图片
One order text browser tool_第8张图片

source code:

REPORT tool_text_change_one_order.
 
PARAMETERS: id   TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '1656',
 
            type TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'ASOP',
 
            tid  TYPE stxh-tdname OBLIGATORY DEFAULT '0090FA0D8DC21EE3ABCE672A80C1470C',
 
            new TYPE string OBLIGATORY DEFAULT 'new' LOWER CASE,
 
            over TYPE char1 AS CHECKBOX DEFAULT 'X'.
 
 
TYPES: text_line(cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength)  TYPE c.
 
 
DATA: lv_char32   TYPE char32, " CRMD_ORDERADM_H-guid,
 
      lv_textname TYPE string,
 
      lv_id       LIKE id,
 
      lv_guid     TYPE crmd_orderadm_h-guid,
 
      lt_stxh     TYPE STANDARD TABLE OF stxh,
 
      ls_stxh     LIKE LINE OF lt_stxh,
 
      ls_notes    TYPE crmt_odata_oppt_notes.
 
DATA: ls_thead                TYPE thead.
 
DATA: lt_text_table           TYPE TABLE OF text_line.
 
 
DATA: ls_bupa_addr            TYPE bapiaddr3.
 
DATA: ls_return               TYPE STANDARD TABLE OF bapiret2.
 
DATA: lt_lines TYPE STANDARD TABLE OF tline,
 
      ls_line  LIKE LINE OF lt_lines.
 
DATA: lt_objects_to_save          TYPE crmt_object_guid_tab.
 
DATA: lt_objects_not_saved        TYPE crmt_object_guid_tab.
 
DATA: lt_saved_objects            TYPE crmt_return_objects.
 
 
lv_id = id.
 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 
  EXPORTING
 
    input  = lv_id
 
  IMPORTING
 
    output = lv_id.
 
 
SELECT SINGLE guid FROM crmd_orderadm_h INTO lv_guid WHERE object_id = id AND process_type = type.
 
IF sy-subrc <> 0.
 
  WRITE: / 'No opportunity found' COLOR COL_GROUP.
 
  RETURN.
 
ENDIF.
 
 
lv_char32 = lv_guid.
 
 
CONCATENATE lv_char32 '%' INTO lv_textname.
 
 
SELECT * FROM stxh INTO TABLE lt_stxh
 
                   WHERE  tdobject  EQ   'CRM_ORDERH'
 
                     AND  tdname    EQ tid.
 
 
IF lines( lt_stxh ) <> 1.
 
  WRITE: / 'Cound not read given text' COLOR COL_NEGATIVE.
 
  RETURN.
 
ENDIF.
 
 
READ TABLE lt_stxh INTO ls_stxh INDEX 1.
 
 
CALL FUNCTION 'READ_TEXT'
 
  EXPORTING
 
    id       = ls_stxh-tdid
 
    language = ls_stxh-tdspras
 
    name     = ls_stxh-tdname
 
    object   = ls_stxh-tdobject
 
  IMPORTING
 
    header   = ls_thead
 
  TABLES
 
    lines    = lt_lines
 
  EXCEPTIONS
 
    OTHERS   = 1.
 
CHECK sy-subrc EQ 0.
 
CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
 
  TABLES
 
    itf_text    = lt_lines
 
    text_stream = lt_text_table.
 
CONCATENATE LINES OF lt_text_table INTO ls_notes-content RESPECTING BLANKS.
 
 
DATA: lt_text         TYPE crmt_text_comt,
 
      ls_text         LIKE LINE OF lt_text,
 
      ls_input_fields TYPE crmt_input_field,
 
      lv_logical_key  TYPE crmt_logical_key,
 
      ls_field_names  TYPE crmt_input_field_names.
 
DATA: lt_input_field_names TYPE crmt_input_field_names_tab,
 
      ls_input_field_name  LIKE LINE OF lt_input_field_names.
 
DATA: lt_input_fields             TYPE crmt_input_field_tab.
 
 
ls_text-ref_handle  = '0000000000'.
 
ls_text-ref_guid = lv_guid.
 
ls_text-ref_kind = 'A'.
 
ls_text-text_object = cl_crm_odata_oppt_constant=>gc_oppt_notes_tdobject.
 
 
MOVE-CORRESPONDING ls_stxh TO ls_text.
 
ls_text-lines = lt_lines.
 
ls_text-mode = 'B'.
 
 
ls_line-tdformat = '*'.
 
ls_line-tdline = new.
 
IF over = abap_true.
 
   CLEAR: ls_text-lines.
 
ENDIF.
 
APPEND ls_line TO ls_text-lines.
 
APPEND ls_text TO lt_text.
 
 
CLEAR ls_input_fields.
 
ls_input_fields-ref_guid = lv_guid.
 
ls_input_fields-ref_kind = 'A'.
 
ls_input_fields-objectname = 'TEXTS'.
 
CONCATENATE ls_text-tdid ls_text-tdspras INTO lv_logical_key.
 
ls_input_fields-logical_key = lv_logical_key.     " use handle or guid ?
 
CLEAR ls_input_fields-field_names.
 
ls_input_field_name-fieldname = 'LINES'.
 
APPEND ls_input_field_name TO ls_input_fields-field_names.
 
"APPEND LINES OF lt_input_field_names TO ls_input_fields-field_names.
 
 
INSERT ls_input_fields INTO TABLE lt_input_fields.
 
 
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
 
  EXPORTING
 
    it_text           = lt_text
 
  CHANGING
 
    ct_input_fields   = lt_input_fields
 
  EXCEPTIONS
 
    error_occurred    = 1
 
    document_locked   = 2
 
    no_change_allowed = 3
 
    no_authority      = 4.
 
IF sy-subrc <> 0 .
 
  WRITE: / 'text modify failed: ' COLOR COL_NEGATIVE, sy-subrc COLOR COL_TOTAL.
 
  RETURN.
 
ENDIF.
 
 
APPEND lv_guid TO lt_objects_to_save.
 
CALL FUNCTION 'CRM_ORDER_SAVE'
 
  EXPORTING
 
    it_objects_to_save   = lt_objects_to_save
 
    iv_update_task_local = abap_true
 
  IMPORTING
 
    et_saved_objects     = lt_saved_objects
 
    et_objects_not_saved = lt_objects_not_saved
 
  EXCEPTIONS
 
    document_not_saved   = 1
 
    OTHERS               = 2.
 
 
IF sy-subrc EQ 0 AND lt_saved_objects IS NOT INITIAL.
 
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 
    EXPORTING
 
      wait = abap_true.
 
  WRITE: / 'text changed successfully' COLOR COL_NEGATIVE.
 
ELSE.
 
  WRITE: / 'text changed failed' COLOR COL_POSITIVE.
 
ENDIF.
 
 
BREAK-POINT.

One order text display tool

Created by Jerry Wang, last modified on Dec 24, 2014

执行report,输入opportunity id, process type和text guid:
One order text browser tool_第9张图片

输出文本内容:
One order text browser tool_第10张图片

text guid可以通过one order text browser tool来获得:
One order text browser tool_第11张图片

source code:

REPORT znote_display_tool.
 
 
PARAMETERS: id   TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '1656',
 
            type TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'ASOP',
 
            tid TYPE stxh-tdname OBLIGATORY DEFAULT '0090FA0D8DC21EE3ABCE672A80C1470C'.
 
 
TYPES: text_line(cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength)  TYPE c.
 
 
DATA: lv_char32   TYPE char32, " CRMD_ORDERADM_H-guid,
 
      lv_textname TYPE string,
 
      lv_id       LIKE id,
 
      lv_guid     TYPE crmd_orderadm_h-guid,
 
      lt_stxh     TYPE STANDARD TABLE OF stxh,
 
      ls_stxh     LIKE LINE OF lt_stxh,
 
      ls_notes    TYPE crmt_odata_oppt_notes.
 
DATA: ls_thead                TYPE thead.
 
DATA: lt_text_table           TYPE TABLE OF text_line.
 
 
DATA: ls_bupa_addr            TYPE bapiaddr3.
 
DATA: ls_return               TYPE STANDARD TABLE OF bapiret2.
 
DATA: lt_lines                TYPE STANDARD TABLE OF tline.
 
 
lv_id = id.
 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 
  EXPORTING
 
    input  = lv_id
 
  IMPORTING
 
    output = lv_id.
 
 
SELECT SINGLE guid FROM crmd_orderadm_h INTO lv_guid WHERE object_id = id AND process_type = type.
 
IF sy-subrc <> 0.
 
  WRITE: / 'No opportunity found' COLOR COL_GROUP.
 
  RETURN.
 
ENDIF.
 
 
lv_char32 = lv_guid.
 
 
CONCATENATE lv_char32 '%' INTO lv_textname.
 
 
SELECT * FROM stxh INTO TABLE lt_stxh
 
                   WHERE  tdobject  EQ   'CRM_ORDERH'
 
                     AND  tdname    EQ tid.
 
 
IF lines( lt_stxh ) <> 1.
 
  WRITE: / 'Cound not read given text' COLOR COL_NEGATIVE.
 
  RETURN.
 
ENDIF.
 
 
READ TABLE lt_stxh INTO ls_stxh INDEX 1.
 
 
CALL FUNCTION 'READ_TEXT'
 
  EXPORTING
 
    id       = ls_stxh-tdid
 
    language = ls_stxh-tdspras
 
    name     = ls_stxh-tdname
 
    object   = ls_stxh-tdobject
 
  IMPORTING
 
    header   = ls_thead
 
  TABLES
 
    lines    = lt_lines
 
  EXCEPTIONS
 
    OTHERS   = 1.
 
CHECK sy-subrc EQ 0.
 
CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
 
  TABLES
 
    itf_text    = lt_lines
 
    text_stream = lt_text_table.
 
CONCATENATE LINES OF lt_text_table INTO ls_notes-content RESPECTING BLANKS.
 
 
CALL METHOD cl_demo_output=>display_text( ls_notes-content ).

 

 

你可能感兴趣的:(CRM)