matinal:SAP ABAP 看看你开发的程序里有多少个SELECT等增删查改的语句

2023-10-14 15:14:41 浏览数 (1)

代码规范校验程序

自己用的小程序

代码语言:javascript复制
REPORT z_matinal.

*PARAMETERS:p_prog like trdir-name .

DATA:gr_scan    TYPE REF TO cl_ci_scan,
     gr_source  TYPE REF TO cl_ci_source_include,
     gs_stat    LIKE LINE OF gr_scan->statements,
     gs_token   LIKE LINE OF gr_scan->tokens,
     gt_token   TYPE stokesx_tab,
     gs_message TYPE char255,
     gt_message LIKE TABLE OF gs_message,
     gs_if      TYPE char255,
     gt_if      LIKE TABLE OF gs_if,
     lv_flag    TYPE n,
     lv_index   TYPE sy-index.

gr_source = cl_ci_source_include=>create( p_name = 'z_matinal' ) .

CREATE OBJECT gr_scan
  EXPORTING
    p_include = gr_source.

LOOP AT gr_scan->statements INTO gs_stat .

  REFRESH gt_token .
  CLEAR lv_index .

  LOOP AT gr_scan->tokens INTO gs_token FROM gs_stat-from TO gs_stat-to .

    lv_index = lv_index   1 .
    APPEND gs_token TO gt_token .

  ENDLOOP .

  "判断SELECT *(公众号:matinal)
  READ TABLE gt_token TRANSPORTING NO FIELDS WITH KEY str = 'SELECT' .
  IF sy-subrc = 0 .

    CLEAR gs_token .
    READ TABLE gt_token INTO gs_token INDEX 2 .
    IF gs_token-str = '*' .
      CLEAR gs_message .
      gs_message = '第' && gs_token-row && '行有SELECT * ' .
      APPEND gs_message TO gt_message .
    ENDIF .

  ENDIF .

  "判断DELETE标准表(公众号:matinal)
  READ TABLE gt_token TRANSPORTING NO FIELDS WITH KEY str = 'DELETE' .
  IF sy-subrc = 0 .

    CLEAR gs_token .
    READ TABLE gt_token INTO gs_token INDEX 2 .
    IF gs_token-str 0(1) <> 'Z' .
      CLEAR gs_message .
      gs_message = '第' && gs_token-row && '行有DELETE标准表' .
      APPEND gs_message TO gt_message .
    ENDIF .

  ENDIF .

  "判断UPDATE标准表(公众号:matinal)
  READ TABLE gt_token TRANSPORTING NO FIELDS WITH KEY str = 'UPDATE' .
  IF sy-subrc = 0 .

    CLEAR gs_token .
    READ TABLE gt_token INTO gs_token INDEX 2 .
    IF gs_token-str 0(1) <> 'Z' .
      CLEAR gs_message .
      gs_message = '第' && gs_token-row && '行有UPDATE标准表' .
      APPEND gs_message TO gt_message .
    ENDIF .

  ENDIF .

ENDLOOP .

LOOP AT gt_message INTO gs_message .
  WRITE gs_message .
ENDLOOP .

0 人点赞