05-17-2012 12:45 AM
Hi all,
What I a trying to do below is to collect the data in my field symbol <lt_tx_data_c1113t> after deleting the data in account component. It doesnt give any error but collect doesn't work. I was hoping it would sum up the records after Account was deleted.
loop at <lt_tx_data_c1113t> ASSIGNING <lt_record>.
ASSIGN COMPONENT 'ACCOUNT' OF STRUCTURE <lt_record> TO <lt_account>.
<lt_account> = ''.
collect <lt_record> into <lt_tx_data_c1113t>.
endloop.
Please help.
Diksha.
05-17-2012 3:35 AM
Hi,
Try to use COLLECT to append into another internal table similar to <lt_tx_data_c1113t>.
Create another internal table similar to <lt_tx_data_c1113t>.
FIELD-SYMBOLS: <lt_tx_data_c1113t_tmp> TYPE STANDARD TABLE .
DATA : lt_collect TYPE REF TO data.
CREATE DATA lt_collect LIKE <lt_tx_data_c1113t>.
ASSIGN lt_collect->* TO <lt_tx_data_c1113t_tmp>.
LOOP AT <lt_tx_data_c1113t> ASSIGNING <lt_record>.
ASSIGN COMPONENT 'ACCOUNT' OF STRUCTURE <lt_record> TO <lt_account>.
<lt_account> = ''.
COLLECT <lt_record> INTO <lt_tx_data_c1113t_tmp>.
ENDLOOP.
Thanks & regards
Bala Krishna
05-17-2012 3:35 AM
Hi,
Try to use COLLECT to append into another internal table similar to <lt_tx_data_c1113t>.
Create another internal table similar to <lt_tx_data_c1113t>.
FIELD-SYMBOLS: <lt_tx_data_c1113t_tmp> TYPE STANDARD TABLE .
DATA : lt_collect TYPE REF TO data.
CREATE DATA lt_collect LIKE <lt_tx_data_c1113t>.
ASSIGN lt_collect->* TO <lt_tx_data_c1113t_tmp>.
LOOP AT <lt_tx_data_c1113t> ASSIGNING <lt_record>.
ASSIGN COMPONENT 'ACCOUNT' OF STRUCTURE <lt_record> TO <lt_account>.
<lt_account> = ''.
COLLECT <lt_record> INTO <lt_tx_data_c1113t_tmp>.
ENDLOOP.
Thanks & regards
Bala Krishna
05-17-2012 4:22 AM
Hi,
First of all understand the concept of collect statement, it will check for the key fields, and if the key fields match only then it will sum up the numeric fields, if you have not defined keys for your internal table, then it will consider the all the continuous character fields as key.
If you want to clear the account then why are you using null value ( '' ). This will work fine but a better option would be to use a simple clear statement.
clear <lt_account>.
In your code, you are trying to collect into the same table that you are looping. First of all the existing record's account will be set to null because you are accessing through field symbols and then you are collecting it into the same table. Please see your logic once. I think you want to have a single record for each and every account but the numeric fields should be summed up. In that case a better option would be to collect into a separate internal table, and while collecting make sure that the key fields are same for which you want to sum up the numeric fields.
Hope this helps.
Thanks and regards,
kartik