sponsored links



No announcement yet.

API - need to retrieve defined printers

  • Filter
  • Time
  • Show
Clear All
new posts

  • API - need to retrieve defined printers

    Hello, I need to retrieve all the printers defined in our ISeries partition and show them so the user can select a printer. We have a program where the user can define a printer for a given report. They can go in and tell us if the report is going to Optio (and therefore needs a network printer name), or is defined via DDS (so it needs the ISeries printer name). The problem is that the users don't know the printer names - heck WE don't know all the printer names! Anyway, I've found an example here at Code400 that lists the objects - and that's a wonderful start.

    What I think I'd like to do is use the QGYRPRTA API because it seems that it would tell me if the writer is started, if it's held, device status,if it's already printing, etc. Doing that will let me "weed out" some of the old printers that no one has ever removed from the system.

    Everything I've learned about API's has come from what I've read online. One great example from Tom Liotta helped me create a process that allows our operators to end everyone's interactive job with one keystroke (they were going through WRKACTJOB and ending jobs one at a time- thank you, Mr. Liotta!!!) I haven't found an example of this API, and I'm not sure I understand it. The required parameter group for the QUSLOBJ API includes user space. QGYRPRTA doesn't. It does have "Receiver Variable" but I'm not sure that's the same thing.

    I guess I just don't know how to start. I'd really appreciate it if someone could give me a push in the right direction on setting up the PR.

    This is what I have right now, and am going to play with it starting with the sample I found of QUSLOBJ.
    **-- Retrieve printer attributes---------------------
    d $ListPrinters Pr ExtPgm( 'QGYRPRTA' )
    d userspace 396a Const
    d Length 4b 0 Const
    d Formatname 8 Const
    d DeviceName 10 Const
    d ErrorCode 32767a Options( *VarSize )

    I guess I'm a little afraid I'm going to break something!!

    Thank you in advance for any advice you have.

  • #2
    Hi Melissa,

    This API returns it's results directly through parameters, so it works a little differently than the "list APIs" (like QUSLOBJ that you cited). The "list APIs" as you know place their results into a user space that you can subsequently read to get the data. This API just returns the results directly though the parameters, which makes it a little earier to use.

    So when it says "receiver variable", that's really all it is. A variable used to receive the output from the API. In this case, the receiver variable would be a data structure in the RPTA0100 format.

    Some important details:

    1) The receiver variable should never have "const" defined on it. Const means "constant", i.e. the program that you're calling won't change the value. So for a receiver variable where the point is to get back data, that would not be the right option.

    2) Since APIs tend to get extended over time (more info added, additional formats allowed, etc) I would not recommend hard-coding the length of the receiver variable. Instead, code it as a very large string and use options(*varsize), exactly as you have done for the error code parameter.

    3) When API documention says "binary(4)" that means it's a 4-byte integer Your prototype is wrong, here, because you've used RPG's "B" data type which is "binary decimal", not a true integer, and yours is only 2 bytes long. ("4b 0" in RPG means it can hold a 4 digit decimal number, and only two bytes of memory are needed for that.) The correct RPG data type for "binary(40" is 10i 0 (or int(10) in free format)

    With that in mind, your code should look something like this (Note: I'll let you code the data structure -- I'm just filling in a few fields as an example... you can code the remaining fields yourself)

         d QGYRPRTA        Pr                  ExtPgm( 'QGYRPRTA' )
         d  userspace                 32767a         Options( *VarSize )
         d  Length                       10i 0 Const
         d  Formatname                    8a   Const
         d  DeviceName                   10a   Const
         d  ErrorCode                 32767a         Options( *VarSize )
         D Dev             s             10a    
         D ErrCode         ds                  qualified
         D   bytesProv                   10i 0 inz(%size(ErrCode))
         D   bytesAvail                  10i 0
         D   msgid                        7a
         D                                1a
         D   msgdta                   32767a
         d RPTA0100        ds                  qualified
         d   bytesRtn                    10i 0
         d   bytesAvail                  10i 0
         d   deviceName                  10a
         d   wtrStarted                   1a
         d   wtrStatus                    1a
          . ... other fields here ...
           dev = 'PRT01';
           QGYRPRTA( RPTA0100
                   : %size(RPTA0100)
                   : 'RPTA0100'
                   : Dev
                   : ErrCode );
    The result should either be an error (so ErrCode is filled in) or the RPT0100 DS will be filled in with data about the printer.

    Good luck


    • #3
      Please forgive the lateness of this reply, but thank you for your help! Your example was just what I needed to get my brain in gear.


      sponsored links