Skip to content

Processing Data Records

This is so common!

In lots of programming tasks we need to be able to process records sequentially. The records can be in files, databases, entered live, or even from data on a distant server that was brought to your program with AJAX.

A record is like a row in a spreadsheet. Here's an example of an employee record:

1000, "John", "Smith", "Engineer", "555-1234"
  • The record has discrete pieces of data that have been separated with commas. Each of the pieces of datum in the record is called a field.

  • In data processing we sometimes call the commas a delineator.

  • A Record Set  (a file) is a bunch of records like the one above. The number of records in a record set can vary from just a few to many millions.

  • Records can exist in many ways and you will learn lots of ways in your coming semesters. The most important way that organizations store data records these days are in databases. This is why there are several semesters of database courses in our programming degree.

Record Processing

One step at a time.

  • JavaScript has an important security feature, it can't access your local hard drive in any way. This is to prevent malicious JavaScript code from doing damage to your computer. This is a really good thing when you are creating applications for real use, but it makes learning how to process records more difficult.

  • Because JavaScript has no file Input/Output (I/O) capabilities we will be using a record processing system that has been custom-made to simulate record processing for the course. It allows us to learn to process records and data in a way that is similar to what you will be using in your future courses.

  • In the unit04/unit04/js/ directory there is a special JavaScript file that contains all the data and some code which allows us to use the data. Feel free to find it and look it over, but you won't need to edit the file in any way. It also might be a little difficult to understand at this point in your programming knowledge. You'll understand all of it before you are done with the degree.

  • Here's how it works. When you are writing a program that needs to process records you will create a variable that stores all the records you need. For example, it might be named "records" as in the following example:

let records;
  • You then use a system function that starts with "open" to make the data available for use in your application. The particular one to use for any given record set will be documented in the lab or project file. After this function has been run your program will be ready to read the first record in the set.
records = openSampleDataRecords();
  • A function to read the next record. This makes the next record available if there are any more to be read. If there aren't anymore records then the function returns false. If there are more records then the function returns true. This is typically called as the loop conditional.
  • Let's see how this all works

Available Record Sets

Here is a list of the available records sets for this unit. We'll be using these for labs, projects, and demos for this unit. Each one is a link to more details about the set.

Student Exam Records

Student Enrollment Records

Inventory Items Records

Employee Payroll Records

Record Processing Demo

Here's a demo of how to loop through one of these record sets.

  This is file unit04/unit04/js/processingDataRecords.js
  It contains the JavaScript code for "Processing Data Records"
  File: /unit04/processingDataRecords.html
function processingDataRecords() {
    "use strict";

    // Declare Variables
    let currentNumber;
    let currentDescription;
    let currentStockAmount;
    let itemRecords;

    // Open the Inventory Items Records and make them
    // available to the script
    itemRecords = openInventoryItemsRecords();

    document.write("The Inventory Items Record Set:<br /><br />");

    // Read the next record, test to see if there
    // is a next record and then output it
    while (itemRecords.readNextRecord()) {
        currentNumber = itemRecords.getItemNumber();
        currentDescription = itemRecords.getItemDescription();
        currentStockAmount = itemRecords.getItemStockAmount();

        document.write(currentNumber + "\t" + currentDescription
                + "\t" + currentStockAmount + "<br />");

** Click me to run processingDataRecords() **

Note: Refresh the page to return to the course content


  1. Lab03: Record Set Processing
    • unit04/labs/lab-03-recordSet.html
  2. Lab04: A Simple Start with Student Enrollment Records
    • unit04/labs/lab-04-student-enroll.html