
Custom CDS View
CLASS zcl_otc_print DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_rap_query_provider .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ZCL_OTC_PRINT IMPLEMENTATION.
METHOD if_rap_query_provider~select.
DATA: lt_tab TYPE TABLE OF ZCUSTOM_FORMAPI.
DATA: lt_master_keys TYPE cl_somu_form_services=>ty_gt_key.
DATA: lv_content TYPE xstring.
DATA: lo_cl_somu_form_services TYPE REF TO cl_somu_form_services,
lt_keys TYPE cl_somu_form_services=>ty_gt_key.
TRY.
** requested data
IF io_request->is_data_requested( ).
**paging
DATA(lv_offset) = io_request->get_paging( )->get_offset( ).
DATA(lv_page_size) = io_request->get_paging( )->get_page_size( ).
DATA(lv_max_rows) = COND #( WHEN lv_page_size = if_rap_query_paging=>page_size_unlimited
THEN 0 ELSE lv_page_size ) .
** Get the selected billing document from UI
TRY.
DATA(lt_parameters) = io_request->get_parameters( ).
** P_BILLINGDOC is the parameter of custom entity
DATA(lv_billdoc) = VALUE #( lt_parameters[ parameter_name = 'P_BILLINGDOC' ]-value OPTIONAL ).
* " --------------------------- Key Value for the Billing Doc content form --------
lt_keys = VALUE #( ( name = 'BillingDocument' value = lv_billdoc )
( name = 'SenderCountry' value = 'DE' )
( name = 'Language'(040) value = 'E' ) ) .
* " --------------------------- Key Value for the master form template ---------------------------
lt_master_keys = VALUE #( ( name = 'PrintFormDerivationRule' value = 'ZINVOICE_FORM' )
( name = 'WatermarkText' value = space )
( name = 'LocaleCountry' value = 'DE')
( name = 'LocaleLanguage' value = 'E' )
( name = 'OutputControlApplicationObjectType' value = 'BILLING_DOCUMENT' )
( name = 'OutputControlApplicationObject' value = lv_billdoc )
( name = 'OutputRequestItem' value = '000001' )
( name = 'OutputDocumentType' value = 'BILLING_DOCUMENT' )
( name = 'Recipient'(041) value = '00000001003' )
( name = 'RecipientRole' value = 'RE' )
( name = 'SenderCountry' value = 'DE' )
( name = 'ReceiverPartnerNumber' value = '00000001003' ) ).
lo_cl_somu_form_services = cl_somu_form_services=>get_instance( ).
TRY.
* " --------------------------- Call GET_DOCUMENT API ---------------------------
lo_cl_somu_form_services->get_document( EXPORTING iv_master_form_name = 'ZZ1_OTC_INVOICE_MASTER_A4'
iv_form_name = 'ZZ1_OTC_INVOICE_OUTPUT'
it_key = lt_keys
it_master_key = lt_master_keys
iv_form_language = 'E'
iv_form_country = 'DE'
IMPORTING ev_content = lv_content
).
CATCH cx_somu_error INTO DATA(lv_formerror).
ENDTRY.
lt_tab = VALUE #( ( stream_data = lv_content
) ).
io_response->set_total_number_of_records( 1 ).
* " -------------- Send the response back to UI------------
io_response->set_data( lt_tab ).
CATCH cx_rap_query_filter_no_range INTO DATA(lv_range).
DATA(lv_msg) = lv_range->get_text( ).
ENDTRY.
ENDIF.
CATCH cx_rap_query_provider.
ENDTRY.
ENDMETHOD.
ENDCLASS.
Service Definition
Service binding
Data Source
This OData data source should be mapped to a UI5 model in manifest file under “models” section.
Model
getPDFData: function () {
// get the Model reference
var oModel = this.getView().getModel("oFormModel");
//get selected line index
var selectedIndex = this.getView().byId('xx.sellbuybackreport::sap.suite.ui.generic.template.ListReport.view.ListReport::ZC_OTC_SELLBUYBACK_DETAILS--GridTable')
.getAggregation("plugins")[0].getSelectedIndex() ;
// get billing document from selected index
var vSelectedBillDoc = this.getView().byId('xx.sellbuybackreport::sap.suite.ui.generic.template.ListReport.view.ListReport::ZC_OTC_SELLBUYBACK_DETAILS--GridTable').
getContextByIndex(selectedIndex).getProperty('CorrectBillingDocZG2');
return new Promise((resolve,reject)=>{
// Perform Read operation and pass billingdoc as parameter to URL
oModel.read( "/ZCUSTOM_FORMAPI(p_billingdoc='" + vSelectedBillDoc + "')/Set" ,
{
success: function (oData,oResponse){
resolve(oData);
},
error: function (oError) {
reject(oError);
}
});
})
},
onPrintPreview: async function(oEvent) {
var opdfViewer = new PDFViewer();
this.getView().addDependent(opdfViewer);
var oBusyDialog = new sap.m.BusyDialog({
title: 'Generating Form...'
} );
oBusyDialog.open();
// Get the PDF data
var vPDF = await this.getPDFData();
let base64EncodedPDF = vPDF.results[0].stream_data;
let decodedPdfContent = atob(base64EncodedPDF);
let byteArray = new Uint8Array(decodedPdfContent.length);
for (var i = 0; i < decodedPdfContent.length; i++) {
byteArray[i] = decodedPdfContent.charCodeAt(i);
}
var blob = new Blob([byteArray.buffer], {
type: 'application/pdf'
});
var pdfurl = URL.createObjectURL(blob);
jQuery.sap.addUrlWhitelist("blob"); // register blob url as whitelist
opdfViewer.setSource(pdfurl);
opdfViewer.setVisible(true);
opdfViewer.setTitle("Billing Document ");
console.log('Reached to PDF')
opdfViewer.open();
oBusyDialog.close();
}
User selects a line and click on Print Preview
Below call was made to the backend API along with selected billing documented in parameter field
Print Preview
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
8 | |
7 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 |