Skip to Content
Author's profile photo Jerry Wang

Bypass CDS view name case conversion in ABAP source code pretty printer

Some colleagues complained that when they consume CDS view in ABAP source code, for example the view below: I_Product

The reason is our team use “Keyword Uppercase” in Pretty Printer setting, and the printer implementation will not differentiate CDS view and normal ABAP variable.
Our requirement is, after Pretty Printer button is clicked, the CDS view name in ABAP source code could remain unchanged. In my example above, it should still be “I_Product”.
They are many ways to achieve this requirement via enhancement, unfortunately the package of pretty printer is configured as non-extensible.
So the only feasible approach is to directly change standard implementation, which is not a good solution but it works.
Open include program LSPPRP04, add a new line in line 167:
CHECK zcl_cds_view_case_tool=>is_cds_view( <abap_token>-lexem ) = abap_false.
The idea is to ignore the LOWER CASE handling of current ABAP token, once it is detected to represent an CDS view.

Test again:before Pretty Printer is clicked, the red line represents the name to be converted, the blue line for CDS view name which will not be touched:
After clicked, it works as expected.

Source code of zcl_cds_view_case_tool:

class ZCL_CDS_VIEW_CASE_TOOL definition
  create public .

public section.

  class-methods IS_CDS_VIEW
      value(RV_RESULT) type ABAP_BOOL .
protected section.
private section.

  TYPES: BEGIN OF ty_result,
            name TYPe ABPTOKEN-LEXEM,
            result TYPE ABAP_BOOL,
        end of ty_result.

  TYPES: tt_result TYPE STANDARD TABLE OF ty_result WITH KEY name.

  class-data:      mt_result TYPE tt_result.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_CDS_VIEW_CASE_TOOL=>IS_CDS_VIEW
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_NAME                        TYPE        ABPTOKEN-LEXEM
* | [<-()] RV_RESULT                      TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method IS_CDS_VIEW.
    CHECK sy-uname = 'WANGJER'.

    READ TABLE mt_result ASSIGNING FIELD-SYMBOL(<result>) WITH KEY name = iv_name.
    IF sy-subrc = 0.
       rv_result = <result>-result.

    SELECT single obj_name INTO @data(ls) FROM TADIR
       WHERE pgmid = 'R3TR' and object = 'DDLS' and obj_name = @iv_name.

    data(ls_result) = value ty_result( name = iv_name result = boolc( sy-subrc = 0 ) ).
    APPEND ls_result to mt_result.

    rv_result = ls_result-result.


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Joachim Rees
      Joachim Rees

      Hey Jerry,

      not an issue I had so far, but I think I would need a similarly "dirty trick" for getting rid of a certain syntax check warning.

      Maybe you have an idea?


      Author's profile photo Jerry Wang
      Jerry Wang
      Blog Post Author

      Hello Joachim,

      I have read your question, and unfortunately I don't have better idea than Peter.

      Best regards,

      Author's profile photo Peter Inotai
      Peter Inotai

      Hi Jerry,
      Which release are you on?
      In lower release it was possible to enhance FM PRETTY_PRINTER. There was even an Add-on for this, it was blogged here:
      I wonder if the same approach can be still used, or it's no longer possible. Would be interesting to know why it was disabled.
      Best regards

      Author's profile photo Jerry Wang
      Jerry Wang
      Blog Post Author

      Hello Peter,

      Thanks a lot for your comment and mention the related blog, especially appreciate that you point it out that PRETTY_PRINTER could be enhanced in lower release.

      When I try to enhance related function module in our internal system, message is raised.

      In the check method, there are a black list of non-extensible packages:

      The release:

      Best regards,

      Author's profile photo Horst Keller
      Horst Keller

      In fact, I don’t think it’s such a good idea to base blogs on releases that are not available for customers yet   -  especially if you don't want to point out release specific things that are officially released already.

      Author's profile photo Peter Inotai
      Peter Inotai

      Hi Jerry,
      Thanks for the info. Release SAP_BASIS 7.52. This is a release which I can only dream about 🙁
      In 7.40 FM PRETTY_PRINTER is in package SCMP.
      I found also OBJ_IS_ENHANCEABLE also in this release and SCMP is not there. Actually also not in your screenshot. So it means it was moved to another package in higher releases.
      It's a pity 🙁
      Best regards

      Author's profile photo Uwe Fetzer
      Uwe Fetzer

      Would be interesting to know, what happens, if you enhance the FM and later upgrade to a release where the FM is not enhancable anymore.