Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
SiddharthaR
Advisor
Advisor
Uploading Large Object and media such as Excel or Image through your application is a common business requirement and the only way to do it through a RAP application was by extending the application and using UI5 tooling to upload the file.

With the latest SAP BTP ABAP 2208 release the RAP framework now supports OData streams. It is now possible to enable your RAP application to maintain and handle Large Objects(LOBs).This feature provides end users an option to upload external files of different file formats such as PDF, XLSX , binary file format and other types hence allowing media handling.

In this Blog we will explore how to upload and handle Large Object such as PDF or Binary files without the need to extend the RAP application in BAS.

Large objects are modeled by means of the following fields:

  • Attachment

  • Mimetype

  • Filename


The field Attachment contains the LOB itself in a RAWSTRING format and is technically bound to the field Mimetype and Filename using semantics annotation.

Mimetype represents the content type of the attachment uploaded and the values for the fields Mimetype and Filename are derived from the field Attachment by the RAP framework based on the maintained CDS annotations. No attachment can exist without its mimetype and vice versa.

For example, when a PDF is uploaded the Mimetype field will be derived and populated with ‘APPLICATION/PDF’.


PDF File Uploaded from RAP application


 

To try this feature out I have built a simple RAP application to upload files directly using RAP Framework.

Database Table 

A Database table was built as per code snippet below.

The field attachment has a data type of RAWSTRING. In BTP ABAP environment you cannot use RAWSTRING domain directly so create a custom domain with data type as RAWSTRING and Length as '0' . This is important as length being '0' would indicate that the RAWSTRING has No length restriction and can accommodate file of larger size. ZMIMETYPE and ZFILENAME are both of type Character and length 128.
@EndUserText.label : 'Invoice Table'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zinvoicetable {
key client : abap.clnt not null;
key invoice : ebeln not null;
comments : char30;
attachment : zattachment;
mimetype : zmimetype;
filename : zfilename;
local_created_by : abp_creation_user;
local_created_at : abp_creation_tstmpl;
local_last_changed_by : abp_locinst_lastchange_user;
local_last_changed_at : abp_locinst_lastchange_tstmpl;
last_changed_at : abp_lastchange_tstmpl;

}

 

Interface View 

CDS annotation @Semantics.largeObject technically binds the MimeType and Filename to the Attachment.

The annotation contentDispositionPreference can be used to define whether, depending on the browser settings, the file attachment is either displayed in the browser (setting #INLINE) or downloaded when selected (option #ATTACHMENT).

Annotation @Semantics.largeObject.acceptableMimeTypes can be used to restrict the Media types which can be uploaded. The validation and Error handling on upload of unsupported media type is handled by the RAP framework.

CDS annotation @Semantics.mimeType: true was used to define the field MimeType as such.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Invoice Table'
define root view entity ZI_INVOICETABLE
as select from zinvoicetable
{
key invoice as Invoice,
comments as Comments,
@Semantics.largeObject:
{ mimeType: 'MimeType',
fileName: 'Filename',
contentDispositionPreference: #INLINE }
attachment as Attachment,
@Semantics.mimeType: true
mimetype as MimeType,
filename as Filename,
@Semantics.user.createdBy: true
local_created_by as LocalCreatedBy,
@Semantics.systemDateTime.createdAt: true
local_created_at as LocalCreatedAt,
@Semantics.user.lastChangedBy: true
local_last_changed_by as LocalLastChangedBy,
//local ETag field --> OData ETag
@Semantics.systemDateTime.localInstanceLastChangedAt: true
local_last_changed_at as LocalLastChangedAt,

//total ETag field
@Semantics.systemDateTime.lastChangedAt: true
last_changed_at as LastChangedAt
}

 

Consumption View 
@EndUserText.label: 'Invvoice Table'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
define root view entity ZC_INVOICE_TABLE
provider contract transactional_query
as projection on ZI_INVOICETABLE
{
key Invoice,
Comments,
Attachment,
MimeType,
Filename,
LocalLastChangedAt
}

 

Metadata Extension

From an UI perspective the User only needs to interact with the Attachment and hence Mimetype and Filename is hidden.
@Metadata.layer: #CORE
@UI: { headerInfo: {
typeName: 'Invoice',
typeNamePlural: 'Invoices',
title: { type: #STANDARD, value: 'Invoice' },
description: { type: #STANDARD, value: 'Invoice' } },
presentationVariant: [{
sortOrder: [{ by: 'Invoice', direction: #ASC }],
visualizations: [{type: #AS_LINEITEM}] }] }
annotate entity ZC_INVOICE_TABLE with
{
@UI.facet: [ {
label: 'General Information',
id: 'GeneralInfo',
type: #COLLECTION,
position: 10
},
{ id: 'Invoicedet',
purpose: #STANDARD,
type: #IDENTIFICATION_REFERENCE,
label: 'Invoice Details',
parentId: 'GeneralInfo',
position: 10 },
{
id: 'Upload',
purpose: #STANDARD,
type: #FIELDGROUP_REFERENCE,
parentId: 'GeneralInfo',
label: 'Upload Invoice',
position: 20,
targetQualifier: 'Upload'
} ]

@UI: { lineItem: [ { position: 10, importance: #HIGH , label: 'Invoice Number'} ] ,
identification: [ { position: 10 , label: 'Invoice Number' } ] }
Invoice;
@UI: { lineItem: [ { position: 20, importance: #HIGH , label: 'Comments'} ] ,
identification: [ { position: 20 , label: 'Comments' } ] }
Comments;
@UI:
{ fieldGroup: [ { position: 50, qualifier: 'Upload' , label: 'Attachment'} ]}
Attachment;

@UI.hidden: true
MimeType;

@UI.hidden: true
Filename;

}

 

I have created a managed Behavior definition with Draft and Created a Service definition and Service binding to expose this as a V4 UI .
managed implementation in class zbp_i_invoicetable unique;
strict ( 2 );
with draft;

define behavior for ZI_INVOICETABLE alias Invoice
persistent table ZINVOICETABLE
draft table zinvoicetdraft
lock master
total etag LocalLastChangedAt
authorization master ( instance )
etag master LastChangedAt
{

// administrative fields: read only
field ( readonly ) LastChangedAt, LocalLastChangedBy, LocalLastChangedAt , LocalCreatedBy ,
LocalCreatedAt;

create;
update;
delete;

draft action Edit ;
draft action Activate;
draft action Discard;
draft action Resume;

draft determine action Prepare ;
}

 

Once the OData is published through service binding , we can preview the application.


List Page


 

You can click on create to Create a new Instance.


Object page With Upload Option


 

On "Upload File" the File Open Dialog comes up to select the file from Presentation Server .


File Selection Dialog


 

Once the File is uploaded the Hyperlink can be used to access the file and based on annotation  contentDispositionPreference the file would either open in a new window or downloaded when selected.

 


After File Upload


 

Once the Instance is saved we can see the new file encoded in RAWSTRING format along with its Mimetype and Name saved in the database.


Database table after Upload


 

In Conclusion, with the Support of OData streams , we can now handle LOBs directly using RAP framework, this really caters to a lot of missing features for which  extensions were needed before. The above application is a very simple example of how this feature can be used.

I am looking forward to explore this more and see how this can be integrated with other solutions such as Content Server and Adobe form.

Please let me know what you think of the this new feature and your feedback is appreciated.

Please refer to the below link for more details.

https://help.sap.com/docs/BTP/923180ddb98240829d935862025004d6/10a3eb645b83413cbbebe4fc1d879a62.html
33 Comments
saumya_das
Explorer
0 Kudos
Great blog post, got to learn something new. Indeed, a very useful feature introduced by SAP considering this to be a very common requirement for business.
Ramjee_korada
Active Contributor
0 Kudos
Thanks Siddarth for sharing.

It looks there are many limitations. Better SAP could document them so that we can plan accordingly.

I mentioned few in the blog post . If you notice further issue, please let me know.

 

Best wishes,

Ramjee Korada
SiddharthaR
Advisor
Advisor
0 Kudos

Hi Ramjee,

Thank you for taking time going through my blog .

I went through your comment in Florian's blog about the limitations and did some small POC's to replicate the same in my system, below are my observations. I am discussing them in this blog as this is more specific to the RAP Stream.

1. Uploading of attachment is possible only in object page of the entity but not possible in table view.

I think the Document can be uploaded both from object page as well as from table view and there is no such restriction to limit the upload from Object page only. I do understand that your expectation was on "Create" instead of routing you to the object page it would open the File Selection Dialog. I don't think that will ever be the case as "Create" is a standard action and will always create the instance associated to it. Once the instance is created the File can be uploaded from both the object page and Table view.

In that regard I do understand that the behavior is a bit different from how we do it in the traditional UI5 world and the UX experience might not be that great .

PFB screenshot where I am uploading/Updating the document from table view itself, but i had to create the instance first using "Create" Action.

Upload From table View

File open Dialog

After Upload

 

2. Also, only one attachment can be there in a single entity. Else, App will run into error.

I don't think this is particularly correct . You can have multiple attachments within one entity and there is no such restriction as to allow only one attachment. The only thing we have to keep in mind is the Attachment, MimeType and Filename fields are unique for different attachments.

As I mentioned in my blog Attachment and MimeType are technically related and hence you need to have separate Mimetype and Filename field for each attachment .

PFB Screenshot where we can see two attachment within a single entity, I have just extended my table and views to have fields to accommodate the additional attachment .

Multiple Attachment within single Entity

 

Ramjee_korada
Active Contributor
0 Kudos
Hi Siddartha,

Thanks to you too for taking time.

Appreciate your comments. I hope you have tried in OData v4 but I was trying in OData v2 version.

#1. However I do understand your explanation on "Create' standard action that creates instance but not attachment. However those attachments were not visible in the table in OData v2 to update/replace. But visible in OData V4.

#2. In OData v2, metadata itself was dumping with reason that it has multiple attachments in an entity. it worked in v4 same as your attempt.

Can I request you try both the points in OData V2 and give me feedback ?

Did you get a chance to look at point #3 ( Non-Draft ) as well ?

Best wishes,

Ramjee Korada

 
SiddharthaR
Advisor
Advisor
0 Kudos

I still need to check point 3 , I am currently facing some issue while publishing a V2 OData in my BTP ABAP environment. I am guessing its related to the recent release and need to check with my colleagues here.
I will provide an update here Once I am able to do that.

Ramjee_korada
Active Contributor
0 Kudos
Yes. Issue seems related to recent release .

 

We have a workaround here . You can expose the projection behavior in any existing service definition whose binding is implemented as OData V2 already.

 

Then refresh the service binding and navigate to the newly generated node or entity to preview Fiori app
seshu_yaramala
Explorer
0 Kudos
Hello Siddarth, thanks for the blog. I tried this example on an S4 Hana 2021 on-premise system but didn't work. Does it only work cloud?
shailesh1992
Explorer
0 Kudos
Dear siddhartha_routh ,

 

Thank you for the blog.

We tried the exact same steps, but in the end we did not get the Create, Delete and Upload attachment button in our UI.

What could be the reason for this?

Thank You in advance.


BR,
Shailesh Yadav
sainithesh21
Active Participant
Hi siddhartha_routh,

Thanks for you blog, I have followed the steps provided and gone through the referred help link. I am facing below.

Please help me on this and let me if I miss anything.
{"error":{"code":"/IWBEP/CM_V4_MED/393","message":"Content-Disposition for non-stream property 'ATTACHMENT' is not allowed","@SAP__common.ExceptionCategory":"Metadata_Error","innererror":{"ErrorDetails":{"@SAP__common.Application":{"ServiceRepository":"SRVD","ServiceId":"ZUI_INVOICETABLE","ServiceVersion":"0001"},"@SAP__common.TransactionId":"6B9DA8E90C730240E0063492664CEA48","@SAP__common.Timestamp":"20221014142517.661012","@SAP__common.ErrorResolution":{"Analysis":"Use ADT feed reader \"SAP Gateway Error Log\" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details","Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"}}}}}

 

Regards,

Sainithesh Gajula
sainithesh21
Active Participant
0 Kudos
Hi shailesh1992,

I have also faced the same issue in the begging. Later I understood that we also need to create Behavior Definition for the project view.

Regards,

Sai Nithesh Gajula
shareef_shaik
Explorer
Hi siddhartha_routh,

 

Nice blog.

is it possible to read attached document and process data then fill into Internal Table(Just like GUI_UPLOAD) in RAP or ABAP for Cloud ?


Thank You.

 

Best Regards,

Shareef Shaik
sandhyad
Member
0 Kudos
Hi Siddhartha,

 

Very nice blog!!

 

I'm trying to upload attachments in object page using composition[1..*] but getting entity set " not found error. This error occurs when I navigate from parent to child and then try to upload the attachments.

Attachments functionality works absolutely fine, If I load the child node directly and upload the attachments.

 

System Details:

S4HANA ON PREMISE - 2021 02 (05/2022) - SAP S/4HANA 2021

 

Regards,

Sandhya
0 Kudos
Hi Siddarth,

Thanks for your sharing, I follow your instruction and create a new attachment entity to be a composition child of my root entity, and the behavior of my root entity is unmanaged.

But I always encounter the error: Method 'CREATE_STREAM' not implemented in data provider class, when I want to create a new instance in Preview.

The error is coming from Gateway DPC, do you have any clue why does this happen?
issabella_martin1995
Participant
0 Kudos
Hi ramjee.korada ,

It also seems we cannot use large objects in Custom Entities (Unmanaged Query).
matiasmiano1982
Explorer
0 Kudos
Great post!!

One simple question, do you have the example of showing the form from database?

Regards
amillanm
Explorer
0 Kudos
Hi,

 

I'm also following this performand, could you developed and tested this solution?

 

Thanks for your time.

Best Regards.
ravi_rajput
Participant
0 Kudos
Great information ! If you can share the sreenshots of domains of all three custom fields. It would be easier for us to try it out.

Thanks !
MKM
Active Participant
Did you manage to get it sorted out later?
mukeshjadhav08
Explorer
0 Kudos

Hi Yunhao,

I did get the same error, when I tried it with OData V2 then I tried with OData V4 and there was no error.

 

Thanks,

Mukesh

mukeshjadhav08
Explorer
0 Kudos
Hi siddhartha_routh

Great blog, I was wondering if you got a chance to explore integration with content server ?

Thanks,

Mukesh
fischerm
Explorer
0 Kudos
Hi Siddhartha,

is it also possible to make a drag & drop field out of it? If yes, do you know how?

Kind regards

Markus
fischerm
Explorer
0 Kudos
Hi siddhartha_routh

How can I make a drag & drop field out of it?

Kind regards

Markus
ashutosh9112
Newcomer
0 Kudos


Anyone have any solution of this problem : The file is too big. The maximum size allowed is 0.000 MB.

termanico
Participant
0 Kudos
We get exactly the same error with S/4HANA on prem 2022 SP02 😞

Any update on this SaiNithesh?

br

Thorsten
archana_a2
Participant
Hello All,

We have a requirement where we need to upload an excel on click of a button using Fiori elements. Here we upload an attachment using the concept of Handling large objects(LOB) in RAP which has a limitations of doing it in object page but is there any concept of uploading a file on click of a button in fiori elements without using UI5. In the attached blog they have achieved it using UI5, but is there any concept similar to LOB in RAP by which we can achieve it?

https://blogs.sap.com/2022/01/27/excel-upload-using-rap-part-2/


 

Thanks a lot in advance for the support!

Regards,

Archana A
suzanne_alivand
Explorer
0 Kudos
Hi Seshu, I had the same issue, for my part the problem was using OData V2. are you using V2 or V4? I do not think it’s an issue with on-Premise system. Use V4 instead of V2 ? and let me know if it works
jostkroeger
Member
0 Kudos
Hello All,

I have replicated the service 1:1 in our system, however, I get the following error message in the ODATA V4 service:


Does anyone have any idea how I can fix this one?
amo_ry
Explorer
0 Kudos
HI ,

When i try this way with ODATA V4 on (S4Hana system) , it not allow me to upload any attachment and by default there is an empty attachment when i click on create button .

it works for me on the cloud but i want to solve this issue in the S4hana system .

can any one help me ?

 
amo_ry
Explorer
0 Kudos
this is the case :

0 Kudos

Hello everyone,

If you're encountering the error "The file is too big. The maximum size allowed is 0.000 MB.", the solution is simple. Check the size of the field (attachment content) in your table. That size will be the maximum file size allowed.

For example: I tested it here with a file up to 265 characters, and the upload worked. If I add just one more character, it starts to give an error.

vinicius_cesar_dias_0-1709480621542.png

Simply increase this size to solve the problem, or set it to zero for "unlimited".

vinicius_cesar_dias_1-1709480715848.png

I tested today (March 3, 2024) in the SAP BTP Trial environment, using both OData V2 and V4. The only difference is that in V2, instead of displaying a popup warning of the error, it resulted in a DUMP.

@ashutosh9112 @termanico 

Jacky_Liu
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi, Siddhartha,

 

What is your progress in using SDM ?

As I know, if we store the uploaded file in database like Hana, there will be size limit for the uploaded file . That is why we need to use BTP SDM to store the uploaded file .  But if we use SDM, the file selector is not in RAP like function GUI_UPLOAD  in classic abap . So we have to use function in Behavior , but function can only be used as read only and we can not save sdm file object ID in instance . Do you have any idea to handle this ?

 

Best regards!

 

Jacky Liu 

 

amo_ry
Explorer
0 Kudos

it cannot upload attach with arabic name 

"File upload failed: Failed to execute 'setRequestHeader' String contains non ISO-8859-1 code point"

rakshithshetty
Associate
Associate
0 Kudos

Hi @SiddharthaR ,

Great Blog!

However, I am not getting an option to upload the documents at list page. Is there any UI annotations that is must for attachment field to appear in the list page?.
I am getting the following error in console whenever the attachment field is added to the list page:

rakshithshetty_0-1713307078841.png

Thanks,