Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Saving ID to database

Former Member
0 Kudos

I have these codes:

-


MODULE USER_COMMAND_9000 INPUT.

CASE SY-UCOMM.

WHEN 'SAVE'.

  • retrieve table from control

CALL METHOD CODE_EDITOR->get_text_as_r3table

IMPORTING

table = DYN_CODE_TABLE

EXCEPTIONS

OTHERS = 1.

LOOP AT DYN_CODE_TABLE INTO wa_lv.

MOVE wa_lv-Line TO WA_PROGRAM-PROGRAM_LINE.

MOVE wa_lv-LINE TO WA_PROGRAM-PROGRAM_CODE.

APPEND WA_PROGRAM TO ITAB_PROGRAM.

ENDLOOP.

IF sy-subrc NE 0.

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

titel = g_repid

txt2 = space

txt1 = text-003.

ENDIF.

-


This is my codes for the save function. Whenever I clicked on the save button, the system will auto generate an ID number and save to my database.

For eg, when I click the first time of the save button, the ID will be 1 and second time is 2. However, after I exit my application and come back again, the ID will be 3 automatically.

Please give me code examples as I am very new to ABAP.

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

May be you can try with

Create a number range using SNRO and call fm 'NUMBER_GET_NEXT' system will give you next number

6 REPLIES 6

former_member194669
Active Contributor
0 Kudos

May be you can try with

Create a number range using SNRO and call fm 'NUMBER_GET_NEXT' system will give you next number

0 Kudos

Can give the code example for me to understand better?

0 Kudos

use snro create number range such as 'ALE_CP'

CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'

EXPORTING

object = 'ALE_CP'

EXCEPTIONS

foreign_lock = 1

object_not_found = 2

system_failure = 3

OTHERS = 4.

IF sy-subrc = 0.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

nr_range_nr = '01'

object = 'ALE_CP'

  • QUANTITY = LV_CPIDENTCOUNT

IMPORTING

number = im_cpidentmax

  • QUANTITY = LV_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

OTHERS = 7

.

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 = 'ALE_CP'

EXCEPTIONS

object_not_found = 1

OTHERS = 2.

ENDIF.

0 Kudos

Can you explain the parameters used in the codes to me or show me how the declaration goes?

0 Kudos

While creating a number range using transaction SNRO, a number object is created. This is the object you mention in the EXPORTING field OBJECT. In the field NR_RANGE_NR, you mention the interval that you have created in the Number Range Object. I cannot put up screens here, but I can tell you the path.

SNRO>Put object name>Display>Goto(Menu Bar)>Number Ranges-->Intervals and in the table control the first field, No. is put in NR_RANGE_NR. This is the path in 4.7 SAP version. In 4.6C, I think Intervals comes as soon as you put object name in SNRO Transaction. There are many more fields in the function module, but I suspect that you want the basic functionality.

0 Kudos

Any tutorial for 'Get_Next_Number' function? I still don't really get it.