EXTMBR and EXTFILE

23 Views


In RPGLE, the keyword EXTMBR (short for External Member) is used in the DCL-F (or fixed-form F-spec) to specify which member of a database file you want to access.

By default, RPG accesses the first member of a file unless you tell it otherwise — that’s where EXTMBR comes in.


๐Ÿ“˜ Use Case

When you have a multi-member physical file, and you want to access a specific member at runtime or compile time.


โœ… Syntax (Free-form RPGLE)

Dcl-F MyFile Usage(*Input) ExtFile('MYPF') ExtMbr('MYMBR');
  • MYPF = physical file

  • MYMBR = member name


โœ… Syntax (Fixed-form RPG)

FMYFILE    IF   E           K Disk    EXTMBR('MYMBR')

๐Ÿ” Example: Read from Specific File Member

Let’s say your file INVOICES has multiple members (2023, 2024, 2025).

Free-form RPGLE Example:

Dcl-F Invoices Usage(*Input) ExtMbr('2024');

Dcl-S InvoiceID Char(10);

Read Invoices;
Dow Not %EOF(Invoices);
   Dsply InvoiceID;
   Read Invoices;
EndDo;

*INLR = *On;
Return;

๐Ÿง  Tips:

  • EXTMBR('MBRNAME'): Hardcoded member name

  • EXTMBR(*ALL): Not valid — RPG only reads one member at a time

  • To dynamically choose a member, use OVRDBF in a CL program:

OVRDBF FILE(INVOICES) TOFILE(INVOICES) MBR(2024)

Then call your RPG program.


Great — let’s talk about EXTFILE in RPGLE, which works hand-in-hand with EXTMBR.


๐Ÿ“˜ What is EXTFILE?

EXTFILE tells the RPG program to use a different external file name than the one used in the DCL-F statement. It allows your RPG variable (file name) to be logically different from the physical or external file name on disk.

This is especially useful when:

  • You want to reuse code with different physical files

  • You want to override the actual file at runtime using OVRDBF


โœ… Syntax (Free-Form)

Dcl-F MyFile Usage(*Input) ExtFile('ACTUALFILE') ExtMbr('MYMBR');
  • MyFile: The RPG internal file name used in your code

  • ACTUALFILE: The actual physical file name on disk

  • ExtMbr('MYMBR'): Optional — specifies a specific member


๐Ÿ”„ Example

Suppose you have two physical files:

  • CUSTOMERS_2023

  • CUSTOMERS_2024

You can write one RPG program like this:

Dcl-F CustFile Usage(*Input) ExtFile('CUSTOMERS_2023');

Then override the file dynamically in CL:

OVRDBF FILE(CUSTFILE) TOFILE(CUSTOMERS_2024)
CALL PGM(MYPGM)

๐Ÿ’ก Notes

Keyword Purpose
EXTFILE() Maps internal RPG file name to actual file
EXTMBR() Selects specific member within that file

๐Ÿงพ Full Example (Free-Form RPGLE)

**FREE

Dcl-F CustFile Usage(*Input) ExtFile('CUSTOMERS') ExtMbr('PARIS');

Dcl-S CustID Char(10);

Read CustFile;
Dow Not %EOF(CustFile);
   Dsply CustID;
   Read CustFile;
EndDo;

*INLR = *On;
Return;

This lets you:

  • Write RPG using CustFile

  • But actually read from CUSTOMERS, member PARIS


 

Post Comments