Application Development and Automation 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: 
Read only

Help in ABAP function module coding.

Former Member
0 Likes
1,376

Hi,

i am having trouble coding the program where i have to select a number from the table and add one to it to create a new record back to the table. example, i've select 1 from the table, i need the program to be able to return 2 and create a new record back into the table and the next time i generate the program, i will select 2 and create a 3 into the table. It needed to be a custom function module as i need to call it in another function module which would concatenate the generated number with some words..

i'm very new to abap programing...so could anyone please provide a detailed on how i could code it...

THANKS alot in advance!!!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,344

Hi Lessy,

Could you please explain it more in details so that one can get it clearly.

What table you are using?

What functionality?

What you want to achieve?

Manas Mishra

11 REPLIES 11
Read only

Former Member
0 Likes
1,345

Hi Lessy,

Could you please explain it more in details so that one can get it clearly.

What table you are using?

What functionality?

What you want to achieve?

Manas Mishra

Read only

0 Likes
1,344

hi,

i am currently creating a gp process where i have to create a unique form number which requires the department name, year and the unique id eg DEPT_YYYY_1234.

so i thought of using a function module to do it.

1. i create a table 'num' for the id.

- i will retrive the latest num in it and add one to the number in one function module 'get_num'

eg. i get 100 from the table, i need the function module to create a 101 into the table num.

2. Concatenate the number with the year and dept.

- i will create another function module to get the current year(should be the system date) and the dept from an existing table in R3.

- then, i need to call the 'get_num' FM to concatenate the id with the retrieved dept and year to have the outcome i need.

ps. this is what i think that can be work but i am not sure about the codings...so is this the right way? or is there any other alternatives that can achieve what i need?

Thanks for your reply 😃

Regards,

leesyy

Read only

0 Likes
1,344

Why do you need FM for that? Just 2 line of code would do the work for you.

Just fetch the recent number and add + 1 to the fetched number.and pass it back to table

Read only

0 Likes
1,344

hi,

i am not sure about the codings...as i've never coded a abap program.

as for the creation of function module...i think i need it because i need to use it for a field in VC.

correct me if i am wrong.

Thanks for thr reply 😃

Regards,

leesyy

Read only

Former Member
0 Likes
1,344

hi,

Better you create a Customer number range object for this.

With the help of FM 'NUMBER_GET_NEXT' you can get the next number. Here you need to pass the Number range object which will be custom developed from Tcode SNRO.

Please revert of you need more help on this.

Regards,

Nikhil

Read only

Former Member
0 Likes
1,344

Hi Lessy,

For this you do not need to create FM. Just create a Z table with 2 fields Unique ID and description.

Select the last record in table and split the number part of unique id and increment it by one and write description of it. Now Insert this record in z table.

Hope this is useful for you.

Thanks

Nitesh

Read only

0 Likes
1,344

hi,

if i don't need a function module, where do i code it?

sorry that i'm really super new to abap programing.

Thanks for the reply

Regards

leesyy

Read only

0 Likes
1,344

Hi,

Please ask your Seniors in your team.

They will guide you in using FM or writing the code.

Regards

Read only

Former Member
0 Likes
1,344

Hi Lessy,

You can use Number ranges for the requirement. The Number range is of two type :

Internal Number assignment & External number assignment . You can use External number assignment ,Here, the user assigns a number within the number range interval allowed. You can define the intervals for external number assignment numerically and alphanumerically.

Thanks

Read only

0 Likes
1,344

Hi Lessy,

i have done the same requirement where my sequence number will automatically get incremented by 1 as new record cames for update.as already discussed you have to cretae the numebr range and call the number range by function module 'Number_get_next'.

PFB the code which will definitely help you.


 CALL FUNCTION 'NUMBER_GET_NEXT'
        EXPORTING
          NR_RANGE_NR                   = '01'  " specify this number this is 
*the same when you cretae numberrange  have specified.
          OBJECT                        = 'ZSEQNUM'    " This the number range 
*i have created
       IMPORTING
         NUMBER                         = wa_msg-seqnr
       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.

      modify lt_message FROM wa_msg TRANSPORTING seqnr.

to cretete number range.

goto transaction SNRO

enter the name,short text, give the number length domain (char10 or what ever is your domain)

click on number range and cretae interval.

give the number , from number and to number.

this number you have to give in FM also (i have given '01').

hope this will help you.for any problem revert back

thanks

Tanmaya

Code Formatted by: Alvaro Tejada Galindo on Jan 13, 2010 4:16 PM

Edited by: Rob Burbank on Jan 13, 2010 5:20 PM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,344

This is the logic


data:prev_no type i,
     new_no type i.

prev_no = 1.
do 100 times.
  write prev_no.    "Select from table
  skip 1.
  new_no = prev_no + 1.
prev_no = new_no.
  write new_no.     "Insert into table.
                    "Commit work and wait.
  skip 1.
enddo.