天天看點

檢視指定 SAP CRM One Order 的 note 資料

源代碼:

REPORT znote_browse_tool.

PARAMETERS: id   TYPE crmd_orderadm_h-object_id OBLIGATORY DEFAULT '25949',
            type TYPE crmd_orderadm_h-process_type OBLIGATORY DEFAULT 'CX01'.

TYPES: text_line(cl_crm_odata_oppt_constant=>gc_oppt_notes_textlength)  TYPE c.
TYPES: BEGIN OF ty_text_detail,
         tdid    TYPE stxh-tdid,
         "tdobject type stxh-tdobject, "CRM_ORDERH
         tdname TYPE stxh-tdname,
         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 ).           

複制

使用方法:

指定任務 id 和任務類型:

檢視指定 SAP CRM One Order 的 note 資料

輸出結果:

檢視指定 SAP CRM One Order 的 note 資料