Chinaunix首页 | 论坛 | 博客
  • 博客访问: 586718
  • 博文数量: 154
  • 博客积分: 10208
  • 博客等级: 上将
  • 技术积分: 2225
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-16 14:02
文章分类

全部博文(154)

文章存档

2012年(4)

2011年(44)

2010年(50)

2009年(4)

2008年(52)

我的朋友

分类:

2008-08-06 14:48:41

BT需求:job定期跑report,并将结果保存到指定的report tree ZTST.

 

解决方案:

1.T-code:serp 创建report tree ZTST,并创建子节点Villy,

 

 

2.选中子节点并选择新建,在弹出的窗口中选择ABAP Report Transaction code,填入程序名称或者T-code,确定。这时你双击子节点进去后会发现如下结果:

 

 

3.修改程序,下面是一个修改后的及其简单的程序:

REPORT  Z_VILLY1.

 

data: g_submit   type c.

DATA:listobject  like abaplist occurs 0 with header line.

 

if sy-batch = 'X'.

  perform  program_batch_run.

  if g_submit is initial.

    exit.

  endif.

endif.

 

write: 'test'.

 

 

*&---------------------------------------------------------------------*

*&      Form  program_batch_run

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

form program_batch_run.

  import g_submit from memory id 'ZRR_CONTRACT_VIEW_STATUS_A'.

  if g_submit is initial.

    g_submit = 'X'.

 

    export g_submit to memory id 'ZRR_CONTRACT_VIEW_STATUS_A'.

    submit (sy-repid) using selection-set sy-slset

           exporting list to memory

           and return.

           

    data:varkey like rstable-varkey.

    varkey = sy-mandt.

    call function 'ENQUEUE_E_TABLE'

     exporting

       tabname              = 'srepolist'

       varkey               = varkey

       _wait                = 'X'

     exceptions

       foreign_lock         = 1

       system_failure       = 2

       others               = 3.

 

    if sy-subrc = 0.

      message i003(zrr) with 'SREPOLIST' sy-datum sy-uzeit.

 

 

      call function 'LIST_FROM_MEMORY'

        TABLES

          listobject = listobject

        EXCEPTIONS

          not_found  = 1

          others     = 2.

      if sy-subrc = 0.

        call function 'WRITE_LIST'

          TABLES

            listobject = listobject

          EXCEPTIONS

            empty_list = 1

            others     = 2.

      endif.

 

* Save list to memory.

      perform save_list_to_report_tree.

      free memory.

 

      commit work.

 

* unlocking the table

      call function 'DEQUEUE_E_TABLE'

       exporting

         tabname            = 'srepolist'

         varkey             =  varkey

      exceptions

         others        = 1.

 

      clear g_submit.

 

    else.           "Job already running aborting

* Batch job is running: Concurrent runs not allowed. Aborting

      message 'Concurrent runs not allowed!' type 'I'.

    endif.

 

  endif.

 

endform.                    " PROGRAM_BATCH_RUN

 

*&---------------------------------------------------------------------*

*&      Form  save_list_to_report_tree

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

form save_list_to_report_tree.

 

  data: l_keylists like skeylists,

        l_repolist like srepolist,

        l_listindex like srepolist-list_index,

        l_sdate     like srepolist-sdate,

        l_stime     like srepolist-stime,

        l_suser     like srepolist-suser.

 

  if sy-batch = space.

    call function 'SAVE_LIST'

      TABLES

        listobject = listobject

      EXCEPTIONS

        others     = 4.

  endif.

 

  check not listobject[] is initial.

 

  l_keylists-tree_id    = 'ZTST'.

  l_keylists-node       = 'VILLY'.

  l_keylists-report     = sy-repid.

  l_keylists-sdate      = sy-datum.

  l_keylists-stime      = sy-uzeit.

  l_keylists-suser      = sy-uname.

  l_keylists-list_index = '00'.

 

  select sdate stime suser list_index

    into (l_sdate, l_stime, l_suser, l_listindex)

    from srepolist up to 1 rows

    where tree_id = l_keylists-tree_id

      and node = l_keylists-node

      and reporttype = space

      and report = l_keylists-report

      and extdreport = space

      and variant = space

      and sdate = l_keylists-sdate

   order by list_index descending.

    exit.

  endselect.

  if sy-subrc = 0.

    l_keylists-sdate = l_sdate.

    l_keylists-stime = l_stime.

    l_keylists-suser = l_suser.

    l_keylists-list_index = l_listindex + 1.

  endif.

*

 

  move-corresponding l_keylists to l_repolist.

 

  l_repolist-credate    = l_keylists-sdate.

  l_repolist-cretime    = l_keylists-stime.

  l_repolist-creuser    = sy-uname.

  l_repolist-publiclist = 'X'.

 

 

  concatenate  'test' sy-uname

  into l_repolist-list_text separated by space.

  CONDENSE l_repolist-list_text.

 

  insert into srepolist values l_repolist .

  export listobject to database serplists(li) id l_keylists.

 

endform.                    " save_list_to_report_tree

 

然后后台运行该程序,运行后可以在report tree 中看到保存的结果。双击子节点进去可以发现多了一行:

 

 

双击多出来的一行就能够看到运行的结果。

 

查看report tree中的结果使用T-code SARP.

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