Skip to Content

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
  public
  final
  create public .

public section.

  class-methods IS_CDS_VIEW
    importing
      !IV_NAME type ABPTOKEN-LEXEM
    returning
      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.
ENDCLASS.



CLASS ZCL_CDS_VIEW_CASE_TOOL IMPLEMENTATION.


* <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.
       RETURN.
    ENDIF.

    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.

  endmethod.
ENDCLASS.
To report this post you need to login first.

7 Comments

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

    1. Jerry Wang 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,
      Jerry

      (1) 
      1. 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.

        (0) 
  1. 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
    Peter

    (0) 
  2. 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.

    (0) 

Leave a Reply