Search code examples
sqlrpgle

Why /copy is not working in ILE module


Ok, so I am a little confused. I have created a simple module with one procedure. It works like a charm when the prototype and Data structure are included internally...

  ctl-opt option(*srcstmt:*nodebugio) nomain ;

     dcl-ds IIM ext end-ds;
     dcl-pr GetIIM LikeDS(IIM);
        *n char(35) options(*nopass) value ;
     end-pr ;


   dcl-proc GetIIM  export ;

     dcl-pi *n LikeDS(IIM);
        Item char(35) options(*nopass) value ;
     end-pi ;

     exec sql
       select * into :IIM
         from iim where iprod=:ITEM;

     return IIM   ;
   end-proc ;          

But when I use /copy, the SQL compiler doesn't like the data-structure and gives me an error...

Prototype

 /if defined(GetIIM)
   dcl-ds IIM ext end-ds;

   dcl-pr GetIIM LikeDS(IIM);
      *n char(35) options(*nopass) value ;
   end-pr ;

     /endif  

Procedure

 ctl-opt option(*srcstmt:*nodebugio) nomain ;
       /define GetIIM
       /copy JAGRACE/SANDBOX3,prototype
       /undefine GetIIM

     dcl-proc GetIIM  export ;

     dcl-pi *n LikeDS(IIM);
        Item char(35) options(*nopass) value ;
     end-pi ;

     exec sql
       select * into :IIM
         from iim where iprod=:ITEM;

     return IIM   ;
   end-proc ;

Procedure

So, what stupid thing am I doing now? The error code is SQL 0312 Variable IIM not defined or not usable.

I thought that the /copy would basically put that code snippet into the source and compile. I understand that the SQL precompiler is having an issue, but I am lost...


Solution

  • Take a look at the RPG preprocessor options (RPGPPOPT) parameter of the Create SQL ILE RPG Object (CRTSQLRPGI) command.

    The online help...

    RPG preprocessor options (RPGPPOPT)

    Specifies if the ILE RPG compiler will be called to preprocess the  
    source member before the SQL precompile is run.  Preprocessing the  
    SQL source member will allow some compiler directives to be handled 
    before the SQL precompile.  The preprocessed source will be placed  
    in file QSQLPRE in QTEMP.  This source will be used for the SQL     
    precompile.                                                        
    
    *NONE                                                              
        The compiler is not called for preprocessing.                  
    
    *LVL1                                                              
        The compiler is called for preprocessing to expand /COPY and   
        handle the conditional compilation directives except the       
        /INCLUDE directive.                                            
    
    *LVL2                                                              
        The compiler will be called for preprocessing to expand /COPY  
        and /INCLUDE and handle the conditional compilation directives.
    

    Make sure you're not using *NONE.