File upload for items in Fiori Elements List Report

Estimated read time 8 min read

1. Introduction

In this blog, we’ll show you how to upload, browse, and delete files on a row-by-line basis by having each row (item) have an item like an “attachment” in the SAP Fiori Elements List Report.
The data source for the List Report covers OData V4 services developed using the ABAP RESTful Application Programming Model (RAP) framework, and provides information about the implementation required to achieve file upload in RAP development.

 

2. Key points for implementing file upload

In the file upload implementation, two points are required: (1) define the table items required for file storage, and (2) provide appropriate annotations for file object storage fields and file type storage fields.

Defining the table items required to store files

Set the following three fields in the custom table (the field names are samples).

File object storage field (abap.rawstring(0) if file size is not specified)example:attachment: abap.rawstring(0);Field for file nameexample:filename: abap.char(128);Field for file Typeexample:mimetype: abap.char(128);Proper Annotation of File Object and File Type Fields in CDS ViewFile object storage fieldexample:@Semantics.largeObject : {
mimeType: ‘Mimetype’,
fileName: ‘Filename’,
contentDispositionPreference: #INLINE
}​Field for file Type@Semantics.mimeType: true

3. Implementation sample

In this blog, we will use the RAP Generator to simplify RAP development. RAP Generator is a tool that allows you to generate RAP objects such as CDS View and Behavior Definition from custom tables using only wizard settings. When using the RAP Generator to generate a RAP object, a service is generated that supports the Managed Runtime with a draft function. Therefore, the table definition must define the required fields for drafting functions and update processing. For more information about RAP Generator, please check the following SAP Help.

Generating a RAP Business Service with the Generate ABAP Repository Objects Wizards

This blog is an example implementation based on the SAP Help: Example: OData UI Service Generation Based on a Database Table

 

1. Create a package to store objects by the RAP Generator.

2. Create a custom table inside the package you created in 1.


 

@EndUserText.label : ‘Custom Table for file upload test’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zpt_file_upload {

key client : abap.clnt not null;
key customer_id : /dmo/customer_id not null;
first_name : /dmo/first_name;
last_name : /dmo/last_name;
title : /dmo/title;
street : /dmo/street;
postal_code : /dmo/postal_code;
city : /dmo/city;
country_code : land1;
phone_number : /dmo/phone_number;
email_address : /dmo/email_address;
attachment : abap.rawstring(0);
filename : abap.char(128);
mimetype : abap.char(128);
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;

}​

 

3. Run the RAP Generator and follow the wizard to configure it.

Right-click on the target custom table → run it with “Generate ABAP Repository Objects…”

 

 

Selecting a Service Type

 

 

Selecting a package for storing generated objects

 

 

Review the generated object and rename or alias it as needed


 

4. Add annotations for file upload to the generated data model (CDS View) and enable the CDS View.

@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: ‘##GENERATED ZPT_FILE_UPLOAD’
define root view entity ZR_PT_FILE_UPLOAD
as select from zpt_file_upload
{
key customer_id as CustomerID,
first_name as FirstName,
last_name as LastName,
title as Title,
street as Street,
postal_code as PostalCode,
city as City,
country_code as CountryCode,
phone_number as PhoneNumber,
email_address as EmailAddress,
@Semantics.largeObject : {
mimeType: ‘Mimetype’,
fileName: ‘Filename’,
contentDispositionPreference: #INLINE
}
attachment as Attachment,
filename as Filename,
@Semantics.mimeType: true
mimetype as Mimetype,
@Semantics.user.createdBy: true
local_created_by as LocalCreatedBy,
@Semantics.systemDateTime.createdAt: true
local_created_at as LocalCreatedAt,
@Semantics.user.localInstanceLastChangedBy: true
local_last_changed_by as LocalLastChangedBy,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
local_last_changed_at as LocalLastChangedAt,
@Semantics.systemDateTime.lastChangedAt: true
last_changed_at as LastChangedAt

}

5. Publish the service binding.

 

6. Select the entity and preview it.

 

7. From the “Create” button, perform data registration and file upload.







 

4. Summary

By implementing the above, using the OData V4 service using the ABAP RESTful Application Programming Model (RAP), you can use the “Attachment” for each row (item) in the SAP Fiori Elements List Report. It is possible to upload, read, and delete files on a line-by-line basis. Please take advantage of it.

 

References

SAPUI5 Document: Enabling Stream Support

 

​ 1. IntroductionIn this blog, we’ll show you how to upload, browse, and delete files on a row-by-line basis by having each row (item) have an item like an “attachment” in the SAP Fiori Elements List Report.The data source for the List Report covers OData V4 services developed using the ABAP RESTful Application Programming Model (RAP) framework, and provides information about the implementation required to achieve file upload in RAP development. 2. Key points for implementing file uploadIn the file upload implementation, two points are required: (1) define the table items required for file storage, and (2) provide appropriate annotations for file object storage fields and file type storage fields.Defining the table items required to store filesSet the following three fields in the custom table (the field names are samples).File object storage field (abap.rawstring(0) if file size is not specified)example:attachment: abap.rawstring(0);Field for file nameexample:filename: abap.char(128);Field for file Typeexample:mimetype: abap.char(128);Proper Annotation of File Object and File Type Fields in CDS ViewFile object storage fieldexample:@Semantics.largeObject : {
mimeType: ‘Mimetype’,
fileName: ‘Filename’,
contentDispositionPreference: #INLINE
}​Field for file Type@Semantics.mimeType: true3. Implementation sampleIn this blog, we will use the RAP Generator to simplify RAP development. RAP Generator is a tool that allows you to generate RAP objects such as CDS View and Behavior Definition from custom tables using only wizard settings. When using the RAP Generator to generate a RAP object, a service is generated that supports the Managed Runtime with a draft function. Therefore, the table definition must define the required fields for drafting functions and update processing. For more information about RAP Generator, please check the following SAP Help.Generating a RAP Business Service with the Generate ABAP Repository Objects WizardsThis blog is an example implementation based on the SAP Help: Example: OData UI Service Generation Based on a Database Table 1. Create a package to store objects by the RAP Generator.2. Create a custom table inside the package you created in 1. @EndUserText.label : ‘Custom Table for file upload test’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zpt_file_upload {

key client : abap.clnt not null;
key customer_id : /dmo/customer_id not null;
first_name : /dmo/first_name;
last_name : /dmo/last_name;
title : /dmo/title;
street : /dmo/street;
postal_code : /dmo/postal_code;
city : /dmo/city;
country_code : land1;
phone_number : /dmo/phone_number;
email_address : /dmo/email_address;
attachment : abap.rawstring(0);
filename : abap.char(128);
mimetype : abap.char(128);
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;

}​ 3. Run the RAP Generator and follow the wizard to configure it.Right-click on the target custom table → run it with “Generate ABAP Repository Objects…”  Selecting a Service Type  Selecting a package for storing generated objects  Review the generated object and rename or alias it as needed 4. Add annotations for file upload to the generated data model (CDS View) and enable the CDS View.@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: ‘##GENERATED ZPT_FILE_UPLOAD’
define root view entity ZR_PT_FILE_UPLOAD
as select from zpt_file_upload
{
key customer_id as CustomerID,
first_name as FirstName,
last_name as LastName,
title as Title,
street as Street,
postal_code as PostalCode,
city as City,
country_code as CountryCode,
phone_number as PhoneNumber,
email_address as EmailAddress,
@Semantics.largeObject : {
mimeType: ‘Mimetype’,
fileName: ‘Filename’,
contentDispositionPreference: #INLINE
}
attachment as Attachment,
filename as Filename,
@Semantics.mimeType: true
mimetype as Mimetype,
@Semantics.user.createdBy: true
local_created_by as LocalCreatedBy,
@Semantics.systemDateTime.createdAt: true
local_created_at as LocalCreatedAt,
@Semantics.user.localInstanceLastChangedBy: true
local_last_changed_by as LocalLastChangedBy,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
local_last_changed_at as LocalLastChangedAt,
@Semantics.systemDateTime.lastChangedAt: true
last_changed_at as LastChangedAt

}5. Publish the service binding. 6. Select the entity and preview it. 7. From the “Create” button, perform data registration and file upload. 4. SummaryBy implementing the above, using the OData V4 service using the ABAP RESTful Application Programming Model (RAP), you can use the “Attachment” for each row (item) in the SAP Fiori Elements List Report. It is possible to upload, read, and delete files on a line-by-line basis. Please take advantage of it. ReferencesSAPUI5 Document: Enabling Stream Support   Read More Technology Blog Posts by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author