• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

vvIfs_openFile creates an unreadable IFS file

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

  • vvIfs_openFile creates an unreadable IFS file

    I am attempting to use your vvIfs service program procedures to create an HTML file on the IFS. I'm getting the file, but the contents are not readable.

    I have my own IFS service program that I've used for quite some time (uses the same C procedures) - I can't use it because our procedures conflict (i.e. readline and writeline).

    In any case, I tried following your example in the online documentation and it produces a file that contains odd characters. I've tried code page 819 and 1252, and adding the OTEXTMODE and/or OCODEPAGE "flags".

    If I omit the codepage value, the file is written using codepage 37. I can read it using WRKLNK, but not from a PC editor.

    I was following documentation here: https://service.cnxcorp.com/valence-..._Toolkit.vvIFS

    Code:
      lStmf = '/tmp/' + gCompany + '-' + lEntity + '.html';
      vvIfs_deleteFile(lStmf);
      fd = vvIfs_openFile(lStmf
                         :OREADWRITE+OCRTNOEXIST
                         :S_IRUSR + S_IWUSR + S_IROTH + S_IWOTH
                         :1252);
      writeOK = vvIfs_writeFile(fd :%addr(lMessageBody:*data) :%len(lMessageBody));
      vvIfs_closeFile(fd);
    ?
    I know the "flags" are simply added to create an integer value to control the open()... My own code looks like this:
    flag = o_wronly + o_creat + o_ccsid + o_excl + o_textdata + o_text_creat;
    mode = s_irusr + s_iwusr + s_iroth + s_iwoth;
    fd = open(%trimr(inStmf):flag:mode:cp:0); ?
    (files using this method can be viewed from WRKLNK as well as PC applications)

    Not sure how to get the same result with your service pgms.

    thx,
    Greg

  • #2
    This CCSID stuff is always a pain for me. Can you try the following?

    Code:
    fd = vvIfs_openFile(lStmf                            
                       :OREADWRITE+OCRTNOEXIST+OCODEPAGE 
                       :S_IRUSR + S_IWUSR + S_IROTH + S_IWOTH                  
                       :UTF8);     // this is a constant already defined     
    
    // convert the data you want to write to UTF8
    //
    lCurrentCCSID = vvUtility_getCurrentCCSID();    // defined as 5,0 
    lMessageBody = vvUtility_convertCCSID(lMessageBody:lCurrentCCSID:UTF8);
    
    // now your original code to vvIFS_writeFile...                      
    ?

    Comment


    • #3
      That worked (I hate CCSID stuff also)

      So before I saw this, I pulled the code out into a standalone RPG program... I used your utilities to create the IFS file from a program called from the command line.
      It worked WITHOUT getting/converting from the current CCSID to UTF8.

      When I put that same code into the button program, the file was still unreadable without the conversion you show above. Even though in debug the button program showed the current CCSID was 37.

      So I remove the conversion program and defined my lMessageBody variable as *UTF8 (this is an option in v7r3 or v7r5):

      Code:
        dcl-s  lMessageBody   varchar(1024) ccsid(*utf8) inz;
      
        vvIfs_deleteFile(lStmf);
        fd = vvIfs_openFile(lStmf
                           :OREADWRITE+OCRTNOEXIST+OCODEPAGE
                           :S_IRUSR + S_IWUSR + S_IROTH + S_IWOTH
                           :UTF8
                           );
      //  lCurrentCCSID = vvUtility_getCurrentCCSID();
      //  lMessageBody = vvUtility_convertCCSID(lMessageBody:lCurrentCCSID:UTF8);
      
        writeOK = vvIfs_writeFile(fd :%addr(lMessageBody:*data) :%len(lMessageBody));
        vvIfs_closeFile(fd);
      ??
      It works great even without your conversion lines (commented out above).

      By defining the variable as *UTF8, the conversion is done automatically.

      Did I mention I hate working with CCSIDs??

      Comment


      • #4
        Good to know...thanks for posting this back.

        Comment

        Working...
        X