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

Add number of records to a field

I need to load data in BW ODS from flat file and want to populate one field ROWID which will hold record numbers starting from 1 if ODS is empty. This ROWID in ODS is used as Key field. I want to populate this ROWID based on number of records in flat file.

If there are already records in ODS and say last record number is 10, next record number will be 11 and will populate rests one by one.

So first I want to read ODS table if there are any records. If empty, ROWID will be populating from record 1 and if not empty, get the last ROWID and populate from next number.

Help me with the code please?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 04:55 PM

    Hi,

    If the select count (*) is successfull then add 1 to the count then move it to the rowid column.

    SELECT COUNT(*) INTO V_COUNT FROM TABLENAME.
    
    IF SY-SUBRC NE 0.
    
    * If no records found then set the counter to 1.
      v_count = 1.
    
    ELSE.
    
    * If the record is found then set the row id of the table by adding 1.
      TABLENAME-ROWID = V_COUNT + 1.
    
    ENDIF.
    
    **If you want to insert multiple records within a loop.
    
    LOOP AT ITAB.
    
    * Increment the counter.
      V_COUNT = V_COUNT + 1.
      
    * Set the row id.
      TABLENAME-ROWID = V_COUNT.
    
    ENDLOOP.

    Hope this helps.

    Thanks

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 04:18 PM

    Hi,

    Use SELECT COUNT(*) to get the number of rows from the table.

    SELECT COUNT(*) INTO v_count FROM tablename.
    
    IF sy-subrc ne 0.
    
    * No record found set the counter to 1
      v_count = 1.
    
    ENDIF.

    Thanks

    Naren

    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.