Skip to Content
avatar image
Former Member

How to upload a file via ABAP RFC with Webdynpro ?

Hi everyone,

I have the follwing problem.

I`m currently creating a webdynpro DC to upload files to a mySAP CRM system via RFC.

The RF-module is already available at the backend side and I have imported it as a model. The ABAP module interface looks like this:

*"  IMPORTING
*"     VALUE(IV_CASE_GUID) TYPE  SCMG_CASE_GUID
*"     VALUE(IV_FILENAME) TYPE  SDOK_PROPV DEFAULT 'Case Document'
*"     VALUE(IV_MODELNODE) TYPE  STRINGVAL DEFAULT '19'
*"     VALUE(IV_FILE_CONTENT_BINARY) TYPE  SDOKCNTBINS OPTIONAL
*"  EXPORTING
*"     VALUE(EV_MESSAGE) TYPE  BAPI_MSG
*"  EXCEPTIONS
*"      UPLOAD_FAILED

The parameter IV_FILE_CONTENT_BINARY of TYPE SDOKCNTBINS is imported into the webdynpro model as input structure ( 0..n cardinality and of collectiontype list) with one child attribute (line) which can be fed with a byte array (data type RAW with length 1022 on ABAP side).

I`m not really familiar with ABAP. To my understanding the structure IV_FILE_CONTENT_BINARY takes lines of byte arrays and that list of arrays will be uploaded with the RFC, right?

Now in my Webdynpro view I implemented the standard FileUpload UI element from which I got a IWDResource object.

Reading the IWD Resource object I got a inputStream from the file I`d like to upload.

Now my question is: how to get the IV_FILE_CONTENT_BINARY list filled with the inputStream?

I at least figured out that reading a byte array and put it into the structure would pretty much look like the follwing:


//create new list object
Sdokcntbin bin = new Sdokcntbin();

//create a temporary byte array with length of the line to be inserted into the list.
byte[] b = new byte[bin.getLine().length]; 

**read the inputStream into the byte array**
inputStream.read(b); ???

//write the byte array into the list
bin.setLine(b);

//add list to input node for RFC
ModelNode.addIv_File_Content_Binary(bin);

Do I need to create a loop to read the file binary as byte array segments of length 1022 each or am I wrong here totally?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 24, 2005 at 09:15 AM

    Xiaopeng,

    Yes, you have to read input stream by 1022 bytes chunk, and create Sdokcntbin per chunk.

    Something like this:

    final int chunkSize = 1022;
    final byte[] chunk = new byte[chunkSize];
    final BufferedInputStream in 
      = new BufferedInputStream(resource.getInputStream());
    try
    {
      int size = -1;
      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, 0);
    
        //create new list object
        final Sdokcntbin bin = new Sdokcntbin();
        //write the byte array into the list
        bin.setLine(chunk);
        //add list to input node for RFC
        <ModelObject>_Input.addIv_File_Content_Binary(bin);
      }
    }
    finally
    {
      in.close();
    }

    Valery Silaev

    EPAM Systems

    http://www.NetWeaverTeam.com

    Message was edited by: Valery Silaev

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi guys,

      >

      > I came accross that code that seems really usefull in my case.

      > However I still have one issue as i'm working on NW04 and don't have Resource type (only available since NW04S).

      > So i end up by trying with a binary type. And so I have a byte array that I use like this

      >

      > final BufferedInputStream in  = new BufferedInputStream(new ByteArrayInputStream(wdContext.currentContextElement().getFileContent()));
      > 

      >

      > Is it the right way to work?

      > Or is there another (better) way to deal with my issue?

      >

      > Thanks for any input or help!

      >

      >

      > Thomas

      Take a look at this upload tutorial for NW04

      http://www.sdn.sap.com/irj/sdn/nw-wdjava?rid=/webcontent/uuid/503f22f6-b978-2a10-bf97-ddc21267e752#41

  • avatar image
    Former Member
    Mar 20, 2007 at 12:48 PM

    Xiaopeng Tan

    I also got a similar requirement. Please let me know the SAP-RFC function module used.

    Thanks,

    Varma

    Add comment
    10|10000 characters needed characters exceeded