07-09-2014 6:56 AM
Hi All ,
when i am using the modify statement to modify the custom table , i need to know how many records are modified , i want the count of records and the record detail.
For ex :
I have an internal table and with the following records ,
field1 field2 field3 field4
1 3 3 34 - new record
3 3 2 23 - existing record
1 2 2 11 - old record
here i need the count as 1 as modified and 1 as new record .
when i am updating the ztable with the following records of internal table , so i need the count of the modified record and its details.
modify table ztable from itab,
I cannot use sy-dbcnt , it will give all the records in internal table , i need only the updated and modified record count and its details.
Please share your ideas!
Thanks,
Pradeep.
07-14-2014 2:47 PM
07-09-2014 7:02 AM
Hi Pradeep,
Before you modify the table, check no.of records existing in the Custom table in which are you updating, those are matching to the records in your internal table (for all entries in your int.table).
Then Modifed Records = [ Existing records - Total records in your internal table ].
Regards,
Vijay
07-09-2014 7:12 AM
Cont. to my previous comment,
To get the count of records already existing in DB table matching to records in internal table, you can use following statement:
SELECT COUNT( * ) INTO L_COUNT FROM DB_TAB
FOR ALL ENTRIES IN INT_TAB
WHERE KFIELD_1 = INT_TAB-FLD1 AND KFIELD_2 = INT_TAB-FLD2.
IF SY-SUBRC = 0.
" you will get no.of records existing already in L_COUNT.
ENDIF.
Then find the Total No.of records in your internal table (Describe Table) into L_LINES.
Modified_records = L_LINES - L_COUNT.
Regards,
Vijay
07-09-2014 7:34 AM
Hi Vijay ,
Thanks for your reply , as you said if i am getting the total line count of custom table
custom table count = 20 .
internal table count = 20 .
then where is the modify statement and count ?
if i minus 20-20 = 0.
Please share..
07-09-2014 7:41 AM
Have you provided complete primary key set in your where condition? Instead of getting count, just fetch the records and check in debugging that how many records are you getting.
Vijay
07-09-2014 7:58 AM
Can you explain to me what the difference is between "existing record" and "old record"? If I can understand this then I can provide you with answer.
07-09-2014 8:03 AM
Hi Glen ,
Sorry for that , old record and changed record ,
I have an internal table and with the following records ,
field1 field2 field3 field4
1 3 3 34 - new record to db table
3 3 2 23 -changed record (already exist in DB table but now it has been changed)
1 2 2 11 - old record (same as DB table)
here i need the count as 1 as modified and 1 as new record .
So now i am expecting the answer..
07-09-2014 8:17 AM
Pradeep,
Just follow these steps.
your custom table name 😆 zctab
internal table name:-> Itab1.
you have data in Internal table. Itab1.
create one more table itab2
1 step : select * from zctab into itab2 for all entry itab1 where condition.
put loop itab1.
check each and every record from itab2.
if something diff.
count++.
else.
same++. "table one variable for checking same record. for example I took same
endif.
end loop.
" here you get modified record.
"now you want to new record added count.
new record = sy-dbcnt - count - same.
you get new record number.
hope you understand and its helps you
Regards,
Sandeep
07-09-2014 8:20 AM
I haven't time to test this code below, so you have to rework it a bit but I would try something like this:
SELECT * FROM dbtab INTO temptab
FOR ALL ENTRIES IN itab
WHERE field1 = field1
AND field2 = field2
AND field3 = field3
AND field4 = field4.
old_record_count = sy-dbcnt.
* here use only test key fields
SELECT * FROM dbtab INTO temptab
FOR ALL ENTRIES IN itab
WHERE field1 = field1
AND field2 = field2
AND field3 = field3
AND field4 ne field4.
changed_record_count = sy-dbcnt.
In the second select statement only use the key fields to test equality and make sure the others are NE to get the number of entries that will be changed.
Hope this helps.
07-09-2014 8:36 AM
Hi Pradeep ,
Use
SELECT COUNT( * )
INTO v_num
FROM DB_table.
V_num is the no. of records in your table.
Then apply modify statement and get the value of sy-dbcnt.
This will give the no. of records updated in your table.
Now, again use
SELECT COUNT( * )
INTO v_numnew
FROM DB_table.
v_numnew is the no. of records in your table ( after updation ).
Now,
No. of new records in your DB table ( newnum ) = V_numnew - V_num
No. of modified records = sy-dbcnt - newnum.
Regards,
Yogendra Bhaskar
07-09-2014 9:30 AM
Hi Yogendra ,
Thanks for your reply ,
As per your suggestion i can get the new records by the differences ,
If i am modifying same record in internal table , the DB table entries numbers(count) will remain same , but in DB the record entry will get modified by the internal table , in that case , it wont work.
07-09-2014 9:55 AM
07-09-2014 10:01 AM
Hi Pradeep ,
In that case sy-dbcnt will get updated for the no. of modified records
Regards
Yogendra Bhaskar
07-09-2014 10:42 AM
Glen ,
Yes , i tried , but how will i find the count of modified record of the current run ?
07-14-2014 2:47 PM
07-14-2014 4:22 PM
Hi All ,
Thanks for posting , i have got resolved by the following code.
Select * from tab into table itab where...
If sy-subrc = 0.
old_count = old_count + 1.
modify tab from table itab
else.
new_count = new_count + 1.
modify tab from itab.
endif.