Skip to Content
author's profile photo Former Member
Former Member

increasing a table field

Hello,

someone knows a way to increase a table field value by one whenever a record is inserted on the same table?.

For example:

Table: zvquery

fields: client, partner, type, count.

So whenever you insert a new record on table zvquery, field count increases automatically by 1.

Thank you very much.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Oct 13, 2005 at 04:38 PM

    There is no such functionality in ABAP. We use number ranges. You call a function module to get the next available number and then use that number to update the database. You set up the number range in transaction SNRO. Then this function module to get the next number.

      call function 'NUMBER_GET_NEXT'
           exporting
            nr_range_nr      = '01' " This is the number range interval  
            object           = 'ZSDINQUIRY'  " This is your object
           importing
                number                  = next_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.

    Welcome to SDN. Please remember to award points for helpful answers and mark your posts as "Solved" if your question has been answered. Thanks.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 13, 2005 at 04:39 PM

    You will have to explicitly code it when you update the table.

    data count type I.

    Select count( * ) into count from zvquery.

    zvquery-count = count + 1 .

    zvquery-partner = 'XXX'.

    zvquery-type = 'XX'.

    insert zvquery.

    Cheers

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 13, 2005 at 04:41 PM

    No automated way. You have to do it programmatically. You can get the count of the existing records add one to it and insert your new record with that value. You can also do it using custom number ranges(tcode SNRO) and then using the FM NUMBER_GET_NEXT.

    Add a comment
    10|10000 characters needed characters exceeded

    • Thanks Rich, coming from top most contributor, that is more than a complement for me.

      I prefer number ranges as opposed to the other approach simply because, number ranges automatically provides you integrity of the number assigned. By that what I mean is, if we program to read the count of the records and increment it, then there are chances that if more than one person executing this program or entering records into it, will get the same numbers. This will not be the case with number range because the moment you call the function module, that number will be reserved and will not be available to another call to the number range object. That avoids the duplicate number assignment.

      Also if the number of records in the table increases, then getting a count(*) is a performance issue, compared to a NUMBER_GET_NEXT.

      Srinivas

  • author's profile photo Former Member
    Former Member
    Posted on Oct 13, 2005 at 04:56 PM

    ok, found the way with your help guys. Thanks a lot

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.