Header Ads

  • Recent Posts

    Sample code to read a file using file layouts and to insert data into a record

    Sample code to read a file using file layouts and to insert data read into a record.

    Local File &MYFILE;
    Local Record &REC;
    Local array of string &ARRAY;
    Local string &FILE_DIRECTORY, &FileName;

    &FileName = "MY_FILE_NAME.txt";
    &FILE_DIRTORY = "/MYDIRECTORY/"
    /*open file for reading*/
    &MYFILE = GetFile(&FILE_DIRECTORY &FileName, "R", %FilePath_Absolute);
    /*create record object*/
    &REC = CreateRecord(Record.MY_RECORD);
    &ARRAY = CreateArrayRept("", 0);
    /*check if file is open*/
    If &MYFILE.IsOpen Then
    /*The SetFileLayout method is a file layout method. It associates a specific file layout definition with the file object executing this method, providing easy access to rowset data.(PeopleBooks)*/
    If &MYFILE.SetFileLayout(FileLayout.FILE_LAYOUT_NAME) Then
    /*read line into &STRING*/
    While &MYFILE.ReadLine(&STRING);
    &ARRAY = Split(&STRING, ",");
    For &I = 1 To &REC.FieldCount
    &REC.GetField(&I).Value = RTrim(LTrim(&ARRAY [&I]));
    End-For;
    /* do additional processing here for converting values */
    &REC.Insert();
    /*count rows inserted into record*/
    &COUNT = &COUNT + 1;
    End-While;
    Else
    /* do error processing - filelayout not correct */
    End-If;
    Else
    /* do error processing - file not open */
    End-If;

    No comments

    Please refrain for marketing messages and unnecessary back links.

    Post Top Ad

    Post Bottom Ad