1

I'm trying to retrieve a list of Objects (no matter what type) from the AS400 based upon a Library name.

I have tried to use WRKOBJ LibName/*all through a command call but the errors recieved back advise I am unable to use the command WRKOBJ in this setting (no other feedback provided).

Current Code:

    StringBuffer getObjects = new StringBuffer("wrkobj " + library + "/*all");
    CommandCall call = new CommandCall(as400);

    if(call.run(getObjects.toString())){

            objectsFound = true;
            logger.debug("Lib: " + library + "  returned objects");

    }else{

            // Hold error message to display in joption pane
            errorMessages = new StringBuffer();
            // Show the messages (returned whether or not there was an error.)
            messagelist = call.getMessageList();

            for (int i = 0; i < messagelist.length; i++){

                // Show each message.
                logger.debug(messagelist[i].getText());
                errorMessages.append(messagelist[i].getText() + "\n");

            }
        }

I'm still looking for a solution to this so if I find anything I will post it but anyone who has any ideas or can point me in the right direction I'd appreciate it !

Nathan
  • 266
  • 4
  • 16
  • 1
    The reason the code with WRKOBJ doesn't work is that the output of WRKOBJ does not go to STDOUT, so you can't extract it from there. – Buck Calabro Jul 10 '14 at 14:05
  • Ahh great thanks for that ! I thought by using AS400Message[] messagelist = call.getMessageList(); i may be able to get the objects that way – Nathan Jul 10 '14 at 15:39
  • Note that by definition all CommandCall's and ProgramCall's run in batch. You cannot run interactive programs in this way. – Thorbjørn Ravn Andersen Jul 10 '14 at 22:20

3 Answers3

2

Yes, but you need to use the jt400.jar for this (which is what the jtopen tag covers)"

If you just need the names the IFSFile class supports listing file names on QSYS objects.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Great I'l give it a go ! – Nathan Jul 10 '14 at 10:46
  • Tried it with the IFSPath and works fine, need to use IFSFile dir = new IFSFile(as400, "QSYS.LIB"); but this returns excess amounts of files (obviously) so just assigned "QSYS.LIB/LibName.LIB" instead to get specific files. Really appreciate the help !! – Nathan Jul 10 '14 at 11:04
  • If you need more information, there is another API to ask deeper but I never got around to use it. I can recommend the midrange mailing list as an alternative to SO. http://archive.midrange.com/java400-l/index.htm – Thorbjørn Ravn Andersen Jul 10 '14 at 11:25
1

Maybe the JT400 class ObjectList would be a better approach? It's purpose built to do exactly this.

David G
  • 3,940
  • 1
  • 22
  • 30
  • 1
    Ahh great thanks for this @david, this gives more degree of control as the constructors look as though they can sort by type of the objects. Thanks very much ! – Nathan Jul 14 '14 at 14:51
0

You can also use JDBC to get more detailed information about the objects in a library. Here's an example using the JDBC client included with JTOpen.

~> java -cp jt400.jar com.ibm.as400.access.jdbcClient.Main jdbc:as400:SYSTEMNAME USERID PASSWORD  
>call QSYS.QCMDEXC(' DSPOBJD OBJ(EBERHARD/*ALL) OBJTYPE(*ALL) DETAIL(*SERVICE) OUTPUT(*OUTFILE) OUTFILE(QTEMP/OBJECTS)                  ', 000000100.00000)
>select * from qtemp.objects fetch first 10 rows only
ODDCEN,ODDDAT,ODDTIM,ODLBNM,ODOBNM,ODOBTP,ODOBAT,ODOBFR,ODOBSZ,ODOBTX,ODOBLK,ODOBDM,ODCCEN,ODCDAT,ODCTIM,ODOBOW,ODSCEN,ODSDAT,ODSTIM,ODSCMD,ODSSZE,ODSSLT,ODSDEV,ODSV01,ODSV02,ODSV03,ODSV04,ODSV05,ODSV06,ODSV07,ODSV08,ODSV09,ODSV10,ODSVMR,ODRCEN,ODRDAT,ODRTIM,ODCPFL,ODSRCF,ODSRCL,ODSRCM,ODSRCC,ODSRCD,ODSRCT,ODCMNM,ODCMVR,ODOBLV,ODUMOD,ODPPNM,ODPPVR,ODPCNR,ODAPAR,ODSSQN,ODLCEN,ODLDAT,ODLTIM,ODSFIL,ODSFLB,ODASP,ODLBL,ODPTFN,ODOBSY,ODCRTU,ODCRTS,ODUUPD,ODUCEN,ODUDAT,ODUCNT,ODTCEN,ODTDAT,ODODMN,ODCPVR,ODCVRM,ODPVRM,ODCPRS,ODOASP,ODAAPI,ODAPIC,ODUATR,ODACEN,ODADAT,ODATIM,ODAUDT,ODSIZU,ODBPUN,ODPGP,ODSSQL,ODOSIG,ODJRST,ODJRNM,ODJRLB,ODJRIM,ODJREN,ODJRCN,ODJRDT,ODJRTI,ODSSZU,ODSBPU,ODASPL,ODLASN,ODOADN,ODLADN,ODSSIG,ODMSIG,ODASSZ,ODALGN,ODOADG,ODLADG,ODSJRA,ODSJRL,ODSJRD,ODSJRG,ODJRJF
1,072514,164203,EBERHARD  ,BIGLOBOUT ,*PGM    ,CLE       ,0,126976,SQL PROCEDURE BIGBLOBOUT                          ,0,0,1,010314,120641,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,010314,120641,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,2, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,248,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLOBOUTX,*PGM    ,CLE       ,0,126976,SQL PROCEDURE BIGBLOBOUTX                         ,0,0,1,011714,144329,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,144329,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,021814,2, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,248,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLO00001,*PGM    ,CLE       ,0,126976,SQL PROCEDURE BIGBLOBOUT22                        ,0,0,1,011714,143919,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,143919,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,1, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,248,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLO00002,*PGM    ,CLE       ,0,126976,SQL PROCEDURE BIGBLOBOUT10                        ,0,0,1,011714,143948,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,143948,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,1, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,248,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLO00003,*PGM    ,CLE       ,0,118784,SQL PROCEDURE BIGBLOBOUT12                        ,0,0,1,011714,144020,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,144020,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,1, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,232,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLO00004,*PGM    ,CLE       ,0,118784,SQL PROCEDURE BIGBLOBOUT13                        ,0,0,1,011714,144049,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,144049,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,1, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,232,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLO00005,*PGM    ,CLE       ,0,118784,SQL PROCEDURE BIGBLOBOUT16                        ,0,0,1,011714,144103,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,144103,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,1, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,232,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 
1,072514,164203,EBERHARD  ,BIGLO00006,*PGM    ,CLE       ,0,118784,SQL PROCEDURE BIGBLOBOUT20                        ,0,0,1,011714,144134,EBERHARD  , ,      ,      ,          ,0,0,          ,      ,      ,      ,      ,      ,      ,      ,      ,      ,      , , ,      ,      ,999999,          ,          ,          , ,      ,      ,CRTPGM ,999999,        ,1,       ,      ,     ,      ,0,1,011714,144134,          ,          ,1,                 ,       ,Z1014P14,EBERHARD  ,Z1014P14,Y,1,011714,1, ,      ,*U,V7R2M0,V7R2M0,      ,N,0,1,0,          , ,      ,      ,*NONE     ,232,512,*NONE     ,0,0,0,          ,          , , , ,      ,      ,0,0,1,1,*SYSBAS   ,*SYSBAS   ,0,0,4096,1,*SYSBAS   ,*SYSBAS   ,          ,          ,          ,          , 

In this example, the last parameter of the QSYS.QCMDEXC call is the length of the first parameter. QSYS.QCMDEXC just calls the DSPBOJD command, which dumps the information about the object in the library to the QTEMP.OBJECT file. From there, we just query the file using a select statement to get the information.

jweberhard
  • 576
  • 3
  • 7