SAP ABAP Report 开发模板范例

该模板可直接运行:
 

************************************************************************
* Program Name      :
* Descriptions      :
* Updates Tables    :
* Input  Parameters :
* Output Parameters :
* Return Codes      :
* Special Logic     :
* Includes          :
************************************************************************
* Modification Log
************************************************************************
*   Date     Ver. Programmer   Descriptions
* ---------- ---- ------------ -----------------------------------------
* 2022/08/05 1.0  XXX  New Create
************************************************************************
report  zmubanreport no standard page heading
                message-id 00 line-size 100 line-count 65.

************************************************************************
* Tables Definitions
************************************************************************
tables: kna1.
type-pools: slis.
************************************************************************
* Data Definitions
************************************************************************
data: begin of w_show,"data:声明可以直接声明一个工作区
  kunnr type kna1-kunnr,"客户
  box   type c,
    end of w_show.

types: begin of ty_kna1,"TYPES:声明一个结构,还得声明工作区
kunnr type kna1-kunnr,"客户
end of ty_kna1.

*----------------------------------------------------------------------*
* 内表定义
*----------------------------------------------------------------------*
data: t_show like standard table of w_show .
*      w_show like ty_show.

data: t_kna1 type standard table of ty_kna1 ,
      w_kna1 type ty_kna1.

data: t_t016t type table of t016t.
data: w_t016t type  t016t.

*----------------------------------------------------------------------*
* 变量定义
*----------------------------------------------------------------------*
data: gt_fieldcat type slis_t_fieldcat_alv with header line,
       gs_layout type slis_layout_alv,
       gs_print  type slis_print_alv,    "ALV打印格式
       g_repid like sy-repid.
data: v_stru_disvar type disvariant,    "ALV 显示格式
      it_sort type slis_t_sortinfo_alv with header line, "ALV 排序内表
      git_events type slis_t_event,     "ALV 事件
      git_listheader  type slis_t_listheader. "ALV 表头
data l_tmp type lvc_title.
*END OF ALV

constants cns_pf_status    type slis_formname value 'ALV_PF_STATUS'.
constants cns_user_command type slis_formname value 'ALV_USER_COMMAND'.


*----------------------------------------------------------------------*
* 宏定义(一个宏中最多有9个参数)
*----------------------------------------------------------------------*
define def_fieldcat.
  clear gt_fieldcat.
  gt_fieldcat-fieldname     = &1 ."字段名
  gt_fieldcat-reptext_ddic  = &2 ."字段描述
  gt_fieldcat-no_zero       = &3 .                          "字段去前置0.
 * gt_fieldcat-edit          = &4 ."字段是否可修改  
 * gt_fieldcat-ref_fieldname         = &5 ."参考字段
 * gt_fieldcat-ref_tabname          = &6 ."参考表
  append gt_fieldcat.
end-of-definition.

***********************************************************************
* Selection Screen
***********************************************************************
select-options: s_kunnr for kna1-kunnr ,"客户
                s_land1 for kna1-land1 ."
parameters:     p_werks like marc-werks obligatory default '1001',
                p_stlan like mast-stlan obligatory default '1'.
selection-screen begin of block b1 with frame title text-b01.
parameters:     p_idnrk as checkbox.
parameters:     p_mehrs as checkbox.
selection-screen end of block b1.
************************************************************************
* Includes Module
************************************************************************


************************************************************************
* Initialization
************************************************************************
initialization.

************************************************************************
* At Selection Screen Output(PBO)
************************************************************************
at selection-screen output.

************************************************************************
* At Selection Screen(PAI)
************************************************************************
at selection-screen.

at user-command.

at line-selection.

************************************************************************
* Report Format
************************************************************************
top-of-page.

end-of-page.

************************************************************************
* Main Process
************************************************************************
start-of-selection.
*  PERFORM check_purview."权限检查
  perform frm_get_data. "数据查询及处理
  if t_show[] is not initial.
    perform frm_alv_show.
  else.
    "(T01)这样写的好处是能够翻译报错
    message '没有符合的数据,请重新查询!'(t01) type 'S' display like 'E' .
  endif.

end-of-selection.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_get_data .
  select kunnr into table t_kna1
    from kna1
    where kunnr in s_kunnr.

  if t_kna1[] is not initial.
    loop at t_kna1 into w_kna1.
      w_show-kunnr = w_kna1-kunnr."客户
      append w_show to t_show.
      clear:w_show.
    endloop.
  endif.
endform.                    " FRM_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_alv_show .
  perform init_layout.  "ALV报表格式控制
  perform init_fieldcat."ALV
  perform frm_output.   "
endform.                    " FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*&      Form  INIT_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form init_layout .
  gs_layout-detail_popup      = 'X'   .
  gs_layout-colwidth_optimize = 'X'   .  "最优化列宽
  gs_layout-f2code            = 'ETA' .
  gs_layout-box_fieldname     = 'BOX' .
  gs_layout-zebra             = 'X'   .  "斑马纹
endform.                    " INIT_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  INIT_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form init_fieldcat .
  refresh gt_fieldcat[].
  def_fieldcat 'KUNNR'    text-001          ''   ."客户
endform.                    " INIT_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_output .
  g_repid = syst-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'"Grid 格式的ALV
    exporting
      i_callback_program       = g_repid
*      i_callback_pf_status_set = cns_pf_status
*      i_callback_user_command  = cns_user_command
      is_layout                = gs_layout
      it_fieldcat              = gt_fieldcat[]
      i_save                   = 'X'
      is_variant               = v_stru_disvar
      it_events                = git_events[]
      it_sort                  = it_sort[]
      is_print                 = gs_print
    tables
      t_outtab                 = t_show
    exceptions
      program_error            = 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.
endform.                    " FRM_OUTPUT
*&---------------------------------------------------------------------*
*&      Form  CHECK_PURVIEW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_purview .
  if sy-uname = 'XXXXXX'"
  else.
    message '当前账号无权使用报表!详情请询问IS' type 'S' display like 'E'.
    stop.
  endif.
endform.                    " CHECK_PURVIEW

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值