cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting Agreements through Scripting

Former Member
0 Kudos

Hi Experts,

I would like to delete some agreements created for testing.

I would like to do it through scripting. What are the classes and methods that I need to use.

Can you please provide me some guidance.

Thanks

Krish

Accepted Solutions (0)

Answers (1)

Answers (1)

kushagra_agrawal
Active Participant
0 Kudos

Hi Krish,

You Cannot delete the Agreements once created in the System but what you can inactivate the agreements either by workbook or via script also.

But it would be easier to inactivate via workbook.

Prepare the workbook and import

If you want to write a script then you have to make an explicit script and in the script you have to make use of Query IAPI.

below link will guide you further:

http://scn.sap.com/community/sourcing/blog/2012/08/08/query-iapis--a-good-alternative-for-dbhandle

Hope it help!

Thanks,

Kushagra A

Former Member
0 Kudos

Hi Kushagra,

Thank You for your reply.

I have inactivated the agreements through workbook import already.

But I would like to delete them permanently through scripting.

Thanks

Krish

kushagra_agrawal
Active Participant
0 Kudos

Hi Krish,

Try below piece of code:

//ZERI_DELETING_MA
import com.sap.eso.api.contracts.ContractIBeanHomeIfc;
import com.sap.odp.api.ibean.IBeanHomeLocator;


 
  maHome=IBeanHomeLocator.lookup(session,ContractIBeanHomeIfc.sHOME_NAME);
 
  maBean=maHome.findByUniqueDocName("MA-2014-002003");
  maHome.upgradeToEdit(maBean);
  maHome.delete(maBean);

What I can suggest is:

1. Make a query which will fetch all the inactive MAs which you want to delete from the System

2. Make an explict called script and write the code as stated above.

3. Call the query in the explicit script, for this refer below blog:

http://scn.sap.com/community/sourcing/blog/2012/08/08/query-iapis--a-good-alternative-for-dbhandle

Let me know if you have any query.

Hope it will help you!

Regards,

Kushagra A

Former Member
0 Kudos

Hi Kushagra,

Thank You for your post.

I found that, we need to do the following changes before deleting any agreement.

1. set the expiration date to past.

2. set the retention date to past.

Then I wrote script for deletion.

Thanks

Krish

kushagra_agrawal
Active Participant
0 Kudos

Hi Krish,

It is working fine in my case. I did not set those fields to past date.

Below is the code:

//ZERI_DELETING_MA
import com.sap.eso.api.contracts.ContractIBeanHomeIfc;
import com.sap.odp.api.ibean.IBeanHomeLocator;
import com.sap.odp.api.comp.query.IapiQueryExecFactory;
import com.sap.odp.api.comp.query.IapiQueryExecIfc;
import com.sap.odp.api.comp.query.IapiQueryResultSetIfc;

void deleteMAs(maBean)

  maHome=IBeanHomeLocator.lookup(session,ContractIBeanHomeIfc.sHOME_NAME);

  maHome.upgradeToEdit(maBean);
  maHome.delete(maBean);
}

void processMAs()
{

queryExec=IapiQueryExecFactory.createQueryExec(session, "ZQUE_INACTIVE_MAs");
paramSet=queryExec.getParameterSet(session, "ZQUE_INACTIVE_MAs");
resultSet = queryExec.execute(new HashMap());
metaData = resultSet.getMetaData();
 
  while(resultSet.next())
   {
     maID=resultSet.getString(0);
     logMessage("maID:"+maID,0);
     maHome=IBeanHomeLocator.lookup(session,ContractIBeanHomeIfc.sHOME_NAME);
     maBean=maHome.findByUniqueDocName(maID);
     deleteMAs(maBean);
   }
 
}


/*    Main Script*/

processMAs();
 
  Hope it help!

Regrads,

Kushagra A