As you might know SAP BW does not allow every possible character in character strings. An upload or activation can terminate in such cases. It occurs frequently with character strings where users (or interfaces) can freely enter text.

SAP delivered various Function Modules for validation of character strings. Unfortunately cleansing of character strings is not provided by SAP. It would be very helpful to have a comprehensive ABAP Add-on for cleansing of character strings.

In blog Introducing an Add-on for Cleansing Character Strings I introduced such an Add-on which I developed. In this document I will provide you with detailed implementation instructions for creating the Character String Cleansing Add-on and using it in Transformation Rules.

Please have a look here to download the attachments.

Create Class

SAP Menu: Tools > ABAP Workbench > Development > Class Builder

T/code: SE24

 

Create Class ZCL_CLEANSE_CHARSTRING as shown in the following screenshot.

 

Figure_1_Class.jpg

Figure 1: Class

 

Refer to one of the attached files depending on your SAP BW release:

  • File ZCL_CLEANSE_CHARSTRING_v1.txt contains the coding for release 7.31 and below;
  • File ZCL_CLEANSE_CHARSTRING_v2.txt contains the coding for release 7.40 and higher.

 

From here you can quite easily build up the class using copy & paste:

  • Source code can be found in Part 1 of the attached file;
  • Description of Title, Attributes, Methods and Parameters can be found in Part 2 of the attached file.

 

For the copy & paste action of the source code you should switch to the Source Code-based Class Builder using the corresponding push button. This is the easiest way to copy and paste all coding. The class will now contain all methods, parameters and attributes. Only the texts of the various metadata elements are missing. This will be a manual copy & paste action for every respective metadata element.

Using the Cleansing Add-on

The Cleansing Add-on is intended to be used in a Transformation Rule and can be considered as a recurring activity. Go to the respective Transformation Rule (e.g. Characteristic 0REF_DOC_NO).

 

Figure_2_Transformation_Rule.jpg

Figure 2: Transformation rule

 

Choose Rule Type “Routine”, specify the source field and write coding in the Routine.

 

The easiest way is to remove all “default” coding, use the Pattern function, choose for ABAP Objects Pattern and specify Class ZCL_CLEANSE_CHARSTRING and Method EXECUTE. Then proceed as follows:

 

  • Fill importing parameter I_CHAVL_INPUT with the respective source field;
  • Fill importing parameter I_ALLOW_LOWERCASE (optional), ‘X’ means lowercase allowed;
  • Fill importing parameter I_REPLACE_CHAR with the replacement character (optional) , default is the SPACE symbol *);
  • Fill exporting parameter E_CHAVL_OUTPUT with the result field.

 

*) The replacement character may contain one of the following characters: _?#* or the SPACE symbol. Any other character will be replaced by the default SPACE symbol.

 

The coding of your routine should look similar as in the next screenshot.

 

Figure_3_Coding_Example.jpg

Figure 3: Coding example

To report this post you need to login first.

10 Comments

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

  1. Raf Boudewijns

    Interesting piece of code, Sander, it’s one of those things everyone could use, but hardly ever has the time to develop him/herself. Thanks for sharing!

    (1) 
  2. Sander van Willigen Post author

    Please note that I replaced the attached file ZCL_CLEANSE_CHARSTRING_v2.txt. This version is developed in SAP BW release 7.4 SP 11. Some minor issues (e.g. with class CL_RS_UTILITIES) are solved.

    If you might encounter problems with the new version on releases lower than 7.4, I suggest to refer to version 1 (which is attached to version 1 of this document).

    (0) 
  3. Bertrand LAFOUGERE

    Thanks Sander very useful.

    You should think of doing a nugget or a Slinkee of it with SapLink.

    I had to correct the following line that was not working on a 7.31

    METHOD class_constructor.



    * Check is the system runs on an AP Platform
    * p_is_ap_system = cl_rs_utilities=>n_is_ap_system.  “SUPP     

      p_is_ap_system = cl_rs_utilities=>IS_AP_SYSTEM( ). “CORR.


    ENDMETHOD.

    (1) 
    1. Sander van Willigen Post author

      Hi Bertrand,

      First of all thanks for your positive feedback.

      The add-on was originally developed in release 7.31. Later on I modified the coding to make it work in release 7.40. I decided to attach both versions to this document:

      • File ZCL_CLEANSE_CHARSTRING_v1.txt contains the coding for release 7.31 and below;
      • File ZCL_CLEANSE_CHARSTRING_v2.txt contains the coding for release 7.40 and higher.

      Best regards,

      Sander

      (0) 
      1. Bertrand LAFOUGERE

        OK I understand now.

        V1 is still an up to date version, in the sense that it’s for the 7.31 and the V2 is for 7.4 and above.

        I think that to avoid future confusion you should rename the V1 with the prefix 731 and the V2 with 740.

        (0) 

Leave a Reply