Application Development 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: 

Count of records when using modify statement

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

former_member201275
Active Contributor
0 Kudos

Hi,

Is your question answered? Please close if this is the case.

15 REPLIES 15

VijayaKrishnaG
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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..

0 Kudos

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

former_member201275
Active Contributor
0 Kudos

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.

0 Kudos

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..

0 Kudos

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

former_member201275
Active Contributor
0 Kudos

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.

yogendra_bhaskar
Contributor
0 Kudos

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

0 Kudos

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.

0 Kudos

did u try my code?

0 Kudos

Hi Pradeep ,

In that case sy-dbcnt will get updated for the no. of modified records

Regards

Yogendra Bhaskar

0 Kudos

Glen ,

Yes , i tried , but how will i find the count of modified record of the current run ?

former_member201275
Active Contributor
0 Kudos

Hi,

Is your question answered? Please close if this is the case.

0 Kudos

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.