Search code examples
ibm-midrangedb2-400rpgle

AS400 RPGLE/free embedded SQL against data structure


I am wondering if it's possible to do an SQL against a data structure, instead of a file.

For example, I have an external data structure with 100 fields, lets say the naming convention is field1, field2, etc.....The data structure name is DS1. The DS1 structure is passed in to the program with all 100 fields containing values. I am wondering if it's possible to do something like this:

/free
  exec sql                 
  update DS1 set field1 = field2;  
/end-free

I'm not sure if it's possible to query a data structure instead of going to disk to an actual file, but if it is it would make things a little faster and simpler.

Thanks!


Solution

  • Simple answer, no.

    Closest thing to what you're asking for is with the VALUES INTO statement.

     d myDS            ds                  qualified
     d  fld1                         10a
     d  fld2                         10a
    
    
      /free
        myDS.fld1 = 'HELLO';
        exec sql
           values (:myDS.fld1) into :myds.fld2;
    
        dsply myDS.fld2;
        *INLR = *ON;
        return;
      /end-free     
    

    Why you'd want to do that is beyond me when a simple myDS.fld2 = myDS.fld1; is sufficient. I assume it has to do with your other question: AS400 RPGLE/free dynamic variables in operations