07-08-2008 5:13 PM
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?
07-08-2008 5: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
07-08-2008 5: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
07-08-2008 5:47 PM
07-08-2008 5: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