User login
|
|
|
Frontpage Sponsor
|
|
|
Poll
|
Would you like to see a separate forum on Baanboard for the ION product? No 13% Yes 87% Total votes: 90 |
Baanboard at LinkedIn
|

|
|
|
 |

11th August 2012, 11:37
|
|
Member
|
|
Join Date: Mar 2003
Location: South Africa Cyprus Canada
Posts: 46
|
|
|
Baan: 4 or 5 -
DB: Oracle -
OS: Unix
|
Count / control number of fields (delimiters) in asci file
Baan: Other/Unknown C/S: None/Unknown
Hi
I'm trying to ensure that the file being imported (3gl... not using exchange) has the correct number of fields per record/string (there should only be 3 in this instance)
Is there a simple way to count the number of decimals ? I cant find such a function. String scan works for this purpose but only if the numer of fields is less than 3. If number of fields in the asci file (for the specific record) is greater than 3 it simply concats the last field (in this case # 3) with the extra fields (incl the delimter/s). So the third delimiter is ignored.
example:
file should contain 3 fields (seperated by 2 delimiters)
if the record has 4 fields (and 3 delimiters) e.g.
X|Y|Z|1
then string.scan returns
Field 1 = "X"
Field 2 = "Y"
Field 3 = "Z|1"
What I want is an error stating something like "number of fields in file is incorrect"
One would assume that a simple function should exist, which, could count the number of delimiters in a string. This would be a simple fix to my problem. Does this function exist or do I need some funky work around?
Your input appreciated
Thanks
|

12th August 2012, 23:04
|
 |
Guru
|
|
Join Date: Sep 2001
Location: Louisville, KY, USA
Posts: 5,975
|
|
|
Baan: Baan 4C4 A&D1 -
DB: Oracle -
OS: Sun Solaris
|
|
Hmmm - never thought of this, but most of my scripts check for <# of fields. You can run a if pos(field 3, "|") > 0 then send an error message. I can't think of a function that counts just the separators.
__________________
Mark
GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.
Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
|

13th August 2012, 19:02
|
 |
Guru
|
|
Join Date: Jan 2002
Location: Lewisville, Texas
Posts: 333
|
|
|
Baan: BAAN IVc3 with A&D2.2b -
DB: ORACLE 9 -
OS: HPUX
|
You would need to write the function.
For example, here is the one that I use - maybe write a similar one for yourself.
Code:
function extern domain tcmcs.long tccomdllzzzz.count.chars(
domain tcmcs.s999 i.string.c,
domain tcmcs.long i.string.length.c,
string i.separator.char.c)
{
domain tcmcs.long p.posn.c
domain tcmcs.long p.chars.c
p.posn.c = 0
p.chars.c = 0
p.posn.c = p.posn.c + 1
while p.posn.c <= i.string.length.c
if i.string.c(p.posn.c;1) = i.separator.char.c
then
p.chars.c = p.chars.c + 1
endif
p.posn.c = p.posn.c + 1
endwhile
return(p.chars.c)
}
|

14th August 2012, 16:41
|
 |
Guru
|
|
Join Date: Aug 2002
Location: Cologne, Germany
Posts: 355
|
|
|
Baan: all -
DB: all -
OS: Unix / Win2K
|
Hi,
here is my usual solution:
Code:
string fields(50, 10)
long number.of.fields
string record.string(200)
....
number.of.fields = string.scan( record.string,
"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s",
fields(1,1), fields(1,2),.....)
if number.of.field = expected then
long.var1 = lval( fields(1,1))
stringvar = trim$(fields(1,2))
etc....
else
|give error
endif
.....
__________________
May the force be with you!
|

16th August 2012, 21:12
|
|
Senior Member
|
|
Join Date: Oct 2005
Location: Northeast Ohio
Posts: 146
|
|
|
Baan: Baan 4c4, 5C, LN -
DB: Informix, Oracle, SQL -
OS: HP UX, Win2K
|
Depending on the level of your tools, you can use a repeat/until loop and the 'pos()' call. You will know if your tools set does not support the offset in POS if you get a 'too manu arguments' error during compile. In LN, you have to set the TIV on the script to at least the base for the version (FP).
Code:
| 'delimit.count' is the number of 'delimeter' characters in
| the 'buffer' string.
delimit.count = 0
mypos = 1 | Start search at character #1
repeat
mypos = pos(buffer, delimiter, mypos)
if (mypos > 0) then
| Delimiter located, count it.
delimit.count = delimit.count + 1
| Advance start position of next search, avoiding overflow
| when the last character of the string is a delimiter.
mypos = (mypos < len(buffer)) ? mypos + 1 : 0
endif
until mypos = 0
This method doesn't limit your search by number of expected characters (which you have to do in string.scan) and can be used for characters other than delimiters to determine numbers or special characters in a string.
|

18th August 2012, 15:12
|
 |
Member
|
|
Join Date: Jun 2004
Location: Netherlands (Eindhoven)
Posts: 31
|
|
|
Baan: B50_c-baan4-erpln -
DB: oracle-mssql -
OS: unix / as400-windows
|
|
Why not use the function stringscan$() then you can extract all the data from the imput string and at the same time check the number of fields.
Regards,
Pieter
|

20th August 2012, 14:49
|
|
Senior Member
|
|
Join Date: Oct 2005
Location: Northeast Ohio
Posts: 146
|
|
|
Baan: Baan 4c4, 5C, LN -
DB: Informix, Oracle, SQL -
OS: HP UX, Win2K
|
Quote:
Originally Posted by Pieter van de L
Why not use the function stringscan$() then you can extract all the data from the imput string and at the same time check the number of fields.
Regards,
Pieter
|
Can use string.scan when you have a maximum number of fields that you will be expecting since the mask string is fixed, based on the number of fields between the delimiters. In the example that I provided, I could have none, one or a hundred instances of a delimiter/character. This way doesn't depend on the number of characters/delimiters in the mask.
|

29th August 2012, 13:10
|
|
Junior Member
|
|
Join Date: Mar 2010
Posts: 6
|
|
|
Baan: FP2 -
DB: Sql server 2000, 2005 -
OS: Windows XP
|
Hi
You can use String.scan function for this. We can add as many strings as we want
Like
ret.num = string.scan(rec,"%s,%s,%d,%d,%s,%s,%s,%f,%f,%s",mitm,opro,opno,seqn,tano,cwoc,tano.n,rutm.n,prte.n,exin.n)
|

29th August 2012, 14:36
|
 |
Guru
|
|
Join Date: Sep 2001
Location: Louisville, KY, USA
Posts: 5,975
|
|
|
Baan: Baan 4C4 A&D1 -
DB: Oracle -
OS: Sun Solaris
|
Quote:
Originally Posted by sareen.sachin02
You can use String.scan function for this. We can add as many strings as we want
Like
ret.num = string.scan(rec,"%s,%s,%d,%d,%s,%s,%s,%f,%f,%s",mitm,opro,opno,seqn,tano,cwoc,tano.n,rutm.n,prte.n,exin.n)
|
That is not the issue - in this case he wants to confirm that only x number of fields are read. So for example if your record contains a,b,c - when you do ret.num=string.scan(rec,"%s,%s", field1, field2), you get field1 containing a and field2 containing b,c. He was wanting to know if there were more fields than expected. In this case string.scan returns 2 in ret.num, but robert was wanting a way to get 3. So string.scan does not work.
__________________
Mark
GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.
Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
|

30th August 2012, 06:30
|
 |
Member
|
|
Join Date: Apr 2006
Location: Gurgaon - India
Posts: 57
|
|
|
Baan: baan IV, LN6 -
DB: Oracle9i -
OS: windows 2003 server
|
|
Hi Mark/Robertp
Taking Mark's example
if your record contains a,b,c - when you do ret.num=string.scan(rec,"%s,%s", field1, field2), you get field1 containing a and field2 containing b,c.
I would suggest you use string.scan as follows
ret.num=string.scan(rec,"%s,%s,%s", field1, field2, field3) (Add 1 field more than you expect in the input string 'rec')
Now if ret.num contains 2 then you can be sure that 'rec' contains 2 fields and if ret.num contains 3 then certainly 'rec' contain more fields then actually required
I accept this is not a perfect solution and it would be better if you use solution provided by 'Baaninohio' but this is an quick n easy fix for your situation
__________________
_______________________
Amit
Effective solutions are worth stealing.
The only thing to do with good advice is to pass it on. It is never of any use to oneself.
|

30th August 2012, 14:49
|
 |
Guru
|
|
Join Date: Sep 2001
Location: Louisville, KY, USA
Posts: 5,975
|
|
|
Baan: Baan 4C4 A&D1 -
DB: Oracle -
OS: Sun Solaris
|
Good solution Amit. In my case this would have worked good if I had coded it that way to start. What I noticed when creating some of my | or , delimited files sometimes excel tosses on extra ,'s at the end. So I usually just pull up an editor and do a replace. I am not sure how our users manager to create some of these files.
Baaninohio is good also - just more coding.
__________________
Mark
GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.
Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
|

4th September 2012, 15:44
|
|
Member
|
|
Join Date: Mar 2003
Location: South Africa Cyprus Canada
Posts: 46
|
|
|
Baan: 4 or 5 -
DB: Oracle -
OS: Unix
|
|
Thanks for the help folks. I'l try the different options.
Cheers
__________________
Better to die on your feet than live on your knees
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|