Skip to topic
    ← Back to course topics

    Fields, records and files — AQA A-Level Computer Science

    In AQA A-Level Computer Science, a field represents a single data item, a record is an ordered collection of related fields representing an entity, and a file stores a collection of records. Mastering these fundamentals is essential for understanding secondary storage management, data serialisation, and database architecture.

    Fields, records and files explained

    Reading and writing a text file means a program transfers data between memory and a file stored on secondary storage, using a file handle that the program opens, uses and closes.

    Read the full explanation

    A text file stores characters as human-readable encoded values, usually one record per line, so a program reads it line by line or character by character and writes it by sending strings to the file. When reading, the program opens the file in read mode, retrieves each line until the end of file is reached, and then closes the file. When writing, the program opens the file in write mode, which normally creates or overwrites the file, or in append mode, which adds to the end of existing content, then sends each string and closes the file. Because the data is stored as characters, numbers read from the file are strings and must be converted before arithmetic is performed on them.

    Your focus

    1. Be able to read/write from/to a text file.

    Which command word is this?

    Set out the causes, reasons, or mechanisms clearly using accurate technical language (e.g. explaining why fixed-length records allow direct addressing).

    Fields, records and files exam tips

    Topic Overview

    Data organisation is a foundational concept in computer science that bridges the gap between high-level programmatic data structures and physical secondary storage. This topic examines the data hierarchy: individual fields combining into records, which in turn are aggregated into files stored on disk.

    Understanding the mechanics of records and files is essential for software development, system design, and database normalisation. It enables students to evaluate trade-offs between memory overhead, disk input/output performance, and algorithmic search efficiency in AQA A-Level Computer Science.

    Key Concepts
    • →Hierarchical data structure: Characters form fields (attributes), fields form records (tuples), and records form files (tables).
    • →Record heterogeneity: Unlike standard arrays which are homogeneous, records can contain elements of disparate data types (e.g. strings, integers, booleans).
    • →Fixed vs Variable Length Records: Fixed-length simplifies byte-offset direct addressing at the cost of internal fragmentation, whereas variable-length optimises capacity using end-of-record delimiters or length-prefix bytes.
    • →File Organisation vs File Access: File organisation defines how records are physically stored on storage media (serial, sequential, indexed sequential, or direct/random), while file access dictates the mechanism used to retrieve them.
    Marking Points
    • Opens the file in the correct mode for the operation, such as read, write or append
    • Reads data line by line or character by character until end of file is detected
    • Writes strings to the file and recognises that numbers must be converted to strings first
    • Converts values read from the file back to numbers before performing arithmetic
    • Closes the file after use to release the file handle and ensure data is saved
    Examiner Tips
    • 💡Trace the code line by line, noting the mode in each open statement
    • 💡Check whether a value read from the file is a string before using it in arithmetic
    • 💡State the effect of the open mode when a question asks what will happen to existing data
    • 💡Always state the primary key or key field when explaining how records are uniquely identified and searched in sequential and indexed-sequential files.
    • 💡When explaining how an operating system reads a fixed-length record directly, always explicitly reference the term 'byte offset' or show the calculation: address = record_number * record_length.
    • 💡Remember that variable-length records require end-of-record markers (such as carriage return/line feed) or field-length indicators so the file pointer knows where one record terminates and the next begins.
    Common Mistakes
    • Treats a text file as holding numeric values directly; the values are stored as characters and must be converted
    • Opens a file in write mode when the intended operation is to add data, which overwrites existing content; use append mode instead
    • Omits the close step, which may leave written data unsaved or the file locked
    • Believing records and arrays are interchangeable: Arrays require identical data types across elements, whereas records deliberately bind heterogeneous fields representing an entity under one identifier.
    • Assuming binary conversion factors equal 1000: When calculating file sizes for AQA assessments, KiB and MiB use binary powers (1024 and 1024^2), not decimal SI units (1000), unless explicitly instructed.
    • Confusing serial files with sequential files: A serial file stores records chronologically as they arrive without an ordering key, while a sequential file stores records logically ordered by a designated primary/key field.
    Revision Plan
    1. 1Day 1-2: Master core terminology. Draw and annotate diagrams depicting a field, record, file, and primary key using clear entity examples.
    2. 2Day 3-5: Practice file size calculation problems involving fixed-length records, ensuring accurate byte summation and conversion into KiB/MiB.
    3. 3Day 6-8: Compare and contrast file organisations (serial, sequential, indexed sequential, and random/hashed), creating a comparison matrix of their time complexities for insertion, deletion, and searching.
    4. 4Day 9-10: Work through past paper questions focusing on the trade-offs between fixed-length and variable-length record architectures.
    Exam Question Types
    • 📋Calculation questions: Determining total file or record size in bytes, KiB, or MiB given individual field constraints and record totals.
    • 📋Comparative structure questions: Contrasting fixed-length records with variable-length records, or arrays with user-defined record structures.
    • 📋File organisation scenario questions: Evaluating whether serial, sequential, or direct access is most appropriate for a given real-world application (e.g. batch payroll vs online booking).
    Command Word Expectations (AQA)
    Explain

    Set out the causes, reasons, or mechanisms clearly using accurate technical language (e.g. explaining why fixed-length records allow direct addressing).

    Calculate

    Perform mathematical operations showing full step-by-step working out, correctly using binary multipliers (1024) where relevant, and including appropriate units (e.g. bytes, KiB).

    Compare

    Identify both similarities and differences between two concepts (e.g. sequential access vs random access), explicitly addressing both items rather than just defining them in isolation.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing the hierarchy between fields, records, and files, or incorrectly conflating a record with a single variable or primitive data type.
    ❌ Weak Answer (Loses Marks):A field is a piece of data and a record is multiple files stored together on a disk.
    Example improved answer:A field is a single attribute or discrete item of data (e.g. Surname). A record is a composite data structure consisting of a fixed collection of related fields, usually of differing data types, describing a single entity. A file is a collection of related records stored under a single name on secondary storage.
    Examiner Tip: Always specify that records can hold heterogeneous data types, whereas arrays hold homogeneous data types, as examiners look for this distinction.
    Pitfall: Failing to explain the differences between fixed-length and variable-length records regarding storage efficiency versus access speed.
    ❌ Weak Answer (Loses Marks):Fixed-length records are easier to use while variable-length records save memory.
    Example improved answer:Fixed-length records allocate an identical predetermined byte size to every record. This allows direct calculation of a record's physical address via an offset (Record Address = Base Address + (Record Number * Record Size)), enabling random access, but can waste storage through padding. Variable-length records save secondary storage space by matching size to content but necessitate scanning sequentially or using an index because record boundaries cannot be calculated mathematically.
    Examiner Tip: Explicitly mention offset calculation when discussing direct access in fixed-length records.
    Step-by-Step Worked Solutions

    Question: A school creates a customer file using fixed-length records. Each record consists of: StudentID (6 bytes, ASCII string), Forename (15 bytes, ASCII string), Surname (20 bytes, ASCII string), DateOfBirth (8 bytes, Date format), and YearGroup (1 byte, Integer). Calculate the total file size in kibibytes (KiB) if the file contains 1,200 student records. Show all workings.

    1. 1.Step 1: Calculate the size of a single record by summing the bytes of each field: 6 (StudentID) + 15 (Forename) + 20 (Surname) + 8 (DateOfBirth) + 1 (YearGroup) = 50 bytes per record.
    2. 2.Step 2: Calculate the total raw data size in bytes for 1,200 records: 1,200 records * 50 bytes = 60,000 bytes.
    3. 3.Step 3: Convert bytes to kibibytes (KiB) by dividing by 1,024: 60,000 / 1,024 = 58.59375 KiB.
    Final Answer: 58.59 KiB (or 58.6 KiB to 3 significant figures)

    Question: A direct access file stores fixed-length customer records of exactly 128 bytes each. The first record (Record 0) begins at physical byte position 0. Outline the mathematical formula used to calculate the starting byte address of Record n, and calculate the exact starting byte address of Record 45.

    1. 1.Step 1: Identify the standard random access offset formula: Starting Address = Base Address + (Record Index * Record Length).
    2. 2.Step 2: Substitute the known values: Base Address = 0, Record Length = 128 bytes, Record Index = 45.
    3. 3.Step 3: Calculate the memory byte offset: Address = 0 + (45 * 128) = 5,760.
    Final Answer: The starting byte address of Record 45 is 5,760.
    Active Recall Memory Test
    What is the structural difference between a record and an array?
    Key Fact: An array is homogeneous (stores elements of the same data type), whereas a record is heterogeneous (stores fields of differing data types grouped together).
    What mathematical formula calculates the byte address of Record n in a zero-indexed file of fixed-length records?
    Key Fact: Address = Base Address + (n * Record Length in bytes).
    Why can direct access not be achieved by simple multiplication in variable-length record files?
    Key Fact: Because each record contains a different number of bytes, meaning there is no constant record size to use as a multiplier.
    What is the purpose of a primary key field within a record?
    Key Fact: To uniquely identify each individual record within a file or table.
    Frequently Asked Questions
    What is the difference between a field and an attribute?
    In Computer Science, 'field' and 'attribute' are frequently used interchangeably. However, 'attribute' is typically the conceptual term used in entity-relationship modelling and relational databases to denote a property of an entity, whereas 'field' is the practical implementation of that attribute within a physical or logical record structure.
    Why do fixed-length records waste disk storage space?
    Fixed-length records reserve a predetermined maximum number of bytes for each field regardless of whether the actual data fills that space. For example, if a Surname field is allocated 30 bytes and the stored name is 'Ali' (3 bytes), the remaining 27 bytes are padded with spaces or null characters, leading to internal fragmentation.
    How does an operating system know where a variable-length record ends?
    Variable-length records rely on specific markers to separate data. The system either places a special delimiter character (such as a null byte or carriage return/newline character) at the end of each field and record, or it prefixes each record/field with an integer that explicitly specifies its length in bytes.
    Are records still used in modern programming languages like Python?
    Yes, although different programming languages use different syntax to represent them. While Python does not have a native keyword named 'record', it implements record structures using dictionaries, namedtuples, or classes with attributes. In languages like C and C++, records are defined using 'struct'.
    What is the difference between sequential access and direct access?
    Sequential access requires reading records one after another in order from the beginning of the file until the target record is reached. Direct access (also called random access) allows the read/write head to jump directly to any specific record instantaneously by calculating its physical byte position or consulting an index.