load delimited file and create new records

bino

Member
Hi all,

This seems pretty simple, but Im having problems. When I run this program it does not create any records. Basically I am loading a comma delimited file. The delimited file simply holds two columns of data: name and email. I think Im not putting the file in the right format to recognize each line name,email.

sample of delimited file contents: John Johnson,jjohnson@yahoo.com.com,Ben Sharp,bsharp@hotmail.com...

My code

def var v-name as char no-undo.
def var v-email as char no-undo.
def var v-file as char no-undo.
def var v-new-seq as int no-undo.
def var v-cust-number as char no-undo.
assign v-file = "emailist.csv"
v-cust-number = "1112".

INPUT FROM v-file.
REPEAT:
IMPORT DELIMITER "," v-name v-email.

find last contact where
contact.cust-number eq v-cust-number
no-lock no-error.

if avail contact
then assign v-new-seq = contact.seq + 1.
else assign v-new-seq = 1.


create contact.
assign contact.seq = v-new-seq
contact.contact = v-name
contact.cust-number = v-cust-number
contact.email-addr = v-email.


END.
INPUT CLOSE.

 

erick.rosales

New Member
Hi all,

This seems pretty simple, but Im having problems. When I run this program it does not create any records. Basically I am loading a comma delimited file. The delimited file simply holds two columns of data: name and email. I think Im not putting the file in the right format to recognize each line name,email.

Try to use a file containing:
John Johnson,jjohnson@yahoo.com.
Ben Sharp,bsharp@hotmail.com.
Erick Rosales,erick@rosales.com

In your code

def var v-name as char no-undo.
def var v-email as char no-undo.
def var v-file as char no-undo.
def var v-new-seq as int no-undo.
def var v-cust-number as char no-undo.
assign v-file = "emailist.csv"
v-cust-number = "1112".

INPUT FROM VALUE(v-file).
REPEAT:
IMPORT DELIMITER "," v-name v-email.

find last contact where
contact.cust-number eq v-cust-number
no-lock no-error.

if avail contact
then assign v-new-seq = contact.seq + 1.
else assign v-new-seq = 1.

create contact.
assign contact.seq = v-new-seq
contact.contact = v-name
contact.cust-number = v-cust-number
contact.email-addr = v-email.

/* I recommend to use a display to see what is happening */

display
contact
with frame f-load.
pause 0.

END.
INPUT CLOSE.

The issue is that the import file read line by line, not delimited field by delimited field.

In the case that you want to read a single line containing all the records you must create a procedure to extract each record of the line. (A little bit industroius but is possible).
 
Top