7.2.3 ADD_ENTRY Examples

Defining, Adding Entries To and Displaying a Browse List

Filling a Browse List with Information from a Database File

Adding Entries to the Beginning or End of a Browse List

Sorting Entries in Browse Lists by Using a Working List

Defining, Adding Entries To and Displaying a Browse List

To define, add two entries to and display a browse list named #EMPBROWSE you would use these commands like this:

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #GIVENAME #SURNAME)

          

CHANGE     #EMPNO    'A0001'

CHANGE     #GIVENAME 'JOHN'

CHANGE     #SURNAME  'SMITH'

ADD_ENTRY  TO_LIST(#EMPBROWSE)

          

CHANGE     #EMPNO    'A0002'

CHANGE     #GIVENAME 'MARY'

CHANGE     #SURNAME  'BROWN'

ADD_ENTRY  TO_LIST(#EMPBROWSE)

          

DISPLAY    BROWSELIST(#EMPBROWSE) 

Filling a Browse List with Information from a Database File

This example asks the user to input a department code (eg: ADM, MKT, etc). 

All employees that work in the specified are then added to a browse list named #EMPBROWSE. The resulting browse list then displayed to the user:

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#SECTION #EMPNO #SURNAME #GIVENAME)

BEGIN_LOOP

REQUEST    FIELDS(#DEPTMENT) BROWSELIST(#EMPBROWSE)

CLR_LIST   NAMED(#EMPBROWSE)

SELECT     FIELDS(#EMPBROWSE) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT)

ADD_ENTRY  TO_LIST(#EMPBROWSE)

ENDSELECT 

END_LOOP

Adding Entries to the Beginning or End of a Browse List

This example asks the user to input sets of employee details.

Each set of employee details is added to a browse list.  

These employee details may be added to the start or the end of the browse list.

Since you can't add entries to the start of a browse list a working list is used to hold the details and a browse list to display them:

DEFINE     FIELD(#WHERE) TYPE(*CHAR) LENGTH(1) LABEL('Top or Bottom') DEFAULT(B)

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #SURNAME #GIVENAME)

DEF_LIST   NAME(#EMPWORKNG) FIELDS(#EMPNO #SURNAME #GIVENAME) TYPE(*WORKING) ENTRYS(9999)

          

BEGIN_LOOP

REQUEST    FIELDS(#WHERE #EMPNO #SURNAME #GIVENAME) BROWSELIST(#EMPBROWSE)

IF         COND('#WHERE = B')

ADD_ENTRY  TO_LIST(#EMPWORKNG)

ELSE      

ADD_ENTRY  TO_LIST(#EMPWORKNG) AFTER(*START)

ENDIF     

          

EXECUTE    SUBROUTINE(VISIBLE)

END_LOOP

This subroutine is used to copy the contents of the working list (#EMPWORKNG) to the visible browse list # EMPBROWSE: 

SUBROUTINE NAME(VISIBLE)

CLR_LIST   #EMPBROWSE

SELECTLIST NAMED(#EMPWORKNG)

ADD_ENTRY  TO_LIST(#EMPBROWSE)

ENDSELECT 

ENDROUTINE

Sorting Entries in Browse Lists by Using a Working List

This example asks the user to input sets of employee details.

Each set of employee details is added to a browse list.  

Function keys are provided to allow the browse list to be sorted in various ways.

Since you can't sort entries in a browse list a working list is used to hold the sorted details and a browse list to display in sorted order:

DEF_LIST   NAME(#EMPBROWSE) FIELDS(#EMPNO #SURNAME #GIVENAME)

DEF_LIST   NAME(#EMPWORKNG) FIELDS(#EMPNO #SURNAME #GIVENAME) TYPE(*WORKING) ENTRYS(9999)

          

DEFINE     FIELD(#UK_EMPNO) REFFLD(#IO$KEY) DEFAULT('''09''')

DEFINE     FIELD(#UK_SURNME) REFFLD(#IO$KEY) DEFAULT('''10''')

DEFINE     FIELD(#UK_GVNNME) REFFLD(#IO$KEY) DEFAULT('''11''')

          

BEGIN_LOOP

REQUEST    FIELDS(#EMPNO #SURNAME #GIVENAME) BROWSELIST(#EMPBROWSE) USER_KEYS((09 EMPNO *NEXT)(10 'SURNAME' *NEXT)(11 'GIVNAME '))

          

CASE       OF_FIELD(#IO$KEY)

WHEN       VALUE_IS('= #UK_EMPNO')

SORT_LIST  NAMED(#EMPWORKNG) BY_FIELDS(#EMPNO)

WHEN       VALUE_IS('= #UK_SURNME')

SORT_LIST  NAMED(#EMPWORKNG) BY_FIELDS(#SURNAME)

WHEN       VALUE_IS('= #UK_GVNNME')

SORT_LIST  NAMED(#EMPWORKNG) BY_FIELDS(#GIVENAME)

OTHERWISE 

ADD_ENTRY  TO_LIST(#EMPWORKNG)

ENDCASE   

          

EXECUTE    SUBROUTINE(VISIBLE)

END_LOOP  

          

SUBROUTINE NAME(VISIBLE)

CLR_LIST   NAMED(#EMPBROWSE)

SELECTLIST NAMED(#EMPWORKNG)

ADD_ENTRY  TO_LIST(#EMPBROWSE)

ENDSELECT 

ENDROUTINE

RETURN