ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Using API QUSLOBJ to list objects

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

  • Using API QUSLOBJ to list objects

    Here is code to pass in library and object type and get a list of those objects in a userspace for processing.

    Its in a rough form

    Code:
          *===================================================
    
          * PROGRAM - @@SPACE
          * PURPOSE - dump objects (DSPOBJD) to userspace
          * WRITTEN -
          * AUTHOR  - jamie 
          *
          * PROGRAM DESCRIPTION
          *   This program will dump objects into a userspace
          *
          *
          * INPUT PARAMETERS
          *   Description        Type  Size    How Used
          *   -----------        ----  ----    --------
          *   InLibary           Char  10      Library to search for objects
          *   InType             Char  10      Type of objects to dump
          *
          * INDICATOR USAGE
          *   03 - Cancel current screen and return to previous screen
          *   30 - SFLCLR
          *   31 - SFLDSP
          *   32 - SFLDSPCTL
          *   33 - SFLEND
          *
          *===================================================
          *
          * Program Info
          *
         d                SDS
         d  @PGM                   1     10
         d  @PARMS                37     39  0
         d  @JOB                 244    253
         d  @USER                254    263
         d  @JOB#                264    269  0
          *
          *  Field Definitions.
          *
         d AllText         s             10    Inz('*ALL')
         d CmdString       s            256
         d CmdLength       s             15  5
         d Count           s              4  0
         d Format          s              8
         d GenLen          s              8
         d InLibrary       s             10
         d InType          s             10
         d ObjectLib       s             20
         d SpaceVal        s              1    inz(*BLANKS)
         d SpaceAuth       s             10    inz('*CHANGE')
         d SpaceText       s             50    inz(*BLANKS)
         d SpaceRepl       s             10    inz('*YES')
         d SpaceAttr       s             10    inz(*BLANKS)
         d UserSpaceOut    s             20
    Ã?     *                                                                                            Ã?
    Ã?     * GenHdr                                                                                     Ã?
    Ã?     *                                                                                            Ã?
         d GenHdr          ds                  inz
         d  OffSet                 1      4B 0
         d  NumEnt                 9     12B 0
         d  Lstsiz                13     16B 0
    Ã?     *                                                                                            Ã?
    Ã?     *  Data structures                                                                           Ã?
    Ã?     *                                                                                            Ã?
         d GENDS           ds
         d  OffsetHdr              1      4B 0
         d  NbrInList              9     12B 0
         d  SizeEntry             13     16B 0
          *
          *
          *
         d HeaderDs        ds
         d  OutFileNam             1     10
         d  OutLibName            11     20
         d  OutType               21     25
         d  OutFormat             31     40
         d  RecordLen             41     44B 0
    
          *
          * API Error Data Structure
          *
         d ErrorDs         DS                  INZ
         d  BytesPrv               1      4B 0
         d  BytesAvl               5      8B 0
         d  MessageId              9     15
         d  ERR###                16     16
         d  MessageDta            17    116
          *
          * Create userspace datastructure
          *
         d                 DS
         d  StartPosit             1      4B 0
         d  StartLen               5      8B 0
         d  SpaceLen               9     12B 0
         d  ReceiveLen            13     16B 0
         d  MessageKey            17     20B 0
         d  MsgDtaLen             21     24B 0
         d  MsgQueNbr             25     28B 0
          *
          * Date structure for retriving userspace info
          *
         d InputDs         DS
         d  UserSpace              1     20
         d  SpaceName              1     10
         d  SpaceLib              11     20
         d  InpFileLib            29     48
         d  InpFFilNam            29     38
         d  InpFFilLib            39     48
         d  InpRcdFmt             49     58
          *
         d ObjectDs        ds
         d  Object                       10
         d  Library                      10
         d  ObjectType                   10
         d  InfoStatus                    1
         d  ExtObjAttrib                 10
         d  Description                  50
    Ã?     *                                                                                            Ã?
          *  Create a userspace
          *
         c                   exsr      $QUSCRTUS
          *
         c                   eval      ObjectLib =  AllText + InLibrary
          *
          * List all the objects to the user space
          *
         c                   eval      Format = 'OBJL0200'
          *
         c                   call(e)   'QUSLOBJ'
         c                   parm      Userspace     UserSpaceOut
         c                   parm                    Format
         c                   parm                    ObjectLib
         c                   parm                    InType
          *
          * Retrive header entry and process the user space
          *
         c                   eval      StartPosit = 125
         c                   eval      StartLen   = 16
          *
          * Retrive header entry and process the user space
          *
         c                   call      'QUSRTVUS'
         c                   parm      UserSpace     UserSpaceOut
         c                   parm                    StartPosit
         c                   parm                    StartLen
         c                   parm                    GENDS
          *
         c                   eval      StartPosit = OffsetHdr + 1
         c                   eval      StartLen = %size(ObjectDS)
          *
          *
    Ã?     *  Do for number of fields                                                                   Ã?
          *
    B1   c                   do        NbrInList
          *
         c                   call(e)   'QUSRTVUS'
         c                   parm      UserSpace     UserSpaceOut
         c                   parm                    StartPosit
         c                   parm                    StartLen
         c                   parm                    ObjectDs
          *
          * [COLOR=Indigo]Put your code here[/COLOR]
          *
         c                   eval      StartPosit = StartPosit + SizeEntry
         c                   enddo
          *
         c                   eval      *Inlr = *On
          *===============================================
          * $QUSCRTUS - API to create user space
          *===============================================
         c     $QUSCRTUS     begsr
          *
          * Create a user space named ListObjects in QTEMP.
          *
         c                   Eval      BytesPrv = 116
         c                   movel(p)  'LISTOBJECTS' SpaceName
         c                   movel(p)  'QTEMP'       SpaceLib
          *
          * Create the user space
          *
         c                   call(e)   'QUSCRTUS'
         c                   parm      UserSpace     UserSpaceOut
         c                   parm                    SpaceAttr
         c                   parm      4096          SpaceLen
         c                   parm                    SpaceVal
         c                   parm                    SpaceAuth
         c                   parm                    SpaceText
         c                   parm                    SpaceRepl
         c                   parm                    ErrorDs
          *
         c                   endsr
          *=================================================
          *    *Inzsr - One time run House keeping subroutine
          *=================================================
         c     *Inzsr        begsr
          *
         c     *entry        plist
         c                   parm                    InLibrary
         c                   parm                    InType
          *
         c                   endsr
          *==============================================
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com
Working...
X