Step 4. Create a CSV File

In this step, you will use the TRANSFORM_LIST built-in function to create a CSV file from the working list.

1.  Drag a push button onto the form, above the Working List entries field.

a.  On the Layout ribbon, change its Alignment to Bottom Center and Flow to Up

b.  Change margin Bottom to 10

c.  Change its Caption to Create CSV File and Name to CreateCSV.

d.  Create a Click event for the push button.

e.  Adjust the Width as needed.

2.  The TRANSFORM_LIST BIF transforms a working list into a text file and has a number of file format options. The output file name will usually be defined including a full path to control where it is written.

     LANSA has a number of system variables which provide a path name which will be valid in both a development and production partition. For example, this assignment would place the file named EMPLIST.csv into the Visual LANSA partition \object folder.

#STD_QSEL := *part_dir_object + 'EMPLIST.CSV'

     For example, the output file path would then be:
c:\Program Files (x86)\LANSA\x_win95\x_lansa\x_ppp\object\ 

     Note: The system variable *part_dir_object returns a path ending in "\".    

     Built-In functions (BIFs) are executed using the USE command. The USE command has the format:

USE Builtin() With_args() To_get()

     A BIF is a called program, and the arguments it receives and returns, are defined in the Repository and supported by the editor. The Command Assistant supports BIFs showing the required input and output parameters. BIFs are implemented with the RDML USE command.






Working list name to transform



Name of file to create or replace

STD_QSEL (path + file name)


Output file format

A - Normal Delimited File (default)

4 to 8

Optional parameters - see Technical Reference



     Your CREATE Click event logic should look like the following:

Evtroutine Handling(#CreateCSV.Click)

If Cond(#LISTCOUNT > 0)

#std_qsel := *PART_DIR_OBJECT + 'emplist.csv'

Use Builtin(transform_list) With_Args(#EmployList #STD_QSel) To_Get(#io$sts)

If (#IO$STS = OK)

Message Msgtxt('File EMPLIST.CSV created in ..\x_' + *partition + '\object folder')






3.  Compile and test your form. Select entries in the list view. The Create CSV File button will write a CSV file containing the working list's entries:

4.  Use Windows Explorer to locate the output file. For example, in a standard Visual LANSA installation:

C:\Program Files\LANSA\x_win95\x_lansa\x_dem\object\EMPLIST.CSV


     Where DEM is the partition being used for training.

     If your PC has MS Office installed, this file will be opened in Excel.

     The next step, will use the System_Command Built in Function to automatically display the CSV file in Notepad. The SYSTEM_COMMAND executes an operating system command. See the Technical Reference guide for information.

5.  Add the highlighted code to your CreateCSV.Click event handling routine

Evtroutine Handling(#CreateCSV.Click)

Define Field(#RetCode) Type(*DEC) Length(7) Decimals(0)

#std_qsel := *PART_DIR_OBJECT + 'emplist.csv'

Use Builtin(transform_list) With_Args(#EmployList #STD_QSel) To_Get(#IO$STS)

If (#IO$STS = OK)

Message Msgtxt('File EMPLIST.CSV created in ..\x_' + *partition + '\object folder')


Use Builtin(SYSTEM_COMMAND) With_Args('X' 'notepad.exe' ' ' #std_qsel) To_Get(#RetCode)





     This will display the CSV file in Notepad once the TRANSFORM_LIST BIF has successfully completed:

Omitting 'Notepad' from the execute string would load the CSV file in Excel if you have MS Office installed.

6. Compile and test your form.