Difference between revisions of "Test268 Section 1"

From MidrangeWiki
Jump to: navigation, search
(Rename Field names of an externally described file=========)
m
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Certifications]]
 
 
[[Category:Test268]]
 
[[Category:Test268]]
[[Category:RPG]]
 
  
 
[[Test268 Section 1|<< Previous Section]] | [[:Category:Test268|Home]] | [[Test268 Section 2|Next Section >>]]
 
[[Test268 Section 1|<< Previous Section]] | [[:Category:Test268|Home]] | [[Test268 Section 2|Next Section >>]]
Line 97: Line 95:
 
|Using a program-global variable that is set by another module. |||If you have specified an override for the file that RPG will open, that |override will be in effect. In the following code, for the file named |INPUT within the RPG program, the file that is opened at runtime |depends on the value of the filename field.  
 
|Using a program-global variable that is set by another module. |||If you have specified an override for the file that RPG will open, that |override will be in effect. In the following code, for the file named |INPUT within the RPG program, the file that is opened at runtime |depends on the value of the filename field.  
  
| Finput    if  f  10        disk    extfile(filename)
+
Finput    if  f  10        disk    extfile(filename)
  
 
==== EXTMBR ====
 
==== EXTMBR ====
Line 112: Line 110:
  
 
==== OPEN ====
 
==== OPEN ====
The USROPN keyword causes the file not to be opened at program initialization. This gives the programmer control of the file's first open. The file must be explicitly opened using the OPEN operation in the calculation specifications. This keyword is not valid for input files designated as primary, secondary, table, or record-address files, or for output files conditioned by the 1P (first page) indicator.  
+
The USROPN keyword causes the file not to be opened at program initialization. This gives the programmer control of the file's first open. The file must be explicitly opened using the OPEN operation in the calculation specifications. This keyword is not valid for input files designated as primary, secondary, table, or record-address files, or for output files conditioned by the 1P (first page) indicator.  
  
 
The USROPN keyword is required for programmer control of only the first file opening. For example, if a file is opened and later closed by the CLOSE operation, the programmer can reopen the file (using the OPEN operation) without having specified the USROPN keyword on the file description specification.
 
The USROPN keyword is required for programmer control of only the first file opening. For example, if a file is opened and later closed by the CLOSE operation, the programmer can reopen the file (using the OPEN operation) without having specified the USROPN keyword on the file description specification.
 +
 +
open myfile;
  
 
==== CLOSE ====
 
==== CLOSE ====
 
  close myfile;
 
  close myfile;
 
  
 
====Rename Field names of an externally described file====
 
====Rename Field names of an externally described file====

Latest revision as of 20:17, 5 August 2007

<< Previous Section | Home | Next Section >>

Section 1 - Externally Described Files in Programs (14%)

Use printer files and "O" specs to define output in a program

Even though this is not used as much anymore, there is still a lot of programs out there that still use this.

FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
FMYOUTPUT  O    F  132        PRINTER OFLIND(OVERFLOW)                                         

OFilename++DF..N01N02N03Excnam++++B++A++Sb+Sa+.............................Comments++++++++++++
OMYOUTPUT  E            HEADINGS          2  1                                                 
O          E            HEADINGS2         2                                                    
O          E            DETAILLINE        1                                                    
O          E            BREAKLINE         1                                                    
O          E            TOTALLINE         1

Use database file I/O operations in a program

Grab one particular record in a file:

      chain (employee) empfile;

Write a record:

      write roperator;

Set the pointer to a spot in the file then read all records that match the key:

      setll (employee) emphist;
      reade (employee) emphist;
      
      dow not %eof();
        ::: Logic here :::
        reade (employee) emphist;
      enddo;

Update a record:

      update record;

Use display file I/O operations in a program

Write a display record:

      write footer;

EXFMT:

      exfmt screen1;

Read a display record:

      read screen;

Use externally described database files in a program

FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
FMYFILE    IF   E           K DISK

Use externally-described printer files in a program

FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
FREPORT    O    E             PRINTER USROPN OFLIND(*IN40)

Use externally-described display files in a program

FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
FREPORT    CF   E             WORKSTN

Create DDS externally described files

.....A..........T.Name++++++RLen++TDpB......Functions+++++++++++++++++++++++++++
     A          R CURCOEMAIL         
     A            CMPNY          4  0
     A            EMAILADDR1   100   
     A            EMAILADDR2   100

Create SQL externally described files

CREATE TABLE LAWCUSTDBF.CUPCOEMAIL ( 
       CMPNY DECIMAL(4, 0) NOT NULL DEFAULT 0 , 
       EMAILADDR1 CHAR(100) CCSID 37 NOT NULL DEFAULT  , 
       EMAILADDR2 CHAR(100) CCSID 37 NOT NULL DEFAULT  ) ;

Use EXTFILE. EXTMBR and OPEN/CLOSE file operations in a program

EXTFILE

specify the value in any of the following forms:

|filename |libname/filename |*LIBL/filename |Notes:


|You cannot specify *CURLIB as the library name.

|If you specify a file name without a library name, *LIBL is used.

|The name must be in the correct case. For example, if you specify |EXTFILE(filename) and variable filename has the value |'qtemp/myfile', the file will not be found. |Instead, it should have the value 'QTEMP/MYFILE'.

|This keyword is not used to find an externally-described file at compile |time.

|If a variable name is used, it must be set before the file is |opened. For files that are opened automatically during the |initialization part of the cycle, the variable must be set in one of the |following ways: ||Using the INZ keyword on the D specification |Passing the value in as an entry parameter |Using a program-global variable that is set by another module. |||If you have specified an override for the file that RPG will open, that |override will be in effect. In the following code, for the file named |INPUT within the RPG program, the file that is opened at runtime |depends on the value of the filename field.

Finput     if   f   10        disk    extfile(filename)

EXTMBR

EXTMBR(membername) | |The EXTMBR keyword specifies which member of the file is opened. You |can specify a member name, '*ALL', or |'*FIRST'. Note that '*ALL' and |'*FIRST' must be specified in quotes, since they are member "names", |not RPG special words. The value can be a literal or a variable. |The default is '*FIRST'.

|The name must be in the correct case. For example, if you specify |EXTMBR(mbrname) and variable mbrname has the value |'mbr1', the member will not be found. Instead, it |should have the value 'MBR1'.

|If a variable name is used, it must be set before the file is |opened. For files that are opened automatically during the |initialization part of the cycle, the variable must be set in one of the |following ways: | |Using the INZ keyword on the D specification |Passing the value in as an entry parameter |Using a program-global variable that is set by another module

OPEN

The USROPN keyword causes the file not to be opened at program initialization. This gives the programmer control of the file's first open. The file must be explicitly opened using the OPEN operation in the calculation specifications. This keyword is not valid for input files designated as primary, secondary, table, or record-address files, or for output files conditioned by the 1P (first page) indicator.

The USROPN keyword is required for programmer control of only the first file opening. For example, if a file is opened and later closed by the CLOSE operation, the programmer can reopen the file (using the OPEN operation) without having specified the USROPN keyword on the file description specification.

open myfile;

CLOSE

close myfile;

Rename Field names of an externally described file

FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
FMYFILE    IF   E             DISK    PREFIX(SS)

you can also include the number of albhabets to be replaced.ie;PREFIX(SS:2)

When using externally described files, show how to rename record formats in a program

FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++Comments++++++++++++
FMYFILE    IF   E             DISK    RENAME(MYFILE:MYREC)

Create Physical, Logical/View, Printer, and Display externally described files

Use a field reference file to create an externally described file

<< Previous Section | Home | Next Section >>