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
Cloverleaf
Remove Leading Zeros
bso its
I have a flat file (see attached)
I need to remove the leading zeros at the start of the line only. ie 00008 to 8
I can remove the leading zeros via a tcl proc but it wont read the message in.
proc removeLeadingZerosPerLine {DATA args} {
echo "RUNNING PROC VERSION: PRE-WRITE SIGNATURE"
echo "removeLeadingZerosPerLine: START"
echo "Original DATA:\n$DATA"
set message $DATA
set outLines {}
set lineNum 0
foreach line [split $message "\n"] {
incr lineNum
set line [string trimright $line "\r"]
echo "Line $lineNum BEFORE: '$line'"
if {[string match "*UKBTSSTART*" $line] ||
[string match "*UKBTSSTOP*" $line]} {
set line "[string range $line 4 end]"
} elseif {[regexp {^0000[0-9]} $line]} {
set line "[string index $line 4][string range $line 5 end]"
}
lappend outLines $line
}
set newMessage [join $outLines "\r\n"]
echo "FINAL transformed DATA:\n$newMessage"
echo "removeLeadingZerosPerLine: END"
return $newMessage
}
I can remove via a translation - using xlateStrTrimLeft 0000 but it will only remove the zeros from the first line and wont read in the other lines (delimited by <CR><LF> - which need to remain.)
(I have create the translation using FRL and VRL)
Any help appreciated
Find more posts tagged with
Clovertech
Comments
david_barr
How are you calling the TCL proc?
Jason Russell
A lot of this is going to depend on how you're pulling the flat file in. Are you reading the file by line or the entire file at once? If you're reading by line and not EOF you should be able to have a simple TPS (or in your xlate) that just looks at the first element and simply either use xlateStrTrimLeft 0 (you only need one) or the full tcl: [string trimleft $var 0]
If you're pulling in the entire file, you can do this in a TPS before you xlate (if it's only at the beginning of a line):
set messageList [split $msg \n]
foreach line $messageList {
lappend newmsg [string trimleft $line 0]
}
set newmsg [join $newmsg \n]
msgset $mh $newmsg
Considering you have the newline last you shouldn't need to split on both \r and \n, just split and join on \n, that should preserve it all.
This also assumes you're using the TPS template from within the GUI to build the TPS with the correct arguments. You would put the script in the prexlate tps script box. Just insert that code in the 'run' portion of the switch statement and you should be good to go.