[CSV_FILE_LOOP] (get CSV file data)
[CSV_FILE_LOOP] specifies the beginning and end of processing to acquire data from a CSV file.
Syntax
[CSV_FILE_LOOP] CSV-file-name [CSV_COLUMN_NAME] column-name=column-number [BEGIN] processing-on-acquired-data [END] [CSV_FILE_LOOP_END]
Values
-
CSV-file-name
Specifies the name of the CSV file from which data is to be acquired in the form of a variable. Specify using a relative path name referenced to the base path specified with the -bp option of the jamscript command. If the -bp option was omitted, Asset-Console-installation-folder\scriptwork is assumed to be the reference folder.
-
column-name=column-number
Maps the name for referencing the data to the column number in the CSV file. Specify a column number assuming 1 as the first column.
-
processing-on-acquired-data
Specifies the processing to perform on the data acquired from the CSV file.
Status
The following table lists and describes the possible statuses:
Status |
Description |
---|---|
NORMAL |
— |
NODATA |
End of data. |
ERROR |
There is a row that contains more than 32 kilobytes of data in a single column. |
MULTI |
— |
- Legend:
-
—: Not applicable
Remarks
Processing stops if the specified CSV file does not exist.
Whether or not importing of data from the CSV file is terminated is determined according to the status referenced by the [CSV_FILE_LOOP_END] loop end tag. If the status is NORMAL, processing continues. If the status is other than NORMAL, processing terminates. This last fact is useful when an error that occurs during processing interrupts processing at the point the error occurred.
When processing continues until no data remains, before determining whether or not to end processing according to the [CSV_FILE_LOOP_END] tag, we recommend that you use the $SETSTATUS embedded function to explicitly specify NORMAL as the status.
The status of the access definition file is updated on an ongoing basis by execution of tags and embedded functions. If processing that updates the status is specified more than once in a [CSV_FILE_LOOP] tag, you must determine whether or not to terminate processing based on the status that was last specified.
Example
The following example acquires data from rows in the CSV file input.csv, and outputs the acquired data by row number:
[SET_VALUE] FILENAME = 'input.csv' CNT = 1 [CSV_FILE_LOOP] FILENAME [CSV_COLUMN_NAME] COLUMN1 = 1 COLUMN2 = 2 COLUMN3 = 3 [SET_VALUE] MSG = ' LINE('+CNT+') ['+COLUMN1+']['+COLUMN2+']['+COLUMN3+']' $ECHO(MSG) CNT = $ADD(CNT,1) [SET_VALUE] $SETSTATUS('NORMAL') [CSV_FILE_LOOP_END] |
- Execution result:
-
LINE(1) [0000000001][R11111][active]
LINE(2) [0000000002][R22222][restore]
LINE(3) [0000000003][R33333][scrap]