Reputation: 33
In a class based framework where a method (process_in_batch) in the parent class generates batches of data (for a given batch size) for any data coming from a method (prepare_data) redefined in each child class to retrieve its own data (of type any).
Both these methods are called within the parent method (execute): process_in_batch( prepare_data( ) ).
Here, prepare_data method is redefined by each child class and then process_in_batch splits the data table into batches of 'batch_size' and then calls a function in background to process each dataset separately.
Any views?
Thanks AK
So far, I only have this:
FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE.
"Dereference the keys data supplied
ASSIGN ir_data->* TO <lt_data>.
IF sy-subrc EQ 0.
FIELD-SYMBOLS: <lt_package_data> TYPE ANY TABLE.
DATA: lr_data_package_ref TYPE REF TO data.
CREATE DATA lr_data_package_ref LIKE <lt_data>.
ASSIGN lr_data_package_ref->* TO <lt_package_data>.
"Process dataset in batches of size requested
LOOP AT <lt_data> INTO DATA(ls_package) GROUP BY ( sy-tabix - 1 ) DIV iv_batch_size + 1.
CLEAR <lt_package_data>. "Clear the group
"Create the (next) Group
<lt_package_data> = VALUE #( FOR ls_group_record IN GROUP ls_package
( CORRESPONDING #( ls_group_record ) ) ).
"Process this dataset
"Call the background function to process this dataset - Serialize the dataset content before processing
process_batch_in_background( iv_batch_data = /ui2/cl_json=>serialize( <lt_package_data> ) ).
ENDLOOP.
ENDIF.
Here IR_DATA is the incoming data generated by specific implementation of method prepare_data and is a reference type to generic data (TYPE REF TO DATA). The above code doesn't compile because:
"<LT_DATA>" has a generic type that cannot be used for declarations.
This is an initial thought process, of course there'd be more errors but I want to know if someone has any other idea as to how this can be done?
Update: I have been able to achieve a compilable code as follows:
FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE.
"Dereference the keys data supplied
ASSIGN ir_data->* TO <lt_data>.
IF sy-subrc EQ 0.
FIELD-SYMBOLS: <lt_package_data> TYPE STANDARD TABLE.
DATA: lr_data_package_ref TYPE REF TO data.
CREATE DATA lr_data_package_ref LIKE <lt_data>.
ASSIGN lr_data_package_ref->* TO <lt_package_data>.
"Process dataset in batches of size requested
LOOP AT <lt_data> ASSIGNING FIELD-SYMBOL(<ls_package>) GROUP BY ( sy-tabix - 1 ) DIV iv_batch_size + 1.
CLEAR <lt_package_data>. "Clear the group
"Create the (next) Group
LOOP AT GROUP <ls_package> ASSIGNING FIELD-SYMBOL(<ls_package_line>).
APPEND INITIAL LINE TO <lt_package_data> ASSIGNING FIELD-SYMBOL(<ls_package_record>).
<ls_package_record> = <ls_package_line>.
ENDLOOP.
IF <lt_package_data> IS NOT INITIAL.
"Process this dataset
"Call the background function to process this dataset
process_batch_in_background( iv_batch_data = /ui2/cl_json=>serialize( data = <lt_package_data> ) ). "Serialize the dataset content before processing
ENDIF.
ENDLOOP.
ENDIF.
Although, I'm now facing another issue. I tried this with a simpler child implementation where the underlying IR_DATA generated was a simpler Standard Table of a character type structure. It ran fine. But when I tried this with another child implementation where the underlying IR_DATA generated is a Sorted Table type containing Packed and Raw data type fields, it resulted in the following shortdump: ASSIGN_TYPE_CONFLICT at line
ASSIGN lr_data_package_ref->* TO <lt_package_data>.
Upvotes: 1
Views: 658
Reputation: 33
(Answering own question as I've found a working solution)
Ended up trying different things and following code worked in all scenarios so far:
FIELD-SYMBOLS: <lt_data> TYPE ANY TABLE.
"Dereference the keys data supplied
ASSIGN ir_data->* TO <lt_data>.
IF sy-subrc EQ 0.
FIELD-SYMBOLS: <lt_package_data> TYPE ANY TABLE.
DATA: lr_data_package_ref TYPE REF TO data.
CREATE DATA lr_data_package_ref LIKE <lt_data>.
ASSIGN lr_data_package_ref->* TO <lt_package_data>.
"Process dataset in batches of size requested
LOOP AT <lt_data> ASSIGNING FIELD-SYMBOL(<ls_package>) GROUP BY ( sy-tabix - 1 ) DIV iv_batch_size + 1.
CLEAR <lt_package_data>. "Clear the group
"Create the (next) Group
LOOP AT GROUP <ls_package> ASSIGNING FIELD-SYMBOL(<ls_package_line>).
INSERT <ls_package_line> INTO TABLE <lt_package_data>.
ENDLOOP.
IF <lt_package_data> IS NOT INITIAL.
"Process this dataset
"Call the background function to process this dataset
process_batch_in_background( iv_batch_data = /ui2/cl_json=>serialize( data = <lt_package_data> ) ). "Serialize the dataset content before processing
ENDIF.
ENDLOOP.
ENDIF.
The 'Append' statement has been replaced with an 'Insert' statement.
Pls feel free to point out any issues with this solution.
Cheers AK
Upvotes: 0