How can i check the object existance in RPG program without
using QCMDEXC command.

Answer Posted / naveen chandra joshi

The question is: 
How can i check the object existence in RPG program without 
using QCMDEXC command?

Answers posted by AS/400 experts:- use Monitor On error; what if file is not in user opened mode and already declared & opened in F specs...this solution will not work in this case and program will throw error when it tries to open the file in F specs itself...(This we can solve using File Information DS)
User wants to know the object existence, it (object)can be file object, program object or any other type of object.
Generally we check object existence by using CHKOBJ command but user said not to use QCMDEXC API...

The solution is(by using QUSROBJD API):
      *---------- Global variables:  ----------------------*
     D ObjNam          s             10a
     D ObjLib          s             10a
     D ObjTyp          s             10a
      *---------- Api error data structure:  --------------*
     D ApiError        Ds
     D  AeBytPro                     10i 0 Inz(          %Size(ApiError))
     D  AeBytAvl                     10i 0 Inz
     D  AeMsgId                       7a
     D                                1a
     D  AeMsgDta                    128a

*-- Retrieve object description:  -----------------------*
     D RtvObjD         Pr               ExtPgm('QUSROBJD')
     D  RoRcvVar         32767a         Options(*VarSize )
     D  RoRcvVarLen                  10i 0 Const
     D  RoFmtNam                      8a   Const
     D  RoObjNamQ                    20a   Const
     D  RoObjTyp                     10a   Const
     D  RoError                   32767a  Options(*VarSize)
     
     C                   Eval      ObjNam     =  '???'
     C                   Eval      ObjLib     =  '*LIBL'
     C                   Eval      ObjTyp     =  '*PGM'
      *
     C                   CallP     RtvObjD( RoData
     C                                    : %Size( RoData )
     C                                    : 'OBJD0100'
     C                                    : ObjNam + ObjLib
     C                                    : ObjTyp
     C                                    : ApiError
     C                                    )
      *
     C                   If        AeBytAvl   >  *Zero And
     C                             AeMsgId    =  'CPF9801' 
      *-- Object doesn't exist...
     C                   EndIf
      *
     C                   Return

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the necessary keyword needed to scroll subfile records?

702


is this a rpg channel?

679


Program to read marks of 10 students for 4 subjects and compute and display total marks and status of each student in rpg

714


How many program bind in one module....

2121


what is *place and *auto keyword in prtf ?plz explain

2724






Please tell me how to read the records from a file with load an array of size with error conditions(The logic answer for this question is ARR is array of 99 elements Z-ADD 0 IDX *LOVAL SETLL FILE READ FILE 99 *IN99 DOWEQ *OFF IDX ANDLT 99 ADD 1 IDX MOVE FIELD ARR,IDX READ FILE 99 ENDDO).So,Please give me the complete of this code.

2051


When we have a file with Duplicate records and I want to read the unique record from the file. For example a file containing Emp Name as 'Ram' and there are 3 entries of it. So how to read a unique record from File?

507


what is an online rpg?

725


How to select highest score of each subject or how to select highest income of every month?

1295


can I touch the array during treatments?

756


Interviewer asked me write down DDS for load all subfile .can anybody write dds

1017


how do I declare a table or array in rpg iv?

737


do you use message subfiles? What are the necessary keywords required coding a message subfile?

687


how can I tell when to replace the array?

702


If my rpg program has a date field, what extra care I have to take while compiling that rpg program? If the file is keyed and I have declared the file as well as key list properly in my program. Still am getting an error message like "chain/reade operation is not allowed" what may be the case?

616