Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7185463
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2007-06-04 20:27:42

*&---------------------------------------------------------------------*
*& Report  Z_BARRY_SEARCH_ABAP_STRING                                  *
*& Scan a set of reports for a particular string                       *
*&---------------------------------------------------------------------*
*&  Ver 1.1 2007.06.04                                                 *
*&---------------------------------------------------------------------*
REPORT ZRS08127 MESSAGE-ID 56  NO STANDARD PAGE HEADING LINE-SIZE 150.
TABLES: d020s,
        tadir,
        trdir,
        tuchk3,
        rsrepl.
TYPES:  BEGIN OF result_ln,
          repname LIKE sy-repid,
          dynnr   LIKE sy-dynnr,
          line_no(6) TYPE n,
*         text    like rstxp-tdline,
          text TYPE string,
          sstring ,
          del_flag,
       END OF result_ln,
       result_tab TYPE result_ln OCCURS 0.
DATA: disptype   VALUE 'A',
      dtab       TYPE result_tab WITH HEADER LINE,
      ftab       TYPE result_tab WITH HEADER LINE,
      hit_count  TYPE i,
      tabix      LIKE sy-tabix,
*     text_line  like rstxp-tdline,
      text_line  TYPE string,
      top_flag.
DATA: BEGIN OF dyn OCCURS 0,
        prog  LIKE d020s-prog,
        dnum  LIKE d020s-dnum,
      END OF dyn,
      BEGIN OF fm OCCURS 0,
        obj_name LIKE tadir-obj_name,
      END OF fm,
      BEGIN OF irdir OCCURS 50,
        name LIKE trdir-name,
      END OF irdir,
      BEGIN OF itab OCCURS 50,
        repname LIKE sy-repid,
      END OF itab,
      itab_ii LIKE itab OCCURS 50 WITH HEADER LINE,
     BEGIN OF rtab OCCURS 0,
*      text like rpy_dyflow-line,
       text(1000),
     END OF rtab,
     rtab_lcase LIKE LINE OF rtab,
     rtab_tmp   LIKE LINE OF rtab.
SELECTION-SCREEN: BEGIN OF BLOCK a10 WITH FRAME TITLE a10.
SELECT-OPTIONS:   repname  FOR trdir-name MEMORY ID scan_repid OBLIGATORY,
                  dynnr    FOR d020s-dnum,
                  subc     FOR trdir-subc,
                  appl     FOR trdir-appl,
                  cnam     FOR trdir-cnam,
                  unam     FOR trdir-unam,
                  devclass FOR tadir-devclass.
SELECTION-SCREEN: END OF BLOCK a10,
                  BEGIN OF BLOCK a20 WITH FRAME TITLE a20.
*SELECT-OPTIONS:   sstring     FOR tuchk3-object NO INTERVALS.
SELECT-OPTIONS:   sstring     FOR rsrepl-tdfind NO INTERVALS OBLIGATORY.
PARAMETERS:       plusminu(2) TYPE n DEFAULT 2,
                  inclu       AS CHECKBOX DEFAULT 'X',
                  modiass     AS CHECKBOX,
                  comment     AS CHECKBOX,
                  mask        AS CHECKBOX.
SELECTION-SCREEN: END OF BLOCK a20,
                  BEGIN OF BLOCK a30 WITH FRAME TITLE a30.
PARAMETERS:       rb_code  RADIOBUTTON GROUP r10,
                  rb_dyn   RADIOBUTTON GROUP r10,
                  rb_all   RADIOBUTTON GROUP r10.
SELECTION-SCREEN: END OF BLOCK a30.
DATA: string LIKE sstring-low.
INITIALIZATION.
  a10 = '报表/屏幕选择'.
  a20 = '搜索标准'.
  a30 = '搜索区域'.
TOP-OF-PAGE.
  PERFORM top_of_page.
TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM top_of_page.
START-OF-SELECTION.
  IF NOT modiass IS INITIAL.
    sstring-sign    = 'I'.
    sstring-option  = 'EQ'.
    sstring-low     = '{'.
    APPEND sstring.
    sstring-low     = '}'.
    APPEND sstring.
  ENDIF.
  READ TABLE sstring INDEX 1.
  DESCRIBE TABLE sstring LINES sy-tfill.
  IF sy-tfill = 1.
    string = sstring-low.
  ELSE.
    CONCATENATE sstring-low
               '...'
                INTO string SEPARATED BY space.
  ENDIF.
  SET PF-STATUS 'MAIN'.
  IF NOT devclass[] IS INITIAL.
    SELECT obj_name INTO TABLE irdir
      FROM tadir
      WHERE pgmid  = 'R3TR'
      AND   object = 'PROG'
      AND   devclass IN devclass .

    SELECT obj_name INTO TABLE fm
      FROM tadir
      WHERE pgmid  = 'R3TR'
      AND   object = 'FUGR'
      AND   devclass IN devclass.
    LOOP AT fm.
      CONCATENATE 'SAPL' fm-obj_name INTO irdir.
      APPEND irdir.
    ENDLOOP.
  ENDIF.
  IF NOT repname[] IS INITIAL.
    SELECT name APPENDING TABLE irdir
      FROM trdir
      WHERE name IN repname
      AND   cnam IN cnam
      AND   unam IN unam
      AND   subc IN subc
      AND   appl IN appl.
  ENDIF.
  CHECK NOT irdir[] IS INITIAL.
  IF rb_code IS INITIAL.
*   Also scan dynpro flow logic
    SELECT prog dnum INTO TABLE dyn
      FROM d020s FOR ALL ENTRIES IN irdir
      WHERE prog = irdir-name
      AND   dnum IN dynnr.
  ENDIF.
  IF NOT inclu IS INITIAL.
    LOOP AT irdir.
      REFRESH itab_ii.
      CALL FUNCTION 'GET_INCLUDES'
        EXPORTING
          progname = irdir-name
        TABLES
          incltab  = itab_ii.
      APPEND LINES OF itab_ii TO itab.
    ENDLOOP.
  ENDIF.
  APPEND LINES OF irdir TO itab.
  SORT itab.
  DELETE ADJACENT DUPLICATES FROM itab.
  IF rb_dyn IS INITIAL.
    LOOP AT itab.
      READ REPORT itab-repname INTO rtab.
      CHECK sy-subrc = 0.
*      IF NOT comment IS INITIAL.
*        DELETE rtab
*          WHERE text(1) = '*'.
*      ENDIF.
      LOOP AT sstring.
        IF mask IS INITIAL.
          SEARCH rtab FOR sstring-low.
          CHECK sy-subrc = 0.
        ELSE.
          sy-tabix = 1.
        ENDIF.
        LOOP AT rtab FROM sy-tabix.
          tabix      = sy-tabix.
          rtab_lcase = rtab.
          TRANSLATE rtab TO UPPER CASE.
          CASE mask.
            WHEN space.
              IF rtab-text CS sstring-low.
                PERFORM: get_hit_set USING rtab_lcase tabix space.
              ENDIF.
            WHEN OTHERS.
              IF rtab-text CP sstring-low.
                PERFORM: get_hit_set USING rtab_lcase tabix space.
              ENDIF.
          ENDCASE.
        ENDLOOP.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
  FREE: itab.
  IF rb_code IS INITIAL.
    LOOP AT dyn.
      PERFORM get_dynpro_flow_logic.
*      IF NOT comment IS INITIAL.
*        DELETE rtab
*          WHERE text(1) = '*'.
*      ENDIF.
      LOOP AT sstring.
        IF mask IS INITIAL.
          SEARCH rtab FOR sstring-low.
          CHECK sy-subrc = 0.
        ELSE.
          sy-tabix = 1.
        ENDIF.
        LOOP AT rtab FROM sy-tabix.
          tabix      = sy-tabix.
          rtab_lcase = rtab.
          TRANSLATE rtab TO UPPER CASE.
          CASE mask.
            WHEN space.
              IF rtab-text CS sstring-low.
                PERFORM: get_hit_set USING rtab_lcase tabix 'D'.
              ENDIF.
            WHEN OTHERS.
              IF rtab-text CP sstring-low.
                PERFORM: get_hit_set USING rtab_lcase tabix 'D'.
              ENDIF.
          ENDCASE.
        ENDLOOP.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
  FREE: dyn.
END-OF-SELECTION.
  IF ftab[] IS INITIAL AND dtab[] IS INITIAL.
    MESSAGE s016 WITH '字符串' string '未找到'.
    EXIT.
  ENDIF.
  SORT: ftab BY repname line_no sstring DESCENDING,
        dtab BY repname dynnr line_no sstring DESCENDING.
  DELETE ADJACENT DUPLICATES FROM: ftab COMPARING repname line_no,
                                   dtab COMPARING repname dynnr line_no.
  MESSAGE s016 WITH hit_count '命中字符串' string.
  PERFORM: display_ftab_alt,
           display_dtab_alt.
AT LINE-SELECTION.
  PERFORM call_editor.
AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'TOGL'.
      CASE disptype.
        WHEN 'M' OR 'L'.
          disptype = 'A'.
          PERFORM: display_ftab_alt,
                   display_dtab_alt.
        WHEN 'A' OR 'L'.
          disptype = 'M'.
          PERFORM: display_ftab,
                   display_dtab.
      ENDCASE.
      sy-lsind = sy-lsind - 1.
    WHEN 'REPT'.
      PERFORM: display_rep_list.
      sy-lsind = sy-lsind - 1.
    WHEN 'DOWN'.
      PERFORM download_list.
    WHEN 'EXIT'.
      LEAVE SCREEN.
  ENDCASE.
*---------------------------------------------------------------------*
*       FORM APPEND_FTAB                                              *
*---------------------------------------------------------------------*
FORM append_ftab USING text    LIKE rtab_lcase
                       line_no LIKE sy-tabix
                       sstring TYPE c
                       source  TYPE c.
  DATA: ln TYPE result_ln.
  ln-line_no = line_no.
  ln-text    = text.
  ln-sstring = sstring.
  IF source IS INITIAL.
    ln-repname = itab-repname.
    APPEND ln TO ftab.
  ELSE.
    ln-repname = dyn-prog.
    ln-dynnr   = dyn-dnum.
    APPEND ln TO dtab.
    CLEAR: ln-dynnr.
  ENDIF.
  IF NOT ln-sstring IS INITIAL.
    ADD 1 TO hit_count.
  ENDIF.
ENDFORM.                    "append_ftab
*---------------------------------------------------------------------*
*       FORM TOP_OF_PAGE                                              *
*---------------------------------------------------------------------*
FORM top_of_page.
  DATA: repname(50).
  DATA: title LIKE trdirt-text .
  FORMAT INTENSIFIED OFF.
  ULINE /(150).
  WRITE: /  sy-vline,
           '源扫描字符串:',
            string  COLOR COL_NEGATIVE INVERSE,
        78 '日期:',
            sy-datum DD/MM/YYYY,
        96  '时间:',
            sy-uzeit,
      150   sy-vline.
  ULINE /(150).
  FORMAT INTENSIFIED ON.
  WRITE: / sy-vline.
  IF top_flag = 'A'.
    repname = ftab-repname.
    CLEAR title.
    SELECT SINGLE text INTO title FROM trdirt
                       WHERE name = repname AND sprsl = sy-langu.
  ELSEIF top_flag = 'D' .
    CONCATENATE dtab-repname
               '屏幕'
                dtab-dynnr
                INTO repname SEPARATED BY space.
  ENDIF.
  CASE disptype.
    WHEN 'A'.
      CONCATENATE '行     源代码 ['
                   repname
                   ']' '    程序描述 [' title ']' INTO text_line.
      WRITE: text_line.
    WHEN 'M'.
      IF top_flag = 'A'.
        WRITE: '源代码', 102 '行     报表'.
      ELSE.
        WRITE: '源代码', 102 '行     屏幕'.
      ENDIF.
    WHEN 'L'.
      WRITE '程序列表'.
  ENDCASE.
  WRITE: 150 sy-vline.
  ULINE (150).
ENDFORM.                    "top_of_page
*---------------------------------------------------------------------*
*       FORM DISPLAY_FTAB                                             *
*---------------------------------------------------------------------*
*       Display search results
*---------------------------------------------------------------------*
FORM display_ftab.
  CHECK rb_dyn IS INITIAL.
  top_flag = 'A'.
  NEW-PAGE.
  LOOP AT ftab.
    IF ftab-sstring IS INITIAL.
      WRITE: / sy-vline,
               ftab-text INTENSIFIED OFF.
    ELSE.
      FORMAT HOTSPOT ON.
      WRITE: / sy-vline .
*               ftab-text INTENSIFIED OFF COLOR COL_TOTAL.
      IF ftab-text+0(1) <> '*'.
        WRITE: ftab-text      INTENSIFIED OFF COLOR COL_TOTAL.
      ELSE.
        WRITE: ftab-text      INTENSIFIED OFF COLOR COL_KEY.
      ENDIF.
      FORMAT HOTSPOT OFF.
    ENDIF.
    WRITE: 100  sy-vline       NO-GAP,
             ftab-line_no   NO-GAP INTENSIFIED,
             sy-vline       NO-GAP,
             ftab-repname   NO-GAP INTENSIFIED,
        150  sy-vline       NO-GAP.
    HIDE: ftab-repname,
          ftab-line_no.
    AT END OF repname.
      ULINE /(150).
    ENDAT.
  ENDLOOP.
ENDFORM.                    "display_ftab
*---------------------------------------------------------------------*
*       FORM DISPLAY_DTAB                                             *
*---------------------------------------------------------------------*
*       Display search results (dynpro)
*---------------------------------------------------------------------*
FORM display_dtab.
  CHECK rb_code IS INITIAL.
  top_flag = 'D'.
  NEW-PAGE.
  LOOP AT dtab.
    IF dtab-sstring IS INITIAL.
      WRITE: / sy-vline,
               dtab-text INTENSIFIED OFF.
    ELSE.
      FORMAT HOTSPOT ON.
      WRITE: / sy-vline,
               dtab-text INTENSIFIED OFF COLOR COL_TOTAL.
      FORMAT HOTSPOT OFF.
    ENDIF.
    WRITE:   sy-vline       NO-GAP,
             dtab-line_no   NO-GAP INTENSIFIED,
             sy-vline       NO-GAP,
             dtab-repname   NO-GAP INTENSIFIED,
             dtab-dynnr     NO-GAP INTENSIFIED,
        150  sy-vline       NO-GAP.
    HIDE:    dtab-repname,
             dtab-dynnr,
             dtab-line_no.
    AT END OF repname.
      ULINE /(150).
    ENDAT.
  ENDLOOP.
ENDFORM.                    "display_dtab
*---------------------------------------------------------------------*
*       FORM DISPLAY_FTAB_ALT
*---------------------------------------------------------------------*
*       Display hit list without report name on every line
*---------------------------------------------------------------------*
FORM display_ftab_alt.
  CHECK rb_dyn IS INITIAL.
  top_flag = 'A'.
  NEW-PAGE.
  IF comment = 'X'.
    LOOP AT ftab.
      IF ftab-text <> '' .
        IF ftab-text+0(1) = '*'.
          ftab-del_flag = 'X'.
          MODIFY ftab.
        ENDIF.
      ENDIF.
    ENDLOOP.
    DELETE ftab WHERE del_flag = 'X'.
  ENDIF.
  LOOP AT ftab.
    AT NEW repname.
      IF sy-tabix > 1.
        NEW-PAGE.
      ENDIF.
    ENDAT.
    WRITE: / sy-vline       NO-GAP,
             ftab-line_no   NO-GAP,
             sy-vline       NO-GAP.
    IF ftab-sstring IS INITIAL.
      WRITE: ftab-text      INTENSIFIED OFF.
    ELSE.
      FORMAT HOTSPOT ON.
      IF ftab-text+0(1) <> '*'.
        WRITE: ftab-text      INTENSIFIED OFF COLOR COL_TOTAL.
      ELSE.
        WRITE: ftab-text      INTENSIFIED OFF COLOR COL_KEY.
      ENDIF.
      FORMAT HOTSPOT OFF.
    ENDIF.
    WRITE: 150 sy-vline.
    HIDE:    ftab-repname,
             ftab-line_no.
    AT END OF repname.
      ULINE /(150).
    ENDAT.
  ENDLOOP.
ENDFORM.                    "display_ftab_alt
*---------------------------------------------------------------------*
*       FORM DISPLAY_DTAB_ALT
*---------------------------------------------------------------------*
*       Display dynpro hit list without report name on every line
*---------------------------------------------------------------------*
FORM display_dtab_alt.
  CHECK rb_code IS INITIAL.
  IF comment = 'X'.
    LOOP AT dtab.
      IF dtab-text <> '' .
        IF dtab-text+0(1) = '*'.
          dtab-del_flag = 'X'.
          MODIFY dtab.
        ENDIF.
      ENDIF.
    ENDLOOP.
    DELETE dtab WHERE del_flag = 'X'.
  ENDIF.
  top_flag = 'D'.
  NEW-PAGE.
  LOOP AT dtab.
    AT NEW repname.
      IF sy-tabix > 1.
        NEW-PAGE.
      ENDIF.
    ENDAT.
    WRITE: / sy-vline       NO-GAP,
             dtab-line_no   NO-GAP,
             sy-vline       NO-GAP.
    IF dtab-sstring IS INITIAL.
      WRITE: dtab-text      INTENSIFIED OFF.
    ELSE.
      FORMAT HOTSPOT ON.
      WRITE: dtab-text      INTENSIFIED OFF COLOR COL_TOTAL.
      FORMAT HOTSPOT OFF.
    ENDIF.
    WRITE: 150 sy-vline.
    HIDE:    dtab-repname,
             dtab-dynnr,
             dtab-line_no.
    AT END OF repname.
      ULINE /(150).
    ENDAT.
  ENDLOOP.
ENDFORM.                    "display_dtab_alt
*----------------------------------------------------------------------*
*       Form  GET_PLUS_MINUS_X_LINES
*----------------------------------------------------------------------*
*       Get x lines before the found string and x lines after
*----------------------------------------------------------------------*
FORM get_hit_set USING value(ctext)   LIKE rtab_lcase
                       value(line_no) LIKE sy-tabix
                       srce_type      TYPE c.
  DATA: end    TYPE i,
        start  TYPE i,
        xtabix LIKE sy-tabix.
  IF plusminu <= 0.
    PERFORM append_ftab USING ctext line_no 'X' srce_type.
    EXIT.
  ENDIF.
  start = line_no - plusminu .
  end   = line_no + plusminu.
  IF start < 1.
    start = 1.
  ENDIF.
  WHILE start <= end.
    READ TABLE rtab INTO ctext INDEX start.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    xtabix = sy-tabix.
    IF start = line_no.
      PERFORM append_ftab USING ctext xtabix 'X' srce_type.
    ELSE.
      PERFORM append_ftab USING ctext xtabix space srce_type.
    ENDIF.
    ADD 1 TO start.
  ENDWHILE.
ENDFORM.                               " GET_HIT_SET
*----------------------------------------------------------------------*
*       Form  CALL_EDITOR
*----------------------------------------------------------------------*
*       Call ABAP or screen painter editor
*----------------------------------------------------------------------*
FORM call_editor.
  CLEAR: ftab,
         dtab.
  READ LINE sy-lilli
       FIELD VALUE ftab-repname
                   ftab-line_no
                   dtab-repname
                   dtab-dynnr
                   dtab-line_no.
  IF ftab-repname IS INITIAL AND dtab-repname IS INITIAL.
    MESSAGE s016 WITH '无效的光标定位'.
    EXIT.
  ENDIF.
  IF dtab-dynnr IS INITIAL.
*   Call ABAP editor
    CALL FUNCTION 'EDITOR_PROGRAM'
      EXPORTING
        display = ''
        program = ftab-repname
        topline = ftab-line_no
      EXCEPTIONS
        OTHERS  = 1.
    SET PARAMETER ID 'RID' FIELD sy-repid.
  ELSE.
    CALL FUNCTION 'RS_SCRP'
      EXPORTING
        abl_line       = dtab-line_no
        dynnr          = dtab-dynnr
        progname       = dtab-repname
        wanted_mode    = 'MODIFY'
      EXCEPTIONS
        already_exists = 1
        not_found      = 2
        not_executed   = 3
        OTHERS         = 4.
  ENDIF.
ENDFORM.                               " CALL_EDITOR
*----------------------------------------------------------------------*
*       Form  GET_DYNPRO_FLOW_LOGIC
*----------------------------------------------------------------------*
*       Get flow logic of the dynpro
*----------------------------------------------------------------------*
FORM get_dynpro_flow_logic.
  DATA: dhead  LIKE d020s,
        dfield LIKE d021s OCCURS 0,
        dflow  LIKE d022s OCCURS 0,
        dmatch LIKE d023s OCCURS 0,
        BEGIN OF dynp_id,
          prog LIKE d020s-prog,
          dnum LIKE d020s-dnum,
       END OF dynp_id.
  dynp_id-prog = dyn-prog.
  dynp_id-dnum = dyn-dnum.
  IMPORT DYNPRO dhead dfield dflow dmatch ID dynp_id.
  rtab[] = dflow[].
ENDFORM.                               " GET_DYNPRO_FLOW_LOGIC
*&---------------------------------------------------------------------*
*&      Form  display_rep_list
*&---------------------------------------------------------------------*
FORM display_rep_list .
  DATA: lineno TYPE i .
  top_flag = 'L'.
  disptype = 'L'.
  CLEAR lineno.
  LOOP AT ftab.
    AT NEW repname.
      lineno = lineno + 1.
      WRITE /(6) lineno .
      WRITE  ftab-repname .
      HIDE ftab-repname.  "可以不要
    ENDAT.
  ENDLOOP.
ENDFORM.                    " display_rep_list
*&---------------------------------------------------------------------*
*&      Form  download_list
*&---------------------------------------------------------------------*
FORM download_list .
  sy-lsind = sy-lsind - 1.
  CALL FUNCTION 'LIST_DOWNLOAD' .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " download_list
 
 
阅读(6298) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

qdbarry2009-01-13 21:15:40

参考程序RPR_ABAP_SOURCE_SCAN,就是在那个程序的基础上修改的

chinaunix网友2009-01-13 20:00:37

你好,可以麻烦把输入界面也截图吗?那些多选框单选框都不知道什么意思耶,麻烦麻烦,谢谢谢谢~~~