ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Need some feedback on using a Service Program

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

  • Need some feedback on using a Service Program

    I found a service program which will wrap text for output and call it LINEWRAP. There is a Module and Service program in my library list. I also followed the instructions to create an SQL procedure. The program works fine with Interactive SQL. However, when try to code it in my SQLRPGLE program, I get an error the object LINEWRAP does not exist.
    If my library list includes the objects, what are they not found, but yet OK using Interactive SQL. I can't figure out what I'm missing.
    exec sql DECLARE C4 CURSOR FOR
    Select lineno, linetext
    From Table(LINEWRAP(:splitline,100)) Comments
    FOR READ ONLY ;
    exec sql OPEN C4;
    exec sql FETCH C4 FOR 3 ROWS INTO :lines ;
    exec sql CLOSE C4;


  • #2
    Is the library list set correctly at run time?

    Comment


    • #3
      There could be one of two things happening here. It could be failing to find the SQL function definition, or it could be failing to find the external service program object. I'm not 100% on which one of these is happening here without the exact error message.

      You could try the following.

      1. Check the service program is in the library list

      You say you've already done this, but we should rule out everything! Run WRKOBJ LINEWRAP *SRVPGM and verify it is in the library you expect

      2. Check the SQL function is in the library list

      Consult the system catalog to make sure the SQL function is present in your library list:

      Code:
      SELECT routine_schema, external_name
      FROM sysfuncs AS f
      INNER JOIN library_list_info AS l
      ON l.schema_name = f.routine_schema
      WHERE f.routine_name = 'LINEWRAP'
      3. Check the external name of the function

      This is most likely fine, since you can use it interactively. However, just confirm the external name from the query above is something like *LIBL/LINEWRAP(procedure)

      4. Try qualifying the function with the library name

      Change your RPG program to specify:

      Code:
      From Table(MYLIB.LINEWRAP(:splitline,100)) Comments
      5. Check the data types of the function parameters

      The system allows you to have many functions with the same name, that accept different types of arguments. So sometimes a "function not found" can really mean "I didn't find a function that was suitable for these argument types".

      Check the definition of the parameter in your SQL function declaration. Then make your splitline variable match that exactly (or CAST it in your SQL statement) and see if that helps.

      Comment


      • #4
        I was able to correct the problem which was caused by a missing parameter not being passed, even though RDI error indicated the object was not found. Thanks for the troubleshooting tips

        Comment


        • #5
          IBMi SQL allows procedure overloading - that is, two procedures with the same name but different numbers of parameters. That's why the error text will say it can't find "Routine ABCD in *N not found with specified parameters" It's not just resolving the procedure name, it's resolving the combination of procedure name and parameter count.

          Comment

          Working...
          X