Skip to Content

SAP CPS Delete export history

Hello,

We are on M33.120.

I am trying to delete export history older than 60 days. Can anyone please help me where I am doing wrong.

Is there any easier way to delete the export or import history without using the redwood script?

import java.util.Iterator;
import com.redwood.scheduler.api.model.Job;
import com.redwood.scheduler.api.model.SchedulerSession;
import com.redwood.scheduler.api.scripting.variables.ScriptSessionFactory;
import com.redwood.scheduler.api.date.DateTimeZone;
import com.redwood.scheduler.api.model.*;
import com.redwood.scheduler.api.model.enumeration.*;
import com.redwood.scheduler.api.model.Export;

{


SchedulerSession session = ScriptSessionFactory.getSession();

String strSql= "delete E.* from Export E where E.CreationTime < ?";
DateTimeZone now = new DateTimeZone();
now.add(-60, TimeUnit.Days);

Iterator it = jcsSession.executeObjectQuery(strSql, new Object [] {new Long(now.getUTCMilliSecs())});
while (it.hasNext())
{
Export E = (Export) it.next();
if (E.getDescription()!= null)
{


jcsOut.println(E.getDescription());

jcsSession.persist();

}

}

}

Below is the error message

Caused by: com.redwood.scheduler.persistence.api.PersistenceException$ParseException: JCS-123101: Unable to parse SQL: "delete E.* from Export E where E.CreationTime < ?"
at com.redwood.scheduler.persistence.impl.SqlCompiler.<init>(SqlCompiler.java:47)
at com.redwood.scheduler.persistence.impl.PreparedStatementContext.<init>(PreparedStatementContext.java:25)
at com.redwood.scheduler.persistence.impl.PreparedStatementImpl.preparePreparedStatementContext(PreparedStatementImpl.java:400)
at com.redwood.scheduler.persistence.impl.PreparedStatementImpl.executeQuery(PreparedStatementImpl.java:521)
at com.redwood.scheduler.persistence.spi.DatabaseHelper.executeQuery(DatabaseHelper.java:78)
... 23 more
Caused by: com.redwood.scheduler.persistence.sql.parser.ParseException: Encountered " "." ". "" at line 1, column 9.
Was expecting one of:
<EOF>
"WHERE" ...

at com.redwood.scheduler.persistence.sql.parser.RedwoodSQLParser.generateParseException(RedwoodSQLParser.java:3601)
at com.redwood.scheduler.persistence.sql.parser.RedwoodSQLParser.jj_consume_token(RedwoodSQLParser.java:3476)
at com.redwood.scheduler.persistence.sql.parser.RedwoodSQLParser.SQLStatement(RedwoodSQLParser.java:172)
at com.redwood.scheduler.persistence.sql.parser.RedwoodSQLParser.TopLevelSQLStatement(RedwoodSQLParser.java:93)
at com.redwood.scheduler.persistence.impl.SqlCompiler.<init>(SqlCompiler.java:43)

Regards,

Chandu

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 17 at 06:01 AM

    The code works if it is changed like below.

    String strSql= "select E.* from Export E where E.CreationTime < ?";
    DateTimeZone now = new DateTimeZone();
    now.add(-60, TimeUnit.Days);


    Iterator it = jcsSession.executeObjectQuery(strSql, new Object [] {new Long(now.getUTCMilliSecs())});
    while (it.hasNext())
    {
    Export E = (Export) it.next();
    if (E.getDescription()!= null)
    {


    jcsOut.println(E.getDescription());
    E.deleteObject();

    jcsSession.persist();

    }

    }

    Regards,

    Chandu

    Add comment
    10|10000 characters needed characters exceeded