Input & Import and How to correctly loop through the tex

Posted by tracylee3124 on 03-Aug-2013 15:54

Evening Folks,

I am using Progress 10.1c

I am trying to bring in two text files: some products and a file with additional attributes about the products.

DEFINE STREAM s-input.

DEFINE STREAM s-input2.

INPUT STREAM s-input FROM C:\Temp\prod.txt.
INPUT STREAM s-input2 FROM C:\Temp\attr.txt.
I have defined two temp tables with the corresponding fields.
CREATE ttProd.
    CREATE ttAttr.
    REPEAT:

       IMPORT STREAM s-input DELIMITER ";" ttProd.cProd ttProd.cSKU ttProd.cQuantity.
     
       END.
    REPEAT:

        IMPORT STREAM s-input2 DELIMITER ";" ttAttr.cColor ttAttr.cCountyMade.
     
    END.
This is according to all the documentation I can find. I need to put these two into temp tables, use all of the data in the first table and if the UPC matches up as having data in the second table, I want to have that data go into a third temp table that will have room for all of the data I want to bring over from the two tables.
I was just going to loop through the temp tables and say if this matches this then assign blah blah blah. The problem is ONE my lack of experience and TWO Repeat scopes records, so I can't access the data outside the Repeat block. I can make a do transaction block around it all, and access the last record, but that is probably bad and it is not useful.
Is there another way to loop through the stream and put it into the temp table that will allow me to access it?
Also, I have been thinking about this for a while and I have pretty much fried my brain.
Thanks,
Tracy
   

All Replies

Posted by Peter Judge on 05-Aug-2013 08:34

Tracy,

You need to do 3 things here:

1) read the products,

2) read the attributes, and

3) associate one with the other.

You can do some optimisations but you will have to do 1 and 2 as 2 loops; unless you are assured that the order of the records is the same in both files, you will have to either read all the records into temp-tables or seek back and forth in one of the files. ABL is much better at finding/looping over temp-tables than it is in operating on files.

I would read the child records (I’m guessing it's the attributes) from their file first. That way, when you're in the parent import, you can do the association immediately after you've created the parent record:

Repeat:

Create ttAttr.

Import stream strAttr ...

End.

Repeat:

Create ttProd.

Import stream strProd ...

For each ttAttr where ...

Assign .

End.

End.

You still have 3 loops (REPEAT, REPEAT, FOR EACH) but the FOR EACH can take advantage of an index (make sure you define one on the TT), which will at least limit it to a smaller number of records.

You can play around with different approaches too, and time them. Look at the MTIME keyword; assign a start and end variable and see how long each approach takes.

HTH,

-- peter

This thread is closed