cancel
Showing results for 
Search instead for 
Did you mean: 

Adapter module to check incomplete files

shweta_walaskar2
Contributor
0 Kudos

Hello ,

In continuation to the post :

Following the suggestion from Supriya,I am trying to develop an adapter module which should check if EOF("/file_end/") string is there and if it is not,it should go to the original status and start polling file again(Instead of picking file by calling CallSapAdapter module)

import com.sap.aii.af.mp.module.*;

import com.sap.aii.af.ra.ms.api.*;

import com.sap.aii.af.service.auditlog.*;

import com.sap.aii.af.ra.ms.api.XMLPayload;

import java.io.BufferedReader;

import javax.ejb.CreateException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import java.io.InputStreamReader;

//import com.sap.aii.af.ra.ms.api.*;

/**

  • @ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>

  • @ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>

  • @ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>

  • @ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>

  • @stateless

*/

public class HandleIncompleteFiles implements SessionBean, Module{

private SessionContext myContext;

public void ejbRemove() {

}

public void ejbActivate() {

}

public void ejbPassivate() {

}

public void setSessionContext(SessionContext context) {

myContext = context;

}

public void ejbCreate() throws CreateException {

}

public ModuleData process(ModuleContext moduleContext,

ModuleData inputModuleData)

throws ModuleException {

try

{

Message msg = (Message)inputModuleData.getPrincipalData();

AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(), AuditDirection.INBOUND);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Handle Incomplete Files: Module called");

XMLPayload xmlpayload = msg.getDocument();

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Handle Incomplete Files: Checking EOF ");

String retXMLData = null;

if(xmlpayload != null)

{

msg.setDocument(xmlpayload);

String line = null;

java.io.InputStream in = xmlpayload.getInputStream();

BufferedReader bufferInput = new BufferedReader(new InputStreamReader(in));

StringBuffer bufferOutput = new StringBuffer();

while((line = bufferInput.readLine()) != null)

bufferOutput.append(line);

retXMLData = bufferOutput.toString();

long t0,t1;

t0=System.currentTimeMillis();

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Handle Incomplete Files: Time0 "+t0);

if(retXMLData.indexOf("/file_end/")!= -1){

inputModuleData.setPrincipalData(msg);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Handle Incomplete Files: EOF found!");

}

else

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Handle Incomplete Files: NO EOF found!");

} else

{

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR, "Handle Incomplete Files: payload is null!");

}

}

catch(Exception ex)

{

Message msg1 = (Message)inputModuleData.getPrincipalData();

AuditMessageKey amk1 = new AuditMessageKey(msg1.getMessageId(), AuditDirection.INBOUND);

Audit.addAuditLogEntry(amk1, AuditLogStatus.ERROR, "Handle Incomplete Files: " + ex.getMessage());

}

return inputModuleData;

}

}

When I check this statement:

if(retXMLData.indexOf("/file_end/")!= -1){

inputModuleData.setPrincipalData(msg);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Handle Incomplete Files: EOF found!");

}

I should be able to redirect my communication channel either to start polling again,skipping the module sequence(if EOF string is not found) or follow the module sequence(pick the file if EOF string is found)

Can someone please help me how to achieve this?

Thanks a lot.

Best Regards,

Shweta

Accepted Solutions (1)

Accepted Solutions (1)

former_member207622
Contributor
0 Kudos

Hi Shweta ,

If you can create a pass through scenario just for taking that file from FTP and placing it on XI server using

recordset per message and quality of service exactly once in order . we can get the file on XI sever and then

following Gauravs Run operating command before processing we can search the EOF and pick file to destination.

http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm

try this if you are not done with adapter module .

Regards

Ninad

shweta_walaskar2
Contributor
0 Kudos

Hello Ninad,

In this case,XI will pick incomplete file and place it on XI server.

After this,script wouldn't help to process incomplete file.Let me know if I have understood it correctly.

Thanks.

Regards,

Shweta

former_member207622
Contributor
0 Kudos

Hi Shweta ,

Your point is write , but what I feel is why the adapter will pick incomplete file ? I mean forget this scenario take a simple scenario say normal file to Idoc and into it file gets picked as soon as its placed even if its on ftp with no errors

Of course I am junior to you, and if you can guide me , i m guessing why incomplete files and dint find any reason .

Do you have any possibility of sender sending acknowlegement files after this file is wriiten .?

We can think on that front as well , if client is ready .

Regards

Ninad

shweta_walaskar2
Contributor
0 Kudos

Hi Ninad,

Nothing like that,we all are learning.

Yes,in normal cases,there are no problems of incomplete file processing.

In this case,XI has to pick a file from R/3 server,this file is written by an ABAP report which might take 10 minutes and will keep on appending records for the same file.

In this duration,XI can pick this file as there are no locks and we can have problems if such incomplete files are processed.

There are two cases,one when this report is scheduled and the process is automated,here,they have a logic to create a file with temp name and rename it once complete.So,we don't have any problem.

There would be some cases when users would execute this report manually.In this case,rename and move cannot be done ,because users don't have OS rights.We have problems in this case.

I am able to achieve checking of EOF in both ways,using Java mapping and Adapter module,but the only thing,I could do is ,to set mapping to failed ,so that incomplete file shouldn't be processed.An acknowledgement would do the same.

But,in both cases,I am not able to stop Adapter to pick the file and hence file is lost.

In Java Mapping,this is anyway not possible,because it will be called only when file is picked.

In adapter module ,I am able to check EOF but I don't know how to exit and force Adapter to start polling again when no EOF is found.

What I can see in Audit log is,status Error is set in Audit log,when no EOF is found,still Module sequence is executed,CallSapAdapter is called and file is picked.

If I force adapter to wait until EOF is found,it creates a deadlock,no file is picked even if the same file is updated ,this is not picked which is quite risky.

Hence,I need to know something like return to original polling if no EOF is found instead of following Module sequence and pick the file.

Hope,the problem is a bit clarified now.

Thanks.

Regards,

Shweta

Answers (2)

Answers (2)

shweta_walaskar2
Contributor
0 Kudos

Finally,we had to go for an option to use Java mapping to check this string at the end and set message status to fail when its not found.

Former Member
0 Kudos

Hi Shweta,

I am currently looking for the same information, how to stop the processing within an adapter module if some conditions are not meet.

I foud some information regarding special parameter in supplementData section Modules in Message Exchange - SAP NetWeaver Process Integration - SAP Library but was not able to get it work by setting within my module


inputModuleData.setSupplementalData("mp.skip", Boolean.TRUE);

maybe the standard CallSapAdapter doesn't check this parameter.

unfortunately in my case java mapping is not a option.

Maybe someone used "mp.skip" already.

Best regards

Jochen

Former Member
0 Kudos

Hi,

As Ninad pointed out, an incomplete file scenario is very very rare.

Because, if an ABAP Program is already writing to a file, it woul be locked. It is an OS principle.

In that case the Adapter will not be able to pick this file.

I suppose u can try this,

Keep the file in the destined location and start renaming it. In thiis way, you have locked the file.

Now, before you finish renaming the file, activate the communication channel so that it starts polling.

You will see that the adapter shall not be able to pick the file.

Complete the renaming and the adapter will pick up the file in next polling cycle.

Regards,

Alka.