NEW_RECORD__END_ROUTINE – How to use it
SAP BW 7.x system, for more information, visit the Business Intelligence homepage,
This Document describes how to use the method NEW_RECORD__END_ROUTINE.
when a transformation gets created we have the following objects getting generated automatically,
- Program RSTRAN_MASTER_TMPL
- Class lcl_transform
- 2 Types _ty_s_SC_1 for the source and _ty_s_TG_1 for the target
start_routine, inverse_start_routine, end_routine, inverse_end_routine and new_record__end_routine
The focus for us in the new_record__end_routine.
Note – There is no new_record__start_routine, we only have the new_record__end_routine.
In the sap BW transformations we have a method “new_record__end_routine”. Now i am going to explain you on how it can be used.
Scenario — I am loading data from one InfoProvider to another. Now i need to add few more records to the incoming data. In the end routine, i could append these records by simple “Append” statement. But this will definitely give an error, if you are going to add the entries without increment the “data record” number.
From InfoProvider A we load data to InfoProvider B. Consider we have 10 records coming from A, now i look up on another InfoProvider C and add 5 more records to the result_package by using an “Append” statement. But the load will fail because of the newly added records, as the newly added records will not have the “record” number.
End routine will always depend on the structure _ty_s_TG_1.This structure will always have a default field called RECORD. This field is automatically populated for every incoming record from source, but when we append the records to the result_package then this field must be populated explicitly or else the load will fail.
So how we can handle this using ABAP code.
- sort the result package by record is descending order.
- read the record. (Highest record number is received)
- Loop the internal table from where, we are doing to add the records to result_package
- Now for each loop increase the record count by 1, before appending to the result_package
- Sort the result package by record in ascending order (optional statement)
This will resolve the error,
Actual code (ZUSER is the InfoObject from where i read and append records to the result_package)
So now this can be totally avoided using the method NEW_RECORD__END_ROUTINE
see the screen shot below,
We export the current table index (SYST-TABIX) to the method and also the segment id. The method returns the last record + 1 to the counter and counter is assigned to the wa_result_package-record.
Note —request, datapackid, segid are part of end_routine, hence we do not have to specifically declare them.
This is the SAP recomended approach to add the records to the result_package.
Thank you - this was very helpful!
I wish there would be more such detailed articles which help to understand without much further reading.
But one more question: how can I call this from an expert routine?
I am happy that my document has been informative to you.
In case of "expert routine" you can use the method new_record__expert_routine.
I tried and it did not really work the same:
Hi Lakshminarasimhan N,
Thank you for the detailed explanation.
I have a similar requirement of adding records to Result_Package for Master Data(time dependent) Info Object.
I have written to increment the Record value by 1 before Append for each record in a loop. Till now its good.
But my loop is running like infinite loop, reason being: the newly added records into the Result_Package are being read into the loop and again the logic is executed on those newly added records and generating a new set of records into the Result_Package.
Can you please provide a solution for this.
Can you copy and paste the code here.
Please can you help me to resolve this Problem.
I want to generate more test data in my standard DSO, in which i already loaded 1 million records from flate files. This has for example 3 infoobjects as keys characteristics c1, c2, c3, 4 others characteristics which are not keys Ca, cb, cc and 5 key figures. Please can you help me to write an end routine to create 50 millions records as test data, where i have only 1 million now.
Many thanks for any help.
Hello. Do you have a sample code link for 'Expert Routine'? I get the warning 'Cross-tab of error handler invalidated: RECORD values will be renumbered' in the DTP logs. The data output also seems weird. I am actually generating records by exploding each source record on time characteristic, based on a certain condition characteristic in the source record and need an example code to use the "new_record__end_routine" method?!