-------------------- -------------------- -------------------- -------

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
*&---------------------------------------------------------------------*
*& Include LZCERT_ORG_FGI02
*&---------------------------------------------------------------------*
* Change 21.08.2009 by AZhuravlev start
*&---------------------------------------------------------------------*
*& Form TEST_NEW_ITEM
*&---------------------------------------------------------------------*
* Проверяет новую запись
*----------------------------------------------------------------------*
* <--PS_EXTRACT text
*----------------------------------------------------------------------*
form test_new_item changing ps_extract like gs_extract.
if ps_extract-regnum is initial
and
ps_extract-zst_organization is initial.
" No data
exit.
endif.
perform get_next_number changing ps_extract-id.
endform. " TEST_NEW_ITEM
*&---------------------------------------------------------------------*
*& Form TEST_EXISTING_ITEM
*&---------------------------------------------------------------------*
* Проверяет существующую запись
*----------------------------------------------------------------------*
* <--PS_EXTRACT text
*----------------------------------------------------------------------*
form test_existing_item changing ps_extract like gs_extract.
if ps_extract-regnum is initial
and
ps_extract-zst_organization is initial.
" No data
message text-000 type 'S' display like 'E'.
sy-subrc = 4.
exit.
endif.
endform. " TEST_EXISTING_ITEM
*&---------------------------------------------------------------------*
*& Form GET_NEXT_NUMBER
*&---------------------------------------------------------------------*
* Возвращает следующий номер в последовательности
*----------------------------------------------------------------------*
* <--P_PS_EXTRACT_ID text
*----------------------------------------------------------------------*
form get_next_number changing p_id like gs_extract-id.
constants:
range_name type nrnr value '01',
object_name type nrobj value 'ZCERTORGID'.
data l_id like p_id.
call function 'NUMBER_GET_NEXT'
exporting
nr_range_nr = range_name
object = object_name
importing
number = l_id
exceptions
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
internal_overflow = 6
others = 7.
* Check if number found...
case sy-subrc.
when 0. "Number found...
p_id = l_id.
when 1. "Interval not found (but object exists)
* Create new Interval to existing object
perform number_create_interval using object_name range_name.
if sy-subrc = 0.
p_id = '0001'.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
.
else.
message text-001 type 'S' display like 'E'.
call function 'BAPI_TRANSACTION_ROLLBACK'.
endif.
when 3. "object not found
* Create the object...
perform number_create_object using object_name.
if sy-subrc = 0.
* Create new Interval to existing object
perform number_create_interval using object_name range_name.
if sy-subrc = 0.
p_id = '0001'.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
.
else.
message text-001 type 'S' display like 'E'.
call function 'BAPI_TRANSACTION_ROLLBACK'.
endif.
else.
message text-002 type 'S' display like 'E'.
call function 'BAPI_TRANSACTION_ROLLBACK'.
endif.
when others.
message text-003 type 'S' display like 'E'.
sy-subrc = 4.
endcase.
endform. " GET_NEXT_NUMBER
*&---------------------------------------------------------------------*
*& Form NUMBER_CREATE_INTERVAL
*&---------------------------------------------------------------------*
* Создаем интервал
*----------------------------------------------------------------------*
* -->P_OBJECT_NAME text
* -->P_RANGE_NAME text
*----------------------------------------------------------------------*
form number_create_interval using p_object_name type nrobj
p_range_name type nrnr.
data:
number type nrfrom value '0001',
to_number type nrto value '9999',
lt_intervals type table of inriv,
ls_interval type inriv,
error_tab type table of nriv,
err type inrer,
warning_occured type char1,
error_occured type char1.
* Fill the interval structure for insert
clear ls_interval.
refresh lt_intervals.
move: p_range_name to ls_interval-nrrangenr,
number to ls_interval-fromnumber,
to_number to ls_interval-tonumber,
number to ls_interval-nrlevel,
'I' to ls_interval-procind.
append ls_interval to lt_intervals.
* Insert the new interval
call function 'NUMBER_RANGE_INTERVAL_UPDATE'
exporting
object = p_object_name
importing
error = err
error_occured = error_occured
warning_occured = warning_occured
tables
error_iv = error_tab
interval = lt_intervals
exceptions
object_not_found = 1.
if sy-subrc <> 0 or not error_occured is initial.
sy-subrc = 4.
exit.
endif.
* Write the Numberrangedata to the Database.
call function 'NUMBER_RANGE_UPDATE_CLOSE'
exporting
object = p_object_name
exceptions
no_changes_made = 1
object_not_initialized = 2.
endform. " NUMBER_CREATE_INTERVAL
* Change 21.08.2009 by AZhuravlev end
*&---------------------------------------------------------------------*
*& Form NUMBER_CREATE_OBJECT
*&---------------------------------------------------------------------*
* Создаем счетчик
*----------------------------------------------------------------------*
* -->P_OBJECT_NAME text
*----------------------------------------------------------------------*
form number_create_object using p_object_name type nrobj.
data:
errors_tab type table of inoer,
wa_obj_attr type tnro,
wa_obj_text type tnrot,
h_ret_code(1) type c.
clear wa_obj_attr.
move: p_object_name to wa_obj_attr-object,
'CHAR4' to wa_obj_attr-domlen,
'X' to wa_obj_attr-buffer,
10 to wa_obj_attr-noivbuffer,
10 to wa_obj_attr-percentage.
clear wa_obj_text.
move: sy-langu to wa_obj_text-langu,
p_object_name to wa_obj_text-object,
text-005 to wa_obj_text-txtshort,
text-004 to wa_obj_text-txt.
* Insert the object...
call function 'NUMBER_RANGE_OBJECT_UPDATE'
exporting
indicator = 'I' "Insert
object_attributes = wa_obj_attr
object_text = wa_obj_text
importing
returncode = h_ret_code
tables
errors = errors_tab
exceptions
object_already_exists = 1
object_attributes_missing = 2
object_not_found = 3
object_text_missing = 4
wrong_indicator = 5.
if sy-subrc ne 0.
exit.
endif.
* save the changes..
call function 'NUMBER_RANGE_OBJECT_CLOSE'
exporting
object = p_object_name
exceptions
object_not_initialized = 1.
endform. " NUMBER_CREATE_OBJECT