Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

How to upload attachments from Mobile Applications for Laptops


by Narayani©

The Backend Configurations, Create the Data Object on the same lines as mentioned in:

 https://www.sdn.sap.com/irj/scn/wiki?path=/display/mobile/Create+applications+using+Binary+Memo+and+Text+Memo+in+Netweaver+Mobile+7.1

Backend Configurations 

Step 1:  Create the following Backend Tables and Function modules

Order Header Table: The fields that represent the TEXT MEMO and the BINARY MEMO fields should not be STRING or RAWSTRING. These fields would be used as a flag to indicate that there is an attachment.

Order Attachment Table: table to be created in order to store the attachments -znk_ord_hattch1

*Domain:Fixed Values(Differentiate between Header Text and Binary Data)

ORDIMG  Order Image

HEDTXT Header Text

 Upload Attachment Function Module

 FUNCTION znk_order_upl_blob_upload.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(ORDERID) TYPE  ZNK_ORDER_HDR-ORDERID
*"     VALUE(E_ORDIMG) TYPE  ZNK_ORD_HATTCH1-ORDERIMG
*"     VALUE(E_HEADERTEXT) TYPE  ZNK_ORD_HATTCH1-HEADERTEXT
*"  TABLES
*"      RETURN STRUCTURE  BAPIRET2
*"----------------------------------------------------------------------

  DATA: wa_att TYPE znk_ord_hattch1,
        w_orderid TYPE znk_order_hdr-orderid.

  wa_att-headertext = e_headertext.
  wa_att-orderimg   = e_ordimg.
  wa_att-zfilename   = 'uploaded from client'.
  wa_att-attchtyp = 'ORDIMG'.
  wa_att-orderid    = orderid.
  wa_att-timestamp = sy-timlo.

  SELECT SINGLE orderid INTO w_orderid FROM
    znk_order_hdr WHERE orderid = orderid.

  IF sy-subrc = 0.
    MODIFY znk_ord_hattch1 FROM wa_att.
  ELSE.
    INSERT znk_ord_hattch1 FROM wa_att.
  ENDIF.

ENDFUNCTION.

II)   DOE Perspective

Create Data Object and add Node Attributes - UPL_BLOB and EXTENSION - Activate the Data Object

III) Create Backend Adapter.

No changes in the existing BAPI Wrappers

Only difference under the GET ATTACHMENTS section we need to put the function module that we created in the backend. (ZNK_ORDER_UPL_BLOB_UPLOAD). Please see the screenshot below.

There is no change in the mapping for the data object with the BAPI wrapper.

Now you also have to do a mapping for the Attachment function modules.


SAVE and Activate Backend Adapter.

Execute the initial download. As of now you will not see any attachments because we will be uploading from the client.

IV) Application Development

  1. Create Simple application:
  2. Add a FileUpload UI element and then assign Resource as the type. (Choose Browse => UIELementDefinitions)

  3. Now add code for Upload:

    For Browse:
     public void onActionUpload_Browse(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
      {
        //@@begin onActionUpload_Browse(ServerEvent)
      InputStream in = null;
      OutputStream out = null;
      try {  url = new URL("http:" + path);      in = url.openStream();       BLOB b = model.createBLOB();    
    wdContext.currentTESTATTACHMENT_ATTACH_ROOTElement().modelObject().setATTACHMENT(b);    
    wdContext.currentTESTATTACHMENT_ATTACH_ROOTElement().modelObject().setEXTENSION(resourcetype.toUpperCase());   
    out = b.setBinaryStream();    byte[] buf = new byte[Byte.MAX_VALUE];   
     int n;    while ((n = in.read(buf)) >= 0)    
     {     out.write(buf, 0, n);    }
    
    
      } catch (IOException e)  
    {    e.printStackTrace();   }  finally {
       if (in != null) {     try {      in.close();     }
    
    
    catch (IOException e)  
    {      e.printStackTrace();     }   }
       if (out != null) {     try {      out.close();     }
    
    
    catch (IOException e)  
    {     e.printStackTrace();    };}
       }
      }
      model.commit();
        //@@end
      }
    
    For Extension - Drop Down
    public void onActionOnSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
     
    {     //@@begin onActionOnSelect(ServerEvent)   
    orderid = wdContext.currentTESTATTACHMENT_ATTACH_ROOTElement().getORDERID();   
    orderid = "Order ".concat(orderid);   
    resourcetype = wdContext.currentUiResourceElement().getType().toUpperCase();   
    extension = WDWebResourceType.getWebResourceTypeForFileExtension(resourcetype);   
    resource =  WDResourceFactory.createResource(new byte[10], orderid, extension);   
    wdContext.currentUiResourceElement().setResource(resource);     //@@end   }
    

    //@@begin others
      Attach_model model = Attach_model.getInstance();
      String image;
      String str;
      IWDCachedWebResource res;
      IWDResource resource;
      String ext;
      byte[] b;
      String resourcetype;
      WDWebResourceType extension;
      String orderid;
     URL url;
     
      //@@end
    
  • No labels