1. Bjarne Anker
  2. PowerBuilder
  3. Wednesday, 15 April 2020 18:27 PM UTC

Hi..

 

I migrated an old application from 2017 , via 2019 to 2019 R2.

None of the XML files we have will generate now using FileOpen(<name>,TextMode!,Write!).

FileWrite all of a sudden returns -1. I works fine when changing to FileWriteEx.

If the FileWrite function now deprecated in 2019 R2?

It says in the help file that FileWriteEx should be used instead.

 

Regards,

 

Bjarne

Maritech Systems

Norway

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 16 April 2020 09:02 AM UTC
  2. PowerBuilder
  3. # 1

I tried exactly what you do and it works.

Is the file that you're trying to open maybe an existing one and it's a 0-byte file?

Do you have access rights in the folder where you are trying to write?

Comment
  1. Bjarne Anker
  2. Thursday, 16 April 2020 09:09 AM UTC
The file was opened using TextMode option instead of LineMode.

Apperantly, FileWrite returns -1 in these cases.

It has been like this for a long time, so a bit surprised that it fails now.

But as mentioned, the app has been PB2017 for long time and was recently migrated to 2019 R2.

Perhaps that's the issue here.

I've changed to FileWriteEx, and it works fine now.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 16 April 2020 09:28 AM UTC
Hmm I forgot to actually do the FileWrite :(

Indeed FileWrite returns -1, which seems to make sense. This is from the pb help:



If the file is opened in stream mode, no conversion is done. If the file was opened in text mode, FileWrite returns -1. Use FileWriteEx to write to files in text mode.
  1. Helpful
There are no comments made yet.
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Thursday, 16 April 2020 08:24 AM UTC
  2. PowerBuilder
  3. # 2

Hi Bjarne,

 

Appeon didn’t modify the FileWrite function in PB 2017 / 2019. It is the same as SAP PB 12.6.

 

For the FileWrite function, you can refer to the link below for more details:

 

https://docs.appeon.com/appeon_online_help/pb2019r2/powerscript_reference/ch10s177.html

FileWrite is maintained for backward compatibility. Use the FileWriteEx function for new development.

If the file was opened in text mode, FileWrite returns -1. Use FileWriteEx to write to files in text mode.

 

https://docs.appeon.com/appeon_online_help/pb2019r2/powerscript_reference/ch10s172.html

The mode in which you open a file determines the behavior of the functions used to read and write to a file. There are two functions that read data from a file: FileRead and FileReadEx, and two functions that write data to a file: FileWrite and FileWriteEx. FileRead and FileWrite have limitations on the amount of data that can be read or written and are maintained for backward compatibility. They do not support text mode.

 

So,We recommend you to use FileWriteEx function.

 

Regards,

Ken

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 15 April 2020 19:51 PM UTC
  2. PowerBuilder
  3. # 3

Hi Bjarne;

   No, the FileWrite() command is not deprecated. In fact, its the only way to write super large files or write data in "chunks" whereas the FileWriteEX() command only supports an "All or Nothing" approach. The same for the FileReadEX() command. Sometimes you need a more granular control over reading & writing. So the older variants of the read & write will always have to be supported (IMHO).

  Please open a Support Ticket for this issue if its reproducible.

Regards ... Chris

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Wednesday, 15 April 2020 19:05 PM UTC
  2. PowerBuilder
  3. # 4

in 2019R2 with filewrite() and fileopen as:

FileOpen(ls_path_doc, LineMode!, Write!, LockWrite!, Append!)

 FileOpen(ls_path_doc, LineMode!, Write!, LockWrite!, Replace!)

 

with no problems

have not tried with textmode

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.