通過上篇對流水號的介紹,下面來個程序來介紹如何使用它,並讓它爲我們做點事啦!
程序執行的效果如下所示:
程序如下所示:
*&---------------------------------------------------------------------*
*& 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
SAP 流水號程序
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.