Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Reports with Member() / Export()

Pattern for generating a report: accumulate rows into a physical table (a data member exclusive to the user/run) and, when done, dump it to a text file on the IFS.

This feature uses varchar in @Variables — see Data types.

1. Full example

@Properties {
    Type : Program
    Name : PTESTME
}
@References {
    Tables = ["../tables/TLT3D01.warp"]
}
@Variables {
    global {
        User        char(10)
        Destination varchar(200)
        T301TIPLOT  char(1)
        T301NROTAR  char(19)
    }
}
@Source {
    &User        = USERID()
    &Destination = "/tmp/report.txt"

    Member(LT3D01, &User)

    For Each In LT3D01 Index LT3D0101
    Where T301TIPLOT = &T301TIPLOT
    Where T301NROTAR = &T301NROTAR
        // ... accumulate rows into LT3D01, e.g. with New In LT3D01 ...
    EndFor

    Export(LT3D01, &Destination)
}

2. Member(Table, expr): one member per user/run

Member(LT3D01, &User)

Attaches a data member (parameterized by expr, typically &User so each user gets their own) to Table for the whole program:

  • Creates it with ADDPFM if it doesn’t exist yet (tolerates the error if it already exists).
  • Leaves it active with OVRDBF — effective for the rest of the program, including any open of that table and any later Export(...) over it.

Position rules (at most once per table, in either case):

  • In a Program: only at the top level of @Source (not nested inside If/While/For/Event/etc.).
  • In a Screen: only at the top level of Event Init (not nested, and not in any other Event) — Init runs exactly once, before the screen’s main loop, the same place a Program’s prologue would go:
@Properties {
    Type : Screen
    Name : SGRIDDEMO
}
@Source {
    Event Init
        Member(LT3D01, &User)
    EndEvent

    Event Load
        For Each In LT3D01 Index LT3D0101
            // ... fills the DataGridView, or reads/writes rows ...
        EndFor
    EndEvent
}

Export(...) still isn’t allowed in a Screen — there’s no use case for exporting a report from an interactive screen.

Important: Member(Table, expr) must appear before any For Each/New over Table in the same body — using it after already reading/writing the table is a runtime error, not a compile-time one.

3. Export(Table, destination): dump to IFS

Export(LT3D01, &Destination)

Copies Table’s active member (the one Member(...) set, if any) to an IFS stream file with CPYTOIMPF, comma-delimited format (RCDDLM(*CRLF) STRDLM(*NONE) FLDDLM(',')), replacing the destination if it already exists (MBROPT(*REPLACE)).

Rules: only valid in Program; unlike Member, no position restriction — use it wherever convenient, typically after the For Each/New that filled the report table.