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: 

Collect <field_symbol>

Former Member
0 Kudos

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.


1 ACCEPTED SOLUTION

former_member585060
Active Contributor
0 Kudos

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

2 REPLIES 2

former_member585060
Active Contributor
0 Kudos

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

Kartik2
Contributor
0 Kudos

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