Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7202807
  • 博文数量: 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)

分类:

2009-09-02 17:01:16

REPORT  z_sm35_log LINE-SIZE 1000 NO STANDARD PAGE HEADING .

TABLES: apqi,t100.
FIELD-SYMBOLS: ,.
DATA: itab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: it_apqi TYPE STANDARD TABLE OF apqi WITH HEADER LINE.
DATA  BEGIN OF bdcld  OCCURS 0.
        INCLUDE STRUCTURE bdcld.
DATA: logname(80),
      local_host(12),
      cnt TYPE i,
      active(1) TYPE c,
      temseid TYPE rstsoname.      " TemSe ID
DATA  END OF bdcld .
DATA  selected_protocol LIKE sy-index .
DATA: logtab LIKE bdcld OCCURS 0 WITH HEADER LINE,
      logtab_temse LIKE apql OCCURS 0 WITH HEADER LINE.
DATA: logname(80).
DATA  BEGIN OF bdclm  OCCURS 0.
        INCLUDE STRUCTURE bdclm.
DATA: longtext TYPE bdc_mpar,
      isdetail(1) TYPE c,
      END OF bdclm .
DATA: lm LIKE bdclm,
      save_mpar TYPE bdc_mpar,
      mtext(124) TYPE c ,
      mtext1(124) TYPE c,
      mtext2(273) TYPE c,
      digits(10) TYPE c VALUE '0123456789',
      parcnt  TYPE i,
      sp_len  TYPE i,
      mtvaroff TYPE i,
      do_condense TYPE c,
      charcnt TYPE i,
      wcnt TYPE i,
      mparcnt TYPE i,
      qfound(04) TYPE n,
      x(1) VALUE 'X'.
DATA: BEGIN OF mt,
       off(02) TYPE n,
       len(02) TYPE n,
       text(99),
      END OF mt.
DATA: BEGIN OF mttab  OCCURS 4,
       off(02) TYPE n,
       len(02) TYPE n,
       text(99),
      END OF mttab.
DATA: BEGIN OF par,
        len(02) TYPE n,
        text(254),
      END OF par.

TYPE-POOLS: slis.

DATA: gd_fieldcat TYPE slis_t_fieldcat_alv.
DATA: sla TYPE slis_layout_alv ,
      ivariant LIKE disvariant,
      i_repid LIKE sy-repid ,
      i_excluding TYPE slis_t_extab.

PARAMETERS: p_group LIKE apqi-groupid .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1.
PARAMETERS: record RADIOBUTTON GROUP typ
                               USER-COMMAND sele DEFAULT 'X'.
PARAMETERS: log RADIOBUTTON GROUP typ.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
  IF p_group IS INITIAL.
    p_group = '*'.
  ENDIF.
  PERFORM get_bdc_list USING p_group.

AT LINE-SELECTION.
  IF record = 'X'.
    PERFORM get_bdc_data.
  ELSE.
    PERFORM get_bdc_log.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  get_bdc_list
*&---------------------------------------------------------------------*
FORM get_bdc_list USING gname TYPE apqi-groupid.
  CALL FUNCTION 'BDC_OBJECT_SELECT'
    EXPORTING
      name             = gname
      datatype         = 'BDC'
    TABLES
      apqitab          = it_apqi
    EXCEPTIONS
      invalid_datatype = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  LOOP AT it_apqi.
    WRITE :/ it_apqi-groupid,it_apqi-creator,
             it_apqi-credate ,it_apqi-cretime .
    HIDE: it_apqi-qid.
  ENDLOOP.
ENDFORM.                    "get_bdc_list

*&---------------------------------------------------------------------*
*&      Form  get_bdc_data
*&---------------------------------------------------------------------*
FORM get_bdc_data.
  CALL FUNCTION 'BDC_OBJECT_READ'
    EXPORTING
      queue_id         = it_apqi-qid
    TABLES
      dynprotab        = itab
    EXCEPTIONS
      not_found        = 1
      system_failure   = 2
      invalid_datatype = 3
      OTHERS           = 4.
  IF sy-subrc <> 0.
  ENDIF.

*  EDITOR-CALL FOR itab DISPLAY-MODE.
*  LOOP AT itab.
*    PERFORM write_wa USING itab 'XXXXX' 'X' 'X'.
*  ENDLOOP.
  PERFORM outdata TABLES itab USING 'ITAB'.
ENDFORM.                    "get_bdc_data

*---------------------------------------------------------------------*
*       FORM write_wa                                                 *
*---------------------------------------------------------------------*
FORM write_wa USING wa fieldmask newline alllen.
  DATA: str TYPE string ,
        str_idx TYPE string ,
        f_index TYPE i ,
        f_len TYPE i .
  FIELD-SYMBOLS: .
  f_len = STRLEN( fieldmask ).
  IF newline = 'X'. WRITE  / ''.ENDIF.
  POSITION 1 .
  DO .
    ASSIGN COMPONENT sy-index OF STRUCTURE wa TO .
    IF sy-subrc <> 0 OR sy-index > f_len.
      EXIT.
    ELSE.
      str_idx = sy-index .
      CONDENSE str_idx.
      f_index = sy-index - 1.
      IF fieldmask+f_index(1) = 'X'.
        IF alllen = ''.
          str = .
          WRITE str.
        ELSE.
          WRITE .
        ENDIF.
      ENDIF.
    ENDIF.
  ENDDO.
ENDFORM.                    "write_wa

*&---------------------------------------------------------------------*
*&      Form  get_bdc_log
*&---------------------------------------------------------------------*
FORM get_bdc_log.
  PERFORM get_logfiles_from_temse USING it_apqi-qid.

  SORT bdcld BY edate DESCENDING etime DESCENDING.
  DESCRIBE TABLE bdcld LINES selected_protocol.
  IF selected_protocol > 0.
    PERFORM get_log USING 1.          " most recent log -> bdclm
    PERFORM extend_message_texts.     " extended texts -> bdclm
    selected_protocol = 1.
  ENDIF.
*  LOOP AT bdclm.
*    PERFORM write_wa USING bdclm 'XXXXXXXXXXXXX' 'X' 'X'.
*  ENDLOOP.

  PERFORM outdata TABLES bdclm USING 'BDCLM'.
ENDFORM.                    "get_bdc_log

*&---------------------------------------------------------------------*
*&      Form  get_logfiles_from_temse
*&---------------------------------------------------------------------*
FORM get_logfiles_from_temse USING qid TYPE apqi-qid.
  CLEAR logtab_temse[].
  CLEAR bdcld[].

  SELECT * FROM apql INTO TABLE logtab_temse WHERE qid = qid.

  CHECK sy-subrc = 0.
  DATA: wa_log LIKE LINE OF logtab_temse,
        wa_ld  LIKE LINE OF bdcld.

  LOOP AT logtab_temse INTO wa_log.
    CLEAR wa_ld.
    wa_ld-temseid = wa_log-temseid.
    wa_ld-lmand   = wa_log-mandant.
    wa_ld-edate   = wa_log-credate.
    wa_ld-etime   = wa_log-cretime.
    wa_ld-luser   = wa_log-creator.
    wa_ld-grpn    = wa_log-groupid.
    wa_ld-quid    = wa_log-qid.
    wa_ld-local_host = wa_log-destsys(8).
    APPEND wa_ld TO bdcld.
  ENDLOOP.

ENDFORM.                    "get_logfiles_from_temse

*&---------------------------------------------------------------------*
*&      Form  get_log
*&---------------------------------------------------------------------*
FORM get_log USING log_index.

  DATA: BEGIN OF logtable OCCURS 50,
          enterdate LIKE btctle-enterdate,
          entertime LIKE btctle-entertime,
          logmessage(400) TYPE c,
        END OF logtable.
  DATA:
        external_date(10),
        internal_date TYPE d.


  READ TABLE bdcld INDEX log_index.
  logname = bdcld-logname.

* get logfile contents from TemSe
  PERFORM read_bdc_log_plain TABLES logtable
                             USING  bdcld-temseid bdcld-lmand.

  IF sy-subrc <> 0.
    MESSAGE s004(ts).
    EXIT.
  ENDIF.

  CLEAR bdclm[].
  LOOP AT logtable.
    CALL 'DATE_CONV_INT_TO_EXT'
         ID 'DATINT' FIELD logtable-enterdate
         ID 'DATEXT' FIELD external_date.

    CALL 'DATE_CONV_EXT_TO_INT'
         ID 'DATEXT' FIELD external_date
         ID 'DATINT' FIELD internal_date.
    IF sy-subrc NE 0.
      CONTINUE.
    ENDIF.

    CLEAR bdclm.
    bdclm-indate  = logtable-enterdate.
    bdclm-intime  = logtable-entertime.
    bdclm+14(352) = logtable-logmessage.
    IF bdclm-mcnt > 0.
      bdclm-mcnt = bdclm-mcnt - 1.
    ENDIF.

    IF bdclm-mid EQ '00'.
      IF   ( bdclm-mnr EQ '162' )
        OR ( bdclm-mnr EQ '368' ).
        bdclm-isdetail = 'X'.
      ENDIF.
    ENDIF.

    APPEND bdclm.
  ENDLOOP.
ENDFORM.                    "get_log

*&---------------------------------------------------------------------*
*&      Form  extend_message_texts
*&---------------------------------------------------------------------*
FORM extend_message_texts.
  LOOP AT bdclm.
    lm = bdclm. save_mpar = bdclm-mpar.
    PERFORM get_text.
    bdclm-longtext = mtext.
    bdclm-mpar = save_mpar.
    MODIFY bdclm.
  ENDLOOP.
ENDFORM.                    "extend_message_texts

*&---------------------------------------------------------------------*
*&      Form  get_text
*&---------------------------------------------------------------------*
FORM get_text.
  DATA: shiftln TYPE i,
        vartcnt TYPE i,
        fdpos LIKE sy-fdpos.

  IF bdclm-mparcnt CN digits.
    bdclm-mparcnt = 0.
  ENDIF.

  SELECT SINGLE * FROM t100
   WHERE sprsl = sy-langu
   AND  arbgb  = bdclm-mid
   AND  msgnr  = bdclm-mnr.
*
  IF sy-subrc EQ 0.
    CLEAR: mtext,parcnt,mparcnt,charcnt,wcnt,mt,sp_len,sy-fdpos.
    MOVE bdclm-mparcnt TO mparcnt.
    IF t100-text CA '$&'.
      MOVE t100-text TO mtext1.
    ELSE.
      MOVE t100-text TO mtext.
      EXIT.
    ENDIF.

    REFRESH mttab.
    CLEAR shiftln.
    DO mparcnt TIMES.
      CLEAR: par, mttab.
      MOVE bdclm-mpar TO par.
      IF par-len CN digits OR par-len EQ 0.
        par-len  = 1.
        par-text = ' '.
        shiftln  = 2.
      ELSE.
        shiftln = par-len + 2.
      ENDIF.
      WRITE par-text TO mttab-text(par-len).
      MOVE par-len  TO mttab-len.
      MOVE mparcnt  TO mttab-off.
      APPEND mttab.
      SHIFT bdclm-mpar BY shiftln PLACES.
    ENDDO.
*
    mtext2 = mtext1.
    IF bdclm-mid EQ  '00' AND
       bdclm-mnr EQ '368' AND
       bdclm-mart EQ 'S'.
      CLEAR mtext2.
      CLEAR mttab.
      READ TABLE mttab INDEX 1.
      WRITE mttab-text TO mtext2+0(mttab-len).
      CLEAR mttab.
      READ TABLE mttab INDEX 2.
      WRITE mttab-text TO mtext2+35(mttab-len).
      mtext = mtext2.
      EXIT.
    ENDIF.

    do_condense = x.
    CLEAR: mt, vartcnt, mtvaroff.
    WHILE vartcnt LE 3.
      vartcnt = vartcnt + 1.
      IF mtext1 CA '$&'.
        parcnt = parcnt + 1.
        IF sy-fdpos GT 0.
          fdpos = sy-fdpos - 1.
        ELSE.
          fdpos = sy-fdpos.
        ENDIF.
        SHIFT mtext1 BY sy-fdpos PLACES.
        IF mtext1(1) EQ '&'.
          SHIFT mtext1 BY 1 PLACES.
          CASE mtext1(1).
            WHEN ' '.                              "'& '
              PERFORM replace_var USING '& ' parcnt fdpos.
            WHEN '$'.                              "'&&'
              PERFORM replace_var USING '&&' 0      fdpos.
            WHEN '1'.                                       "'&1'
              PERFORM replace_var USING '&1' 1      fdpos.
            WHEN '2'.                                       "'&2'
              PERFORM replace_var USING '&2' 2      fdpos.
            WHEN '3'.                                       "'&3'
              PERFORM replace_var USING '&3' 3      fdpos.
            WHEN '4'.                                       "'&4'
              PERFORM replace_var USING '&4' 4      fdpos.
            WHEN OTHERS.                           "'&'
              PERFORM replace_var USING '&<' parcnt fdpos.
          ENDCASE.
        ENDIF.
        IF mtext1(1) EQ '$'.
          SHIFT mtext1 BY 1 PLACES.
          CASE mtext1(1).
            WHEN ' '.                              "'$ '
              PERFORM replace_var USING '$ ' parcnt  fdpos.
            WHEN '$'.                              "'$$'
              PERFORM replace_var USING '$$' 0       fdpos.
            WHEN '1'.                                       "'$1'
              PERFORM replace_var USING '$1' 1       fdpos.
            WHEN '2'.                                       "'$2'
              PERFORM replace_var USING '$2' 2       fdpos.
            WHEN '3'.                                       "'$3'
              PERFORM replace_var USING '$3' 3       fdpos.
            WHEN '4'.                                       "'$4'
              PERFORM replace_var USING '$4' 4       fdpos.
            WHEN OTHERS.                           "'$'
              PERFORM replace_var USING '$<' parcnt  fdpos.
          ENDCASE.
        ENDIF.
      ENDIF.
    ENDWHILE.
*
    IF mtext2 CA '%%_D_%%'.
      REPLACE '%%_D_%%' WITH '$' INTO mtext2.
    ENDIF.
    IF mtext2 CA '%%_A_%%'.
      REPLACE '%%_A_%%' WITH '&' INTO mtext2.
    ENDIF.
    IF do_condense EQ space.
      mtext = mtext2.
    ELSE.
      CONDENSE mtext2 .
      mtext = mtext2.
    ENDIF.
  ELSE.
    mtext = '???????????????????????????????????????????????????'.
  ENDIF.
*
ENDFORM.                    "get_text

*&---------------------------------------------------------------------*
*&      Form  READ_BDC_LOG_PLAIN
*&---------------------------------------------------------------------*
FORM read_bdc_log_plain TABLES log_table
                        USING  log_name log_client.

  DATA: charcp LIKE rststype-charco VALUE '0000'.

  FREE log_table.

  CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
    EXPORTING
      authority     = ' '
      client        = log_client
      name          = log_name
    IMPORTING
      charco        = charcp
    EXCEPTIONS
      fb_error      = 1
      fb_rsts_other = 2
      no_object     = 3
      no_permission = 4
      OTHERS        = 5.

  IF cl_abap_char_utilities=>charsize > 1.
    charcp = '0000'.
  ENDIF.

  CALL FUNCTION 'RSTS_OPEN_RLC'
    EXPORTING
      name           = log_name
      client         = log_client
      authority      = 'BATCH'
      prom           = 'I'
      rectyp         = 'VNL----'
      charco         = charcp
    EXCEPTIONS
      fb_call_handle = 4
      fb_error       = 8
      fb_rsts_noconv = 12
      fb_rsts_other  = 16
      no_object      = 20
      OTHERS         = 24.

  IF sy-subrc > 0.
    EXIT.
  ENDIF.

  CALL FUNCTION 'RSTS_READ'
    TABLES
      datatab        = log_table
    EXCEPTIONS
      fb_call_handle = 4
      fb_error       = 8
      fb_rsts_noconv = 12
      fb_rsts_other  = 16
      OTHERS         = 16.

  IF sy-subrc > 0.
    EXIT.
  ENDIF.

  CALL FUNCTION 'RSTS_CLOSE'
    EXCEPTIONS
      OTHERS = 4.

  IF sy-subrc > 0.
    EXIT.
  ENDIF.
ENDFORM. " READ_BDC_LOG_PLAIN

*&---------------------------------------------------------------------*
*&      Form  replace_var
*&---------------------------------------------------------------------*
FORM replace_var USING vark vari varpos.

  DATA: var(02),
        var1,
        moff TYPE i.

  CLEAR: mttab , moff.
  var = vark.
  SHIFT var BY 1 PLACES.
  CASE var.
    WHEN ' '.                              "'& '
      READ TABLE mttab INDEX vari.
      IF sy-subrc EQ 0.
        moff = varpos + mtvaroff.
        ASSIGN mtext2+moff(*) TO .
        ASSIGN mttab-text(mttab-len) TO .
        var1 = vark.
        REPLACE var1 WITH      INTO .
        mtvaroff = mttab-len.
      ELSE.
        IF vari GT mparcnt.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE vark WITH '  ' INTO .
          mtvaroff = 2.
        ELSE.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE vark WITH '%%_Z_%%' INTO .
          mtvaroff = 7.
        ENDIF.
      ENDIF.
    WHEN '$'.                              "'&&'
      moff = varpos + mtvaroff.
      ASSIGN mtext2+moff(*) TO .
      REPLACE vark WITH '%%_D_%%' INTO .
      mtvaroff = 7.
    WHEN '&'.                              "'&&'
      moff = varpos + mtvaroff.
      ASSIGN mtext2+moff(*) TO .
      REPLACE vark WITH '%%_A_%%' INTO .
      mtvaroff = 7.
    WHEN '<'.                                               "'&1'
      READ TABLE mttab INDEX vari.
      IF sy-subrc EQ 0.
        IF vark EQ '&<'.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          ASSIGN mttab-text(mttab-len) TO .
          REPLACE '&' WITH      INTO .
          mtvaroff = mttab-len.
        ENDIF.
        IF vark EQ '$<'.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          ASSIGN mttab-text(mttab-len) TO .
          REPLACE '$' WITH      INTO .
          mtvaroff = mttab-len.
        ENDIF.
      ELSE.
        IF vark EQ '&<'.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE '&' WITH ' ' INTO .
          mtvaroff = 1.
        ENDIF.
        IF vark EQ '$<'.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE '$' WITH ' ' INTO .
          mtvaroff = 1.
        ENDIF.
      ENDIF.
    WHEN '1'.                                               "'&1'
      READ TABLE mttab INDEX 1.
      IF sy-subrc EQ 0.
        moff = varpos + mtvaroff.
        ASSIGN mtext2+moff(*) TO .
        ASSIGN mttab-text(mttab-len) TO .
        REPLACE vark WITH      INTO .
        mtvaroff = mttab-len.
      ELSE.
        IF vari GT mparcnt.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE vark WITH '  ' INTO .
          mtvaroff = 2.
        ELSE.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE vark WITH '%%_Z_%%' INTO .
          mtvaroff = 7.
        ENDIF.
      ENDIF.
    WHEN '2'.                                               "'&2'
      READ TABLE mttab INDEX 2.
      IF sy-subrc EQ 0.
        moff = varpos + mtvaroff.
        ASSIGN mtext2+moff(*) TO .
        ASSIGN mttab-text(mttab-len) TO .
        REPLACE vark WITH      INTO .
        mtvaroff = mttab-len.
      ELSE.
        IF vari GT mparcnt.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE vark WITH '  ' INTO .
          mtvaroff = 2.
        ELSE.
          moff = varpos + mtvaroff.
          ASSIGN mtext2+moff(*) TO .
          REPLACE vark WITH '%%_Z_%%' INTO .
          mtvaroff = 7.
        ENDIF.
      ENDIF.
    WHEN '3'.                                               "'&3'
      READ TABLE mttab INDEX 3.
      IF sy-subrc EQ 0.
        moff = varpos + mtvaroff.                    "neu
        ASSIGN mtext2+moff(*) TO .              "neu
        ASSIGN mttab-text(mttab-len) TO .
        REPLACE vark WITH      INTO .     "neu
        mtvaroff = mttab-len.                        "neu
      ELSE.
        IF vari GT mparcnt.
          moff = varpos + mtvaroff.                    "neu
          ASSIGN mtext2+moff(*) TO .              "neu
          REPLACE vark WITH '  ' INTO .     "neu
          mtvaroff = 2.                        "neu
        ELSE.
          moff = varpos + mtvaroff.                    "neu
          ASSIGN mtext2+moff(*) TO .              "neu
          REPLACE vark WITH '%%_Z_%%' INTO .     "neu
          mtvaroff = 7.                   "neu
        ENDIF.
      ENDIF.
    WHEN '4'.                                               "'&4'
      READ TABLE mttab INDEX 4.
      IF sy-subrc EQ 0.
        moff = varpos + mtvaroff.                    "neu
        ASSIGN mtext2+moff(*) TO .              "neu
        ASSIGN mttab-text(mttab-len) TO .
        REPLACE vark WITH      INTO .     "neu
        mtvaroff = mttab-len.                        "neu
      ELSE.
        IF vari GT mparcnt.
          moff = varpos + mtvaroff.                    "neu
          ASSIGN mtext2+moff(*) TO .              "neu
          REPLACE vark WITH '  ' INTO .     "neu
          mtvaroff = 2.                        "neu
        ELSE.
          moff = varpos + mtvaroff.                    "neu
          ASSIGN mtext2+moff(*) TO .              "neu
          REPLACE vark WITH '%%_Z_%%' INTO .     "neu
          mtvaroff = 7.                   "neu
        ENDIF.
      ENDIF.
*
  ENDCASE.
  do_condense = space.
ENDFORM.                    "replace_var

*&---------------------------------------------------------------------*
*&      Form  outdata
*&---------------------------------------------------------------------*
FORM outdata TABLES itab USING tabname.
  sla-colwidth_optimize = 'X'.
  sla-zebra             = 'X'.
  i_repid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = i_repid
      i_internal_tabname     = tabname
      i_inclname             = i_repid
    CHANGING
      ct_fieldcat            = gd_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = i_repid
      it_fieldcat        = gd_fieldcat[]
      i_save             = 'A'
      is_variant         = ivariant
      is_layout          = sla
      it_excluding       = i_excluding
    TABLES
      t_outtab           = itab
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

ENDFORM.                    " outdata

阅读(4895) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~