现在的位置: 首页 > 综合 > 正文

SAP 流水号程序

2013年12月14日 ⁄ 综合 ⁄ 共 3627字 ⁄ 字号 评论关闭

   通过上篇对流水号的介绍,下面来个程序来介绍如何使用它,并让它为我们做点事啦!
程序执行的效果如下所示:


程序如下所示:
*&---------------------------------------------------------------------*
*& Report  ZFFJ_RANGE
*&
*&---------------------------------------------------------------------*
*& create by   : flying
*& create date : 2009/11/06
*& descriptions: 试验流水号(当点击下一个按钮的时候执行并把下一个值反填到
*&               下一个值的文本框中)
*&---------------------------------------------------------------------*

report  zffj_range.

TABLES: sscrfields.

*---------------------------------------------------------------------*
*   define internal tables
*   定义内表
*
*---------------------------------------------------------------------*
data: begin of t_nriv occurs 0,
object like tnro-object,              "范围对象
nrrangenr like nriv-nrrangenr,        "区间编号
end   of t_nriv.
data: w_nriv like t_nriv.                    "定义工作区

*--------------------------------------------------------------------*
*   define variable
*   定义全局变量
*
*--------------------------------------------------------------------*
data: l_next(20) type c.             "定义下一个值.

*--------------------------------------------------------------------*
*   selection-screen
*   选择屏幕
*
*--------------------------------------------------------------------*
selection-screen begin of block blk with frame title text-001.
parameters: p_object like tnro-object obligatory,           "范围对象
p_num    like nriv-nrrangenr obligatory,        "区间编号
p_next(20) type c.                              "下一个值
selection-screen end   of block blk.

selection-screen function key 1.                          "设置选择屏幕的按钮,可以支持5个按钮,对应的功能码从FC01--FC05.
*selection-screen function key 2.
*selection-screen function key 3.
*--------------------------------------------------------------------*
*  initialzation
*  初始化屏幕
*
*--------------------------------------------------------------------*
initialization.
sscrfields-functxt_01  = '下一个'.                      "这里设置按钮为文本了也可以为图标
* sscrfields-functxt_02  = '上一个'.

*-------------------------------------------------------------------*
*  at selection-screen
*  处理选择屏幕的按钮事件
*
*-------------------------------------------------------------------*
at selection-screen.
case sy-ucomm.                   "获得当前系统的功能码
when 'FC01'.
perform frm_get_data.
perform frm_get_next.
p_next = l_next.
when 'ONLI'.                  "这个对应的是执行的功能码(F8)
endcase.

*--------------------------------------------------------------------*
*  form frm_get_data
*  根据输入条件从表获取相关数据
*
*--------------------------------------------------------------------*
form frm_get_data.
* 把数据放到工作区w_nriv
select object
nrrangenr
into corresponding fields of w_nriv
from nriv
where object eq p_object
and nrrangenr eq p_num.
endselect.

if w_nriv is initial.
message '没有可查询的相关数据' type 'I'.
stop.
endif.
endform.                    "frm_get_data

*--------------------------------------------------------------------*
*  form frm_get_next
*  获得当前的范围对象和区间编号对应的流水号
*
*--------------------------------------------------------------------*
form frm_get_next.
call function 'NUMBER_RANGE_ENQUEUE '
exporting
object           = p_object
exceptions
foreign_lock     = 1
object_not_found = 2
system_failure   = 3
others           = 4.
*  **如果号码范围存在
if sy-subrc eq 0 .
*  ****得到一个号码,
call function 'NUMBER_GET_NEXT '
exporting
nr_range_nr             = p_num              "这个就是维护的间隔号
object                  = p_object           "这个就是流水号对象
importing
number                  = l_next             "获得的流水号
*   quantity = quant
*   returncode = code
exceptions
interval_not_found      = 1
number_range_not_intern = 2
object_not_found        = 3
quantity_is_0           = 4
quantity_is_not_1       = 5
interval_overflow       = 6
buffer_overflow         = 7
others                  = 8.
*  ***将号码累加
call function 'NUMBER_RANGE_DEQUEUE '
exporting
object           = p_object
exceptions
object_not_found = 1
others           = 2.
else .
raise num_range_error .
endif .

endform.                    "frm_get_next

抱歉!评论已关闭.