Adapt data to transfer
BAdI /AEB/TA_MATERIAL_02
The following site will assist you how to adapt the data of a material which is transferred to Product Classification.
Let us start with adapting the alternative material number. The standard just fill the alternative material number with the external represenation of the SAP material no.
The first thing you have to know: Some of our fields with simple data types like char or string are implemented as so called nullable values. So we have a class representation of each simple data type.
If you change such a field you need to use the correct type. For the material number you have to use the class /AEB/CL_01_CHAR_50_NV. NV means nullable values. To create this nullable value, the BAdI method offers you the parameter im_nullable_value_factory. Each nullable value has the attribte v for value.
Why do we use nullable values? To differentiate between whether or not an empty value will lead to an update in Product Classification. In case of a wanted update you have to create the nullable value without assign a value to v. If there should be no update, set the alternative material number in the interface to "NULL".
DATA:
matnr_nv TYPE REF TO /aeb/cl_01_char_50_nv,
matnr TYPE matnr,
alt_matnr TYPE REF TO /aeb/cl_01_char_50_nv.
matnr_nv = im_value->get_material_no( ).
matnr = matnr_nv->v.
IF matnr = 'M-11'.
alt_matnr = im_nullable_value_factory->char_50( 'M-11-TEST' ).
im_value->set_alt_material_no( alt_matnr ).
ENDIF.
Okay, know to a more complex case. You like to adapt the value of a classification. In the following example we will change the value of COCO_IMPORT (commodity code for import 10/11 digits) for the classification for 'DE' to a hard coded value.
First you have to loop over the classifications. Then you have to check if the country_iso is 'DE'. And then you have to check it the value is the COCO_IMPORT. In this case we change it to a fixed value of '01022959310'.
DATA:
classifications TYPE /aeb/if_ta_pb_ft_mcls20_do=>tt_ft_mcls20_do,
current_cls TYPE REF TO /aeb/if_ta_pb_ft_mcls20_do,
country_iso_nv TYPE REF TO /aeb/cl_01_char_2_nv,
values TYPE /aeb/if_ta_pb_mat_cls_val_do=>tt_mat_cls_val_do,
current_value TYPE REF TO /aeb/if_ta_pb_mat_cls_val_do,
identcode_nv TYPE REF TO /aeb/cl_01_char_20_nv,
value_nv TYPE REF TO /aeb/cl_01_string_nv.
classifications = im_value->get_classifications( ).
LOOP AT classifications INTO current_cls.
country_iso_nv = current_cls->get_countryisocode( ).
IF country_iso_nv->v = 'DE'.
values = current_cls->get_values( ).
LOOP AT values INTO current_value.
identcode_nv = current_value->get_identcode( ).
IF identcode_nv->v = 'COCO_IMPORT'.
value_nv = im_nullable_value_factory->string( '01022959310' ).
current_value->set_value( value_nv ).
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
As you see the whole material is implemented object-oriented. So in order to access the classifications you have to call the method get_classifications.
How to add a classification? See the example below.
DATA:
identcode_nv TYPE REF TO /aeb/cl_01_char_50_nv,
value_nv TYPE REF TO /aeb/cl_01_char_255_nv,
classification_code TYPE REF TO /aeb/if_ta_pb_mat_cls_code_do.
identcode_nv = im_nullable_value_factory->char_50( 'ID_123' ).
value_nv = im_nullable_value_factory->char_255( 'VALUE_123' ).
classification_code = im_data_object_factory->new_ta_pb_mat_cls_code_do(
im_identcode = identcode_nv
im_value = value_nv ).
classification_code->set_approved( im_nullable_value_factory->boolean( 'X' ) ). "optional, add if you want to release the classification value
classification_code->set_iso_code( im_nullable_value_factory->char2( 'DE' ) ). "optional, add if the classification is country dependent
im_value->add_classification_code( classification_code ).
Ok let us try another thing. If you like to add a certificate to a classification you have to select the classification you like to add the certificate to and then call the method add_certificate. To create a certificate you have to use the parameter im_data_object_factory which is provided by the BAdI method.
DATA:
certificate TYPE REF TO /aeb/if_ta_pb_ft_cert_do,
add_expl TYPE REF TO /aeb/cl_01_char_35_nv,
reference TYPE REF TO /aeb/cl_01_char_35_nv,
detail TYPE REF TO /aeb/cl_01_char_12_nv,
geo_id TYPE REF TO /aeb/cl_01_char_10_nv,
type_code TYPE REF TO /aeb/cl_01_char_5_nv,
type_qualifier TYPE REF TO /aeb/cl_01_char_3_nv,
date TYPE REF TO /aeb/cl_01_dats_nv,
cls_dos TYPE /aeb/if_ta_pb_ft_mcls20_do=>tt_ft_mcls20_do,
cls_do TYPE REF TO /aeb/if_ta_pb_ft_mcls20_do,
country_iso_nv TYPE REF TO /aeb/cl_01_char_2_nv.
add_expl = im_nullable_value_factory->char_35( 'To be filled' ).
reference = im_nullable_value_factory->char_35( '1235434' ).
detail = im_nullable_value_factory->char_12( 'The detail' ).
geo_id = im_nullable_value_factory->char_10( 'US' ).
type_code = im_nullable_value_factory->char_5( 'Y921' ).
type_qualifier = im_nullable_value_factory->char_3( 'ZW' ).
date = im_nullable_value_factory->dats( '20190101' ).
certificate = im_data_object_factory->new_ta_pb_ft_cert_do(
im_cert_additional_expl = add_expl
im_cert_date_of_issue = date
im_cert_detail = detail
im_cert_reference = reference
im_geo_id = geo_id
im_type_code = type_code
im_type_qualifier = type_qualifier
im_valid_from = date).
cls_dos = im_value->get_classifications( ).
LOOP AT cls_dos INTO cls_do.
country_iso_nv = cls_do->get_countryisocode( ).
IF country_iso_nv->v = 'DE'.
cls_do->add_certificate( certificate ).
ENDIF.
ENDLOOP.
And here another example which shows how to add attachments to your material.
Please note that this example uses fronted service. This won't work in productiv implementation, but for testing it will work.
DATA:
attachment TYPE REF TO /aeb/if_ta_pb_mat_att_do,
file_name_nv TYPE REF TO /aeb/cl_01_char_250_nv,
attachment_data TYPE /aeb/01_rawstring,
description_nv TYPE REF TO /aeb/cl_01_string_nv,
encoding_nv TYPE REF TO /aeb/cl_01_char_50_nv,
property TYPE REF TO /aeb/if_ta_pb_mat_prop_do,
mime_type_nv TYPE REF TO /aeb/cl_01_char_50_nv,
lt_file_table TYPE filetable,
lv_file TYPE string,
lv_rc TYPE i,
file_manager TYPE REF TO cl_file_system_manager,
string TYPE string,
lt_rawtab TYPE TABLE OF char255.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select file'
file_filter = ''
initial_directory = ''
multiselection = ''
CHANGING
file_table = lt_file_table
rc = lv_rc.
READ TABLE lt_file_table INTO lv_file INDEX 1.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_file
CHANGING
data_tab = lt_rawtab.
READ TABLE lt_rawtab INTO string INDEX 1.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = string
IMPORTING
buffer = attachment_data.
file_name_nv = im_nullable_value_factory->char_250( 'Testfile' ).
description_nv = im_nullable_value_factory->string( 'This is just a test' ).
encoding_nv = im_nullable_value_factory->char_50( 'UFT-8' ).
mime_type_nv = im_nullable_value_factory->char_50( 'text/plain' ).
attachment = im_data_object_factory->new_ta_pb_mat_att_do(
im_file_name = file_name_nv
im_attachment_data = attachment_data
im_attachment_description = description_nv
im_encoding = encoding_nv
im_mime_type = mime_type_nv ).
im_value->add_attachment( attachment ).
DATA:
attachment TYPE REF TO /aeb/if_ta_pb_mat_att_do,
file_name_nv TYPE REF TO /aeb/cl_01_char_250_nv,
attach_descr_nv TYPE REF TO /aeb/cl_01_string_nv,
attachment_data TYPE /aeb/01_rawstring. " Just a dummy..
" The file Name is the Link
file_name_nv = im_nullable_value_factory->char_250( 'https://www.aeb.com/en' ).
attach_descr_nv = im_nullable_value_factory->string( 'Description of the attachment' ).
attachment = im_data_object_factory->new_ta_pb_mat_att_do(
im_file_name = file_name_nv
im_attachment_data = attachment_data
im_attachment_description = attach_descr_nv ).
im_value->add_attachment( attachment ).
If you like to have context data for example of the material (MARA, MARC..) or if you like to have the relevant org. units use the parameter "IM_MATERIAL_CONTEXT". This parameter has some methods for example get_mara with which you can the actual content of the table mara (include the content which is not yet persistent).
To add additional goods properties to your material you have to use method add_property.
lv_id = 'PROPERTY_ID'.
lv_value = 'PROPERTY_VALUE'.
lo_property = im_data_object_factory->new_ta_pb_mat_prop_do( im_identcode = lv_id
im_value = lv_value ).
im_value->add_property( im_value = lo_property ).
Updated 6 months ago