"Do inRomeSAP asRomansSAPers (SAPients or .. alright, call them however you like) do"
.....
@ObjectModel:
{
updateEnabled: true
}
define view ZCDS_C_SKUIMAGE
as select from z<namespace>_cat_sku as CatalogSku
inner join makt as SKUDesc
on ( CatalogSku.matnr = SKUDesc.matnr )
association [1..*] to ZCDS_I_IMAGE as _Image
on ( CatalogSku.matnr = _Image.CatalogSKU )
{
key CatalogSku.matnr as CatalogSKU,
CatalogSku.ctlg_itm_key as CatalogItmKey,
SKUDesc.maktx as CatalogSKUDesc,
_Image,
//creating URL
concat(replace('/sap/opu/odata/sap/Z<namespace>_IMAGES_SRV/ZCDS_I_IMAGE(CatalogSKU=''matnr'',', 'matnr', CatalogSku.matnr),
replace('image_key=imageKey)/$value', 'imageKey',
cast (_Image.image_key as abap.char( 20 )))) as GetUrl
}
where SKUDesc.spras = $session.system_language
and CatalogSku.inactive = ''
....
@ObjectModel:{
createEnabled: true,
updateEnabled: true,
deleteEnabled: true
}
define view ZCDS_I_IMAGE
as select from z<namespace>_cat_sku as Image
{
key Image.matnr as CatalogSKU,
key Image.image_key as image_key,
Image.ctlg_itm_key as CatalogItmKey,
Image.image_name,
Image.mime_type,
@Semantics.imageUrl: true
Image.image_url as ImageUrl,
} where Image.inactive = ''
"/sap/opu/odata/sap/ZFIAP_SOS_IMAGES_SRV/ZCDS_I_SOS_IMAGE(CatalogSKU='000000000600000106',image_key=0001)/$value".
METHOD define.
super->define( ).
DATA:
lr_entity TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lr_property TYPE REF TO /iwbep/if_mgw_odata_property.
lr_entity = model->get_entity_type( iv_entity_name = 'ZCDS_I_IMAGEType' ).
* specifying mimetype property of media set
IF lr_entity IS BOUND.
* setting a data object as media type means that it gets a special semantic by having a url * and allows streaming etc.
lr_entity->set_is_media( ).
lr_property = lr_entity->get_property( iv_property_name = 'mime_type' ).
lr_property->set_as_content_type( ).
ENDIF.
ENDMETHOD.
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
DATA: ls_key TYPE /iwbep/s_mgw_name_value_pair,
...
lv_matnr TYPE matnr,
ls_image TYPE z<namespace>_cat_sku,
ls_lheader TYPE ihttpnvp,
ls_stream TYPE ty_s_media_resource,
lv_filename TYPE string,
lt_tab TYPE solix_tab,
ls_tab TYPE solix,
lv_leng TYPE i,
lv_buffer TYPE xstring,
lv_imageurl TYPE zzimage_url.
CASE iv_entity_name.
WHEN 'ZCDS_I_IMAGEType'.
*----------IMPORTANT READING -------------------------------------------*
*Get the key field values of the entity and retrive the image file path
*For simplification, we are showing the image storage is in
*application server directory, but adapt to your own chosen storage type
*(content repository etc.)
*-----------------------------------------------------------------------*
...
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = ls_key-value
IMPORTING
output = lv_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
CLEAR lv_matnr.
ENDIF.
* Get the image details from catalog AKu table
SELECT SINGLE * FROM z<namespace>_cat_sku
INTO ls_image
WHERE matnr = lv_matnr.
IF sy-subrc = 0.
* Open the application server file and read the file contents
OPEN DATASET ls_image-image_url FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
DO.
READ DATASET ls_image-image_url INTO ls_tab.
IF sy-subrc = 0.
APPEND ls_tab TO lt_tab.
CLEAR ls_tab.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET ls_image-image_url.
ENDIF.
ENDIF.
* Convert the binary file content to rawstring
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = ls_image-file_size
IMPORTING
buffer = lv_buffer
TABLES
binary_tab = lt_tab
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc = 0.
* Pass the rawstring data to image stream
ls_stream-value = lv_buffer.
ls_stream-mime_type = ls_image-mime_type.
lv_filename = ls_image-image_name.
lv_filename = escape( val = lv_filename
format = cl_abap_format=>e_url ).
ls_lheader-name = 'Content-Disposition'.
ls_lheader-value = |inline; filename="{ lv_filename }"|.
set_header( is_header = ls_lheader ).
copy_data_to_ref( EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
<Annotations Target="Z<namespace>_IMAGES_SRV.ZCDS_C_SKUIMAGEType">
<Annotation Term="UI.LineItem">
<Collection>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="GetUrl"/>
<Annotation Term="UI.Importance" EnumMember="UI.ImportanceType/High"/>
<PropertyValue Property="Label" String="{@i18n>IMAGE}"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="CatalogSKU"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="CatalogSKUDesc"/>
</Record>
</Collection>
</Annotation>
<Annotations Target="Z<namespace>_IMAGES_SRV.ZCDS_C_SKUIMAGEType/GetUrl">
<Annotation Term="UI.IsImageUrl"/>
</Annotations>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |