27
SAP Tutorial for ABAP Developers - Create Number Range Object using SAP Transaction Code SNRO Step by step Number Range Creation using SNRO SAP Transaction In SAP Easy Access screen, call SAP transaction code SNRO Enter Number Range name in the Number Range Object input text field. Enter Short Text and Long Text descriptive texts for Number Range Object. Enter a number length domain for the number range object If you want a warning define an integer smaller than 100 in the Warning % field. You can enter 5 or 10 as common warning percentage values.

SAP Tutorial for ABAP Developers

Embed Size (px)

Citation preview

Page 1: SAP Tutorial for ABAP Developers

SAP Tutorial for ABAP Developers - Create Number Range Object using SAP Transaction Code SNROStep by step Number Range Creation using SNRO SAP Transaction

In SAP Easy Access screen, call SAP transaction code SNRO

Enter Number Range name in the Number Range Object input text field.

Enter Short Text and Long Text descriptive texts for Number Range Object.

Enter a number length domain for the number range object

If you want a warning define an integer smaller than 100 in the Warning % field.You can enter 5 or 10 as common warning percentage values.

Page 2: SAP Tutorial for ABAP Developers

Click on the Save button to save the number range definition.

Page 3: SAP Tutorial for ABAP Developers

Click on Yes button to continue.The next screen displayed is Create Object Directory Entry screen.

I select Local Object

Now the Change documents and Number ranges buttons are displayed in the Number Range Object : Change SAP screen.

Click on "Number ranges" button.

Click on Change Intervals buttons.

Click on "Add Interval" button

Page 4: SAP Tutorial for ABAP Developers

Enter an integer number like 1 at interval number and a range of numbers with integer values identifying from number and to number. If you have entered required fields press Enter button.

Click on "Save" button. And the number range interval you have just declared will be listed in the Number Range object 's number intervals list.

Page 5: SAP Tutorial for ABAP Developers

The following "Transport number range intervals" warning screen is displayed.

The number range intervals are not included in automatic recording of customizing changes. Transport of all the changes made within number range interval maintenance must be triggered manually.

In the initial screen for number range interval maintenance choose the function Interval -> Transport.

Please note the information that you get when transporting number range intervals.

 

Here is the display screen of the Number Range object.

Page 6: SAP Tutorial for ABAP Developers

REPORT ztreenodes .

" INRI : Number ranges function module interface structureCONSTANTS :" Name of number range object - CHAR 10 c_rangeobj LIKE inri-object VALUE 'Z_TREENODE'," Number range number - CHAR 2 c_rangeno LIKE inri-nrrangenr VALUE '1'.

DATA : " NodeId from Number Generator Object gv_nodeid TYPE i.

START-OF-SELECTION.

 PERFORM nextnum USING gv_nodeid c_rangeobj c_rangeno. WRITE gv_nodeid.

END-OF-SELECTION.

FORM nextnum USING

 le_nextnum TYPE i le_rangeobj LIKE inri-object le_rangeno LIKE inri-nrrangenr.

DATA : lv_nextnum TYPE i.

CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'

Page 7: SAP Tutorial for ABAP Developers

 EXPORTING  object = le_rangeobj EXCEPTIONS  foreign_lock = 1  object_not_found = 2  system_failure = 3  OTHERS = 4.IF sy-subrc NE 0.* message e086 with 'Lock error' sy-subrc.ENDIF.

CALL FUNCTION 'NUMBER_GET_NEXT' EXPORTING  nr_range_nr = le_rangeno  object = le_rangeobj* QUANTITY = '1'* SUBOBJECT = ' '* TOYEAR = '0000'* IGNORE_BUFFER = ' ' IMPORTING  number = lv_nextnum " Number generated by Range Generator Object* QUANTITY =* RETURNCODE = lv_returncode 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.IF sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.

CALL FUNCTION 'NUMBER_RANGE_DEQUEUE' EXPORTING  object = le_rangeobj.IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.

le_nextnum = lv_nextnum.

ENDFORM. " NEXTNUM

Page 8: SAP Tutorial for ABAP Developers

How to Create you own Number Range ? (SNRO)

Number Range - SNRO

by P surjith kumar, Enteg Infotech, Bangalore, India.

Number Range Object - SNRO

In an Invoice creation number range is the one which refer to unique invoice. This is vital to identify the specific

invoice. The custom define Number Range Object can be create in the Transaction Code SNRO and the object has

to be called in program with the help of a Function Module NUMBER_GET_NEXT.

Scenario

In an Organization for the custom defines applications like invoice generation, reimbursement or Expense payment,

etc. needs auto generated number for reference, which is done through a Number Range object. The creation and

the implementation of Number Range Object based on the Employee's Company code and the current Year is

explained in this article.

Creating Number Range Step by Step

    The following steps are necessary to create a Number Range,

1. Log to Transaction Code SNRO.

2. Number Range Object Creation.

3. Assigning Domain and the Sub-object for Number Range Object.

4. Assigning Sub-object for Number Range Object.

5. Assigning Number for the Number range Object

6. Implementation of Number range Object.

7. Execution and viewing the newly generated Number Range.

1) Log to Transaction Code SNRO                  

  Give a name for the Number Range Object.  

 

2) Number Range Object Creation

Page 9: SAP Tutorial for ABAP Developers

Once the name given for the Number Range Object,

click the create icon to create the number range Object as shown below.

 

 

3)  Assigning Domain and the Sub-object for Number Range Object

Once the create icon is clicked the below mentioned screen will appear.

Then the value has to enter in Subobject data element, Number length domain and Warning % as mention below.

Page 10: SAP Tutorial for ABAP Developers

Then Same Screen Explained in Detail below,

a) Short and Long Description

 

a short and long description for the Number Range. 

b) Interval Characteristics 

Page 11: SAP Tutorial for ABAP Developers

 

 

Subobject data element: This determines whether the number range intervals distinguish subobjects.

Enter the Company code data element "BUKRS" for the subject, like Company code Personnel area and other field

can be entered as per the requirement.

To-year flag:  If the check box is selected this Flag will set and it determining, whether the number range intervals are

distinguished according to the financial year.

Number length domain: Assign the (Domain) Data type and length for the Number range.

Enter the data type "NUM10" or as per the requirement.

No interval rolling:  If the check box is select the flag will set and it prevents the number range object intervals from

automatically starting from the beginning at the upper limit.

c) Customizing Specifications

 

Number range transaction:  Transaction code to call number range maintenance is assigned. And it Dependencies is

this transaction code is automatically entered in the transaction code table.

Warning %:  This indicates the Percentage of numbers remaining in a number range, once the percentage is reached

it will show a warning. For Examples if you have defined an interval from 1 to 100 and you want to issue a warning at

the number 90, you have to enter 10 (%) here.

Enter the warning Percentage (%) "10". If the requirement is "15" or "5" assign the given value here.

Main memory buffering:  Selecting the flag determines whether the number intervals are buffered for assignments

and checks.

Benefits: 

The number interval buffer is in the Shared Memory of the application server. Each buffer is used to store the external

number intervals and a certain number (subinterval) of the internal number intervals. If the numbers of an internal

number interval are used up, numbers are taken from the database via the number range server. The status of the

number interval in the database is increased by the number of numbers fetched to the buffer.

Dependencies:

When buffering number intervals, gaps may result in number assignment. Buffering is therefore not possible for

applications, which require continuous number assignment.

Page 12: SAP Tutorial for ABAP Developers

No. of numbers in buffer:  This number which you assign determines how many numbers are reserved in the

application server buffer for the intervals.

d) Group Specification

 

Group table:  Name of the table for number range groups.

Benefits: Number range intervals are identified uniquely by a number range number. When numbers are assigned or

checked, the number range group elements determine the number range interval via the number range number.

Number range group elements are assigned in the group table.

Subobject field in group table:   It is Number range table subobject field name, the Field name of the group table

containing the subobject if the group table takes subobjects into account.

Fld  NoRangeElement:  It is  Name of the number range element field, During assignment and checking of number

range numbers, the number range group elements determine the number range interval via the number range

number. For Example For the material master, the material type determines the number range interval. Here, the

element field is the material type field.

Fields int./ext. no.range no.: Name of the number range field (in the group table), which contains the internal

number range number.

Fld. NoRangeNo: Field name of the group table, which contains the number range number.

Display element text:  Mention the Short text for number range object maximum 20 characters.Once the SubObject

name, Domain (Length & Data type) and warning % is entered save the changes.

 After saving, a message window will appear as below and Click yes.

 

 

Then the same screen will appear as shown below. 

Page 13: SAP Tutorial for ABAP Developers

4)  Assigning Sub-object for Number Range Object.

 

 

Then a new screen will appear as shown below.

Page 14: SAP Tutorial for ABAP Developers

 

Enter the Company "IN01" and Click the Intervals.                  

5) Assigning Number for the Number range Object

 

 

Then a new screen will appear as below.

Page 15: SAP Tutorial for ABAP Developers

 

Page 16: SAP Tutorial for ABAP Developers

 

Page 17: SAP Tutorial for ABAP Developers

 

Once the numbers assigned then Press Enter.  

 

And the below screen will appear.  

Page 18: SAP Tutorial for ABAP Developers

 

Then save it a message widow will appear as mentioned below.

Page 19: SAP Tutorial for ABAP Developers

 

Then click the Tick Mark.  

Page 20: SAP Tutorial for ABAP Developers

 

Then the number range object can be used your application. If any changes need to made

Then the Number range Object is called inside the Program or function module or Inside the method of Webdynpro

Component, etc.

6) Implementation of Number range Object.    

  Number range with Sub-Object and Year Dependency used in the program is explained below.     

 a) Go to Transaction Code - SE38

Page 21: SAP Tutorial for ABAP Developers

 

 

Enter the Title of the Program.

 

Page 22: SAP Tutorial for ABAP Developers

 

Save and write the below Program to get the Number range

 

Page 23: SAP Tutorial for ABAP Developers

 

 

b) Call the Number Range Object in the Program using the Function Module "NUMBER_GET_NEXT".

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

*& Report  YSURJITH_NORANGE

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

* Created by: P SURJITH KUMAR, Enteg Infotech, Bangalore

* Version   :  1.0

* Purpose   : Number Range for Invoice Generation

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

REPORT  YSURJITH_NORANGE.

DATA:

Page 24: SAP Tutorial for ABAP Developers

lv_number_range(10) TYPE n,    "-- Variable to hold Newly generated Number Range

lv_year TYPE inri-toyear,              "-- Variable to hold Year

lv_subobject TYPE  t001-bukrs,     "-- Variable to hold Company Code

lv_rc TYPE inri-returncode.            "-- Variable to hold the Return Code

lv_year = '2008'.         "--- Assign Current Year

lv_subobject = 'IN01'.  "--- Assign the Company Code

CALL FUNCTION 'NUMBER_GET_NEXT'

  EXPORTING

    nr_range_nr            = '01'                "-- This hold the Newly generated Number

    object                    = 'YINVNUM'       "---- Passing the Number Range Object

    subobject               = lv_subobject    "-- Pass the Company code

    toyear                   = lv_year            "-- Pass the Year

  IMPORTING

    number                  = lv_number_range "-- Newly generated Number 

    returncode              = lv_rc                   "-- The Return Code Number

  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.

IF sy-subrc <> 0.

  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

WRITE : / 'The New Number is  :'(001), lv_number_range,

       /  'The Return Code is :'(002), lv_rc.

*&--- End of Report  YSURJITH_NORANGE -----&*

Then Save and Activate the Program, then execute it. 

Return Code (lv_rc)

1) lv_rc =  ' ' , Everything is working fine

2) lv_rc = '1', The assigned number lies in the critical area.       

3) lv_rc =  '2',  This was the last number, next time the first number will be assigned           

7) Execution and viewing the newly generated Number

Then Execute and get the output as below,

Page 25: SAP Tutorial for ABAP Developers

 

 

The same Program you can assign in your application as per your Requirement.