Today I was assigned with a task to generate a list of all request objects used in each WHEN statement in include LCRM_ORDER_OWF03.
Since this include has 608 lines and I am too lazy to populate the list manually, I decide to write a report to create the list.
The basic idea is to use keyword SCAN ABAP-SOURCE to split the include source code into tokens, and I only care about the tokens which come directly after “WHEN”. Once all such words are extracted, I export the list into clipboard with markdown format, so that I can just press ctrl+c in markdown editor and send the result to my colleague.
Here is the report:
REPORT zread_report.
INCLUDE: crm_object_names_con.

TYPES:
  BEGIN OF ty_clipdata,
    data TYPE c LENGTH 100,
  END   OF ty_clipdata .
TYPES:
  tt_formatted TYPE STANDARD TABLE OF ty_clipdata .

DATA: lt_source    TYPE string_table,
      lv_ret       TYPE int4,
      lt_token     TYPE TABLE OF stokes,
      lt_statement TYPE TABLE OF sstmnt,
      lt_export    TYPE tt_formatted.

CONSTANTS: gc_variable TYPE char20 VALUE 'Variable',
           gc_value    TYPE char20 VALUE 'Value'.
READ REPORT 'LCRM_ORDER_OWF03' INTO lt_source .

SCAN ABAP-SOURCE lt_source TOKENS INTO lt_token
                      STATEMENTS INTO lt_statement.

WRITE:  10 gc_variable COLOR COL_NEGATIVE, 40 gc_value COLOR COL_POSITIVE.

APPEND |{ gc_variable } \| { gc_value } | TO lt_export.
APPEND '-----|-----' TO lt_export.
LOOP AT lt_token ASSIGNING FIELD-SYMBOL(<when>) WHERE str = 'WHEN'.
  DATA(lv_name) = lt_token[ sy-tabix + 1 ]-str.
  ASSIGN (lv_name) TO FIELD-SYMBOL(<name>).
  WRITE:/  lv_name UNDER gc_variable, <name> UNDER gc_value.
  APPEND |{ lv_name } \| { <name> }| TO lt_export.
ENDLOOP.

cl_gui_frontend_services=>clipboard_export(
    EXPORTING
        no_auth_check        = abap_true
        IMPORTING
          data                 = lt_export
        CHANGING
          rc                   = lv_ret
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
      ).
Here is report output:
And then I go to a markdown editor for example github issue:
And here is the final generated list:
To report this post you need to login first.

2 Comments

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

  1. Joachim Rees

    Hey Jerry,

     

    I probably would have copied the source to notepad++ (CTRL+A, CTRL+C, tab, CTRL+V) and then used CTRL+f ‘find al’l on “when”.

     

    Or I might have used

    grep when 

    on the command line.

     

    As most often, there a many different ways to achieve something!

     

    best

    Joachim

     

    (0) 
    1. Jerry Wang Post author

      Hello Joachim,

      Thank you for sharing different but efficient approach to achieve the same 🙂

      The requirement here is, to display not only the constant variable used in WHEN, for example GC_OBJECT_NAME-MESSAGES, but also the value defined for this constant, for example “MESSAGES” must be displayed. All the constant are defined in another include crm_object_names_con. In this case, I think it is inevitable to use ABAP programming to fulfill the requirement. Nevetheless your tip is still very useful when trying to accomplish some light-weight text analysis task. Thank you very much!

      Best regards,

      Jerry

      (0) 

Leave a Reply