Step 4 Create a CSV File

Visual LANSA

Step 4. Create a CSV File

FRM075 - Using a Working List

In this step you will use the TRANSFORM_LIST BIF to create a CSV file from the working list.

1.  Drag and drop a push button onto the form, above the Working List entries field. Change its Caption to Create CSV File and Name to CREATE. Create a Click event for it.

2.  The TRANSFORM_LIST BIF can be used to transform a working list into a text file, with 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 may be used to 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'

 

     Note: The system variable *part_dir_object provides 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. The Command Assistant fully supports BIFs, just like any RDML command. Your CREATE Click event logic should look like the following:

Evtroutine Handling(#CREATE.Click)
#STD_QSEL := *part_dir_object + 'EMPLIST.CSV'
Use Builtin(transform_list) With_Args(#emplist #STD_QSel) To_Get(#io$sts)

If (#io$sts = OK)

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

Endroutine

 

     Note: The message text uses a system variable *partition which contains the 3 character partition name.

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 is opened in Excel.

     The next step will use the System_Command Built in Function to automatically display the CSV file in Notepad.

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

Evtroutine Handling(#CREATE.Click)
Define #retcode type(*dec) length(3) decimals(0) 
#STD_QSEL := *part_dir_object + 'EMPLIST.CSV'
Use Builtin(transform_list) With_Args(#emplist #STD_QSel) To_Get(#io$sts)
If (#io$sts = OK)
Message Msgtxt('File EMPLIST.CSV created in ..\x_' + *partition + '\object folder')
#std_qsel := ('notepad ' + #std_qsel)
Use Builtin(system_command) With_Args(X #STD_QSEL) To_Get(#retcode)

Endif
Endroutine

 

     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.