ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Create streamfile with 819 code page with C API's

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

  • Create streamfile with 819 code page with C API's

    Hi guys,
    Can you help me with some tips regarding the creation of a streamfile in a IFS folder with codepage 819? I made a program who generate XML files as streamfiles with extension .xml in a folder in IFS, using C API's - open, write, close.
    But I don't have the right codepage -> I saw that I have 297 as CCSID file and the same value for Job CCSID ( - this informations are available with WRKLNK -> option 5 on my file -> F15 Services).

    How I must to declare the open statement to can use the mode: 819 and to have a codepage 819?

    Now I have like this:

    * open()
    D open PR 10I 0 ExtProc('open')
    D path * value options(*string)
    D openflags 10I 0 value
    D mode 10U 0 value options(*nopass)
    D ccsid 10U 0 value options(*nopass)
    D* txtcreatid 10U 0 value options(*nopass)


    fd = open('myfolder/ifsfile.xml'
    : O_CREAT+O_TRUNC+O_WRONLY: (6*64) + (6*8) + (4));

    -> I tried to change with:

    fd = open('/ifstest/somefile.txt': O_CREAT+O_WRONLY+O_CODEPAGE: mode: 819) But I have a compile error for the "mode"- like not declared: RNF7030 30 The name or indicator mode is not defined.

  • #2
    You have a parameter defined as 10U 0, but no variable. Actually, the "names" on the PR are practically meaningless. From the ILE RPG language reference under defining prototype parameters:
    "For a prototype parameter definition, the name entry is optional. If a name is specified, the name is ignored."
    So, the name that you have ("mode") is not really meaningful except as documentation.

    Create an additional simple variable named "mode" as 10U 0 and initialize it with the value you want. See how it compiles with your second example.
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      You weren't very explicit about what your requirements are. I don't understand why you are passing the word 'mode' as a parameter when the mode you had before seemed to be working for you?

      But, if the goal is to simply mark the file as a particular CCSID but do no character set conversion (because your data is already in CCSID 819, so it's not needed) then you'd do this (which seems to be what you did?)
      Code:
      unlink('/ifstest/somefile.txt');
      
      fd = open( '/ifstest/somefile.txt'
               : O_CREAT+O_WRONLY+O_CCSID
               : (6*64) + (6*8) + (4)
               : 819 );
      Its far more common, however, for the RPG program to have EBCDIC data rather than ASCII. If you'd like the data to be converted from EBCDIC to ASCII, then you'd do this:
      Code:
      unlink('/ifstest/somefile.txt');
      
      fd = open( '/ifstest/somefile.txt'
               : O_CREAT+O_WRONLY+O_CCSID+O_TEXTDATA+O_TEXT_CREAT
               : (6*64) + (6*8) + (4)
               : 819
               : 0 );
      If you want to stop hard-coding the mode, you can inherit it from the directory. This is handy because it means your system administrator can change the mode assigned to files simply by changing the directory, they don't have to ask you to go and change the hard-coded mode in your programs. To do that, add the O_INHERITMODE parameter. In that case the mode parameter is ignored, so you can simply pass a zero for that parameter

      Code:
      unlink('/ifstest/somefile.txt');
      
      fd = open( '/ifstest/somefile.txt'
               : O_CREAT+O_WRONLY+O_CCSID+O_TEXTDATA+O_TEXT_CREAT+O_INHERITMODE
               : 0
               : 819
               : 0 );
      This all assumes that you don't mind doing this with the (Unix-type) IFS APIs. You mention briefly that you'd like to use the C APIs instead... but I suspect this was just confusion. If you do want to use the C APIs such as _C_ifs_fopen(), then please ask again and clarify that point.

      In all cases, it's a good idea to unlink the file beforehand. Otherwise you will have to deal with data and parameters that are left over from old copies of the file on disk. Unless you plan to add to an existing file or update data in an existing file, I strongly recommend unlinking it before calling open().

      Comment

      Working...
      X