Search code examples
jt400jtopen

Need to get Object's creation date and time from AS400 in Java application


I am trying to get information about created date and time for a set of objects in AS400. I have created an outfile using DSPOBJD in AS400. Below is code snippet for getting information about one object. Now, after this i will have to open connection to AS400 and query the outfile to get creation date and time. I want to know of there is a better way of doing this.

String serverIP="XXX.XX.XXX.XX";
String userName="UserId";
String password="Password";

String commandString="DSPOBJD OBJ(ABCD) OBJTYPE(*PGM) OUTPUT(*OUTFILE)   
 OUTFILE(Library/FileName) OUTMBR(*FIRST *ADD)";
 AS400 as400=null;
 try
 {
    as400=new AS400(serverIP,userName,password);
    CommandCall command = new CommandCall(as400);
    System.out.println("Executing Command "+commandString);
    boolean success = command.run(commandString);
    if(success)
    {
        System.out.println("Executed Successfully");
    }
    else
    {
        System.out.println("Encountered Error");
    }
    AS400Message [] messageList=command.getMessageList();
    for(AS400Message message:messageList)
    {
        System.out.println(message.getText());
    }
    System.out.println("Deleting Object");
    Thread.sleep(10000);
    command.run("DLTOBJ OBJ(Library/FileName) OBJTYPE(*FILE)");
    System.out.println("Deleted...");
}
catch(Exception ex)
{
    ex.printStackTrace();
}
finally
{
    try
    {

        as400.disconnectAllServices();
    }    catch(Exception e)
    {System.out.println("Excpetion in closing connection: "); 
        e.printStackTrace();
    }}

Thanks in advance!!


Solution

  • I did something similar to get an Object's size.

                    AS400 as400 = new AS400(iseries, login, password);
                    ObjectDescription aFile = new ObjectDescription(as400, library, fileName, "FILE", iasp);
                    if (aFile.exists()) {
                        aFile.refresh();
                        aFile.getValue(ObjectDescription.CREATION_DATE);
                        aFile.getValue(ObjectDescription.OBJECT_SIZE);
                    }