Skip to Content

Hello everyone! In this post, I hope to add some clarity and demystify how to create custom mail forms for ChaRM. There are a few posts on the topic, however I was not able to find all of the information that I needed in one place. With this post, I hope to make it easier for you to use Mail Forms.

In this scenario, we are generating mails forms in ChaRM for transaction types, ZMCR and in the Change Documents.

This post contains the following sections:

1. Creating custom fields to appear in the mail form

2. Maintain Attribute Contents for Mail Forms

3. Create a BADI to populate the fields

4. Create a Mail Forms containing standard and custom fields.

5. To maintain the HTML in the Mail Form directly

6. Add special fields to the form like….

     a) Insert a Company Logo

     b) Insert a hyperlink the the ChaRM

     c) Text Element Conditions

7. Test your changes

8. Update the Action and Conditions.

So here we go.  All screen shots are from 7.1 SP13.

Step 1) Creating custom fields to appear in the mail form

Create a custom structure containing the fields needed in your mail form. For example, this one contains business partners, textbox contents, and other fields.

/wp-content/uploads/2015/05/1_698623.jpg

Step 2) Maintain Attribute Contents for Mail Forms*

SPRO -> Customer Relationship Management -> Marketing -> Marketing Planning and Champaign Management -> Personalized
Mail -> Maintain Attribute Contexts for Mail Forms,

Create an attribute that will reference the new structure with “With no Marketing Attributes” and type = Not Relevant.

/wp-content/uploads/2015/05/2_698651.jpg

Select the new Attribute and assign the new structure selecting All Fields…

/wp-content/uploads/2015/05/2_5_698652.jpg

When you view the fields assigned, all of the fields in the structure should be displayed.

Note: I did encounter an issue when I was adding additional fields to the structure after it was in use. They did not always appear immediately in this list. This was because table CRMC_IM_FIELDS maintained via the view was not being updated on save. This took some trial and error. I needed to delete the attribute and re-add it and reactivate the table. It finally worked, but you may need patience. Another time when I updated the structure, the changes were immediately shown. Weird.

Step 3) Create a BADI to populate the fields

SPRO -> Customer Relationship Management -> Marketing -> Marketing Planning and Champaign Management -> Campaign Execution -> Badi: Maintain Additional Attributes for Mail Form Attribute Contents

This will create a BADI for definition CRM_IM_ADD_DATA_BADI. Assign the filter value to the name of the Attribute created in Step 2. Assign no type to the filter.

/wp-content/uploads/2015/05/4_698657.jpg

Here were the Attributes needed in the Class..

/wp-content/uploads/2015/05/4_1_698658.jpg

Here are the Types needed….

/wp-content/uploads/2015/05/4_2_698659.jpg

In method IF_EX_CRM_IM_ADD_DATA_BADI~CRM_IM_BPSELE, add the logic to populate the fields in the structure.

Being general, here is some high level logic. I trimmed out a lot of the logic for brevity, just so you would get the idea. But, if you have specific questions about how I populated by specific fields on my form, let me know and I’ll share more.

DATA:     lv_tabname           TYPE tabname,

lv_fieldname         tYPE fieldname,
ls_index             type SYTABIX,
ls_TJ30T             type tj30t,
ls_ct_att_value_temp type line of CRMT_IM_NAME_VALUE_TAB,
ls_ext_reference     type CRMT_PO_NUMBER_UC,
….

data: lt_tsocm_cr_context type table of tsocm_cr_context,
ls_tsocm_cr_context type tsocm_cr_context.

FIELD SYMBOLS:<fs_table_buffer>   TYPE ty_tables,               
<fs_att_value>      TYPE crmt_im_name_value,
<fs_table>          TYPE table,           
<fs_field>          TYPE any,
<fs_value>          TYPE any.

CONSTANTS:  
                 lc_CR_number        type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER’,
                 lc_textid_longdesc  type TDID value ‘CR01’,
…..

* 1) filter check
  If flt_val-SCENARIO ne lc_filtername.
    exit.
  endif.

* 2) ChaRM header data
  clear: ls_CRMD_ORDERADM_H.
  read table ct_att_values into ls_ct_att_value_temp with key name = lc_CR_number.
  if sy-subrc = 0.
    ls_cr = ls_ct_att_value_temp-value.
  endif.

* 2b) Read CR/CD record
  select single * from CRMD_ORDERADM_H into ls_CRMD_ORDERADM_H where object_id = ls_cr.

* 2c) Read context
  case ls_CRMD_ORDERADM_H-PROCESS_TYPE.
    when lc_CR. “RfC
* 2d) CR scope data
      SELECT * FROM tsocm_cr_context INTO TABLE lt_tsocm_cr_context
               WHERE guid = ls_CRMD_ORDERADM_H-guid.

    when others. “CDs
* 2e) CD scope data
      SELECT * FROM tsocm_cr_context INTO TABLE lt_tsocm_cr_context
               WHERE created_guid = ls_CRMD_ORDERADM_H-guid.  “for CD guid
  endcase.

* 3) For all variables passed
  LOOP AT ct_att_values ASSIGNING <fs_att_value>.
    ls_index = sy-tabix.

* 3a) See if the field name is already passed to badi
    SPLIT <fs_att_value>-name AT ‘-‘ INTO lv_tabname lv_fieldname.
    READ TABLE mt_tables WITH KEY table_name = lv_tabname ASSIGNING <fs_table_buffer>.

    IF sy-subrc = 0.
      ASSIGN <fs_table_buffer>-table_content->* TO <fs_table>.

      READ TABLE <fs_table> WITH KEY (lc_product_guid) = is_bp_act-obj_guid ASSIGNING <fs_field>.
      IF sy-subrc <> 0.
        CONTINUE.
      ENDIF.

      ASSIGN COMPONENT lv_fieldname OF STRUCTURE <fs_field> TO <fs_value>.
      IF sy-subrc = 0.
        <fs_att_value>-value = <fs_value>.
      ELSE.
        CONTINUE.
      ENDIF.
    else.

* 4) If field is not already passed, read table to populate
      CASE lv_fieldname.
        when ‘EXT_REFERENCE’. “external refencence
          SELECT single po_number_uc FROM crmd_order_index INTO ls_ext_reference
                                     WHERE header = ls_CRMD_ORDERADM_H-guid.
          if ls_ext_reference is not initial.
            <fs_att_value>-value = ls_ext_reference.
            MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.
          endif.

        when ‘PROJECT_ID’. “Project assigned to CR. There’s only one per CR
          LOOP AT lt_tsocm_cr_context INTO ls_tsocm_cr_context where PROJECT_ID is not initial.
            <fs_att_value>-VALUE = ls_tsocm_cr_context-project_id.
            exit.
          ENDLOOP.
          MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.
        when ‘TEXT_LONG_DESC’.           “Text box – long description
          clear ls_text_value.
          CALL FUNCTION ‘Z_SM_READ_CHARM_TEXTBOX’
            EXPORTING P_GUID     = ls_CRMD_ORDERADM_H-guid
      P_TEXTTYPE = lc_textid_longdesc
            IMPORTING PT_TEXTS   = ls_text_value.

          <fs_att_value>-VALUE = ls_text_value.
          MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.
      endcase.
    ENDIF.
  ENDLOOP.
endmethod.

Step 4)  Create the Mail Forms.
Tcode SM_CRM -> business role ZSOLMANPRO -> Service Operations. Create -> Mail Form (under section Search).

/wp-content/uploads/2015/05/5_698660.jpg

Select to create a new Mail Form and update the header fields…

/wp-content/uploads/2015/05/5_3_698661.jpg

The field Attribute Context will control the fields that are available for selection.  In my form, fields from standard attributes and from the custom attributes are needed.
To get some of the standard fields, I set the Attribute Context to Service Request Attributes.

/wp-content/uploads/2015/05/5_5_698662.jpg

Select Add Attributes.

/wp-content/uploads/2015/05/6_698663.jpg

Select the field needed and Insert…

/wp-content/uploads/2015/05/6_1_698664.jpg

Then, to add the custom fields, update the the Attribute Context to the new custom attibute that was added in Step 2….

/wp-content/uploads/2015/05/6_2_698665.jpg

Select the Add Attribute button again and change the Attribute Category to Additional Fields to see the custom fields. 
/wp-content/uploads/2015/05/7_698666.jpg

Select the field and insert.

As you add fields, the form will be displayed in WYSIWYG (what you see is what you get) format …
/wp-content/uploads/2015/05/8_698668.jpg

Step 5) To maintain the HTML
You may want to maintain the HTML directly, for example to format the fields into table columns so the labels and values up nicely.  To do that, select DESIGN <->SOURCE to toggle back and forth between the HTML and WYSIWYG screens….

/wp-content/uploads/2015/05/8_5_698669.jpg

If you are not comfortable with HTML, don’t fear it here! Just start with the one generated automatically by the WYSIWYG setup. 

To keep the sections easier to read, I inserted documentation lines like this… <!– ROW STATUS –>

If you want to format the fields into table columns, here some logic to get you started. 
1) <table class=”Data3″> indicates the name of the table, so you can have several tables in your form, if you want. This small part of my html has three tables.
2) <tr> and </tr> indicate the start and end to a table row. 
3) <td and </td> indicate the start and end to a table column.

This small part of the html will show the ChaRM status, the ChaRM document number, and the Multi Level categorization assigned….

<table class=”Data3″>
<tbody>
<tr>
<td class=”Data3″><font color=”black” size=”2″><strong><font face=”Arial”>Status</font></strong></font></td>
<td class=”Data3″><span style=’font-family: “Arial”,sans-serif;’><strong><font size=”2″>                 </font></strong></span> <font color=”red” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_STATUS” value=”Status”></span></font></td>
</tr>
</tbody>
</table>
<!– CHARM DETAILS –>
<h2><font size=”3″><u>ChaRM Detail</u></font></h2>
<font face=”Arial”><!– ROW3–></font>
<table class=”Data”>
<tbody><!– CHARM NO –>
<tr>
<td class=”Data”><font color=”black” size=”2″><strong><font face=”Arial”>ChaRM ID</font></strong></font></td>
<td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER” value=”Service Request ID”></span></font></td>
</tr>
</tbody>
</table>
<!– CATEGORIES –>
<table class=”DataCat”>
<tbody>
<tr>
<td class=”DataCat”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Categorization     </strong></span></font></td>
<td class=”DataCat”><span style=’font-family: “Arial”,sans-serif;’><font color=”black” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT1″ value=”Subject Category 1″> /</font></span> <span style=’font-family: “Arial”,sans-serif;’><font color=”red” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT2″ value=”Subject Category 2″> <font color=”#000000″>/</font></font></span> <span style=’font-family: “Arial”,sans-serif;’><font color=”black” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT3″ value=”Subject Category 3″></font></span></td>
</tr>
</tbody>
</table>

Play around with the html.  It’s not as difficult as it looks.   Also, if you miss an end indicator, for example, the tool will try to fix the html automatically. Toggle back and forth between the WYSIWYG and HTML to see your changes and the auto changes.

Step 6) Add special fields to the form….
a) Insert a Company Logo.
Select Insert Picture and browse for the JPG of the logo to insert…
/wp-content/uploads/2015/05/9_698670.jpg

b) Insert a hyperlink the the ChaRM
/wp-content/uploads/2015/05/9_06_698672.jpg

c) Create a new Text Element to be display in Production
I have a hyperlink to open the ChaRM document in my mail form. Since the hyperlink for the Development and Production systems will differ, you’ll want to control which is displayed. There are a couple of ways to do that.  One way to create the URL hyperlink to work in SolMan production is to update, create a new Text Element and create conditions to check the source SolMan system ID.

/wp-content/uploads/2015/05/9_07_698674.jpg

Cut and paste the HTML from the original Text Element into the new Text Element.
/wp-content/uploads/2015/05/9_08_698675.jpg
Return to the WYSIWYG format and remove the original hyperlink that was copied…

/wp-content/uploads/2015/05/9_11_698676.jpg

Create a new hyperlink for the production system…

/wp-content/uploads/2015/05/9_11_698676.jpg

Update URL color if needed.

Since two Text Elements now exist, you need to add conditions to determine with each will be used.  Select EDIT STRUCTURE to create the Mail Conditions.

/wp-content/uploads/2015/05/9_13_698679.jpg

Select the Attribute Context that will be used to determine the condition. In my scenario, I have a custom attribute that was created for the SolMan system id and populated in my BADI.  Select the original Text Element and INSERT….
/wp-content/uploads/2015/05/9_14_698680.jpg

Select to assign the attribute …
/wp-content/uploads/2015/05/9_15_698681.jpg

,

Select the field and INSERT…

/wp-content/uploads/2015/05/9_16_698682.jpg
Enter the System ID for the SolMan development system.  You can add additional conditions if needed.

/wp-content/uploads/2015/05/9_17_698683.jpg

Select the other Text Element (e.g for production) and enter those conditions as needed….

/wp-content/uploads/2015/05/9_18_698684.jpg

When finished, select BACK…

/wp-content/uploads/2015/05/9_19_698685.jpg

Step 7) Test Changes after updating the HTML

On the WYSIWYG screen, select TEST SEND & PREVIEW (at the top) and select SAVE.
Select PREVIEW.

Step 8) Maintain the Actions / Conditions

Locate the email action for the form. Verify the method assigned is SEND_MAIL_WITH_MAIL_FORMS.

Set the method parameter “Mail template name” to match Mail Form created in the UI (Note that it is case sensitive).

Update the conditions to generate the form when needed.

Here is the resulting email in Outlook. (I did remove the logo and adjusted format a bit manually so it would fit in the screen shot better, but you get the idea. 🙂

/wp-content/uploads/2015/05/9_21_698686.jpg

Thank you for reading this long post! There was a lot to cover.   I think I covered everything.  If you find that I missed a part or something should have more detail, let me know and I’ll update the post.  

Have a great day!!!

To report this post you need to login first.

39 Comments

You must be Logged on to comment or reply to a post.

    1. Robyn Osby Post author

      Hi Tirrie,

      In the protect section of the Z class, here is the code…

      protected section.

      *”* protected components of class ZCL_IM_CHARM_MAIL_1

      *”* do not include other source files here!!!


        types:

          BEGIN OF ty_tables,

                 table_name    TYPE        tabname,

                 table_content TYPE REF TO data,

               END OF ty_tables .

        types:     ty_tables_tab TYPE STANDARD TABLE OF ty_tables .

        data MT_TABLES type TY_TABLES_TAB .

      (0) 
    2. Robyn Osby Post author

      Hi Tirrie,

      In response to your email, here is the BADI’s declaration section in full.  It contains more fields than I included in my BADI code above, since I moved some of the code in the BADI for brevity. Perhaps this will give you some ideas on what can be done in your mail form…

      DATA:         lv_tabname           TYPE tabname,
                      lv_fieldname         tYPE fieldname,
                      ls_index             type SYTABIX,
                      ls_TJ30T             type tj30t,
                      ls_ct_att_value_temp type line of CRMT_IM_NAME_VALUE_TAB,

                      ls_PO_STATUS_PROFILE TYPE  CRM_J_STSMA,
                      ls_PO_STATUS         TYPE  CRM_J_STATUS,
                      ls_PO_STATUS_TEXT    TYPE  J_TXT30,

                      ls_CRMD_ORDERADM_H   type CRMD_ORDERADM_H,
                      ls_CRMD_ACTIVITY_H   type CRMD_ACTIVITY_H,
                      ls_SCPRIOT           type SCPRIOT,

                      ls_cr                type CRMD_ORDERADM_H-object_id, “CR#
                      ls_ext_reference     type CRMT_PO_NUMBER_UC,

                      lt_cr_dates          type CRMT_DATE_WRKT, “Dates assigned to CR
                      LS_cr_dates          TYPE LINE OF CRMT_DATE_WRKT,
                      ls_text_value        type string,

                      lt_sid   type table of ZSYSTEMID20,   “all sids on CR
                      ls_sid   like line of lt_sid,
                      lt_ibase type table of ZIBINSTANCE20, “all ibases assigned to CR
                      ls_ibase like line of lt_ibase,
                      lt_type_cd type table of ZPROCTYPE_cd, “trans types for all assigned CDs
                      ls_type_cd like line of lt_ibase,

                      ls_PARTNER_NO         TYPE  CRMT_PARTNER_NO,
                      ls_PARTNER_NAME_FIRST TYPE  BU_NAMEP_F,
                      ls_PARTNER_NAME_LAST  TYPE  BU_NAMEP_L,

                      lt_partner_detail TYPE  ZCHARM_PARTNER_DETAIL_FOR_FCT,
                      ls_partner_detail TYPE  ZCHARM_PARTNER_DETAIL,

                      l_temp_c(10).

        data: begin of ls_crmt_detail,
                guid         type CRMT_OBJECT_GUID,
                object_id    type CRMT_OBJECT_ID_DB,
                process_type type CRMT_PROCESS_TYPE_DB,
              end of ls_crmt_detail.

        data: lt_tsocm_cr_context type table of tsocm_cr_context,
              ls_tsocm_cr_context type tsocm_cr_context.

        FIELD-SYMBOLS: <fs_table_buffer>   TYPE ty_tables,
                       <fs_att_value>      TYPE crmt_im_name_value,
                       <fs_table>          TYPE table,
                       <fs_field>          TYPE any,
                       <fs_value>          TYPE any.

        CONSTANTS:     lc_product_guid     TYPE string VALUE ‘PRODUCT_GUID’,

                       lc_filtername              type CRMD_IM_DYN_ATTR_FILTER value ‘xxxxxx’,”<<< CHANGE THIS TO THE IMPLEMENTATION FILTER VALUE

                       lc_due_date         type CRMT_APPTYPE value ‘SRV_RREADY’,

                       lc_CR_number        type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER’,
                       lc_priority         type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_PRIORITY’,
                       lc_CR_status_text   type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_STATUS’,
                       lc_none(6)                      value ‘<none>’,

                       lc_textid_longdesc  type TDID value ‘CR01’,
                       lc_textid_reason    type TDID value ‘CR02’,
                       lc_textid_just      type TDID value ‘ZJST’,
                       lc_textid_deploymt  type TDID value ‘ZDPI’,

                       lc_CR               type CRMT_PROCESS_TYPE_DB value ‘ZMCR’,

                       lc_status_profile_zmcr type CRM_J_STSMA value ‘ZMCRHEAD’,
                       lc_status_profile_zmmj type CRM_J_STSMA value ‘ZMMJHEAD’,
                       lc_status_profile_zmhf type CRM_J_STSMA value ‘ZMHFHEAD’,
                       lc_status_profile_zmad type CRM_J_STSMA value ‘ZMADHEAD’,

                       lc_SDCR0002 type CRMT_PARTNER_FCT value ‘SDCR0002’, “Change Manager
                       lc_ZMCRCRM1 TYPE CRMT_PARTNER_FCT VALUE ‘ZMCRCRM1’, “CRM
                       lc_zmcrtdc1 type CRMT_PARTNER_FCT value ‘ZMCRTDC1’, “Solution Architect
                       lc_smcd0001 type CRMT_PARTNER_FCT value ‘SMCD0001’, “Developer
                       lc_smcd0002 type CRMT_PARTNER_FCT value ‘SMCD0002’. “Tester

      (0) 
  1. Stefan Pietsch

    Hi together,

    many thanks to Robyn for the Blog, it’s very helpful.

    I have adapted the coding of method CRM_IM_BPSELE from your example to my needs and I have copied the coding for the operations CRM_IM_BUFSELE and CRM_IM_BUFCLEAR from the standard class CL_IM_CRM_IOBJ_MAIL_ATTR.

    I have a short question to those who are experiencing with these forms:

    In step 1, its mentioned that you need to create a structure for the fields that you want to use additionally. Have you also created a database table that uses this structure?

    When I try to use the “preview” function for my mail form, an error message is thrown:

    “BSP error … The database table <my structure name> is unknown.” –> the structure I created is activated.

    Best Regards

    Stefan

    (0) 
    1. Robyn Osby Post author

      Hello Stefan,

      I am so sorry for the delayed response! I just noticed your question now! Not sure why I didn’t get the notification.

      No, I only have a structure, not a table. Did you put the structure in the IMG Maintain Attribute Contexts for Mail Forms?

      Also, I’m only using BPSELE, not BUFSELE or BUFCLEAR. Maybe your error is related to that?

      (0) 
  2. Sebastian Hockmann

    Hello.

    thanks a lot for your great work. I’m trying to adapt this for Service Desk / Incident Management and the ERMS Scenario.

    When clicking on the “Save” button of Incident PPF Action SEND_MAIL_WITH_FORMS is selected the BADI is triggered from FM AI_CRM_ERMS_MAIL_COMPOSE and variable ls_cr is filled with e.g. number ‘8000000481’.

    But when trying to select information via statement.

    select single * from crmd_orderadm_h into ls_crmd_orderadm_h where object_id = ls_cr

    I get no data ( sy-subrc = 4 ) because the db table  crmd_orderadm_h does not contain the number 8000000481 at this time. ( i suggest commit work was not called )


    Do you have an idea how to solve this issue ?

    Thanks a lot for your help !

    Sebastian

    .

    (0) 
    1. Robyn Osby Post author

      Hi Sebastian,

      Is that the first SAVE in your ChaRM flow? If so, it could be the ChaRM number was generated but the table crmd_orderadm_h is not yet updated.

      Our flow has a SAVE before the first Email is triggered. I configured an custom action before status Validation, so it would force consistancy checks to be executed and allow the user to make changes before sending the emails to the group who receives the email at status Validation. It also allows the user to SAVE and finish later, since I didn’t want the change manager group to be triggered before the user was really done.  So, I did not encounter your error in my scenario.  But a similar solution may work for you. 🙂

      (0) 
  3. Johan Bellardi

    Thank you very much for this document. I need to create a structure to be able to add the solution text box to a mail form. Any chance that you might shed a bit more detail on how you accomplished that in point 1 (creating the structure and using the badi to fill the fields for the text value with solution text type). I am sure that I can have some example I can work out the rest.

    (0) 
    1. Robyn Osby Post author

      Hi Johan,

      Create a new structure in SE11 with the solution text field, mapped to the solution text domain.  In Step 3, I show my Badi code. Your badi will be similar.  I don’t have that field on my form, so I’m not sure which table you need to read it from.  Check the BSP code for the Solution field to find out where the UI is getting it.

      (0) 
      1. Johan Bellardi

        Would you mind to share your full Badi. I get to derive values in my own badi (reading the values), but seem to be missing the link to populate the structure .

        edit:

        — I  found my own problem and I now get my custom field values now to populate

        thanks

        (0) 
        1. Robyn Osby Post author

          Hi Johan,

          Here is my entire BADI….

          method IF_EX_CRM_IM_ADD_DATA_BADI~CRM_IM_BPSELE.

          *******************************************************************************************
          * Created: 1/29/2015 Robyn Osby
          * Usage  : Populate mail form fields called in ChaRM UI. This is written for a CR only. If
          *          logic is needed for a CD, refer to specific check of ZMCR and adjust accordingly.
          *
          * Note    : When maintaining field contents, refer to both the CR and CD sections.
          *
          * Flow   :
          * 1) xyz filter check
          * 2) Read CR Data
          * 2a) ChaRM header data
          *
          * 3) For RfCs —————-
          * 4) CR scope data
          * 5) For all variables passed
          * 5a) See if the field name is already passed to badi
          * 6b) If field is not already passed, read table to populate
          * 7) Read date fields
          * 8) Assign extra CR fields
          * 9) Assign scope-related fields
          * 10) Assign textbox contents
          * 11) Partners
          *
          * 12) For CDs —————-
          * 13) CD scope data
          * 14) For all variables passed
          * 15a) See if the field name is already passed to badi
          * 15b) If field is not already passed, read table to populate
          * 16) Read date fields
          * 17) Assign extra CR fields
          * 18) Assign scope-related fields
          * 19) Assign textbox contents
          * 20) Partners
          *******************************************************************************************

            DATA:         lv_tabname           TYPE tabname,
                          lv_fieldname         tYPE fieldname,
                          ls_index             type SYTABIX,
                          ls_TJ30T             type tj30t,
                          ls_ct_att_value_temp type line of CRMT_IM_NAME_VALUE_TAB,

                          ls_PO_STATUS_PROFILE TYPE  CRM_J_STSMA,
                          ls_PO_STATUS         TYPE  CRM_J_STATUS,
                          ls_PO_STATUS_TEXT    TYPE  J_TXT30,

                          ls_CRMD_ORDERADM_H   type CRMD_ORDERADM_H,
                          ls_CRMD_ACTIVITY_H   type CRMD_ACTIVITY_H,
                          ls_SCPRIOT           type SCPRIOT,

                          ls_cr                type CRMD_ORDERADM_H-object_id, “CR#
                          ls_ext_reference     type CRMT_PO_NUMBER_UC,

                          lt_cr_dates          type CRMT_DATE_WRKT, “Dates assigned to CR
                          LS_cr_dates          TYPE LINE OF CRMT_DATE_WRKT,
                          ls_text_value        type string,

                          lt_sid   type table of ZSYSTEMID20,   “all sids on CR
                          ls_sid   like line of lt_sid,
                          ls_sid3(3),
                          ls_SMSY_SYSDESCR type Z_SMSY_DESCR,

                          lt_ibase type table of ZIBINSTANCE20, “all ibases assigned to CR
                          ls_ibase like line of lt_ibase,
                          lt_type_cd type table of ZPROCTYPE_cd, “trans types for all assigned CDs
                          ls_type_cd like line of lt_ibase,

                          ls_PARTNER_NO         TYPE  CRMT_PARTNER_NO,
                          ls_PARTNER_NAME_FIRST TYPE  BU_NAMEP_F,
                          ls_PARTNER_NAME_LAST  TYPE  BU_NAMEP_L,

                          lt_partner_detail TYPE  ZCHARM_PARTNER_DETAIL_FOR_FCT,
                          ls_partner_detail TYPE  ZCHARM_PARTNER_DETAIL,

                          l_temp_c(10).

            data: begin of ls_crmt_detail,
                    guid         type CRMT_OBJECT_GUID,
                    object_id    type CRMT_OBJECT_ID_DB,
                    process_type type CRMT_PROCESS_TYPE_DB,
                  end of ls_crmt_detail.

            data: lt_tsocm_cr_context type table of tsocm_cr_context,
                  ls_tsocm_cr_context type tsocm_cr_context,

                  ls_CRMC_PROC_TYPE_T type CRMC_PROC_TYPE_T,
                  lt_CRMC_PROC_TYPE_T type table of CRMC_PROC_TYPE_T.

            FIELD-SYMBOLS: <fs_table_buffer>   TYPE ty_tables,
                           <fs_att_value>      TYPE crmt_im_name_value,
                           <fs_table>          TYPE table,
                           <fs_field>          TYPE any,
                           <fs_value>          TYPE any.

            CONSTANTS:     lc_product_guid     TYPE string VALUE ‘PRODUCT_GUID’,
                           lc_xyz              type CRMD_IM_DYN_ATTR_FILTER value ‘Zxyz_CHARM’,”implementation filter value
                           lc_due_date         type CRMT_APPTYPE value ‘SRV_RREADY’,

                           lc_CR_number        type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER’,
                           lc_priority         type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_PRIORITY’,
                           lc_CR_status_text   type string value ‘CRMS_SRQM_GEN_FIELDS-CRM_SRQM_STATUS’,
                           lc_none(6)                      value ‘N/A’,

                           lc_textid_longdesc  type TDID value ‘CR01’,
                           lc_textid_reason    type TDID value ‘CR02’,
                           lc_textid_just      type TDID value ‘ZJST’,
                           lc_textid_deploymt  type TDID value ‘ZDPI’,

                           lc_CR               type CRMT_PROCESS_TYPE_DB value ‘ZMCR’,

                           lc_status_profile_zmcr type CRM_J_STSMA value ‘ZMCRHEAD’,
                           lc_status_profile_zmmj type CRM_J_STSMA value ‘ZMMJHEAD’,
                           lc_status_profile_zmhf type CRM_J_STSMA value ‘ZMHFHEAD’,
                           lc_status_profile_zmad type CRM_J_STSMA value ‘ZMADHEAD’,

                           lc_SDCR0002 type CRMT_PARTNER_FCT value ‘SDCR0002’, “Change Manager
                           lc_ZMCRCRM1 TYPE CRMT_PARTNER_FCT VALUE ‘ZMCRCRM1’, “CRM
                           lc_zmcrtdc1 type CRMT_PARTNER_FCT value ‘ZMCRTDC1’, “Solution Architect
                           lc_smcd0001 type CRMT_PARTNER_FCT value ‘SMCD0001’, “Developer
                           lc_smcd0002 type CRMT_PARTNER_FCT value ‘SMCD0002’, “Tester
                           lc_smcd0003 type CRMT_PARTNER_FCT value ‘SMCD0003’. “Operator

          *==========================================================================================
          * 1) xyz filter check
            If flt_val-SCENARIO ne lc_xyz.
              exit.
            endif.

          * 2) Read CR Data
            clear: ls_CRMD_ORDERADM_H.

          * 2a) ChaRM header data
          *   Read CR/CD number
            sort ct_att_values by name.
            read table ct_att_values into ls_ct_att_value_temp
                                     with key name = lc_CR_number
                                     binary search.
            if sy-subrc = 0.
              ls_cr = ls_ct_att_value_temp-value.
            endif.

          * 2b) Read CR/CD record
            select single * from CRMD_ORDERADM_H into ls_CRMD_ORDERADM_H
                            where object_id = ls_cr.

            select single * from CRMD_ACTIVITY_H into ls_CRMD_ACTIVITY_H
                            where guid = ls_CRMD_ORDERADM_H-guid.

            SELECT single po_number_uc FROM crmd_order_index INTO ls_ext_reference
                                       WHERE header = ls_CRMD_ORDERADM_H-guid. “ext ref #

            select * from CRMC_PROC_TYPE_T into table lt_CRMC_PROC_TYPE_T. “trans type descriptions

          * 2c) Read context
            case ls_CRMD_ORDERADM_H-PROCESS_TYPE.
              when lc_CR. “RfC
          * 2d) CR scope data
                SELECT * FROM tsocm_cr_context INTO TABLE lt_tsocm_cr_context
                         WHERE guid = ls_CRMD_ORDERADM_H-guid.

              when others. “CDs
          * 2e) CD scope data
                SELECT * FROM tsocm_cr_context INTO TABLE lt_tsocm_cr_context
                         WHERE created_guid = ls_CRMD_ORDERADM_H-guid.  “for CD guid
            endcase.

          * ============================================================================================
          * 3) For all variables passed
            LOOP AT ct_att_values ASSIGNING <fs_att_value>.
              ls_index = sy-tabix.

          * 3a) See if the field name is already passed to badi
              SPLIT <fs_att_value>-name AT ‘-‘ INTO lv_tabname lv_fieldname.
              READ TABLE mt_tables WITH KEY table_name = lv_tabname ASSIGNING <fs_table_buffer>.

              IF sy-subrc = 0.
                ASSIGN <fs_table_buffer>-table_content->* TO <fs_table>.

                READ TABLE <fs_table> WITH KEY (lc_product_guid) = is_bp_act-obj_guid ASSIGNING <fs_field>.
                IF sy-subrc <> 0.
                  CONTINUE.
                ENDIF.

                ASSIGN COMPONENT lv_fieldname OF STRUCTURE <fs_field> TO <fs_value>.
                IF sy-subrc = 0.
                  <fs_att_value>-value = <fs_value>.
                ELSE.
                  CONTINUE.
                ENDIF.
              else.

          * 4) If field is not already passed, read table to populate
                CASE lv_fieldname.

          *===========================================================================================
          * 5) Read date fields
                  WHEN ‘DATLO’. “date email generated
                    write sy-datum to l_temp_c mm/dd/yyyy.
                    <fs_att_value>-value  = l_temp_c.
                    MODIFY ct_att_values FROM <fs_att_value>
                                 INDEX ls_index
                                 TRANSPORTING value.

          *——————————————————————————————
                  WHEN ‘TIMLO’. “time email generated
                    write sy-uzeit to l_temp_c USING EDIT MASK ‘__:__:__’.
                    <fs_att_value>-value  = l_temp_c.
                    MODIFY ct_att_values FROM <fs_att_value>
                                 INDEX ls_index
                                 TRANSPORTING value.

          *——————————————————————————————
                  WHEN ‘CREATED_AT’. “CR created on
                    <fs_att_value>-value = ls_CRMD_ORDERADM_H-created_at.
                    MODIFY ct_att_values FROM <fs_att_value>
                                 INDEX ls_index
                                 TRANSPORTING value.

          *——————————————————————————————
                  WHEN ‘DUE_DATE’. “Due Date / Target Date
                    CALL FUNCTION ‘Z_SM_CHARM_DATES’
                      EXPORTING
                        PI_CHARM_ID          = ls_CRMD_ORDERADM_H-object_id
                      IMPORTING
                        PT_DATES             = lt_cr_dates
                      EXCEPTIONS
                        GUID_NOT_FOUND       = 1
                        NO_CHARM_DATES_FOUND = 2
                        ERROR_FOUND          = 3
                        OTHERS               = 4.

                    IF SY-SUBRC <> 0.
                    ENDIF.
                    read table lt_cr_dates INTO LS_cr_dates with key APPT_TYPE = lc_due_date.
                    IF SY-SUBRC = 0.
                      write LS_cr_dates-Date_from to l_temp_c mm/dd/yyyy. “DUE DATE
                      <fs_att_value>-value  = l_temp_c.
                      MODIFY ct_att_values FROM <fs_att_value>
                                   INDEX ls_index
                                   TRANSPORTING value.
                    ENDIF.

          *===============================================================================================
          * 6) Assign extra CR fields
                  WHEN ‘PROCESS_TYPE’.”transaction type
                    <fs_att_value>-value = ls_CRMD_ORDERADM_H-PROCESS_TYPE.
                    MODIFY ct_att_values FROM <fs_att_value>
                                 INDEX ls_index
                                 TRANSPORTING value.

          *——————————————————————————————
                  when ‘EXT_REFERENCE’. “external refencence
                    if ls_ext_reference is not initial.
                      <fs_att_value>-value = ls_ext_reference.
                      MODIFY ct_att_values FROM <fs_att_value>
                                   INDEX ls_index
                                   TRANSPORTING value.
                    endif.

          *——————————————————————————————
                  when ‘PRIORITY_TEXT’.
                    select single * from SCPRIOT into ls_SCPRIOT
                                    where priority = ls_CRMD_ACTIVITY_H-PRIORITY
                                      and langu = ‘E’.
                    if sy-subrc = 0.
                      <fs_att_value>-VALUE = ls_SCPRIOT-txt_long.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    endif.

          *===============================================================================================================
          * 7) Assign scope-related fields
          *     GUID <> ITEM_GUID means it’s an scope item(Change Document). Otherwise the it’s the Change Request itself.
                  when ‘IB_INSTANCE’. “Ibase component
                    LOOP AT lt_tsocm_cr_context INTO ls_tsocm_cr_context.
                      append ls_tsocm_cr_context-ibase_instance TO lt_ibase.
                    ENDLOOP.
                    sort lt_ibase.
                    delete adjacent duplicates from lt_ibase.
                    loop at lt_ibase into ls_ibase.
                      shift ls_ibase left deleting leading ‘0’.
                      if sy-tabix = 1.
                        <fs_att_value>-VALUE = ls_ibase.
                      else.
                        concatenate <fs_att_value>-VALUE ls_ibase into <fs_att_value>-VALUE separated by space.
                      endif.
                    endloop.

                    shift <fs_att_value>-VALUE left deleting leading space.
                    MODIFY ct_att_values FROM <fs_att_value>
                                        INDEX ls_index
                                        TRANSPORTING value.

          *——————————————————————————————
                  when ‘Z_SMSY_DESCR’. “SMSY SID and SID description
          *………Read SIDs assigned to RfC
                    LOOP AT lt_tsocm_cr_context INTO ls_tsocm_cr_context.
                      append ls_tsocm_cr_context-sid TO lt_sid.
                    ENDLOOP.
                    sort lt_sid.
                    delete adjacent duplicates from lt_sid.

          *………Read SID descriptions
                    loop at lt_sid into ls_sid.
                      ls_sid3 = ls_sid.
                      if ls_sid3 is not initial.
                        CALL METHOD Zxyz_CHARM=>READ_SID_DESCRIPTION
                          EXPORTING
                            SID             = ls_sid3
                          IMPORTING
                            SID_DESCRIPTION = ls_SMSY_SYSDESCR.
                        if <fs_att_value>-VALUE is initial. “1st SID found?
                          concatenate ls_sid3 ‘(‘ ls_SMSY_SYSDESCR ‘)’ into <fs_att_value>-VALUE.
                        else.
                          concatenate <fs_att_value>-VALUE ‘,’ ls_sid3 ‘(‘ ls_SMSY_SYSDESCR ‘)’ into <fs_att_value>-VALUE.
                        endif.
                      endif.
                    endloop.

                    shift <fs_att_value>-VALUE left deleting leading space.
                    MODIFY ct_att_values FROM <fs_att_value>
                                        INDEX ls_index
                                        TRANSPORTING value.

          *——————————————————————————————
                  when ‘TRANS_TYPE_DESC’. “transaction type description
                    case ls_CRMD_ORDERADM_H-PROCESS_TYPE.
                      when lc_CR. “RfC

          *         Only read CD transaction types so filter CR record
                        LOOP AT lt_tsocm_cr_context INTO ls_tsocm_cr_context where PROCESS_TYPE ne ‘ZMCR’.
                          append ls_tsocm_cr_context-PROCESS_TYPE TO lt_type_cd.
                        ENDLOOP.
                        sort lt_type_cd.
                        delete adjacent duplicates from lt_type_cd.
                        loop at lt_type_cd into ls_type_cd.
                          shift ls_type_cd left deleting leading space.
                          read table lt_CRMC_PROC_TYPE_T into ls_CRMC_PROC_TYPE_T
                                                         with key PROCESS_TYPE = ls_type_cd
                                                                  langu = ‘E’.
                          if sy-subrc = 0.
                            if <fs_att_value>-value is initial. “1st CD type found?
                              <fs_att_value>-value = ls_CRMC_PROC_TYPE_T-P_DESCRIPTION_20. “trans type desc
                            else.
                              concatenate <fs_att_value>-VALUE ‘,’ ls_CRMC_PROC_TYPE_T-P_DESCRIPTION_20 into <fs_att_value>-VALUE separated by space.
                            endif.

                          else. “shouldn’t happen but… if CD found with no desc…
                            if <fs_att_value>-value is initial. “1st CD type found?
                              <fs_att_value>-value = ls_type_cd. “trans type desc
                            else.
                              concatenate <fs_att_value>-VALUE ‘,’ ls_type_cd into <fs_att_value>-VALUE separated by space.
                            endif.
                          endif.
                        endloop.

                        shift <fs_att_value>-VALUE left deleting leading space.
                        MODIFY ct_att_values FROM <fs_att_value>
                                            INDEX ls_index
                                            TRANSPORTING value.

                      when others. “processing CD…
                        read table lt_CRMC_PROC_TYPE_T into ls_CRMC_PROC_TYPE_T
                                                       with key PROCESS_TYPE = ls_CRMD_ORDERADM_H-PROCESS_TYPE
                                                                langu = ‘E’.
                        if sy-subrc = 0.
                          if <fs_att_value>-value is initial. “1st CD type found?
                            <fs_att_value>-value = ls_CRMC_PROC_TYPE_T-P_DESCRIPTION_20. “trans type desc
                          else.
                            concatenate <fs_att_value>-VALUE ‘,’ ls_CRMC_PROC_TYPE_T-P_DESCRIPTION_20 into <fs_att_value>-VALUE separated by space.
                          endif.

                        else. “shouldn’t happen but… if CD found with no desc…
                          if <fs_att_value>-value is initial. “1st CD type found?
                            <fs_att_value>-value = ls_type_cd. “trans type desc
                          else.
                            concatenate <fs_att_value>-VALUE ‘,’ ls_type_cd into <fs_att_value>-VALUE separated by space.
                          endif.
                        endif.

                        shift <fs_att_value>-VALUE left deleting leading space.
                        MODIFY ct_att_values FROM <fs_att_value>
                                            INDEX ls_index
                                            TRANSPORTING value.

                    endcase.”CR or CD

          *——————————————————————————————
                  when ‘OBJECT_GUID_RFC’. “RFC’s guid for link
                    loop at lt_tsocm_cr_context into ls_tsocm_cr_context.
                      <fs_att_value>-VALUE = ls_tsocm_cr_context-guid. “original CR’s guid
                      exit.
                    endloop.

                    MODIFY ct_att_values FROM <fs_att_value>
                                        INDEX ls_index
                                        TRANSPORTING value.

          *——————————————————————————————
                  when ‘PROJECT_ID’. “Project assigned to CR. There’s only one per CR
                    LOOP AT lt_tsocm_cr_context INTO ls_tsocm_cr_context where PROJECT_ID is not initial.
                      <fs_att_value>-VALUE = ls_tsocm_cr_context-project_id.
                      exit.
                    ENDLOOP.
                    MODIFY ct_att_values FROM <fs_att_value>
                                        INDEX ls_index
                                        TRANSPORTING value.

          *——————————————————————————————
                  when ‘SOURCE_SID’. “Source SolMan system ID
          *             This will be used in the mail conditions to cause the correct SolMan URL in the link.
          *             Read the first 3 char from the CR’s logic system
                    <fs_att_value>-VALUE = ls_CRMD_ORDERADM_H-logical_system(3).
                    MODIFY ct_att_values FROM <fs_att_value>
                                  INDEX ls_index
                                  TRANSPORTING value.

          *===========================================================================================
          * 10) Assign textbox contents
                  when ‘TEXT_LONG_DESC’.           “Text box – long description
                    clear ls_text_value.
                    CALL FUNCTION ‘Z_SM_READ_CHARM_TEXTBOX’
                      EXPORTING
                        P_GUID     = ls_CRMD_ORDERADM_H-guid
                        P_TEXTTYPE = lc_textid_longdesc
                      IMPORTING
                        PT_TEXTS   = ls_text_value.

                    <fs_att_value>-VALUE = ls_text_value.
                    MODIFY ct_att_values FROM <fs_att_value>
                                  INDEX ls_index
                                  TRANSPORTING value.

          *——————————————————————————————
                  when ‘TEXT_JUSTIFICATION’.         “Text box – Justification for Emergency
                    clear ls_text_value.
                    CALL FUNCTION ‘Z_SM_READ_CHARM_TEXTBOX’
                      EXPORTING
                        P_GUID     = ls_CRMD_ORDERADM_H-guid
                        P_TEXTTYPE = lc_textid_just
                      IMPORTING
                        PT_TEXTS   = ls_text_value.

                    if ls_text_value is not initial.
                      <fs_att_value>-VALUE = ls_text_value.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    endif.

          *——————————————————————————————
                  when ‘TEXT_LONG_REASON’.         “Text box – Reason for Change/Justification
                    clear ls_text_value.
                    CALL FUNCTION ‘Z_SM_READ_CHARM_TEXTBOX’
                      EXPORTING
                        P_GUID     = ls_CRMD_ORDERADM_H-guid
                        P_TEXTTYPE = lc_textid_reason
                      IMPORTING
                        PT_TEXTS   = ls_text_value.

                    if ls_text_value is not initial.
                      <fs_att_value>-VALUE = ls_text_value.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    endif.

          *——————————————————————————————
                  when ‘TEXT_DEPLOY_INSTR’.         “Text box – Deployment Instructions
                    clear ls_text_value.
                    CALL FUNCTION ‘Z_SM_READ_CHARM_TEXTBOX’
                      EXPORTING
                        P_GUID     = ls_CRMD_ORDERADM_H-guid
                        P_TEXTTYPE = lc_textid_deploymt
                      IMPORTING
                        PT_TEXTS   = ls_text_value.

                    if ls_text_value is not initial.
                      <fs_att_value>-VALUE = ls_text_value.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                      MODIFY ct_att_values FROM <fs_att_value>
                                    INDEX ls_index
                                    TRANSPORTING value.
                    endif.

          *==============================================================================================
          * 11) Partners
                  when ‘PNTR_SDCR0002’. “Change Manager
                    CALL FUNCTION ‘Z_CRM_ORDER_READ’
                      EXPORTING
                        PI_GUID           = ls_CRMD_ORDERADM_H-guid
                        PI_PARTNER_FCT    = lc_SDCR0002
                      IMPORTING
                        PO_PARTNER_DETAIL = lt_partner_detail.

                    if lt_partner_detail[] is not initial.
                      loop at lt_partner_detail into ls_partner_detail.
                        if ls_partner_detail-PARTNER_NO is not initial.
                          if sy-tabix ne 1. “more than one partner assinged to function?
                            concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                          endif.
                          concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                        endif.
                      endloop.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                    endif.
                    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

          *——————————————————————————————
                  when ‘PNTR_ZMCRCRM1’.
                    CALL FUNCTION ‘Z_CRM_ORDER_READ’
                      EXPORTING
                        PI_GUID           = ls_CRMD_ORDERADM_H-guid
                        PI_PARTNER_FCT    = lc_ZMCRCRM1
                      IMPORTING
                        PO_PARTNER_DETAIL = lt_partner_detail.

                    if lt_partner_detail[] is not initial.
                      loop at lt_partner_detail into ls_partner_detail.
                        if ls_partner_detail-PARTNER_NO is not initial.
                          if sy-tabix ne 1. “more than one partner assinged to function?
                            concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                          endif.
                          concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                        endif.
                      endloop.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                    endif.
                    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

          *——————————————————————————————
                  when ‘PNTR_ZMCRTDC1’. “Solution Architect
                    CALL FUNCTION ‘Z_CRM_ORDER_READ’
                      EXPORTING
                        PI_GUID           = ls_CRMD_ORDERADM_H-guid
                        PI_PARTNER_FCT    = lc_ZMCRTDC1
                      IMPORTING
                        PO_PARTNER_DETAIL = lt_partner_detail.

                    if lt_partner_detail[] is not initial.
                      loop at lt_partner_detail into ls_partner_detail.
                        if ls_partner_detail-PARTNER_NO is not initial.
                          if sy-tabix ne 1. “more than one partner assinged to function?
                            concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                          endif.
                          concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                        endif.
                      endloop.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                    endif.
                    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

          *——————————————————————————————
                  when ‘PNTR_SMCD0001’. “Developer
                    CALL FUNCTION ‘Z_CRM_ORDER_READ’
                      EXPORTING
                        PI_GUID           = ls_CRMD_ORDERADM_H-guid
                        PI_PARTNER_FCT    = lc_SMCD0001
                      IMPORTING
                        PO_PARTNER_DETAIL = lt_partner_detail.

                    if lt_partner_detail[] is not initial.
                      loop at lt_partner_detail into ls_partner_detail.
                        if ls_partner_detail-PARTNER_NO is not initial.
                          if sy-tabix ne 1. “more than one partner assinged to function?
                            concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                          endif.
                          concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                        endif.
                      endloop.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                    endif.
                    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

          *——————————————————————————————
                  when ‘PNTR_SMCD0002’. “Tester
                    CALL FUNCTION ‘Z_CRM_ORDER_READ’
                      EXPORTING
                        PI_GUID           = ls_CRMD_ORDERADM_H-guid
                        PI_PARTNER_FCT    = lc_SMCD0002
                      IMPORTING
                        PO_PARTNER_DETAIL = lt_partner_detail.

                    if lt_partner_detail[] is not initial.
                      loop at lt_partner_detail into ls_partner_detail.
                        if ls_partner_detail-PARTNER_NO is not initial.
                          if sy-tabix ne 1. “more than one partner assinged to function?
                            concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                          endif.
                          concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                        endif.
                      endloop.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                    endif.
                    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.
          *——————————————————————————————
                  when ‘PNTR_SMCD0003’. “Operator
                    CALL FUNCTION ‘Z_CRM_ORDER_READ’
                      EXPORTING
                        PI_GUID           = ls_CRMD_ORDERADM_H-guid
                        PI_PARTNER_FCT    = lc_SMCD0003
                      IMPORTING
                        PO_PARTNER_DETAIL = lt_partner_detail.

                    if lt_partner_detail[] is not initial.
                      loop at lt_partner_detail into ls_partner_detail.
                        if ls_partner_detail-PARTNER_NO is not initial.
                          if sy-tabix ne 1. “more than one partner assinged to function?
                            concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                          endif.
                          concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                        endif.
                      endloop.
                    else.
                      <fs_att_value>-VALUE = lc_none.
                    endif.
                    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.
                endcase.
              ENDIF.
            ENDLOOP.

          endmethod.

          (0) 
          1. Satish Sreedhara

            Hi Robyn ,

            Kudos to you on such a wonderful article .

            I am in need of small help from you , is there anyway you can share the html code of the Z Mail form you have . This is really a great help on you .

            Regards,

            Satish

            (0) 
            1. Robyn Osby Post author

              Hi Satish,

              Here is the full HTML with identifying fields changed to “xyz”…

              <HTML><head>
              <meta content=”text/html; charset=utf-8″ http-equiv=”content-type”>
              <style type=”text/css”>
              /*<![CDATA[*/
              <!–
              /* Font Definitions */
              @font-face
                      {font-family:”Cambria Math”;
                      panose-1:2 4 5 3 5 4 6 3 2 4;}
              @font-face
                      {font-family:”Segoe UI”;
                      panose-1:2 11 5 2 4 2 4 2 2 3;}
              /* Style Definitions */
              p.MsoNormal, li.MsoNormal, div.MsoNormal
                      {margin-top:0in;
                      margin-right:0in;
                      margin-bottom:8.0pt;
                      margin-left:0in;
                      line-height:107%;
                      font-size:11.0pt;
                      font-family:”Calibri”,sans-serif;}
              .MsoChpDefault
                      {font-family:”Calibri”,sans-serif;}
              .MsoPapDefault
                      {margin-bottom:8.0pt;
                      line-height:107%;}
              /* Page Definitions */
              @page WordSection1
                      {size:8.5in 11.0in;
                      margin:1.0in 1.0in 1.0in 1.0in;}
              div.WordSection1
                      {page:WordSection1;}
              –>
              /*]]>*/
              </style>

              </head><body>
              <!– –>
              <form><!– –>
              <p align=”right”><span style=’font-family: “Arial”,sans-serif;’><img alt=”” src=”/sap/bc/contentserver/300?get&amp;pVersion=0046&amp;contRep=CRMFILESYSTEM&amp;docId=005056AC38241EE58E80056EE8563901&amp;compId=xyz-logo.png&amp;accessMode=r&amp;authId=CN%3Dxyz&amp;expiration=20151015211731&amp;secKey=MIHwBgkqhkiG9w0BBwKggeIwgd8CAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHATGBvzCBvAIBATATMA4xDDAKBgNVBAMTA1NQUAIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTUxMDE1MTkxNzMxWjAjBgkqhkiG9w0BCQQxFgQUX1yLR2PJY%2BMXBufOAbvMvctiwJMwCQYHKoZIzjgEAwQtMCsCE1qGbwaCoq%2BByjDDTswRn8h0U5kCFB7O3LyFxZ%2FdoguYxPMkB0gmEil8″></span></p>
              <!– –>
              <p style=”margin: 0in 0in 0pt;” align=”right”><span style=’font-family: “Arial”,sans-serif;’><font color=”black” size=”1″><span style=’font-family: “Arial”,sans-serif;’><em>Generated: <input dir=”ltr” id=”%SAP_SYST-DATLO” value=”Local date”> <font color=”black” size=”1″><input dir=”ltr” id=”%SAP_SYST-TIMLO” value=”Local Time”></font></em></span></font></span></p>
              <p>You are being notified of a status change and possible action needed on the following Request for Change.<br>
              Please select the LINK to process the actions accordingly. <span style=’font-family: “Arial”,sans-serif;’><a href=”https://sxyzdb.xyz.com:12345/sap/bc/bsp/sap/crm_ui_start/default.htm?CRM-OBJECT-TYPE=AIC_OB_CMCR&CRM-OBJECT-ACTION=B&CRM-OBJECT-VALUE=%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_GUID“><font color=”red” size=”2″><font face=”Arial”>ChaRM Request for Change</font></font></a></span></p>
              <!– ROW STATUS –>
              <table class=”Data3″>
              <tbody><!– ROW CHARM NO and EXT REF –>
              <tr>
              <td class=”Data3″><font color=”black” size=”2″><strong><font face=”Arial”>Status</font></strong></font></td>
              <td class=”Data3″><font color=”red” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_STATUS” value=”Status”></span></font></td>
              </tr>
              </tbody>
              </table>
              <!– CHARM DETAILS –>
              <h2><font size=”3″><u>ChaRM Detail</u></font></h2>
              <font face=”Arial”><!– ROW3–></font>
              <table class=”Data”>
              <tbody><!– CHARM NO –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″><strong><font face=”Arial”>ChaRM ID</font></strong></font></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER” value=”Service Request ID”></span></font></td>
              </tr>
              <!– TITLE –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″ face=”Arial”><strong>Title</strong></font></td>
              <td id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_DESC” class=”Data<input dir=”><span style=’font-family: “Arial”,sans-serif;’><font color=”black” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_DESC” value=”Description”></font></span></td>
              </tr>
              <!– EXT REF –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>ESMS Ticket</strong></span></font></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-EXT_REFERENCE” value=”External Reference No.”></span></font></td>
              </tr>
              <!– TRANS TYPE –>
              <tr>
              <td class=”Data”><strong><font size=”2″ face=”Arial”>Change Types</font></strong></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-TRANS_TYPE_DESC” value=”ChaRM Trans Type desc”></span></font></td>
              </tr>
              <!– PROJECT –>
              <tr>
              <td class=”Data”><span style=’font-family: “Arial”,sans-serif;’><strong><font size=”2″>Project Name</font></strong></span></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-PROJECT_ID” value=”Project Name”></span></font></td>
              </tr>
              <!– DATE –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Target Date</strong></span></font></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-DUE_DATE” value=”ChaRM Due Date / Target Date”></span></font></td>
              </tr>
              <!– PRIORITY –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Assigned Priority</strong></span></font></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-PRIORITY_TEXT” value=”Priority Text”></span></font></td>
              </tr>
              <!– INSTANCE –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>IBase Instance(s)</strong></span></font></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-IB_INSTANCE” value=”IB_INSTANCEs”></span></font></td>
              </tr>
              <!– SID –>
              <tr>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>System ID(s)</strong></span></font></td>
              <td class=”Data”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-Z_SMSY_DESCR” value=”SMSY Description”></span></font></td>
              </tr>
              </tbody>
              </table>
              <!– CATEGORIES –>
              <table class=”DataCat”>
              <tbody>
              <tr>
              <td class=”DataCat”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Categorization</strong></span></font></td>
              <td class=”DataCat”><span style=’font-family: “Arial”,sans-serif;’><font color=”black” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT1″ value=”Subject Category 1″> /</font></span> <span style=’font-family: “Arial”,sans-serif;’><font color=”red” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT2″ value=”Subject Category 2″> <font color=”#000000″>/</font></font></span> <span style=’font-family: “Arial”,sans-serif;’><font color=”black” size=”2″><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT3″ value=”Subject Category 3″></font></span></td>
              </tr>
              </tbody>
              </table>
              <p><!– PARTNERS –>
              <strong><u>Partners Assigned</u></strong></p>
              <table class=”DataP”>
              <tbody>
              <tr>
              <td class=”DataP”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Requestor</strong></span></font></td>
              <td class=”DataP”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_REP_FULL” value=”Reporter Full Name”></span></font></td>
              <td class=”Data”>
              </td>
              <tr>
              <td class=”DataP”><font size=”2″ face=”Arial”><strong>Change Manager</strong></font></td>
              <td class=”DataP”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-PNTR_SDCR0002″ value=”Change Manager”></span></font></td>
              </tr>
              <tr>
              <td class=”DataP”><font size=”2″ face=”Arial”><strong>CRM</strong></font></td>
              <td class=”DataP”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-PNTR_ZMCRCRM1″ value=”CRM”></span></font></td>
              </tr>
              <tr>
              <td class=”DataP”><font size=”2″ face=”Arial”><strong>Solution Architect</strong></font></td>
              <td class=”DataP”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-PNTR_ZMCRTDC1″ value=”Solution Architect”></span></font></td>
              </tr>
              </tbody>
              </table>
              <p><!– TEXTBOX CONTENTS –>
              <strong><u>Supporting Texts</u></strong></p>
              <table class=”DataT”>
              <tbody>
              <tr>
              <td class=”DataT”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Problem Description</strong></span></font></td>
              <td><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-TEXT_LONG_DESC” value=”ChaRM Textbox – Long Description”></span></font></td>
              </tr>
              <!– 2 –>
              <tr>
              <td class=”DataT”><font color=”black” size=”2″ face=”Arial”><strong>Justification for Emergency</strong></font></td>
              <td><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-TEXT_JUSTIFICATION” value=”Justification for Emergency”></span></font></td>
              </tr>
              <!– 3 –>
              <tr>
              <td class=”DataT”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Reason for Change</strong></span></font></td>
              <td><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-TEXT_LONG_REASON” value=”ChaRM textbox Reason for Change”></span></font></td>
              </tr>
              <!– 4 –>
              <tr>
              <td class=”DataT”><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><strong>Deployment Steps</strong></span></font></td>
              <td><font color=”black” size=”2″><span style=’font-family: “Arial”,sans-serif;’><input dir=”ltr” id=”%SAP_ZCHARM_MAILFORM-TEXT_DEPLOY_INSTR” value=”ChaRM Textbox – Deployment Instructions”></span></font></td>
              </tr>
              </tbody>
              </table>
              <!– FOOTER –>
              <p><font color=”black” size=”2″><font color=”black” size=”2″><em><font face=”Arial”>Best regards,</font></em></font></font> <font color=”black” size=”2″><font color=”black” size=”2″><em><span style=’font-family: “Arial”,sans-serif;’>SAP Solution Manager Administration</span></em></font></font></p>
              </form>
              <table class=”DataT”>

              </table></body></HTML>

              (0) 
  4. Diana Tsvetkova

    Hi,

    I am getting a message ” Mail from can not be found” by executing action SEND_MAIL_WITH_MAIL_FORMS. Do you have an idea?

    Solution Manager Release is 7.1 SP10. Actually the mail forms are created and I can find them in table CRMD_PML_HEAD.

    Cheers

    Diana

    (0) 
    1. Robyn Osby Post author

      Hi Diana,

      Adding to what Satish mentioned, confirm the upper/lower case of the form template name is correct in the container field too.

      Cheer!

      Robyn

      (0) 
    1. Robyn Osby Post author

      Hi Diana,

      Sorry. Can’t think if anything off the top of head without seeing your config. I’ll look at my config again to see if anything rings a bell.

      (0) 
  5. Miroslav Oprsteny

    Hello,

    I have just a minor comment to this:

    LOOP AT ct_att_values ASSIGNING <fs_att_value>.

    ...

    MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

    ...

    ENDLOOP.

    The MODIFY command is definitelly NOT necessary. Once you’re working with field symbols, you’re accessing values of CT_ATT_VALUES rows directly (modifying a value in the field symbol = changing value of a field in a row of CT_ATT_VALUES).

    MODIFY command would be necessary only in case you are working with work-area.

    (0) 
    1. Robyn Osby Post author

      Hello Jose,

      I don’t understand your question. What are you not able to find on that step?  Please explain further and I’ll try to help.

      (0) 
      1. Shiva Shankar reddy

        Hi Robyn,

        i would like to know the below piece of code which u said in the block Description

        SAP Mail Forms Demystified

        1) Partners
                when ‘PNTR_SDCR0002’. “Change Manager
                  CALL FUNCTION ‘Z_CRM_ORDER_READ’
                    EXPORTING
                      PI_GUID           = ls_CRMD_ORDERADM_H-guid
                      PI_PARTNER_FCT    = lc_SDCR0002
                    IMPORTING
                      PO_PARTNER_DETAIL = lt_partner_detail.

                  if lt_partner_detail[] is not initial.
                    loop at lt_partner_detail into ls_partner_detail.
                      if ls_partner_detail-PARTNER_NO is not initial.
                        if sy-tabix ne 1. “more than one partner assinged to function?
                          concatenate <fs_att_value>-VALUE ‘/’ into <fs_att_value>-VALUE separated by space.
                        endif.
                        concatenate ls_partner_detail-PARTNER_NAME_FIRST ls_partner_detail-PARTNER_NAME_LAST into <fs_att_value>-VALUE separated by space.
                      endif.
                    endloop.
                  else.
                    <fs_att_value>-VALUE = lc_none.
                  endif.
                  MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

        Note: i am unable to find function module Z_CRM_ORDER_READ. can you please help me function module code .

        thanks

        shiva shankar reddy

        (0) 
  6. Ahmad Salam

    Dear Robyn,

    Gr8 Blog and many thanks for it.

    However am haveing a hard time to create the structure of step 1.

    will you please share some notes for this specific step i need to create one exactly like urs.

    Many Thanks.

    (0) 
  7. Scott Waterman

    Robyn,

    Excellent blog!

    I am running with 7.1 SP12…I am looking specifically to implement Step 6c) “Create a new Text Element to be display in Production”

    I have implemented the custom structure/attributes/BADI, containing ‘sap system id’ custom attribute which is the key for the conditions for the development/production text Elements…

    When Mail Form Attribute Context is set to ‘Service Request Attributes’ and I select [Test & Send Preview] only the SRQ attributes are populated (for the service request entered), the custom BADI is never called, hence the ‘sap system id’ is never populated and I receive the contents of both Text Elements in the Email…

    When Mail Form Attribute Context is set to ‘My Custom Mail Form Fields’ and I select [Test & Send Preview] there is no ability to enter the service request # (only Business Partner, B2B Scenario, etc…) however Test Send and Preview from here does call the custom BADI, ‘sap system id’ is populated, I receive the contents of the correct Text Element in the Email (provided Check Conditions check box is also checked)…however in this case, the SRQ attributes are not populated…

    Can you comment on how it is possible to have both SRQ and Custom attributes populated simultaneously in a Mail Form?

    Thank you!

    -Scott

    (0) 
  8. saloni varma

    HI Robyn,

    i am trying to follow this post, but i have 1 query.

    i have implemented the BADI as mentioned and trying to put my code in IF_EX_CRM_IM_ADD_DATA_BADI~CRM_IM_BPSELE but on doing that process from CRM UI the BADI is not getting triggered.

    Any clue wat can be done for this?

    Thanks,

    Saloni Varma

    (0) 
  9. Eli Steklov

    Hi Robyn,

    Thanks for the great Blog, It’s very helpful.

    I have one issue, I can’t find a CR_ID or CR_GUID in the BADI.

    the code lines:

      clear: ls_CRMD_ORDERADM_H.
      read table ct_att_values into ls_ct_att_value_temp with key name = lc_CR_number.
      if sy-subrc = 0.
        ls_cr = ls_ct_att_value_temp-value.
      endif.

    ct_att_values contain only my struct fields and I get always SY-SUBRC = 4.

    Thanks
    Eli

    (0) 
  10. Florian Sperling

    Thanks for the post, it actually helped me a lot.

    Does anybody knows weather there is an option to change the displayed sender name of an email generated via mail forms?

    Thanks

    Florian

     

    (0) 
    1. Meghan Rosser

      Hi Florian, there is a note with steps for adjusting the sender: 788626 – PPF: adjusting the Smart Form documents

       

      Regards,
      Meghan

      (0) 
  11. Zhou REN

    Dear Robyn,

    Thanks for this great post.

    Actually, I’m facing an issue while implementing the BADI. I want to get the text description (SU99) value when sending the mail at ‘New’ status of an incident ticket. The issue is that, I got no value because when click on ‘save’ button, the badi will be called, but the data is not written into database yet.

    So could you advise how I can get value during the runtime?

    Thank you in advance,

    Best regards,

    Zhou

    (0) 

Leave a Reply