ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Can I use a qsys2.http_get function as the "line" value for qsys2.ifs_write?

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

  • Can I use a qsys2.http_get function as the "line" value for qsys2.ifs_write?

    I successfully use http_get() to retrieve documents from a web service of up to 4Mb and store them on the IFS using ifs_write(). Unfortunately, some of the documents requested are larger than what RPG allows (~16Mg if I remember).

    I was wondering if I can skip over the need for a host variable and combine two functions into a single SQL request?

    I've tried a few different variations to no avail. The current version shown here results in the error "SQL0301 Input variable *N or argument 2 not valid":
    Code:
    exec sql
         call qsys2.ifs_write(
            path_name => :llFileName ,
            line => (values( qsys2.http_get_blob( :ggUrl , :ggOptions ) ) ) ,
            overwrite => 'REPLACE');
    Is there a way to use two functions and avoid a BLOB host variable?

    Thanks in advance for any help.

  • #2
    I would use file locator in RPG.
    This is the easiest and fastest way to do so.

    Code:
    DCL-S Loc_File SQLTYPE(Clob_File) CCSID(1208);
    
    Clear Loc_File;
    
    Loc_File_Name = '/home/yourdir/YourIFSFile.txt';
    Loc_File_NL = %Len(%Trim(Loc_File_Name));
    Loc_File_FO = SQFOVR; //Create or override existing IFS File
    
    Exec SQL Set :Loc_File = qsys2.http_get_blob(...);
    ?

    Comment


    • #3
      Thank you, Andreas! I saw clob_file while doing my research but over-looked putting it together as the solution.

      Comment


      • #4
        I have yet another web service that I'm trying to use. I'm running this sql statement:
        Code:
          exec sql
            select response_message,
                   cast(response_http_header as varchar(5000))
              into :ggResponseFile, :ggResponseHeader
              from table(qsys2.http_post_verbose( :llUrl, :ggFileName, :llOptions )) ;​
        ggResponseFile is sqltype(clob_file)
        ggResponseHeader is char(5000)

        ggResponseFile_fo = SQFOVR;

        I'm running Axis trace and see the response data is received (385 bytes). The file specified by ggResponseFile gets created with zero bytes and I get this error message in the joblog:
        ​​
        Message . . . . : Unable to access a file that is referred to by a file
        reference variable.
        Cause . . . . . : The file referred to by the file reference variable (host
        variable 1) could not be accessed because of reason code 3021. The reason​
        UPDATE: I'm leaving this post to keep myself humble and to let others know the error can be caused by trying to access the file for INPUT without changing the _fo value to SQFRD, which was happening in a separate procedure in the program.

        Comment

        Working...
        X