DATA(unusual) = 'á Ă é Ä Ö Ü ä ö ü ß'.
DATA(pretty) = VALUE string( ).
CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
EXPORTING
intext = unusual
IMPORTING
outtext = pretty.
WRITE / unusual.
WRITE / pretty. "a A e Ae Oe Ue ae oe ue ss
Category: SAP
SAP
[CAP] min and max functions
Since there is nothing in the official CAP documentation about min and max functions, I figured out the following syntax:
const result1 = await cds.run(`SELECT *, MAX(seqNr) FROM ${myTable} LIMIT 1`) //returns array
const result2 = await SELECT.one.from(myTable, [`MAX(seqNr)`]).columns('*') //returns object
const result3 = await SELECT.one.from(myTable).columns('MAX(seqNr)') //returns object containing only the max counter value
[ABAP] Display Table data as HTML
REPORT z_table_to_html.
TRY.
SELECT * FROM sflight INTO TABLE @DATA(flights) UP TO 100 ROWS.
cl_demo_output=>write_data( flights ).
DATA(lv_html) = cl_demo_output=>get( ).
cl_abap_browser=>show_html( title = 'Flights'
html_string = lv_html
container = cl_gui_container=>default_screen ).
" force cl_gui_container=>default_screen
WRITE: space.
CATCH cx_root INTO DATA(e).
WRITE: / e->get_text( ).
ENDTRY.
[SuccessFactors] Check if IAS is activated for a tenant
Go to Upgrade Center
, select Platform
in the Filter By
Dropdown. In the Optional Upgrades
Column, search for:
Initiate the SAP Cloud Identity Services Identity Authentication Service Integration
If the entry exists, IAS is not yet set up. If it does not exist, the IAS configuration is probably already done.
[ABAP] Get URL for BSP Page
cl_http_ext_webapp=>create_url_for_bsp_application( EXPORTING bsp_application = bsp_application " Name der BSP Applikation
bsp_start_page = bsp_start_page " Startseite der BSP Applikation
bsp_start_parameters = bsp_start_parameters " Startparameter der BSP Applikation
IMPORTING abs_url = DATA(lv_absolute_url ). " Absolute URL (Protokol, Host, Port, ...) der BSP Applikation
[ABAP] Display PDF in HTML Control
DATA(lt_data) = cl_bcs_convert=>xstring_to_solix( lv_xstring ). " xstring pdf data
DATA(o_html) = NEW cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).
* URL zu HTML holen
DATA: lv_url TYPE swk_url.
o_html->load_data( EXPORTING type = 'BIN'
subtype = 'PDF'
IMPORTING assigned_url = lv_url
CHANGING data_table = lt_data ).
* HTML anzeigen
o_html->show_url( lv_url ).
* erzwingt Anzeige über cl_gui_container=>default_screen
WRITE: / space.
[ABAP] OData – Request Parameter
You can access the request parameter from anywhere in the *_DPC_EXT class via:
mr_request_details->parameters
[ABAP] Convert table of strings to a single string
DATA(lv_string) = REDUCE #( INIT str = || FOR line IN table_of_strings NEXT str = str && line).
[CAP] Posting form data to a destination using executeHttpRequest
const { executeHttpRequest } = require('@sap-cloud-sdk/http-client')
const FormData = require('form-data')
try {
//Create payload
const form = new FormData()
form.append('file', fileContent, {
contentType: 'application/pdf'
filename: 'test.pdf'
})
//Create headers
const headers = {
...form.getHeaders(),
'Content-Length': form.getLengthSync(),
}
//Send to Destination
const response = await executeHttpRequest(
{ destinationName: 'TESTINATION' },
{
method: 'POST',
url: 'myApiPath',
headers: headers,
data: form,
responseType: 'arraybuffer' // if you need the response data as buffer to prevent UTF-8 encoding
}
)
console.log({response})
} catch (error) {
console.error(error.message)
}
[CAP] Fiori Elements – Add section with PDFViewer
I have a CAP Service that provides a PDF file that I needed to display in a Fiori Elements frontend using the sap.m.PDFViewer. The viewer should be placed in a section on the object page after navigating from the ListReport main page.
My CAP Service has the following annotations to provide the PDF.
entity pdfFiles : cuid, managed {
content : LargeBinary @stream @Core.MediaType: mediaType @Core.ContentDisposition.Filename: fileName @Core.ContentDisposition.Type: 'inline';
mediaType : String @Core.IsMediaType: true;
fileName : String @mandatory;
}
Add a custom section to your view following this example: https://sapui5.hana.ondemand.com/test-resources/sap/fe/core/fpmExplorer/index.html#/customElements/customSectionContent
Two steps are necessary.
1. Add a new section via the manifest. The template path should match your app namespace.
"ObjectPage": {
"type": "Component",
"id": "ObjectPage",
"name": "sap.fe.templates.ObjectPage",
"viewLevel": 1,
"options": {
"settings": {
"editableHeaderContent": false,
"entitySet": "pdfFiles",
"content": {
"body": {
"sections" : {
"myCustomSection": {
"template": "sap.fe.core.fpmExplorer.customSectionContent.CustomSection",
"title": "{i18n>pdfSection}",
"position": {
"placement": "After",
"anchor": "StandardSection"
}
}
}
}
}
}
}
}
2. Add the section content by defining a new fragment in the file CustomSection.fragment.xml
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:macro="sap.fe.macros">
<ScrollContainer
height="100%"
width="100%"
horizontal="true"
vertical="true">
<FlexBox direction="Column" renderType="Div" class="sapUiSmallMargin">
<PDFViewer source="{content}" title="{fileName}" height="1200px">
<layoutData>
<FlexItemData growFactor="1" />
</layoutData>
</PDFViewer>
</FlexBox>
</ScrollContainer>
</core:FragmentDefinition>
On the ObjectPage you will now have a new section containing the PDFViewer.
