How to use normal table as temp table using code.
In this blog we will see how to use normal table as Temp table during runtime. It's useful to store the temporary data at runtime.
Refer to the below code. Every table has a method setTmp which will be used to make that table act as temp table at runtime.
class VendTableTemp { public static void main(Args _args) { VendTable vendTable; vendTable.setTmp(); vendTable.AccountNum = '1000'; vendTable.Blocked = CustVendorBlocked::No; vendTable.Party = 1; vendTable.doInsert(); vendTable.clear(); vendTable.AccountNum = '1002'; vendTable.Blocked = CustVendorBlocked::All; vendTable.Party = 2; vendTable.doInsert(); while select vendTable { info(strFmt( "%1 - %2", vendTable.AccountNum, vendTable.Blocked)); } } }
In the code, we first call the setTmp() method on the VendTable table to make it temporary in the scope of this method. This means that any data changes will be lost once the execution of this method is completed and the actual table content will not get affected.
Next, we are inserting two back-to-back sample records and we are calling Do Insert method to skip any additional logic. But keep in mind that we have made the table as temporary, but all the standard methods will be called like update, delete, init value method etc.
Last thing we have added is while select statement to see the inserted records with the same buffer. While running the class, you will get only the 2 records we inserted earlier. It won't show other records present in the table. Also, these records we inserted, doesn't get reflected into the actual table.
Thanks.
*This post is locked for comments