Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
robynhosby
Active Participant

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! :smile:   

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!

4 Comments
0 Kudos
Hello Robyn

Thank you very much for this helpful information. We have implemented the function module successfully and when executing it, get a page to enter information for P_GUID and P_TEXTTYPE import parameters. Could you please clarify as to what should be entered here and how this function module should be used to report the required information for the CHaRM textbox?

Regards

Vineeth
robynhosby
Active Participant
Hello Vineeth,

p_guid is the ChaRM guid

p_texttype is the textbox text id (e.g. CR05)

 

Cheers, Robyn
0 Kudos
Hey Robyn can you post the 'Z_COM_TEXT_READ_HIST_API’' sourcecode ?
robynhosby
Active Participant
0 Kudos
Sure. Here it is....

 

FUNCTION Z_COM_TEXT_READ_HIST_API.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IV_OBJECT) TYPE TDOBJECT
*" REFERENCE(IV_PROCEDURE) TYPE COMT_TEXT_DET_PROCEDURE
*" REFERENCE(IV_CONTROLLER) TYPE XFELD OPTIONAL
*" REFERENCE(IV_NO_AUTH_CHECK) TYPE BOOLEAN OPTIONAL
*" VALUE(P_TEXTTYPE) TYPE TDID
*" EXPORTING
*" REFERENCE(PI_TEXTDATA) TYPE COMT_TEXT_TEXTDATA_T
*" REFERENCE(ET_ERROR) TYPE COMT_TEXT_ERROR_T
*" CHANGING
*" REFERENCE(IT_TEXTCOM) TYPE COMT_TEXT_TEXTCOM_T
*"----------------------------------------------------------------------

***********************************************************************
* Created : 1/2/2015
* Usage : Based on COM_TEXT_READ_HIST_API.
* Updated to read specific text id via parameter P_TEXTTYPE.
* Removed data that does not apply to current SolMan
* release. Returning only text lines as documented in
* textbox.
***********************************************************************
FIELD-SYMBOLS:
<textcom> TYPE comt_text_textcom.
DATA:
lv_error1 TYPE xflag,
lv_error2 TYPE xflag,
lv_subrc TYPE sy-subrc,
ls_textcom TYPE comt_text_textcom,
lt_textcom1 TYPE comt_text_textcom_t,
lt_textcom2 TYPE comt_text_textcom_t,
ls_header LIKE thead,
ls_textdata TYPE comt_text_textdata,
lv_tdname TYPE com_text_tdname,
lt_xthead TYPE comt_text_textdata_t,
lv_utc TYPE timestamp,
lv_timconv(17) TYPE c,
lt_text_struc1 TYPE comt_text_cust_struc1_tab,
ls_text_struc1 TYPE comt_text_cust_struc1_rec.

* Prepare textcom_data for read_routine
SORT it_textcom BY stxh_key-tdname DESCENDING.

LOOP AT it_textcom INTO ls_textcom.
AT NEW stxh_key-tdobject.
* textobject in standard sap-script known?
PERFORM check_object
USING ls_textcom-stxh_key-tdobject
CHANGING lv_subrc.
IF lv_subrc IS INITIAL.
lv_error1 = gc_false.
ELSE.
lv_error1 = gc_true.
ENDIF.
ENDAT.

AT NEW stxh_key-tdname.
IF ls_textcom-stxh_key-tdname IS INITIAL
OR ls_textcom-stxh_key-tdname = '*'.
lv_error2 = gc_true.
ELSE.
lv_error2 = gc_false.
ENDIF.
ENDAT.

IF lv_error1 = gc_false AND lv_error2 = gc_false.
* everything o.k.
INSERT ls_textcom INTO TABLE lt_textcom1.
ELSE.
* error with textobject or the textname
IF lv_error1 = gc_true.
MESSAGE e001(com_text) WITH ls_textcom-stxh_key-tdobject
INTO gv_msgli.
ENDIF.
IF lv_error2 = gc_true.
MESSAGE e002(com_text) INTO gv_msgli.
ENDIF.
ENDIF.
ENDLOOP. "at IT_TEXTCOM

* standard CRM. Determine all the textkeys
CLEAR lt_textcom2. " = Output of SELECT_TEXT
PERFORM textkey_select_hist
USING
lt_textcom1[]
lt_textcom2[]
et_error.

CALL FUNCTION 'COM_TEXT_GET_DATA'
IMPORTING
ET_TEXTDATA = lt_xthead
EXCEPTIONS
ERROR_OCCURED = 1
OTHERS = 2.
if SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

* read customizing
CALL FUNCTION 'COM_TEXT_CUST_I_STRUC1_READ'
EXPORTING
IV_OBJECT = IV_OBJECT
IV_PROCEDURE = IV_PROCEDURE
iv_aut_unchecked = iv_no_auth_check
CHANGING
ET_STRUC1 = lt_text_struc1.

LOOP AT lt_text_struc1 INTO ls_text_struc1.
IF ls_text_struc1-changeable EQ gc_changeable-protocol OR
ls_text_struc1-changeable EQ gc_changeable-history.
ELSE.
DELETE lt_text_struc1 INDEX sy-tabix.
ENDIF.
ENDLOOP.

* Read textlines
LOOP AT lt_textcom2 ASSIGNING <textcom>.

if <textcom>-stxh_key-tdid = P_TEXTTYPE.

* only log texts and the log to be processed here.
CLEAR ls_text_struc1.
READ TABLE lt_text_struc1 INTO ls_text_struc1
WITH KEY textid = <textcom>-stxh_key-tdid.
IF NOT sy-subrc IS INITIAL.
CONTINUE.
ENDIF.
move <textcom>-stxh_key-tdname to lv_tdname.
CLEAR ls_textdata.
CLEAR ls_header.

* protocolled entries (changeable=P) have a time stamp (utc)
if not lv_tdname-utc is initial.
CALL FUNCTION 'READ_TEXT'
EXPORTING
object = <textcom>-stxh_key-tdobject
name = <textcom>-stxh_key-tdname
id = <textcom>-stxh_key-tdid
language = <textcom>-stxh_key-tdspras
IMPORTING
header = ls_header
TABLES
lines = ls_textdata-lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING ls_header TO ls_textdata-stxh.
MOVE sy-mandt TO ls_textdata-stxh-mandt.
INSERT ls_textdata INTO TABLE pi_textdata.
ELSE.
MESSAGE e003(com_text) WITH 'READ_TEXT' INTO gv_msgli.
ENDIF.

else.

* entries with no time stamp: set time stamp from stxh for sorted
* list only if history text (changable=R) also add texts which are
* stored under R (from predecessor)
read table lt_xthead into ls_textdata with key
stxh-tdobject = <textcom>-stxh_key-tdobject
stxh-tdname = <textcom>-stxh_key-tdname
stxh-tdid = <textcom>-stxh_key-tdid
stxh-tdspras = <textcom>-stxh_key-tdspras.
if sy-subrc = 0.
move ls_textdata-stxh-tdname to lv_tdname-name.
if ls_textdata-stxh-tdftime is initial.
move: sy-timlo to ls_textdata-stxh-tdftime,
sy-datlo to ls_textdata-stxh-tdfdate.
endif.
convert date ls_textdata-stxh-tdfdate
time ls_textdata-stxh-tdftime
into time stamp lv_utc
time zone sy-zonlo.
move lv_utc to lv_timconv.
shift lv_timconv by 2 places.
move: lv_timconv to lv_tdname-utc,
lv_tdname to ls_textdata-stxh-tdname.
append ls_textdata to pi_textdata.

else.

* if no R-texts in gt_xthead look what is stored in DB
CALL FUNCTION 'READ_TEXT'
EXPORTING
object = <textcom>-stxh_key-tdobject
name = <textcom>-stxh_key-tdname
id = <textcom>-stxh_key-tdid
language = <textcom>-stxh_key-tdspras
IMPORTING
header = ls_header
TABLES
lines = ls_textdata-lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING ls_header TO ls_textdata-stxh.
MOVE sy-mandt TO ls_textdata-stxh-mandt.

INSERT ls_textdata INTO TABLE pi_textdata.
"<<<<<returned data
ENDIF.
endif.
endif.
endif.

ENDLOOP.

ENDFUNCTION.
Labels in this area