ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to write txt-file in IFS with UCS2-Data?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to write txt-file in IFS with UCS2-Data?

    Hi,

    I have a PF with several fields. One field is defined as 140G CCSID(13488).

    Now I want to write data in a txt-file in the IFS. I've already done this with other programs via IFS API, but I don't know how to do this with the UCS2-Field.

    In the program I have a DS with likerec to the PF which get filled with a chain.

    I found this article http://iprodeveloper.com/rpg-program...nicode-ifs-rpg

    According to the post of Scott I opened a file with O_CREAT+O_WRONLY+O_CCSID+O_TEXTDATA and CP_UCS2 (CCSID 1200) and then wrote the data with write(fd: %addr(data): %len(%trimr(data))*2) where data is the field from the likerec-DS with CCSID(13488).

    But the output in the file is not correct.
    Latin-Text is formatted with spaces. E.G. "Test" is written as " T e s t".
    Kyrillian-Text is unreadable.

    Also with CCSID 13488 for the txt-file there is no difference.

    Where is the error?

  • #2
    Do you really have just one field in the DS that is UCS2? If so, I would expect the translation on the write operation to be problematic. You may need to create a DS that includes UCS2 versions of the other fields, populate it with EVAL-CORR and then write from there. There are other ways but ...

    This is not a CSV right? All the data goes in the text file in one big lump? If it is CSV the answer is a bit different.

    What release are you compiling for? I ask because the amount of automatic code point translation done by RPG varies by release.

    If you are having to do write a lot of these kinds of programs you might want to look at my Open Access IFS writer - you would need to make some mods to the handler for the USC2 data but it will make your life simpler in future. You can read about it here: http://www.ibmsystemsmag.com/ibmi/de...Access/?page=3 the relevant part is page 3 onwards. An updated version of that article - which describes the template I now use for all OA programs - is here: http://www.ibmsystemsmag.com/ibmi/de...ess-templates/ and is an enhanced version of the earlier program.

    Comment


    • #3
      It sounds like the program you're viewing the file with is not viewing it as 16-bit unicode. What program are you viewing it with?

      Comment


      • #4
        I replied in the following thread because I didn't know you posted this question twice. (Why do people do that? Isn't it harder to follow the discussion when it is in two places?)

        Comment


        • #5
          Originally posted by Scott Klement View Post
          I replied in the following thread because I didn't know you posted this question twice. (Why do people do that? Isn't it harder to follow the discussion when it is in two places?)
          http://www.code400.com/forum/forum/i...2-with-ifs-api
          Hi Scott
          If the OP is the exactly the same and I notice that it's a duplicate, I generally merge the threads. No need then to post in both.
          And yes, it is irritating.

          Kit
          Regards

          Kit
          http://www.ecofitonline.com
          DeskfIT - ChangefIT - XrefIT
          ___________________________________
          There are only 3 kinds of people -
          Those that can count and those that can't.

          Comment


          • tomliotta
            tomliotta commented
            Editing a comment
            Are posts from new users automatically visible for them? Or do they need to be 'approved' first?

        • #6
          Originally posted by tomliotta View Post
          Are posts from new users automatically visible for them? Or do they need to be 'approved' first?
          Heck, we can't even get my replies to be approved
          IIRC, it's about 5 posts before they will automagically see their posts. This allows for moderators to delete spam before anyone else gets to see it.
          Regards

          Kit
          http://www.ecofitonline.com
          DeskfIT - ChangefIT - XrefIT
          ___________________________________
          There are only 3 kinds of people -
          Those that can count and those that can't.

          Comment


          • tomliotta
            tomliotta commented
            Editing a comment
            The anti-spam element is understood. But a new user can think a post is dropped, so they post a second time. Maybe depends on how clearly any notice that the post will be delayed before they see it, especially for non-English or even for less experienced Internet forum users. How many moderators are there in different time zones?
        Working...
        X