SQL Server administration and T-SQL development, Web Programming with ASP.NET and Javascript, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz Development Resources
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.




Win FREE BOOK
from Kodyaz



CRM Companies List
Web Based CRM Software





SAP Tutorial for ABAP Developers - Create Number Range Object using SAP Transaction Code SNRO


ABAP developers and SA professionals require an auto number field especially in the key fields of a database table during ABAP coding in their SAP applications.
Actually an auto incrementa field is a general requirement for al developers in all development environments and platforms
In SAP environment the solution is creating to create number range object and use number range object in ABAP codes for ABAP developers
Actually, database providers like Microsoft SQL Server and Oracle have more advanced solutions for such requirements that does not require maintanence and so much steps in number range creation process.

Let's start our task in this SAP tutorial, number range creation using SNRO SAP Transaction code.


Step by step Number Range Creation using SNRO SAP Transaction

In SAP Easy Access screen, call SAP transaction code SNRO

sap-transaction-code-snro-for-number-range

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

sap-transaction-code-snro-number-range-screen

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-transaction-code-snro-create-number-range-for-auto-number

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

sap-buffering-methods

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

sap-abap-create-object-directory-entry-for-number-range

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.

change-number-range-object-abap

Click on Change Intervals buttons.

sap-change-intervals-in-number-range-object

Click on "Add Interval" button sap-number-range-add-interval-button

sap-maintain-number-range-intervals-screen

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.

insert-interval-for-number-range-intervals-in-sap

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.

snro-number-range-object-number-intervals-list

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

snro-abap-transport-number-range-intervals

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.

sap-snro-display-number-range-object





SAP professionals and ABAP developers have seen how to create Number Range Object till this point in this SAP tutorial.
Now ABAP developers are readyto go further and learn how to use number range objects in ABAP code.
Key ABAP function for implementing and using a number range in ABAP codes is NUMBER_GET_NEXT ABAP function.
In order to use a number range for auto increment column numbers safely in SAP, NUMBER_GET_NEXT ABAP function is used with NUMBER_RANGE_ENQUEUE and NUMBER_RANGE_DEQUEUE.

ABAP developers can copy and paste the following ABAP report source code and execute the ABAP program in their development and test environments.
The sample ABAP report reads the next number in an SAP Number Range Object and displays the auto number value on the screen.
The ABAP NUMBER_RANGE_ENQUEUE function sets a lock on the number range object.
If the lock is successfully set on the SAP number range, using NUMBER_GET_NEXT function call the next number in the number range interval is read and passed into an ABAP variable.
The last step is calling NUMBER_RANGE_DEQUEUE function and removing the loc on the relate SAP number range object.

REPORT ztreenodes .

" INRI : Number ranges function module interface structure
CONSTANTS :
" 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'
 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

I hope ABAP developers will fing this number range and NUMBER_GET_NEXT function call implementation useful.







SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table














Recent and Top SAP Tutorial and ABAP Tutorials

Change Output Condition Records
Web Dynpro Text Translation using Assistance Class
Move Minus Sign from Right to Left of Negative Number in SAP Smartform
Read Address Data using FM ADDR_GET instead of Querying ADRC Table
Add Value Help to Web Dynpro Select Options
Add Web Dynpro Applications to SAP Favorites Menu
Component Usage ALV Does Not Have an Active Component
Web Dynpro Component Service Syntax Error in Program /1BCWDY/O3EC1AX6A3OVKK9L5FXO==CP
Web DynPro Tutorial - Display Spool Requests using Web DynPro Table
Web DynPro Tutorial - How to create Web Dynpro Application (Web Dynpro Component)
Display Data on Web DynPro Table Element
Test Web Dynpro ABAP Component by Creating Web Dynpro Application
Graphics White Background Displayed Grey on SAP Smartform Output
Get SAP Document Flow using SD_DOCUMENT_FLOW_GET ABAP Function Module
How to Spell Numbers using ABAP Spell_Amount Function Module
How to Transport SAP Graphics using SE78 Transaction
How to Delete Standard Text using SO10 SAP Transaction
Dynamic Programming using Field Symbols in ABAP Reports
How to Disable Word Editor in SAP Smartform Text
How to Debug Popup Screen in ABAP
TVAP Item Category and SAP Table TVAPT for Text Translations
ABAP Runtime Error ST22 Transaction using Short Dump Analysis
Create Transport Request for Text Translations using RS_LXE_RECORD_TORDER
SAP Invoice Output Determination Analysis for Not Created Output Message
Set Default Single Values List for SAP Selection Screen Parameter
SAP Payment Terms Table and ZTERM Texts Table for ABAP Developers
How to Create SAPScript Text using SO10 Transaction Code
SAP Smartforms Tutorial - Table Calculations using Sum Total
SAP Smartforms Tutorial - Table Calculations using Count
SAP Smartforms Tutorial - How to Create Smartform
SAP NetWeaver Installation Guide using installshield wizard
SAP Smartforms Table for Sales Order and Invoice Outputs
Email Spool Request using SAPOffice - Spool to PDF
How to Display SAP Graphics using SE78 Transaction Code
SAPScript Transaction Codes
ABAP Tutorial - ABAP String Split Example Code
Sales Tables among ABAP Tables (SAP Sales and Distribution SD Tables)
How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module
ALV Grid Color - Table Row Background Color in ALV List
Multi Color ALV Grid Color Alternate using ALV Layout info_fname Property
How to Debug SmartForms - Debugging SAP SmartForm in ABAP ?
ABAP - Create Hierarchy Tree List using rs_tree_construct, rs_tree_list_display and snodetext
Create CL_GUI_ALV_GRID ALV Grid Column Header using ABAP Data Element
ABAP Tutorial - SAP Split and ABAP Split String Function
Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
SAP Smartforms Tutorial - Create Smartforms Example
SAP Smartforms - How to Call Smartform within ABAP Program
Complete List of SAP Modules






Copyright © 2004 - 2011 Eralper Yilmaz. All rights reserved.
Community Server, by Telligent Systems