on 06-14-2007 9:44 PM
All,
I want to upload the File from webdynpro to R/3. I want to store it in some Ztable. How can I do that. Can anyone help me. I already saw the upload/Download tutorial. Its not explaining how to read the uploaded file & stroe it in R/3.
Pls help me..
BM
BM,
I assume that by "tutorial", you mean "Uploading and Downloading Files in Web Dynpro Java" by Bertram Ganz. That tutorial contains a getFileSize() method that takes as input the IWDResource resource that is bound to the file upload control.
The IWDResource class has a read() method (arguably mis-named) that returns you a Java InputStream that you use to read the contents of the uploaded file. The tutorial just uses the InputStream to determine the size of the upload file. But there's much more you can do. See the javadoc for java.io.InputStream for the methods you can use.
Then you would, for example, have an RFC model class that would the take upload contents you read from the InputStream and insert them in an R/3 table.
In the application I'm working on the upload file is ftp'd to a server where it is picked up by XI and loaded into R/3.
Hope this helps,
Kelly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bharathi,
You can find my code below. I can upload file to R/3.
for (int k = 0; k <wdThis.wdGetContext().nodeRequisitionsTable().size(); k++)
{
IPublicNewPurchaseReqCust.IRequisitionsTableElement tn =wdThis.wdGetContext().nodeRequisitionsTable().getRequisitionsTableElementAt(k);
IPublicNewPurchaseReqCust.IFileUploadElement tableelement =wdThis.wdGetContext().nodeFileUpload().getFileUploadElementAt(k);
if(purgrptbl.getPurchaseGroup().equals(tableelement.getPurGroup()))
{
if (!(tn.getGr_Ind()))
{
if(tableelement.getFileSource()!=null)
{
IWDResource resource = tableelement.getFileSource();
Zbapi_Pr_Create_Attachment_Input inputattach = new Zbapi_Pr_Create_Attachment_Input();
wdContext.nodeZbapi_Pr_Create_Attachment_Input().bind(inputattach);
inputattach.setBanfn(wdContext.currentOutput_PRCreateElement().getNumber());
//file inputstream basla
Soli objhead1 = new Soli();
objhead1.setLine("&SO_FILENAME="+resource.getResourceName());
inputattach.addObjhead(objhead1);
Soli objhead2 = new Soli();
objhead2.setLine("&SO_FORMAT=BIN");
inputattach.addObjhead(objhead2);
final int chunkSize = 255;
final byte[] chunk = new byte[chunkSize];
try
{
final BufferedInputStream in
= new BufferedInputStream(tableelement.getFileSource().read(false));
int size = this.getFileSize2(resource);
while((size=in.read(chunk, 0, chunkSize))> 0)
{
// If last chunk is partial, pad rest with zeros
if ( size < chunkSize )
Arrays.fill( chunk, size, chunkSize, (byte) 0);
//create new list object
final Solix objbin = new Solix();
//write the byte array into the list
objbin.setLine(chunk);
//add list to input node for RFC
inputattach.addObjcont_Bin(objbin);
}
in.close();
}
catch (IOException e2)
{
e2.printStackTrace();
}
//file inputstream end
Sood1 headchange = new Sood1();
headchange.setObjla("TR");
headchange.setObjnam("Bildirim2");
int strleng=resource.getResourceName().length();
String Filename=resource.getResourceName().substring(0,strleng-4);
headchange.setObjdes(Filename);
headchange.setFile_Ext(resource.getResourceType().getFileExtension());
headchange.setObjlen(Integer.toString(this.getFileSize2(resource)));
inputattach.setObject_Hd_Change(headchange);
try
{
inputattach.execute();
} // END TRY
catch (WDDynamicRFCExecuteException ce)
{
IWDMessageManager manager = wdComponentAPI.getMessageManager();
manager.reportException(ce.getMessage(), false);
} // END CATCH
}//if(tableelement.getFileSource()!=null)
}//!(tn.getGr_Ind()))
}//purgrptbl.getPurchaseGroup().equals(tableelement.getPurGroup())
}
BM,
I hate to say "RTFM" but the "Uploading and Downloading Files in Web Dynpro Java" tutorial by Bertram Ganz is, IMHO, the best place to start. Please take a look at that and ask questions if you have any problems.
Basically you:
-Insert a Web Dynpro FileDownload control in a view.
-Bind its "resource" property to a context element of type com.sap.ide.webdynpro.uielementdefinitions.Resource
-Set the value of the context element to the resource you want to download when the user clicks the download link. The tutorial shows how to do this with an image that is loaded into the browser. In my app, I have a file that is created "on the fly". So I use code like:
downloadFile = new File (downloadFileString);
IWDResource resource = WDResourceFactory.createResource(
new FileInputStream (downloadFile),
downloadFile.getName(), WDWebResourceType.UNKNOWN, true);
wdContext.currentDownloadDataElement().setFileResource(resource);
You can specify the MIME data type so that the browser can display the resource or open the resource in the application associated with the MIME type you specify.
Hope this helps.
Regards,
Kelly
Hi Bharthi,
In our case also we are storing the content of the file in the table, can you please tell me what data element you are taken for the File content.
Because in our case we are taking data Element as so_raw255 but when we try to download the file it is giving error file is damaged.
Please do reply.
Thanks & Regards
Sandeep
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.