Saving and Restoring a List from a File

Visual LANSA

Saving and Restoring a List from a File

This example shows how you can save and load the contents of a list to a file. It displays a List View containing employee details.

When the Load from DBMS button is clicked the employee list is loaded from the PSLMST table.  When the Load from File button is clicked, the employee list is loaded from a file named c:\Employee_List.dat which is in tab delimited format.   When the Save to File button is clicked, the employee list is saved into a file named c:\Employee_List.dat in tab delimited format.  

To see how the example works,  copy this code and paste it to a form component:

FUNCTION options(*DIRECT)
BEGIN_COM role(*EXTENDS #PRIM_FORM) HEIGHT(346) LEFT(327) TOP(120) WIDTH(620)
DEFINE_COM class(#PRIM_LTVW) name(#EMPLIST) DISPLAYPOSITION(1) FULLROWSELECT(True) HEIGHT(285) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(1) TOP(16) WIDTH(481)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_1) DISPLAYPOSITION(1) PARENT(#EMPLIST) SOURCE(#EMPNO) WIDTH(22)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_2) DISPLAYPOSITION(2) PARENT(#EMPLIST) SOURCE(#SURNAME) WIDTH(22)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_3) DISPLAYPOSITION(3) PARENT(#EMPLIST) SOURCE(#GIVENAME) WIDTH(29)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_4) DISPLAYPOSITION(4) PARENT(#EMPLIST) SOURCE(#SALARY) WIDTH(25)
DEFINE_COM class(#PRIM_PHBN) name(#PB_DBMS) CAPTION('Load from DBMS') DISPLAYPOSITION(2) LEFT(512) PARENT(#COM_OWNER) TABPOSITION(2) TOP(128) WIDTH(90)
DEFINE_COM class(#PRIM_PHBN) name(#PB_FILE) CAPTION('Load from File') DISPLAYPOSITION(3) LEFT(512) PARENT(#COM_OWNER) TABPOSITION(3) TOP(176) WIDTH(88)
DEFINE_COM class(#PRIM_PHBN) name(#PB_SAVE) CAPTION('Save to File') DISPLAYPOSITION(4) LEFT(512) PARENT(#COM_OWNER) TABPOSITION(4) TOP(226) WIDTH(90)
DEFINE_COM class(#PRIM_PHBN) name(#PB_CLEAR) CAPTION('Clear List') DISPLAYPOSITION(5) LEFT(514) PARENT(#COM_OWNER) TABPOSITION(5) TOP(272) WIDTH(87)
DEFINE field(#RETCODE) type(*CHAR) length(2)
EVTROUTINE handling(#com_owner.Initialize)
ENDROUTINE
EVTROUTINE handling(#PB_DBMS.Click)
CLR_LIST named(#EMPLIST)
SELECT fields(#EMPLIST) from_file(PSLMST)
ADD_ENTRY to_list(#EMPLIST)
ENDSELECT
ENDROUTINE
EVTROUTINE handling(#PB_FILE.Click)
CLR_LIST named(#EMPLIST)
USE builtin(TRANSFORM_FILE) with_args(#EMPLIST 'C:\EMPLOYEE_LIST.DAT' O) to_get(#RETCODE)
ENDROUTINE
EVTROUTINE handling(#PB_SAVE.Click)
USE builtin(TRANSFORM_LIST) with_args(#EMPLIST 'C:\EMPLOYEE_LIST.DAT' O) to_get(#RETCODE)
ENDROUTINE
EVTROUTINE handling(#PB_CLEAR.Click)
CLR_LIST named(#EMPLIST)
ENDROUTINE
END_COM

 

Ý 6.15.8 Working with Items in Lists