infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Read Only Archives
Cloverleaf
Tcl Library
Reading a file
Mike Campbell
I've successfully been able to create and write a file out using tcl.
Now, in another xlate, I need to read the file and retrieve a specific value.
The table consists of the Message ID from the MSH segment and a Medical Record Number.
I'm doing the read using a foreach loop. It is reading all of the records in the file, but I'm not able to select the one I need. Do I need to set it up as an array? I set up a counter that does increment as the foreach is executed. The $message_id is passed out of the Xlate
CL 6.0.2. AIX system.
[Just s snippet of the tcl code. All variables are defined.]
foreach line [ split $msg n ] {
echo "Data is: " $msg
incr indx
echo "Counter is: " $indx
set file_msg_id [ string range $msg 0 19 ]
set mrn_found_id [ string range $msg 21 27 ]
if { $file_msg_id == $message_id } {
set RESULTS $mrn_found_id
echo "Results to send back is:" $RESULTS
}
}
Find more posts tagged with
Clovertech
Comments
jcobane1
Mike,
You may want to consider utilizing the SQLite functionality for this type of store/retrieval. Check the link below for some examples.
https://usspvlclovertch2.infor.com/viewtopic.php?t=6686&start=0&postdays=0&postorder=asc&highlight=
Jim Cobane
Henry Ford Health
Mike Campbell
Thanks James. Our management would prefer we don't use the SQLite option. So I'll try to figure out the array if that is the only other way.
jcobane1
Mike,
Just curious as to why your management is opposed to the SQLite option. It's functionality built into Cloverleaf / Tcl and is probably more efficient than using straight file-based lookups.
Jim Cobane
Henry Ford Health
Charlie Bursell
Mike
I, like Jim, am perplexed as to why your management would not want you to use the best tool for the job.
With that said, if you must do the file there are two issues. How often does the contents of the file change? Do you need to read the whole file everytime? Is the format of the file consistent?
You do not need to loop through every line or read the entire file every time.
Here is what I woud do (making some assumptions)
I would store the contents of the file and last mod time of the file in global variables - in Xlate, by definition all variables are global.
If the variables do not exist it is the first time, so read the file into the proper variable (use read_file) and the last mod time into the proper variable. If the variables exist, get the last mod time of the file. If it is different, read the file and update the last mod time. Else leave as is.
Assuming the file you created is like: (FIELD FIELD)
MSGID MRN
MSGID MRN
Use a regexp
set mrn ""; regexp -line -- "^$message_id (.*?)$" $file {} mrn
If mrn is empty the ID was not found. Do something.
You might want to make sure the file exists before any of this and take some sort of action if not - if {![file exists ]} {Do something}
In regexp:
-line
Enables newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning. With this flag,
Mike Campbell
I've convinced the folks to let me try the sqlite approach. Working on that now. Thanks Charlie for the file option if needed.