Hello everyone!
Sometimes, in Solution Manager, there is a requirement to report Change Request Management (ChaRM) textbox contents.
In this post, I will provide the code to do just that. Enjoy!
Create a function module with the following code:
FUNCTION Z_SM_READ_CHARM_TEXTBOX .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(P_GUID) TYPE CRMT_OBJECT_GUID
*" VALUE(P_TEXTTYPE) TYPE TDID
*" EXPORTING
*" REFERENCE(PT_TEXTS) TYPE STRING
*"----------------------------------------------------------------------
data: ls_orderadm_h_wrk TYPE LINE OF crmt_orderadm_h_wrkt,
ls_PROCEDURE TYPE COMT_TEXT_DET_PROCEDURE,
ls_PROC_TYPE TYPE CRMC_PROC_TYPE,
lt_struc_p TYPE comt_text_cust_struc2_tab,
lt_struc_r TYPE comt_text_cust_struc2_tab,
ls_struc_p LIKE LINE OF lt_struc_p,
lt_struc2_r TYPE comt_text_cust_struc2_tab,
lt_textcom_p TYPE comt_text_textcom_t,
ls_textcom_p LIKE LINE OF lt_textcom_p,
lt_textdata TYPE comt_text_textdata_t,
lt_textdata_h LIKE lt_textdata,
Ls_TEXTDATA_H type COMT_TEXT_TEXTDATA,
ls_textdata_h_lines type TLINE,
lt_texts_all type table of TDLINE,
ls_tabix like sy-tabix.
constants:
lc_object TYPE COMT_TEXT_TEXTOBJECT value 'CRM_ORDERH',
lc_OBJECT_KIND(1) value 'A',
lc_no_auth_check(1) value 'X'.
* 1) Read CR's info
CALL FUNCTION 'CRM_ORDERADM_H_READ_OW'
EXPORTING
IV_ORDERADM_H_GUID = p_guid
IMPORTING
ES_ORDERADM_H_WRK = ls_orderadm_h_wrk
EXCEPTIONS
item_not_found = 98
OTHERS = 99.
* 2) Read text procedure
CALL FUNCTION 'CRM_ORDER_PROC_TYPE_SELECT_CB'
EXPORTING
iv_process_type = ls_orderadm_h_wrk-process_type
IMPORTING
es_proc_type = ls_proc_type
EXCEPTIONS
entry_not_found = 1
text_entry_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ls_procedure = ls_proc_type-text_procedure.
CALL FUNCTION 'COM_TEXT_CUST_I_PROTEXTID_READ'
EXPORTING
iv_object = lc_object "CRM_ORDERH
iv_procedure = ls_procedure "ZMCR0001
IMPORTING
et_struc2_r = lt_struc2_r
CHANGING
et_struc2 = lt_struc_p
EXCEPTIONS
textobject_missing = 1
textobject_not_found = 2
textprocedure_missing = 3
textprocedure_not_found = 4
other_error = 5
OTHERS = 6.
IF NOT lt_struc_p IS INITIAL.
MOVE lc_object TO ls_textcom_p-stxh_key-tdobject.
MOVE p_guid TO ls_textcom_p-stxh_key-tdname.
LOOP AT lt_struc_p INTO ls_struc_p.
MOVE ls_struc_p-textid TO ls_textcom_p-stxh_key-tdid.
APPEND ls_textcom_p TO lt_textcom_p.
ENDLOOP.
* 3) Read text lines
CALL FUNCTION 'Z_COM_TEXT_READ_HIST_API'
EXPORTING
iv_object = lc_object "CRM_ORDERH
iv_procedure = ls_procedure "ZMCR0001
iv_no_auth_check = lc_no_auth_check
p_texttype = p_texttype
IMPORTING
PI_TEXTDATA = lt_textdata_h
CHANGING
it_textcom = lt_textcom_p.
ENDIF.
* 4) Format text line into one line
sort LT_TEXTDATA_H by stxh."by guid and date/time stamp
loop at LT_TEXTDATA_H into Ls_TEXTDATA_H.
loop at ls_textdata_h-lines into ls_textdata_h_lines.
concatenate pt_texts ls_textdata_h_lines-TDLINE into pt_texts
separated by space.
endloop.
endloop.
shift pt_texts left deleting leading space.
ENDFUNCTION.
If function module 'Z_COM_TEXT_READ_HIST_API', it is a modified version of COM_TEXT_READ_HIST_API. I updated it to read specific text id via parameter P_TEXTTYPE, removed data that was not relevant, and returned only text lines as documented in
Cheers!