Buffering internally within your program

While writing programs that access huge database tables or access db tables repeatedly (in a loop) etc., it is a good idea to build a buffer internally within your program (in an internal table) and then access these tables rather than going to the database for each loop. One way to do this would be to build up an internal table at each call to the database (while looping) and check in this buffer internal table for a corresponding entry before actually going into the database tables to retrieve entries. A second way could be to dump selected entries into an internal table (using select f1, f2.....fn into table itab where <conditions> ) and then loop on the internal table to retrieve data rather than accessing the database at each loop.

loop at itab1.

read table itab_buffer key f1 = k1 ,,,,, fn = kn (binary search).

If sy-subrc ne 0.

select single relevant fields from dbtable where f1 =k1 , ,,,, fn = kn.

move dbtable-fields to itab_buffer-fields.
append  itab_buffer.

move dbtable-fields to itab1-fields.

move itab_buffer to itab1-fields.
 modify itab1.

    Requires Free Membership to View

This was first published in April 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.