Skip to end of metadata
Go to start of metadata


DOCUMENTATION FOR CODE INSPECTOR

Main steps for creating a new check

-                                  Create new category ZCL_CI_CATEGORY_CONVENTIONS

-                                  Create new check ZCL_CI_TEST_SCAN

-                                  Create new check ZCL_CI_TEST_IMUD_TAW_A

-                                  Create structure - ZSCI_SELECT

-                                  Create table type ZCI -line type - ZCISELECT

-                                  Create Function group - ZASDINSPPECTOR

-                                  Create FM - Z_ASD_INSPECTOR

-                                  Create & maintain table - ZPREFIX

-                                  Activate new categories and checks

 1.    Creating a new category (SE24)

A) Copy CL_CI_CATEGORY_TEMPLATE to ZCL_CI_CATEGORY_CONVENTIONS.

B) Select the package in the popup (e.g.: $TMP)

C) Change the CONSTRUCTOR method to the following:

METHOD CONSTRUCTOR.

  super->constructor( ).

  description = 'XYZ Company RICEF Guidelines' (000).

  category    = 'CL_CI_CATEGORY_TOP'.

  position    = '005'.

ENDMETHOD.


 

Create the text elements and activate your class.

This method sets the attributes of this category in the code inspector check tree.

2.      Creating a new check ZCL_CI_TEST_SCAN

A) Copy CL_CI_TEST_SCAN to ZCL_CI_TEST_SCAN.

B) Select the package in the popup (e.g.: $TMP)

C) Add the following METHODs to the class:

1) DATA_PREFIX                       Instance Method    Private          Get Prefix

SELECT *

    FROM zprefix

    INTO TABLE it_prefix.


2) DATA_CHECK_BEGIN_END    Instance Method   Private    Check Begin End

DATA : l_temptabix LIKE sy-tabix .

  l_temptabix = l_tabix + 1 .

  READ TABLE  ref_scan->tokens INTO token_wa INDEX l_temptabix.

  IF token_wa-str = 'BEGIN' .

    l_begin = 'X' .

  ENDIF .

  IF token_wa-str = 'END' .

    CLEAR l_begin .

    l_tabix = l_tabix + 2 .

  ENDIF .



 

3) DATA_GET_DATA_TYPE      Instance Method     Private       Get Data Type

DATA: l_offset TYPE rsymb-dtix .

  DATA : wa_rsymb LIKE LINE OF it_rsymb.

  DATA : wa_rdata LIKE LINE OF it_rdata.

  READ TABLE it_rsymb INTO wa_rsymb WITH KEY txof = str.

  IF sy-subrc = 0 .

*   Local Data

    IF wa_rsymb-flocal EQ 'X' .

      l_keyword = 'LOCAL'(009) .

      EXIT .

    ENDIF .

    l_offset = wa_rsymb-dtix + 1.

    CLEAR wa_rdata .

    READ TABLE it_rdata INDEX l_offset INTO wa_rdata.

*   Check for Internal table, Object reference, structure

    CASE wa_rdata-type.

      WHEN 'h' .

        l_keyword = 'INTERNAL_TABLE'(005) .

      WHEN 'r' .

        l_keyword = 'OBJECT_REFERENCE'(006) .

      WHEN 'u' .

*       Check if Internal table of form IT_TAB[] exists

        CONCATENATE str '[]' INTO str.

        READ TABLE it_rsymb WITH KEY txof = str INTO wa_rsymb.

        IF sy-subrc EQ 0 .

          CALL METHOD me->DATA_get_data_type

            EXPORTING

              str       = str

            CHANGING

              l_keyword = l_keyword.

        ELSE  .

              l_keyword = 'STRUCTURE'(007) .

        ENDIF .

      WHEN 'v'.

         l_keyword = 'STRUCTURE'(007).

    ENDCASE .

  ELSE .

*   Check for Data of form l_data(20)

    SEARCH str FOR '(' .

    IF sy-subrc EQ 0 .

      str = str+0(sy-fdpos).

      CALL METHOD me->DATA_get_data_type

        EXPORTING

          str       = str

        CHANGING

          l_keyword = l_keyword.

    ENDIF .

  ENDIF .



 

4) DATA_SHOW                            Instance Method     Private      Show Select

CALL FUNCTION 'Z_ASD_INSPECTOR'

    TABLES

      zci = zci.




 

Analyze

Level

Visibility

Description

D)  

We have to redefine  some of the existing methods:

a)

GET_MESSAGE_TEXT

Instance Method

Public

Return Message




Source Code

CASE p_code.
    WHEN '0001'. p_text = '&1'(101).
    WHEN '0010'. p_text = 'SCAN-Fehler: &1'(110).
    WHEN '0009'.
      p_text =
   '&3 &1 does not meet XYZ Company's Standards. Name should start with &2'.
    WHEN '0011'.
      p_text =
      '&1 Select Clause does not meet the Standard Format!!'.
    WHEN '0018'.
      p_text =
      'Dont use &1.Instead use  ''''   '''' (&2)'.
    WHEN '0050'.
      p_text =
      'Avoid using &1.'.
    WHEN '9050'.
      p_text = 'Please use Authorization objects for all Programs'.
  ENDCASE.
condense p_text.



b)

RUN

Instance Method

Public

Execute test


Source Code

*______________________________________________________________________*
 DATA : zci            TYPE   zci                                      ,
        p_keyword      TYPE   string                                   ,
        l_object_name  TYPE   sobj_name                                ,
        l_errcnt       TYPE   sci_errcnt                               ,
        l_column       TYPE   token_col                                ,
        l_keyword      TYPE   zprefix-keyword                          ,
        tabix          TYPE   i                                        ,
        g_big          TYPE   i                                        ,
        expectedon     TYPE   i                                        ,
        wrongline      TYPE   i                                        ,
        col            TYPE   i                                        ,
        selectcol      TYPE   i                                        ,
        p_result       TYPE   string                                   ,
        temp_token(30)                                                 ,
        it_prefix      TYPE   STANDARD TABLE OF zprefix                ,
        wa_zci         LIKE   LINE OF zci                              ,
        l_tabix        LIKE   sy-tabix                                 ,
        l_len          LIKE   sy-tabix                                 ,
        token_wa_tmp   LIKE   token_wa                                 ,
        l_prefix       LIKE   LINE OF it_prefix                        ,
        l_msg(255)     VALUE 'INCORRECT. Name must begin with'         ,
        flag                                                           ,
        on                                                             ,
        l_begin                                                        .
*______________________________________________________________________*
 
  REFRESH zci                                                         .
  CALL METHOD me->data_prefix
    IMPORTING
      it_prefix = it_prefix.
  IF ref_scan IS INITIAL                                              .
    CHECK get( ) = 'X'                                                .
  ENDIF                                                               .
  CHECK ref_scan->subrc EQ 0                                          .
  LOAD REPORT program_name PART 'DATA' INTO  it_rdata                 .
  LOAD REPORT program_name PART 'SYMB' INTO  it_rsymb                 .
 
 
*_____________________________________________________________________*
 
  IF trdir-secu EQ space                                            .
 
    IF trdir-subc = 'M' OR trdir-subc = '1'                         .
 
      l_errcnt      = l_errcnt + 1                                  .
      CALL METHOD inform(
        p_sub_obj_type = c_type_include
        p_sub_obj_name = trdir-name
        p_line = 0
        p_column = 0
        p_errcnt = l_errcnt
        p_kind = 'E'
        p_test = my_name
        p_code = '9050'
        p_suppress = '"#EC CHANGe SaP'
        p_param_1 = space
        p_param_2 = space
        ) .
 
    ENDIF                                                           .
 
  ENDIF                                                             .
 


*_____________________________________________________________________*
 
  LOOP AT ref_scan->statements INTO statement_wa                      .
 
    LOOP AT ref_scan->tokens INTO token_wa
              FROM statement_wa-from TO statement_wa-to
                            WHERE str EQ 'DATA'
                               OR str EQ 'CONSTANTS'
                               OR str EQ 'RANGES'
                               OR str EQ 'TYPES'
                               OR str EQ 'PARAMETERS'
                               OR str EQ 'SELECT-OPTIONS'             .
 
      l_tabix   =   sy-tabix                                          .
      l_keyword =   token_wa-str                                      .
      IF token_wa-str EQ 'PARAMETERS'                                 .
 
        addtabixx                                                     .
        READ TABLE ref_scan->tokens INTO token_wa INDEX l_tabix       .
        addtabixx                                                     .
        READ TABLE ref_scan->tokens INTO token_wa_tmp INDEX l_tabix   .
        IF token_wa_tmp-str = 'AS'                                    .
          addtabixx                                                   .
          READ TABLE ref_scan->tokens INTO token_wa_tmp INDEX l_tabix .
          IF token_wa_tmp-str EQ 'CHECKBOX'                           .
            l_keyword = 'CHECKBOX'                                    .
          ENDIF                                                       .
        ELSE                                                          .
          IF token_wa_tmp-str EQ 'RADIOBUTTON'                        .
            l_keyword = 'RADIOBUTTON'                                 .
          ENDIF                                                       .
        ENDIF                                                         .
      ELSE                                                            .
 
        IF token_wa-str EQ 'DATA' OR token_wa-str EQ 'TYPES'          .
          CALL METHOD me->data_check_begin_end
            CHANGING
              l_begin = l_begin
              l_tabix = l_tabix.
        ENDIF                                                         .
        IF token_wa-str EQ 'DATA' OR token_wa-str EQ 'TYPES'          .
 
          CALL METHOD me->data_check_begin_end
            CHANGING
              l_begin = l_begin
              l_tabix = l_tabix.
 
        ENDIF                                                         .
        CHECK l_begin NE 'X'                                          .
        addtabixx                                                     .
        READ TABLE ref_scan->tokens INTO token_wa INDEX l_tabix       .
        CHECK sy-subrc EQ 0                                           .
        IF l_keyword EQ  'DATA'                                       .
          temp_token = token_wa-str.
          CALL METHOD data_get_data_type
            EXPORTING
              str       = temp_token
            CHANGING
              l_keyword = l_keyword.
 
        ENDIF                                                         .
 
      ENDIF                                                           .
      LOOP AT it_prefix INTO l_prefix WHERE keyword CP l_keyword      .
 
        l_len = STRLEN( l_prefix-prefixvalue )                        .
        IF l_prefix-prefixvalue EQ token_wa-str+0(l_len)              .
          CLEAR l_msg                                                 .
          EXIT                                                        .
        ELSE                                                          .
 
          l_object_name = get_include( )                              .
          l_errcnt      = l_errcnt + 1                                .
          CALL METHOD inform(
            p_sub_obj_type = c_type_include
            p_sub_obj_name = l_object_name
            p_line = token_wa-row
            p_column = token_wa-col
            p_errcnt = l_errcnt
            p_kind = 'E'
            p_test = my_name
            p_code = '0009'
            p_suppress = '"#EC CHANGe SaP'
            p_param_1 = token_wa-str
            p_param_2 = l_prefix-prefixvalue
            p_param_3 = l_keyword
            ) .
 
        ENDIF                                                         .
 
      ENDLOOP                                                         .
 
    ENDLOOP                                                           .
 
  ENDLOOP                                                             .
 
*_____________________________________________________________________*
 
  LOOP AT ref_scan->statements INTO statement_wa                      .
 
    CLEAR :expectedon,flag,wrongline,col,on                           .
    LOOP AT ref_scan->tokens INTO token_wa
            FROM statement_wa-from TO statement_wa-to                 .
 
      CLEAR col                                                       .
      g_big = STRLEN( token_wa-str ).
      IF g_big GE 5.
       IF token_wa-str(5) EQ 'TEXT-'                                   .
          temp_token = token_wa-str.
 
          CALL METHOD me->keyword
            RECEIVING
              p_result = p_keyword.
         IF p_keyword NE 'SELECTION-SCREEN'                            .
 
           l_object_name = get_include( )                              .
           l_errcnt      = l_errcnt + 1                                .
 
 
 
            CALL METHOD inform(
                    p_sub_obj_type = c_type_include
                    p_sub_obj_name = l_object_name
                    p_line         = token_wa-row
                    p_column       = token_wa-col
                    p_errcnt       = l_errcnt
                    p_kind         = 'W'
                    p_test         = my_name
                    p_code         = '0018'
                    p_suppress     = '"#EC CHANGe SaP'
                    p_param_1      = temp_token
                    p_param_2      = temp_token+5
*                    p_param_2      = token_wa-str
                   )                                                   .
 
         ENDIF                                                         .
 
       ENDIF                                                           .
      ENDIF.
      IF token_wa-str EQ 'MOVE-CORRESPONDING'                         .
 
        l_object_name = get_include( )                                .
        l_errcnt      = l_errcnt + 1                                  .
        CALL METHOD inform(
          p_sub_obj_type = c_type_include
          p_sub_obj_name = l_object_name
          p_line = token_wa-row
          p_column = token_wa-col
          p_errcnt = l_errcnt
          p_kind = 'W'
          p_test = my_name
          p_code = '0050'
          p_suppress = '"#EC CHANGe SaP'
          p_param_1 = token_wa-str
          p_param_2 = space
          ) .
 
      ENDIF                                                           .
 
    ENDLOOP                                                           .
    IF flag EQ 'X'                                                    .
 
      l_object_name = get_include( )                                  .
      l_column      = token_wa-col                                    .
      l_errcnt      =  l_errcnt + 1                                   .
      LOOP AT ref_scan->tokens INTO token_wa
         FROM statement_wa-from TO statement_wa-to                    .
 
        CONCATENATE l_msg  token_wa-str INTO l_msg SEPARATED BY space .
*TBD
*temp_token = token_wa-stokex..
*       wa_zci-stokex   = token_wa
        wa_zci-programm = l_object_name                               .
        wa_zci-sstmnt   = statement_wa                                .
        APPEND wa_zci TO zci                                          .
 
      ENDLOOP                                                         .
 
    ENDIF                                                             .
 
  ENDLOOP                                                             .
 
*_____________________________________________________________________*


  LOOP AT ref_scan->statements INTO statement_wa                      .
 
    LOOP AT ref_scan->tokens INTO token_wa
              FROM statement_wa-from TO statement_wa-to
                            WHERE str EQ 'READ'.
          CALL METHOD me->keyword
            RECEIVING
              p_result = p_keyword.
 
    ENDLOOP.
  ENDLOOP.
 
 
 
*  CALL METHOD me->data_show
*    EXPORTING
*      zci = zci.



c)

GET

Instance Method

Protected

Specify Test Basis


Source Code

data:
    L_OBJECT_NAME type SOBJ_NAME,
    L_INCLUDE     type SOBJ_NAME,
    L_ERRCNT      type SCI_ERRCNT,
    L_ROW       type SCIR_SELCT-ROW,
    L_COL       type SCIR_SELCT-COL.

  if REF_INCLUDE is initial.
    check SUPER->GET( ) = 'X'.
  endif.
 
  check REF_INCLUDE->SUBRC = 0.
 
  if REF_SCAN is initial.
    create object REF_SCAN exporting P_INCLUDE = REF_INCLUDE.
  else.
    if REF_SCAN->SUBRC = 0.
      P_RESULT = 'X'.
    endif.
    return.
  endif.
 
  if REF_SCAN->SUBRC <> 0.
 
    L_OBJECT_NAME = REF_SCAN->INCLUDE.
 
*-- Include could be missing !
    if not L_OBJECT_NAME is initial.
      L_ERRCNT = L_ERRCNT + 1.
      read table SCIMESSAGES into SMSG
                        with table key TEST = MY_NAME
                                       CODE = '0010'.
      raise event MESSAGE
            exporting P_SUB_OBJ_TYPE = C_TYPE_INCLUDE
                      P_SUB_OBJ_NAME = L_OBJECT_NAME
                      P_LINE         = REF_SCAN->LINE
                      P_COLUMN       = 0
                      P_ERRCNT       = L_ERRCNT
                      P_KIND         = C_ERROR           "SMSG-KIND
                      P_TEST         = MY_NAME
                      P_CODE         = '0010'
                      P_SUPPRESS     = ' '
                      P_PARAM_1      = REF_SCAN->MESSAGE.
    else.
*-- Missing Include
      loop at REF_SCAN->STATEMENTS into STATEMENT_WA where TYPE = 'J'.
*-- J = INCLUDE prog does not exist
        L_INCLUDE = GET_INCLUDE( ).
        L_OBJECT_NAME = GET_TOKEN_ABS( P_N = STATEMENT_WA-TO ).
        GET_LINE_COLUMN_ABS( exporting P_N = STATEMENT_WA-TO
                             importing P_LINE   = L_ROW
                                       P_COLUMN = L_COL ).

        L_ERRCNT = L_ERRCNT + 1.
        read table SCIMESSAGES into SMSG with table key TEST = MY_NAME
                                                        CODE = '0011'.
        raise event MESSAGE
              exporting P_SUB_OBJ_TYPE = C_TYPE_INCLUDE
                        P_SUB_OBJ_NAME = L_INCLUDE
                        P_LINE         = L_ROW
                        P_COLUMN       = L_COL
                        P_ERRCNT       = L_ERRCNT
                        P_KIND         = C_ERROR        "SMSG-KIND
                        P_TEST         = MY_NAME
                        P_CODE         = '0011'
                        P_SUPPRESS     = ' '
                        P_PARAM_1      = L_OBJECT_NAME.
      endloop.
    endif.
*--    clear ref_scan.
  else.
    P_RESULT = 'X'.
  endif.



d)

CONSTRUCTOR

Instance Method

Public

Constructor


Source Code

call method  super->constructor( ).
  description = XYZ Company Checks'(6a2).
VERSION     = '000'.
 
    category    = 'ZCL_CI_CATEGORY_CONVENTIONS'.

*  category = '<ROOT>'.
*  category    = 'ZCL_CI_TEST_CHANGE'.
*  category    = 'CL_CI_CATEGORY_SLIN'.
 
  position    = '010'.
 
*  define FILL_MESSAGE.
*    clear SMSG.
*    SMSG-TEST = MY_NAME.
*    SMSG-CODE = &1.  "message code
*    SMSG-KIND = &2.  "message priority
*    SMSG-TEXT = &3.  "message text
*    SMSG-PCOM = &4.  "pseudocomment
*    INSERT SMSG INTO TABLE SCIMESSAGES.
*  end-of-definition.
*
**-------------------------Error when scanning: &1
*  FILL_MESSAGE '0010' 'E' text-110 ' '.
*
**-------------------------Missing Include: &1
*  FILL_MESSAGE '0011' 'E' text-111 ' '.



e)

 
GET

Instance Method

Protected

Specify Test Basis


Source Code

data:
    L_OBJECT_NAME type SOBJ_NAME,
    L_INCLUDE     type SOBJ_NAME,
    L_ERRCNT      type SCI_ERRCNT,
    L_ROW       type SCIR_SELCT-ROW,
    L_COL       type SCIR_SELCT-COL.
 
  if REF_INCLUDE is initial.
    check SUPER->GET( ) = 'X'.
  endif.
 
  check REF_INCLUDE->SUBRC = 0.
 
  if REF_SCAN is initial.
    create object REF_SCAN exporting P_INCLUDE = REF_INCLUDE.
  else.
    if REF_SCAN->SUBRC = 0.
      P_RESULT = 'X'.
    endif.
    return.
  endif.
 
  if REF_SCAN->SUBRC <> 0.
 
    L_OBJECT_NAME = REF_SCAN->INCLUDE.
 
*-- Include could be missing !
    if not L_OBJECT_NAME is initial.
      L_ERRCNT = L_ERRCNT + 1.
      read table SCIMESSAGES into SMSG
                        with table key TEST = MY_NAME
                                       CODE = '0010'.
      raise event MESSAGE
            exporting P_SUB_OBJ_TYPE = C_TYPE_INCLUDE
                      P_SUB_OBJ_NAME = L_OBJECT_NAME
                      P_LINE         = REF_SCAN->LINE
                      P_COLUMN       = 0
                      P_ERRCNT       = L_ERRCNT
                      P_KIND         = C_ERROR           "SMSG-KIND
                      P_TEST         = MY_NAME
                      P_CODE         = '0010'
                      P_SUPPRESS     = ' '
                      P_PARAM_1      = REF_SCAN->MESSAGE.
    else.
*-- Missing Include
      loop at REF_SCAN->STATEMENTS into STATEMENT_WA where TYPE = 'J'.
*-- J = INCLUDE prog does not exist
        L_INCLUDE = GET_INCLUDE( ).
        L_OBJECT_NAME = GET_TOKEN_ABS( P_N = STATEMENT_WA-TO ).
        GET_LINE_COLUMN_ABS( exporting P_N = STATEMENT_WA-TO
                             importing P_LINE   = L_ROW
                                       P_COLUMN = L_COL ).
 
        L_ERRCNT = L_ERRCNT + 1.
        read table SCIMESSAGES into SMSG with table key TEST = MY_NAME
                                                        CODE = '0011'.
        raise event MESSAGE
              exporting P_SUB_OBJ_TYPE = C_TYPE_INCLUDE
                        P_SUB_OBJ_NAME = L_INCLUDE
                        P_LINE         = L_ROW
                        P_COLUMN       = L_COL
                        P_ERRCNT       = L_ERRCNT
                        P_KIND         = C_ERROR        "SMSG-KIND
                        P_TEST         = MY_NAME
                        P_CODE         = '0011'
                        P_SUPPRESS     = ' '
                        P_PARAM_1      = L_OBJECT_NAME.
      endloop.
    endif.
*--    clear ref_scan.
  else.
    P_RESULT = 'X'.
  endif.



f)

ANALYSE

Instance Method

Protected

Analysis of Token       A+B(C)




Source Code

data:
    L_LENGTH type I,
    L_POS    type I.
 
  field-symbols <L_FS> type CLIKE.
  search P_TOKEN for '+'.
  if SY-SUBRC = 0.
    if SY-FDPOS > 0.
      P_A = P_TOKEN(SY-FDPOS).
    else.
      P_A = SPACE.
    endif.
    L_POS = SY-FDPOS + 1.
    search P_TOKEN+L_POS(star)
for '('.
    if SY-SUBRC = 0.
      if SY-FDPOS > 0.
        P_B = <L_FS>+L_POS(SY-FDPOS).
      else.
        P_B = SPACE.
      endif.
      add 1 to SY-FDPOS.
      describe field <L_FS> length L_LENGTH in character mode.
      L_LENGTH = L_LENGTH - SY-FDPOS - 2.
      if L_LENGTH > 0.
        P_C = <L_FS>+SY-FDPOS(L_LENGTH).
      endif.
    else.
      P_C = SPACE.
    endif.
  else.
    P_B = SPACE.
    search P_TOKEN for '('.
    if SY-SUBRC = 0.
      if SY-FDPOS > 0.
        P_A = P_TOKEN(SY-FDPOS).
      else.
        P_A = SPACE.
      endif.
      add 1 to SY-FDPOS.
      L_LENGTH = STRLEN( P_TOKEN ).
      L_LENGTH = L_LENGTH - SY-FDPOS - 1.
      if L_LENGTH > 0.
        P_C = P_TOKEN+SY-FDPOS(L_LENGTH).
      else.
        P_C = SPACE.
      endif.
    else.
      P_A = P_TOKEN.
      P_C = SPACE.
    endif.
  endif.


E)    We have to make some changes in Visibility of the METHODs:

Ø     Public

public

  inheriting from CL_CI_TEST_INCLUDE

  create public .

*"* public components of class ZCL_CI_TEST_SCAN

*"* do not include other source files here!!!

public section.

  class-methods CLASS_CONSTRUCTOR .

  methods CONSTRUCTOR .

  methods CLEAR

    redefinition .

  methods GET_ATTRIBUTES

    redefinition .

  methods GET_MESSAGE_TEXT

    redefinition .

  methods RUN
Ø     Private

private section.

  constants MY_NAME type SEOCLSNAME value 'ZCL_CI_TEST_SCAN'. "#EC NOTEXT

  data:

    IT_RDATA TYPE TABLE OF RDATA .

  data:

    IT_RSYMB TYPE TABLE OF RSYMB .

  methods DATA_PREFIX

    exporting

      !IT_PREFIX type TABLE .

  methods DATA_CHECK_BEGIN_END

    changing

      !L_BEGIN type CHAR1

      !L_TABIX type SY-TABIX .

  methods DATA_GET_DATA_TYPE

    importing

      value(STR) type SYCHAR30

    changing

      !L_KEYWORD type ZPREFIX-KEYWORD .

  methods DATA_SHOW

    importing

      !ZCI type ZCI .
 

F)  IN Attributes replace C_MY_NAME with MY_NAME as

Attribute

Level

Visibility

Associated Type

Initial Value

MY_NAME

Constant 

   Private

SEOCLSNAME

'ZCL_CI_TEST_SCAN'


                                                               

           And create two new entries as

Attribute

Level

Visibility

IT_RDATA

Instance Attribute

Private

IT_RSYMB

Instance Attribute

Private


  

3.    Creating a new check ZCL_CI_TEST_IMUD_TAW_A    (Tcode-SE24)

A) Copy CL_CI_TEST_IMUD_TAW_A to ZCL_CI_TEST_IMUD_TAW_A.

B) Select the package in the popup (e.g.: $TMP)

C) We have to redefine  some of the existing methods:

Analyze

Level

Visibility

Description


CONSTRUCTOR

Instance Method

Public  

Constructor


data:
    l_name like line of glob_data_ids.

  CALL METHOD super->constructor( ).
  description = 'Check if SAP Standard tables are being IMUD'.
 
  category    = 'ZCL_CI_CATEGORY_CONVENTIONS'.
  position    = '020'.
  version     = '000'.
  CALL METHOD add_obj_type( c_type_program ).
  has_attributes = c_true.
*  pa_nofield  = c_true.
*  pa_nofirst  = c_true.
*  pa_noclient = c_true.
 
  attributes_ok  = c_true.

*  define fill_name.
*    l_name-sign   = &1.
*    l_name-option = &2.
*    l_name-low    = &3.
*    l_name-high   = space.
*    append l_name to &4.
*  end-of-definition.
*
*  fill_name 'I' 'CP' 'T_*'  glob_data_ids.
 
    l_name-sign   = 'I'.
    l_name-option = 'CP'.
    l_name-low    = 'Y*'.
    l_name-high   = space.
    append l_name to glob_data_ids.
 
    l_name-sign   = 'I'.
    l_name-option = 'CP'.
    l_name-low    = 'Z*'.
    l_name-high   = space.
    append l_name to glob_data_ids.

*    l_name-sign   = &1.
*    l_name-option = &2.
*    l_name-low    = &3.
*    l_name-high   = space.
*    append l_name to &4.



d) We have to make some changes in Visibility of the methods:

Ø     Public

class ZCL_CI_TEST_IMUD_TAW_A definition

  public

  inheriting from CL_CI_TEST_IMUD_TAW

  create public .

*"* public components of class ZCL_CI_TEST_IMUD_TAW_A

*"* do not include other source files here!!!

public section.

  methods CONSTRUCTOR .

  methods GET_ATTRIBUTES

    redefinition .

  methods IF_CI_TEST~QUERY_ATTRIBUTES

    redefinition .

  methods PUT_ATTRIBUTES

    redefinition .

  methods RUN

    redefinition .

  methods GET_MESSAGE_TEXT

    redefinition .


 

Ø     Private

private section.

  constants MY_NAME type SEOCLSNAME value 'ZCL_CI_TEST_IMUD_TAW_A'. "#EC NOTEXT

  data GLOB_DATA_IDS type SCIR_ABAPID .


 

E)    IN Attributes delete following attributes:

PA_NOWHERE

PA_NOFIRST

PA_NOFIELD

PA_NOCLIENT

C_MY_NAME

And create two new entries as:

Attribute

Level

Visibility

Associated type

Description

MY_NAME

Constant

Private

SEOCLSNAME

 

GLOB_DATA_IDS

Instance Attribute

Private

SCIR_ABAPID

Range of SCI_ABAPID


Before the creation of all above said classes we need to create some objects as following:

4) Create structure - ZSCI_SELECT

Component

Component Type

Data Type

Length

Deci

Short Text

PROGRAMM

PROGRAMM

CHAR

40

0

ABAP Program Name

SSTMNT

SSTMNT


0

0

Description of an ABAP/4 source analysis statement

STOKEX

STOKEX


0

0

Extended description of an ABAP/4 source analysis token



5)   Create table type ZCI -line type - ZSCI_SELECT

6)   Create Function group - ZASDINSPPECTOR

    Short text --Code Inspector

7)   Create Function Module - Z_ASD_INSPECTOR

A) Function Group- ZASDINSPECTOR

B) Attributes as Code Inspector: Select

C) In Changing add parameters as:

Parameters Name

Type Spec.

Associated Type

Short Text

ZCI

TYPE

ZCI

Code Inspector select clause


D) In Source Code add the following code:

FUNCTION z_asd_inspector.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      ZCI TYPE  ZCI
*"----------------------------------------------------------------------
 
  PERFORM init.
  LOOP AT zci.
 
    AT NEW programm.
 
    ENDAT.
    tabix = tabix + 1.
    IF temp_row = 0.
 
      temp_row = zci-stokex-row.
 
    ENDIF.
    wa_source+zci-stokex-col(zci-stokex-len) =  zci-stokex-str .
    temp_row = tabix + 1.
    READ TABLE zci INDEX temp_row INTO wa_zci ."TRANSPORTING
    IF wa_zci-stokex-row GT zci-stokex-row OR sy-subrc NE 0.
 
      APPEND wa_source TO  source.
      CLEAR  wa_source .
 
    ENDIF.
    IF g_from GT zci-stokex-row OR  g_from EQ 0.
 
      g_from = zci-stokex-row.
 
    ENDIF.
    IF g_to LE zci-stokex-row OR  g_from EQ 0.
 
      g_to = zci-stokex-row.
 
    ENDIF.
    CASE zci-stokex-str.
 
      WHEN 'SELECT'  .      wa_source1+2 =  zci-stokex-str .
      WHEN 'FROM'    .      wa_source1+4 =  zci-stokex-str .
      WHEN 'INTO'    .      wa_source1+4 =  zci-stokex-str .
      WHEN 'WHERE'   .      wa_source1+3 =  zci-stokex-str .
      WHEN 'INNER'   .      wa_source1+3 =  zci-stokex-str .
      WHEN 'UP'      .      wa_source1+3 =  zci-stokex-str .
      WHEN 'AND'     .      wa_source1+5 =  zci-stokex-str .
      WHEN 'OR'      .      wa_source1+6 =  zci-stokex-str .
      WHEN 'ON'      .      wa_source1+6 =  zci-stokex-str .
      WHEN 'FOR'     .      wa_source1+5 =  zci-stokex-str .
      WHEN OTHERS.
        IF zci-stokex-str = '='.
 
          zci-stokex-str = 'EQ'.
 
        ENDIF.
        IF zci-stokex-str = '<>'.
 
          zci-stokex-str = 'NE'.
 
        ENDIF.
        IF zci-stokex-str = '<'.
 
          zci-stokex-str = 'LT'.
 
        ENDIF.
        IF zci-stokex-str = '>'.
 
          zci-stokex-str = 'GT'.
 
        ENDIF.
        len1 = STRLEN( wa_source1 ).
        len2 = STRLEN( zci-stokex-str ).
        len1 = len1 + len2.
        IF len1 LE 72.
 
          IF NOT leftover IS INITIAL.
 
            CONCATENATE leftover wa_source1 zci-stokex-str
                   INTO wa_source1 SEPARATED BY space.
          ELSE.
 
            CONCATENATE  wa_source1 zci-stokex-str
                   INTO wa_source1 SEPARATED BY space.
 
          ENDIF.
          CLEAR leftover.
        ELSE.
 
          APPEND wa_source1 TO  source1.
          CLEAR  wa_source1 .
          leftover+9 = zci-stokex-str.
 
        ENDIF.
 
    ENDCASE.
    temp_row = tabix + 1.
    READ TABLE zci INDEX temp_row INTO wa_zci .
    IF wa_zci-stokex-str EQ 'FROM'
    OR wa_zci-stokex-str EQ 'INTO'
    OR wa_zci-stokex-str EQ 'WHERE'
    OR wa_zci-stokex-str EQ 'UP'
    OR wa_zci-stokex-str EQ 'FOR'
    OR wa_zci-stokex-str EQ 'INNER'
    OR wa_zci-stokex-str EQ 'AND'
    OR wa_zci-stokex-str EQ 'OR'
    OR wa_zci-stokex-str EQ 'ON'
    OR wa_zci-sstmnt-to GT zci-sstmnt-to
    OR sy-subrc NE 0.
 
      APPEND wa_source1 TO  source1.
      CLEAR  wa_source1 .
 
    ENDIF.
    AT END OF sstmnt-to .
      CALL SCREEN 100.
      IF sy-ucomm EQ 'REJL'.
 
        EXIT.
 
      ENDIF.
      temp_row = 0.
      CLEAR :g_from,g_to.
      REFRESH : source,source1.
    ENDAT.
    AT END OF programm.
      LOOP AT sourcemain.
 
        sourcemain-no = sy-tabix.
        MODIFY sourcemain.
 
      ENDLOOP.
      LOOP AT sourcemain.
 
        IF sourcemain-no LE sourceinsert-to.
          CONTINUE.
 
        ENDIF.
        LOOP AT sourceinsert WHERE from LE sourcemain-no
                               AND to GE sourcemain-no.
 
          sourcefinal-line = sourceinsert-line.
          APPEND sourcefinal.CLEAR sourcefinal.
 
        ENDLOOP.
        IF sy-subrc NE 0.
 
          sourcefinal-line = sourcemain-line.
          APPEND sourcefinal.CLEAR sourcefinal.
 
        ENDIF.
 
      ENDLOOP.
      CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
        EXPORTING
          textline1 = 'Transfer suggestion to Program?'
          titel     = 'XYZ Company:Code Inspector'
        IMPORTING
          answer    = ans.
      IF ans EQ 'J'.
 
*        INSERT REPORT zci-programm FROM sourcefinal.
        REFRESH sourcefinal.
 
      ENDIF.
    ENDAT.
 
  ENDLOOP.
 
ENDFUNCTION.


8)    Create Table ZPREFIX:

Fields

Data Type

Length

Short Text

KEYWORD

CHAR

30

ABAP Keyword

PREFIXVALUE

CHAR

5

Prefix value of Object name




 Maintain the table with following data:


KEYWORD

PREFIXVALUE

1.

CHECKBOX

CB_

2

CONSTANTS

C_

3

INTERNAL_TABLE

IT_

4

PARAMETERS

P_

5

RADIOBUTTON

RB_

6

RANGES

R_

7

SELECT-OPTIONS

S_

8

STRUCTURE

Gs_

9

TYPES

T_


9)   Activate new categories and checks


Start transaction SCI. Navigate to Goto-> Test Administration in the menu. Set the flag for the new category and check in order to make them available in the framework.

Now the new created check can be tested in transaction SCII.

1 Comment

  1. I saw this pice of code..after a long time....i forgot it.....

    Thanks Craig Cmehil for editing.