One of the most common pieces of code developers have to write is to copy a record from one table to another. Recently I had to copy a record from a table into an audit table on changes. The issue with writing such piece of code in Event Rules or NER’s is that you have to create a variable each for the value to be fetched, and inserted. For big standard tables with over 100 fields, this will be a very hectic process.
There’s an easy way to get this done using C BSFN’s. For now we take an example that, we need to write an audit record into a copy of F4801, say F554801. The Primary Key of F554801 has been updated to incorporate an additional sequence number (SEQ5) so that multiple records can be inserted for the same document number (DOCO).
So the logic for the BSFN will be something like
- Fetch the latest sequence number from F554801 for the Document number (Primary Key)
- Increment the Sequence number by 1.
- Retrieve the record from original table F4801 to be copied.
- Insert the retrieved record into F554801 along with the incremented Sequence number.
The BSFN is not a big deal, only catch here is to assign the table data-structure values from F4801 to F554801. For this, what we do is to modify the JDB_Fetch statement.
The return datastructure of the JDB_Fetch is the target table instead of the source table on which its fetched. i.e.: we return the results into the F554801 datastructure in the Step-3 above.
Visit the following Link to download the complete Business Function files.