kiran kumar
10th January 2013, 10:53
Hi team,
I am not able to separate those fields since the separator space is not fixed and its not fixed length lines, also there is thousand separator comma (,) which is not allowing me to convert in numbers with below sample data.
Can any one help?

Sample data
-------------
A1 CAM (79A) ZING- 1XSAND 6 163,668.00 982,008.007915PPC
B1 SAM (698) TROU - 2.40G/ 6 Nos 75,079.00 450,474.0069Y5PPC
C1 JAN (497) MOE GB (2GB 432 Nos 4,753.00 199,626.0049YPPC
D1 PAN (90Y) OON 3GB SFF 2 Nos 7,092.00 85,104.0090Y8PPC
E1 CAN (81U) 1 7.K 6S NL 36 Nos 12,513.00 450,468.0081Y9PPD
F1 TAN (46M) SAS HBA 12 Nos 7,352.00 88,224.0046M0PPJ

For example-
Here last 7 characters are item code (7915PPC), before that item value (982,008.00), before that item price (163,668.00) and before that qty (6).

I just need last 4-5 fields, also for first record unit (Nos) is not there.

Note: Tried with string.scan() but not getting the expected result.

mark_h
10th January 2013, 15:52
What you have to do is write your own parsing routine. Of course I am assuming that each number field will be " ZZZZZZZ.ZZ" - it starts with a space. So the first decimal would give you the item code, then first space the number for the item code, then next space the number before it. Also you item codes could not have a "." in them. You could try using something like below - only did the first two fields, but this should give you an idea on how to parse it.


long i,j

some.rec= "A1 CAM (79A) ZING- 1XSAND 6 163,668.00 982,008.007915PPC"

i = len(some.rec)
j = len(some.rec)
while some.rec(i;1)<>"." and i<>0
i = i - 1
endwhile
item.code = some.rec(i+3;j-i)
j = i
while some.rec(j;1)<>" " and j<>0
j=j-1
endwhile
hold.num = some.rec(j+1; i+2-j)

kiran kumar
11th January 2013, 12:09
Hi Mark,
Thanks for your quick support.The solution looks perfect to me but not able to separate next three fields i.e. price, unit, qty..can u pl modify the code for that too..also since unit is optional field how do i take care since the field value will deffered due to value unavailability and finally how do remove comma from the price. Please help...

mark_h
11th January 2013, 14:22
Well I did a quick little test and borrowed some code from another of my subroutines. This will get the last three fields. I only stripped the comma from one of the numbers. The test did work. Now I do not know which field is which. I am not sure what you can do for the optional field - you can get it at long as it is surrounded by spaces. Maybe if you get the unit you can test it by querying against another table - don't know since I don't know your data or system. Then if it is invalid you can make the qty field or something like that. You are just going to have to apply the below logic to your records and see what happens.

function parse.it()
{
string item.code(30)
string hold.num(30)
string hold.num1(30)
string some.rec(60)
double num1,num2
long i,j,k

some.rec= "A1 CAM (79A) ZING- 1XSAND 6 163,668.01 982,008.017915PPC"

i = len(some.rec)
j = len(some.rec)
while some.rec(i;1)<>"." and i<>0
i = i - 1
endwhile
item.code = some.rec(i+3;j-i)
j = i
while some.rec(j;1)<>" " and j<>0
j=j-1
endwhile
hold.num = some.rec(j+1; i+2-j)
k=j-1
while some.rec(k;1)<>" " and k<>0
k=k-1
endwhile
hold.num1 = some.rec(k+1; j-k-1)
hold.num1 = strip.comma(hold.num1)
num1 = val(hold.num1)

}
function domain tcmcs.str45 strip.comma(domain tcitem some.item)
{
domain tcmcs.str45 barcode.item
domain tcmcs.long barcode.length, i

barcode.item = strip$(some.item)
barcode.length = len(strip$(barcode.item))
for i = 1 to barcode.length
if barcode.item(i;1) = "," then
barcode.item = barcode.item(1;i-1) & barcode.item(i+1;barcode.length)
endif
endfor
return(barcode.item)
}