Reading data file using Progress 8.3b

smitht3863

New Member
I have Progress 8.3b and I'm trying to read data from a FedEx file. It's not a fix length. What is the best method to read this data into Progress. This is the data file. I'm only interested with the data following 37, and 112,

[FONT=r_ansi]0,"120"1,""10,"181702826"34,"300"35,"136"36,"0"37,"436"60,"1"112,"1"116,"1"421,"
0"428,"0"429,"0"430,"0"431,"N"498,"145690"543,"0"1086,"0"1089,"0"1090,"USD"1092,
""1274,"92"1393,"11"1596,"0"1598,"436"1690,"N"1942,"N"1943,"N"1944,"N"2399,"0"24
00,"0"3018,"N"3039,"0"3040,"0"3041,"0"3058,"3"99,""
[/FONT]
 
It looks for me like an usual formatted string which can be described by the following mask:

number0,"string1"number1,"string2"number2,...,"stringN"numberN,"stringN+1"

To get data you need you can read the string as a list. Here's a sample:

Code:
DEFINE VARIABLE i AS INTEGER    NO-UNDO.
DEFINE VARIABLE it AS CHARACTER     NO-UNDO.
DEFINE VARIABLE str AS CHARACTER  NO-UNDO INIT <here's your string>.
DEFINE VARIABLE data1 AS CHARACTER  NO-UNDO.
DEFINE VARIABLE data2 AS CHARACTER  NO-UNDO.
/* Reading each element of the list*/
DO i = 1 TO NUM-ENTRIES(str):
   /* Getting the next element */
   it = ENTRY(i,str).
   /* Comparing it with your mask and getting the first data */
   IF it MATCHES "~"*~"37" THEN
   DO:
      data1 = ENTRY(2,ENTRY(i + 1,str),"~"").
   END.
      /* Comparing it with your mask and getting the second data */
   IF it MATCHES "~"*~"112" THEN
   DO:
      data2 = ENTRY(2,ENTRY(i + 1,str),"~"").
   END.
END.
/* Showing data */
MESSAGE data1 SKIP data2
   VIEW-AS ALERT-BOX INFO BUTTONS OK.

HTH
 
Or, and this is the way I normally do it nowadays:

def var this_field as char extent 200 no-undo.
/* Or however many distinct fields are in the line */
def var this_filename as char initial "c:\mydir\myfile.txt" no-undo.
/* Or whatever your filename is */

def var mydata as char extent 4.
/* Or whatever data you want to extract from the line */

input from value (this_filename).
repeat:
this_field = "". /* To make sure it is a clean import */
import delimiter "," this_field.
display this_field with side-labels 1 down.
mydata [1] = this_field [13].
mydata [2] = this_field [14].
mydata [3] = this_field [17].
mydata [4] = this_field [18].

end.
input close.

This allows you to import lines which might otherwise fill a single character field. It also allows you to access the fields fairly easily. You might have a problem if the format is not always the same, regarding double-quotes, but I suppose you could check for certain fields, such as "USD" to make sure they were in the right place.

Simon
 
Progress 8.3b data passthrough

Thanks for the help. The data within the quotes does change. I use bulklodd solution with some modification. It works great. I was pulling hair out of my bald head and thats BAD. Since you guys are available, maybe you can give me some advice on another solution.

I have Progress 8.3b on a HP-UNIX Server. I'm using Windows XP as a workstation and Relection 9.0 emulator. I have a external scale on my serial port. When a package is laid on the scale, I'm trying to read data from scale into Progress.
 
Back
Top