
Name | Key | Edm Core Type | Prec | Scale | Max | Abap Field Name |
---|---|---|---|---|---|---|
matDescTR | Edm.String | 0 | 0 | 40 | MATDESCTR | |
matDescEN | Edm.String | 0 | 0 | 40 | MATDESCEN | |
baseUOM | Edm.String | 0 | 0 | 3 | BASEUOM | |
matType | Edm.String | 0 | 0 | 4 | MATTYPE | |
indSector | Edm.String | 0 | 0 | 4 | INDSEC | |
materialNum | X | Edm.String | 0 | 0 | 40 | MATNR |
DATA: ls_headdata TYPE bapimathead,
ls_clientdata TYPE bapi_mara,
ls_clientdatax TYPE bapi_marax,
ls_materialdesc TYPE bapi_makt,
lt_materialdesc TYPE TABLE OF bapi_makt,
ls_return TYPE bapiret2.
DATA: ls_request_input_data TYPE zcl_zxxx_mpc=>ts_creatematerial,
lo_message_container TYPE REF TO /iwbep/if_message_container.
CALL METHOD me->/iwbep/if_mgw_conv_srv_runtime~get_message_container
RECEIVING
ro_message_container = lo_message_container.
"""""""""""""""""""""" READ REQUEST DATA """"""""""""""""""""""""""""""""""""""""
io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ).
""""""""""""""" INSERT DATA TO TABLE WITH BAPI """""""""""""""""""""""""
* Populate material data structure
ls_headdata-material = ls_request_input_data-matnr.
ls_headdata-ind_sector = ls_request_input_data-indsec.
ls_headdata-matl_type = ls_request_input_data-mattype.
ls_headdata-basic_view = 'X'.
ls_clientdata-base_uom = ls_request_input_data-baseuom.
ls_clientdatax-base_uom = 'X'.
IF ls_request_input_data-matdescen IS NOT INITIAL.
ls_materialdesc-langu = 'EN'.
ls_materialdesc-matl_desc = ls_request_input_data-matdescen.
APPEND ls_materialdesc TO lt_materialdesc.
ENDIF.
IF ls_request_input_data-matdesctr IS NOT INITIAL.
ls_materialdesc-langu = 'TR'.
ls_materialdesc-matl_desc = ls_request_input_data-matdesctr.
APPEND ls_materialdesc TO lt_materialdesc.
ENDIF.
* Call BAPI to create material
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = ls_headdata
clientdata = ls_clientdata
clientdatax = ls_clientdatax
IMPORTING
return = ls_return
TABLES
materialdescription = lt_materialdesc.
* Check for errors and return message
IF ls_return IS NOT INITIAL.
CALL METHOD lo_message_container->add_message_from_bapi
EXPORTING
is_bapi_message = ls_return
iv_add_to_response_header = abap_true " Flag for adding or not the message to the response header
iv_message_target = CONV string( ls_return-field ).
EXIT.
ELSE.
CALL METHOD lo_message_container->add_message
EXPORTING
iv_msg_type = /iwbep/cl_cos_logger=>error
iv_msg_id = 'ZTEST'
iv_msg_number = '000'
iv_msg_text = `An error occured.`
iv_add_to_response_header = abap_true. "add the message to the header
EXIT.
ENDIF.
er_entity = ls_request_input_data. "Fill Exporting parameter ER_ENTITY
//...
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "<-- your namespace -->.i18n.i18n"
}
},
"globalModel": {
"type": "sap.ui.model.json.JSONModel",
"settings": {},
"preload": true
},
"": {
"dataSource": "mainService",
"preload": true,
"settings": {
"useBatch": false
}
}
},
//...
We'll set up the user interface (UI) for our app using the provided code below. Code includes binding the previously created model to this view. This binding process ensures that the data stored in the model is displayed and accessible within the user interface.
<mvc:View
controllerName="<-- your namespace -->.controller.Main"
xmlns:mvc="sap.ui.core.mvc"
displayBlock="true"
xmlns="sap.m"
xmlns:u="sap.ui.unified"
xmlns:t="sap.ui.table"
xmlns:l="sap.ui.layout"
>
<Page
id="page"
title="{i18n>title}"
class="sapUiContentPadding sapUiContentPadding--header sapUiResponsivePadding--header sapUiResponsivePadding--subHeader sapUiResponsivePadding--content sapUiResponsivePadding--footer"
showNavButton="false"
showHeader="true"
>
<!-- ========================== -->
<!-- Excel Bar FlexBox -->
<!-- ========================== -->
<FlexBox
id="_IDGenFlexBox1"
wrap="Wrap"
class="sapUiMediumMarginTop"
justifyContent="Center"
>
<Input
id="searchInput"
width="100%"
editable="false"
value="{globalModel>/excelFileName}"
>
<layoutData>
<FlexItemData
id="_IDGenFlexItemData1"
growFactor="6"
/>
</layoutData>
</Input>
<FlexBox id="_IDGenFlexBox2">
<u:FileUploader
id="FileUploaderId"
class="sapUiSmallMarginBegin"
buttonText="Excel Upload"
sameFilenameAllowed="true"
iconOnly="false"
buttonOnly="true"
fileType="XLSX,xlsx"
icon="sap-icon://excel-attachment"
multiple="false"
iconFirst="true"
style="Emphasized"
change="handleImportData"
/>
</FlexBox>
</FlexBox>
<!-- ============= -->
<!-- Table -->
<!-- ============= -->
<t:Table
id="table"
rows="{
path:'globalModel>/materialsExcel',
sorter: {
path: 'SIMILARITY',
descending: true
}
}"
selectionMode="MultiToggle"
ariaLabelledBy="title"
visibleRowCount="20"
class="sapUiMediumMarginTop"
>
<t:extension>
<OverflowToolbar
id="_IDGenOverflowToolbar1"
style="Clear"
>
<Title
id="title"
text="Materials"
/>
<ToolbarSpacer id="_IDGenToolbarSpacer1" />
<Button
id="uploadButton"
type="Emphasized"
enabled="false"
icon="sap-icon://upload"
press="onPressUpload"
text="Upload"
class="sapUiSmallMarginBegin"
ariaDescribedBy="acceptButtonDescription genericButtonDescription"
/>
</OverflowToolbar>
</t:extension>
<t:rowSettingsTemplate>
<t:RowSettings
id="rowSettings"
highlight="{globalModel>status}"
highlightText="{globalModel>statusText}"
/>
</t:rowSettingsTemplate>
<t:columns>
<t:Column
width="8rem"
id="_IDGenColumn1"
>
<Label
id="_IDGenLabel1"
text="Status"
/>
<t:template>
<Text
busy="{globalModel>isBusy}"
id="_IDGenText2"
text="{globalModel>statusText}"
wrapping="false"
/>
</t:template>
</t:Column>
</t:columns>
</t:Table>
</Page>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"../libs/xlsx",
"../libs/jszip",
],
/**
* @param {typeof sap.ui.core.mvc.Controller} Controller
*/
function (Controller, xlsx, jszip) {
"use strict";
return Controller.extend("<-- your namespace -->.controller.Main", {
onInit: function () {
},
handleImportData: function (oEvent) {
this._import(oEvent.getParameter("files") && oEvent.getParameter("files")[0]);
},
_import: function (file) {
var that = this;
var excelData = {};
if (file && window.FileReader) {
that.getView().getModel('globalModel').setProperty("/excelFileName", file.name);
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});
for (var i in workbook.SheetNames) {
excelData = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[workbook.SheetNames[i]]);
break;
}
for (let index = 0; index < excelData.length; index++) {
excelData[index].statusText = 'Ready to Upload';
excelData[index].status = 'Information';
excelData[index].isBusy = false;
}
that.getView().getModel('globalModel').setProperty("/materialsExcel", excelData);
that._prepareTableColumns()
};
reader.onerror = function (ex) {
console.log(ex);
};
reader.readAsBinaryString(file);
}
},
onPressUpload: function (oEvent) {
var oTable = this.getView().byId('table');
var aSelectedIndex = oTable.getSelectedIndices();
var aMaterials = this.getView().getModel('globalModel').getProperty("/materialsExcel");
var aUploadMaterial = [];
aSelectedIndex.map(element => {
var aSelectedMat = aMaterials[element];
var oCreateData = {
"materialNum": aSelectedMat['PartNo'],
"matDescEN": aSelectedMat['DESCRIPTION'],
"baseUOM": aSelectedMat['BaseUOM'],
"matType": aSelectedMat['MatType'],
"indSector": aSelectedMat['IndustrialSector']
}
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/isBusy`, true);
this.getOwnerComponent().getModel().create("/createMaterialSet", oCreateData, {
success: $.proxy(function (data, resp) {
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/isBusy`, false);
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/status`, 'Success');
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/statusText`, 'Material Created');
},
this),
error: $.proxy(function (oError) {
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/isBusy`, false);
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/status`, 'Error');
this.getView().getModel('globalModel').setProperty(`/materialsExcel/${element}/statusText`, 'An error Occured');
}, this)
});
});
},
_prepareTableColumns: function () {
var oTable = this.getView().byId('table');
var oTableExtPoint = new sap.ui.table.extensions.Pointer(oTable);
var aTableCatalog = Object.keys(this.getView().getModel('globalModel').getProperty("/materialsExcel")[0])
aTableCatalog.map(aElement => {
if (aElement !== 'statusText' && aElement !== 'status' && aElement !== 'isBusy') {
var oLabel = new sap.m.Title({
text: aElement
});
var oTemplate = new sap.m.Text({ text: `{globalModel>${aElement}}`, wrapping: false })
var oColumn = new sap.ui.table.Column({
label: oLabel,
width: "10rem",
template: oTemplate,
filterProperty: aElement,
defaultFilterOperator: "Contains"
})
oTable.addColumn(oColumn);
}
})
var aTableColumns = oTable.getColumns();
for (var i = aTableColumns.length; i >= 0; i--) {
oTableExtPoint.doAutoResizeColumn(i);
}
this.getView().byId('FileUploaderId').setEnabled(false);
this.getView().byId('uploadButton').setEnabled(true);
},
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 |