Importing .d Created From Data Dictionary

IanC74

Member
Hi All

Im having a complete brain freeze moment (been a while since i touced Progress) and hope someone can help me.

I have a data file which was created via Data Dictionary and i need to read the output into a temporary table (so not using data load back into the DB), however i cant remember how to do this as its not delimiter so not sure how to idetify when the next field starts!

Plese can someone help.
Thanks.
 

Stefan

Well-Known Member
If your temp-table is defined with the same field data types as the database table then its just:

Code:
define temp-table tt no-undo
   field cc as char extent 100
   .

input from "myfile.d".
repeat:
   create tt.
   import tt.
end.
input close.
 

IanC74

Member
Great thank you - i remembered a couple of minutes after id submitted the post. Thank you for your time.
 
Code:
def temp-table latabla like yourtable.

input from  yourtablefile.d.

repeat transaction:
create latabla.
import latabla.
end.
input close.
Important: Don't use NO-UNDO on the temp-table definition, and use the TRANSACTION on the repeat, or you will get an extra empty record.
 

Cringer

ProgressTalk.com Moderator
Staff member
So that's why that happens? Brilliant! I never did work that one out.
 

RealHeavyDude

Well-Known Member
You can get around that by using a defined buffer on the temp-table and strong scope it, and the transaction too, of course. IMHO, whenever you CRUD records in a temp-table you should use defined buffers and strong buffer and transaction scope.

Heavy Regards, RealHeavyDude.
 

oli

Member
I must have missed something RealHeavyDude, 'cos even with strong scoped buffer & transaction, I still have the blank record... unless the temp-table is defined without the NO-UNDO option:

Code:
DEF TEMP-TABLE tt NO-UNDO
  FIELD fld AS CHAR.

RUN proc_import.

FOR EACH tt:
  DISPL "*" tt.fld.
END.

RETURN.

PROCEDURE proc_import:
  DEF BUFFER btt FOR tt.
  
  INPUT FROM c:\temp\tt.txt.
  REPEAT FOR btt TRANSACTION:
    CREATE btt.
    IMPORT btt.
    RELEASE btt.
  END.
  INPUT CLOSE.

  RETURN.
END PROCEDURE.

I'm really interested in an alternative to the "undoable" temp-table or the record deletion afterwards (as suggested by Progress in: IMPORT of a text file into a TEMP-TABLE or WORK-TABLE creates a blank record)
 

RealHeavyDude

Well-Known Member
There are two things that from my point of view:
  1. When I do an import like this I never directly import into a temp-table ( or a database table ) with the import statement. I always use variables and perform serveral validations on them before I create the temp-table. If it it just for the sake of writing a temp-table out to a file and read it back in I always use write-xml () and read-xml ( ).
  2. Get rid of the release statement - it is bad practice and most likely won't do what you expect it to do. Since you use a define buffer on the temp-table strongly scoped to the repeat block, it does not make any sense at all.
Heavy Regards, RealHeavyDude.
 

oli

Member
Thank you for the clarification.
So, in the end, strong scoping buffer and transaction does not prevent creation of the empty record.
We have to delete it afterwards, or define the temp-table as "undo", or use variables and validations.
 

TomBascom

Curmudgeon
NO-UNDO means what it says...

If you CREATE the record prior to reading the data it will NOT be un-created when the IMPORT fails due to end of file. Which is exactly the way it should behave.

You might try using SEEK to proactively detect EOF. I've not tried that myself. I just delete the extra record and move on.
 
Top