7 72 3 OPEN Examples

LANSA Technical

7.72.3 OPEN Examples

Example 1: Open the customer master file CUSTMST during the first screen interaction.

OPEN FILE(CUSTMST)
 

or

OPEN FILE(CUSTMST) USE_OPTION(*FIRSTSCREEN)
 

Example 2: Open all files immediately, except for the customer master file which should be opened "on demand".

OPEN FILE(*ALL) USE_OPTION(*IMMEDIATE)
OPEN FILE(CUSTMST) USE_OPTION(*ONDEMAND)
 

Example 3: Open file STATES, load all records into working list #WRK_LIST and then close file STATES.

OPEN      FILE(STATES) USE_OPTION(*IMMEDIATE)
SELECT    FIELDS(#WRK_LIST) FROM_FILE(STATES)
ADD_ENTRY TO_LIST(#WRK_LIST)
ENDSELECT
CLOSE     FILE(STATES)
 

Example 4: Open file STATES, load all records into working list #WRK_LIST in state name (STATNM) order, and then close file STATES.

OPEN      FILE(STATES) USE_OPTION(*OPNQRYF) KEYFLD('STATNM')
SELECT    FIELDS(#WRK_LIST) FROM_FILE(STATES)
ADD_ENTRY TO_LIST(#WRK_LIST)
ENDSELECT
CLOSE     FILE(STATES)
 

Example 5: Open file STATES, load all records into working list #WRK_LIST in state name (STATNM) order, select only records where the post code (POSTCD) is in the range 2000 to 3999, and then close file STATES.

OPEN      FILE(STATES) USE_OPTION(*OPNQRYF) KEYFLD('STATNM') QRYSLT('(POSTCD *GE 2000) *AND (POSTCD *LE 3999)')
SELECT    FIELDS(#WRK_LIST) FROM_FILE(STATES)
ADD_ENTRY TO_LIST(#WRK_LIST)
ENDSELECT
CLOSE     FILE(STATES)
 

Example 6: Create a completely user driven name and address report that will answer just about any name and address query request. The name and address file is called NAMES.

    DEFINE    FIELD(#SELECTION) TYPE(*CHAR) LENGTH(100) LABEL('Select :')
    DEFINE    FIELD(#ORDER_BY)  TYPE(*CHAR) LENGTH(100) LABEL('Sort   :')
    DEF_LINE  NAME(#LINE1) FIELDS(#CUSTNO #NAME #ADDR1 #ADDR2 #ADDR3 #POSTCD #CRTDATE)
L1: REQUEST   FIELDS(#SELECTION #ORDER_BY)
 
    OPEN      FILE(NAMES) USE_OPTION(*OPNQRYF) IO_ERROR(L1) QRYSLT(#SELECTION) KEYFLD(#ORDER_BY)
 
    SELECT    FIELDS(#LINE1) FROM_FILE(NAMES)
    PRINT     LINE(#LINE1)
    ENDSELECT
 
    CLOSE     FILE(NAMES)
 

Example 7: Create a report that will allow the user to scan the name and address file for a suburb name in any of the 3 address lines. Print details of all customers that contain the required suburb.

DEFINE    FIELD(#SRCHSUB) TYPE(*CHAR) LENGTH(20) LABEL('Suburb :')
DEFINE    FIELD(#SELECT) TYPE(*CHAR) LENGTH(256)
DEF_LINE  NAME(#LINE1) FIELDS(#CUSTNO #NAME #ADDR1 #ADDR2 #ADDR3 #POSTCD #CRTDATE)
REQUEST   FIELDS(#SRCHSUB)
USE  BUILTIN(TCONCAT) WITH_ARGS('''(ADDR1 *CT "'''  #SRCHSUB '''")''') TO_GET(#SELECT)
USE  BUILTIN(TCONCAT) WITH_ARGS(#SELECT ''' *OR (ADDR2 *CT "''' #SRCHSUB '''")''') TO_GET(#SELECT)
USE  BUILTIN(TCONCAT) WITH_ARGS(#SELECT ''' *OR (ADDR3 *CT "''' #SRCHSUB '''")''') TO_GET(#SELECT)
OPEN      FILE(NAMES) USE_OPTION(*OPNQRYF) QRYSLT(#SELECT) KEYFLD(*FILE)
SELECT    FIELDS(#LINE1) FROM_FILE(NAMES)
PRINT     LINE(#LINE1)
ENDSELECT
CLOSE     FILE(NAMES)
 

Example 8: Open file STATES, load all records into browse list #BROWSEL, select only records where the states = 'NSW' and 'QLD' and the post code is within the range of 2000 and 4999.

DEFINE    FIELD(#FIELDA) TYPE(*CHAR) LENGTH(256) 
DEFINE    FIELD(#FIELDB) TYPE(*CHAR) LENGTH(256) 
CHANGE    FIELD(#FIELDA) TO('(DEPTMENT *EQ "ADM") *OR (DEPTMENT *EQ "MNT") OR ')
CHANGE    FIELD(#FIELDB) TO('(DEPTMENT *EQ "FLT") *OR (DEPTMENT *EQ "MIS")')
EXCHANGE  FIELDS(#FIELDA)
EXCHANGE  FIELDS(#FIELDB)
OPEN      FILE(STATES) USE_OPTION(*OPNQRYF) QRYSLT('=EXCHANGE')
SELECT    FIELDS((#BROWSEL)) FROM_FILE(STATES)
ADD_ENTRY TO_LIST(#BROWSEL)
ENDSELECT