WRITE to a file

aztecconsultingaztecconsulting Member Posts: 55
I am using WRITE to output some data to a file. The problem I am having is that each line is being appended with a binary Carriage Return and Line Feed but I only want the Line Feed as the line termination character so the mainframe can read the file. Is there another method like WRITE or a setting I'm not setting to have Navision just output the data?

Comments

  • krikikriki Member, Moderator Posts: 9,118
    I didn't try it out, but you can try something like this:
    txcLF := 'X';
    txcLF[1] := 10;
    REPEAT 
      fil.WRITE("Your Variable");
      fil.TEXTMODE(FALSE);
      fil.SEEK(fil.LEN - 2); // put filepointer on the CR-char
      fil.WRITE(txcLF); // Write the LF
      fil.TEXTMODE(TRUE); // get back to textmode
    UNTIL "Some Test";
    

    If this doesn't work, you can also try this:

    txcLF := 'X';
    txcLF[1] := 10;
    fil.TEXTMODE(FALSE); // write all in binary mode
    fil.CREATE(...);
    REPEAT
      txtHelp := FORMAT("Your Variable");
      fil.WRITE(COPYSTR(txtHelp,1,STRLEN(txtHelp));
      fil.WRITE(txcLF);
    UNTIL "Some Test";
    

    Some info : the COPYSTR in the binary mode is necessary, because otherwise the WRITE writes the complete string, even if the string is not completely filled up.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • KowaKowa Member Posts: 925
    You can also create a new WriteIntoUNIXFile -Function.
    Set Textmode(FALSE) for the file and write each character from the string separately with a FOR-NEXT statement.

    WriteIntoUNIXFile(Field : Text[250])
    LF := 10 // use char variable
    Length := STRLEN(Field);
    FOR I := 1 TO Length DO BEGIN
    Z := Field[I];
    MyFile.WRITE(Z);
    END;
    MyFile.WRITE(LF); // Line Feed
    
    Kai Kowalewski
  • krikikriki Member, Moderator Posts: 9,118
    Kowa wrote:
    You can also create a new WriteIntoUNIXFile -Function.
    Set Textmode(FALSE) for the file and write each character from the string separately with a FOR-NEXT statement.

    WriteIntoUNIXFile(Field : Text[250])
    LF := 10 // use char variable
    Length := STRLEN(Field);
    FOR I := 1 TO Length DO BEGIN
    Z := Field[I];
    MyFile.WRITE(Z);
    END;
    MyFile.WRITE(LF); // Line Feed
    
    Yes, but printing character by character can be slow.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.