cancel
Showing results for 
Search instead for 
Did you mean: 

Upload File and Store it in R/3

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks for your reply..

Could you post the sample code which you have to store it R/3?, so that it will be very helpful for me. Do i need to conert the data into any other file format like Binary or Hex..

Thanks again..

BM

Former Member
0 Kudos

Can anyone help me on this?

BM

Message was edited by:

Bharathi M

Former Member
0 Kudos

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())

}

Former Member
0 Kudos

Can anyone tell me how to download the file from SAP and show it in webdynpro.

BM

Former Member
0 Kudos

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

Former Member
0 Kudos

I already solved it.Thanks for the help..

BM

Former Member
0 Kudos

Harumph

Woulda been courteous of you to post your solution before I wasted my time replying.

Kelly

Former Member
0 Kudos

Thanks for your time..I rewarded for your time...:)

BM

Former Member
0 Kudos

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

Answers (0)