09- RPGLE - Subfiles

DURATION:
12 Hours
ID:
09
?>
PRICE
1,999.00

INSTRUCTORS:

Mrs.Lalitha
Junior Lecturer - Web Design

Categories

Advanced

Subfiles in RPGLE (RPG IV) are a powerful feature that allows you to display and manage lists of data on a screen. They are particularly useful for handling large datasets in a user-friendly manner. Here’s an overview of how to work with subfiles in RPGLE:

Key Concepts

  1. Subfile: A subfile is a temporary storage area in a display file that holds multiple records, which are displayed on the screen as a list.
  2. Subfile Control Record: Manages the subfile, including operations like loading, displaying, and clearing the subfile.
  3. Subfile Record Format: Defines the layout of each record in the subfile.

Steps to Create and Use a Subfile

1. Define the Subfile in the Display File (DSPF)

You need to define the subfile and its control record in the display file. Here’s a simplified example:

plaintext

A          R SFLCTLR                SFLCTL(SFL)

A                                      SFLSIZ(9999)

A                                      SFLPAG(10)

A                                      SFLDSP

A                                      SFLDSPCTL

A  90                                  SFLCLR

A  91                                  SFLEND

A                                      OVERLAY

A          R SFL                      SFL

A            FLD1            10A

A            FLD2             5Y 0

A            FLD3             8Y 2

2. Define the Subfile in the RPGLE Program

In your RPGLE program, you define the subfile and the subfile control records. You load data into the subfile and display it.

rpg

**FREE

// Define the display file

FMYDSPF   CF   E             WORKSTN;

// Declare variables for subfile handling

DCL-S subfileRRN INT(5); // Relative record number

DCL-S recordLoaded IND;  // Indicator for record loading

// Load the subfile

subfileRRN = 1;

recordLoaded = *OFF;

// Loop to load records into the subfile

DOU recordLoaded;

  // Set subfile fields

  FLD1 = ‘Record ‘ + %CHAR(subfileRRN);

  FLD2 = subfileRRN * 10;

  FLD3 = subfileRRN * 0.75;

  // Write to the subfile

  WRITESFL SFL;

  // Update the relative record number

  subfileRRN += 1;

  // Stop after loading 10 records (for example)

  IF subfileRRN > 10;

    recordLoaded = *ON;

  ENDIF;

ENDDO;

// Display the subfile

EXFMT SFLCTLR;

*INLR = *ON;

RETURN;

Explanation

  • Subfile Control (SFLCTLR): Controls the subfile operations, such as displaying and clearing the subfile.
  • Subfile Record Format (SFL): Defines the layout of each record in the subfile, including the fields displayed.
  • Loading the Subfile: The loop loads records into the subfile, setting the fields and writing each record to the subfile.
  • Displaying the Subfile: The EXFMT operation displays the subfile control record, which in turn displays the subfile records.

Advanced Features

  • Paging: You can handle large datasets by loading subfile pages dynamically based on user actions (e.g., scrolling).
  • Selection: You can allow users to select records from the subfile for further actions.
  • Editing: You can enable users to edit records directly in the subfile and save changes.

Subfiles provide a flexible and powerful way to manage lists of data in RPGLE applications, enhancing user experience and interaction. If you have specific scenarios or need more detailed examples, feel free to ask!

Leave a Reply

Your email address will not be published. Required fields are marked *