Skip to Content
0

Cross Entity Derivation For Plant Related UIBBs

Feb 16 at 06:22 AM

96

avatar image
Former Member

Hello all,

I write the Derivations for plant related UIBBs in Cross Entity Badi.There is small technical challenge which I am facing.

My Derivations are Based on Material Type.But in Between Plant is there.So when I select the material type the derivations are not working because the plant UIBBs are disabled.When I select plant the derivations which I wrote inside cross entity badi is not working.

When I add plant the derivations Has to work based on material type.can somebody help me how to achieve this.where exactly I'm doing a mistake inside Cross Entity badi. Quick Help would be appreciated.

*get material data
io_changed_data->read_data(EXPORTING
i_entity = 'MATERIAL'
i_struct = io_model->gc_struct_key_attrIMPORTING
er_t_data_ins = lr_t_ins
er_t_data_upd = lr_t_upd ).ASSIGN lr_t_ins->* TO <lt_ins>.ASSIGN lr_t_upd->* TO <lt_upd>.*Proceed only if data is returnedI

F <lt_upd> IS NOT ASSIGNED OR <lt_upd> IS INITIAL.

RETURN.ELSE.READ TABLE <lt_upd> ASSIGNING <ls_data> INDEX 1.IF sy-subrc = 0.ASSIGN COMPONENT 'MATERIAL' OF STRUCTURE <ls_data> TO <l_var>.ASSIGN COMPONENT 'MTART' OF STRUCTURE <ls_data> TO <l_var1>.ASSIGN COMPONENT 'USMDX_S_UPDATE' OF STRUCTURE <ls_data> TO <l_var2>.*Proceed only if BU_HEADER has valueIF <l_var2> IS INITIAL.RETURN.ENDIF.ENDIF.ENDIF.
**Ensure BU_header value is changed on the UI* CHECK <l_flag> IS NOT INITIAL.
*create data reference for entity type BP_TAXNUMCALL METHOD io_model->create_data_referenceEXPORTING
i_fieldname = 'MARCMRPPP'
i_struct = 'KATTR' "Keys + Attributes According to IT_ATTRIBUTE
i_tabtype = if_usmd_model_ext=>gc_tabtype_standardIMPORTING
er_data = lrt_entity_data.*assign entity to table . This table if populated will be used to write dataASSIGN lrt_entity_data->* TO <lt_table>.*assign entity to table . This table if populated will be used to delete dataASSIGN lrt_entity_data->* TO <lt_table1>.
*using context class get the change request number
go_context = cl_usmd_app_context=>get_context( ).CALL METHOD go_context->get_attributesIMPORTING
ev_crequest_id = iv_cr_number.

ls_sel-sign = lc_incl.
ls_sel-option = lc_equal.
ls_sel-fieldname = usmd0_cs_fld-crequest.
ls_sel-low = iv_cr_number.INSERT ls_sel INTO TABLE lt_sel.*using above derived change request number get the entity. This is redundant and may be taken out later on.*We are getting BP number from io_model->read_data aboveCALL METHOD io_model->read_char_valueEXPORTING
i_fieldname = usmd0_cs_fld-crequest
it_sel = lt_sel
if_use_edtn_slice = abap_falseIMPORTING
et_data = lt_objlist.READ TABLE lt_objlist INTO ls_objlist INDEX 1.

lv_matnr = ls_objlist-usmd_value.
ls_sel-sign = lc_incl.
ls_sel-option = lc_equal.
ls_sel-fieldname = 'MATERIAL'. " 'DISPR'. " 'DISMM'.
ls_sel-low = lv_matnr.INSERT ls_sel INTO TABLE lt_sel.*get taxnum assigned to BP_TAXNUM if any.CALL METHOD io_model->read_char_valueEXPORTING
i_fieldname = 'MARCMRPPP'
it_sel = lt_selIMPORTING
et_data = <lt_table1>.
* Here we can enter further logic to assign a different MRP Profile based on Material TypeCLEAR wa_tab.
wa_tab-material = <l_var>.*wa_tab-werks = '0001'. "No need to add the plant at this point, so commented out*wa_tab-dismm = 'ND'. "No need to add MRP Type at this point. If needed, uncomment and pass the reqd valueIF <l_var1> = 'FERT' OR
<l_var1> = 'HALB'.
wa_tab-dismm= 'PD'.ELSE.
wa_tab-dismm = ''.ENDIF.
APPEND wa_tab TO lt_tab.

*logic to create dynamic structure for the new entity*
gs_comp-name = 'MATERIAL'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'MATNR' ).APPEND gs_comp TO gt_comp.

gs_comp-name = 'WERKS'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'WERKS_D' ).APPEND gs_comp TO gt_comp.

gs_comp-name = 'MARCMRPPP'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'DISMM' ).APPEND gs_comp TO gt_comp.

gs_comp-name = 'DISMM'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'DISMM' ).APPEND gs_comp TO gt_comp.
TRY.
r_type_struct = cl_abap_structdescr=>create(
p_components = gt_comp ).CATCH cx_sy_struct_creation .ENDTRY.*TRY.
r_type_table = cl_abap_tabledescr=>create( r_type_struct ).
CATCH cx_sy_table_creation .ENDTRY.*CREATE DATA: r_data_tab TYPE HANDLE r_type_table,
r_data_str TYPE HANDLE r_type_struct.*ASSIGN: r_data_tab->* TO <lt_table>,
r_data_str->* TO <lv_system>.*populating <lt_table> to write dataLOOP AT lt_tab INTO wa_tab.MOVE-CORRESPONDING wa_tab TO <lv_system>.APPEND <lv_system> TO <lt_table>.ENDLOOP.
*populating attribute tableCREATE DATA lr_descr_struc LIKE LINE OF <lt_table>.
lo_structdescr ?= cl_abap_structdescr=>describe_by_data_ref( p_data_ref = lr_descr_struc ).LOOP AT lo_structdescr->components ASSIGNING <lf_component>.INSERT <lf_component>-name INTO TABLE lt_attribute.ENDLOOP.
*delete old value, if any* IF <l_flag> IS NOT INITIAL AND <lt_table1> IS NOT INITIAL.IF <lt_table1> IS NOT INITIAL.
io_write_data->delete_data(EXPORTING
i_entity = 'MARCMRPPP'
it_data = <lt_table1> ).ENDIF.
*write MRP ProfileIF <lt_table> IS NOT INITIAL.TRY.
io_write_data->write_data(EXPORTING
i_entity = 'MARCMRPPP'
it_attribute = lt_attribute
it_data = <lt_table> ).CATCH cx_usmd_write_error. " Error During Write AccessRETURN.ENDTRY.ENDIF.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Rohit Singh Feb 20 at 11:50 PM
0

Hi Vidya,

Finding a fault in this code, surely people need time to first analyze :-).

However, I am not sure the approach that you are using is quite good enough. When you are adding/changing a plant, you need your derivation to kick in. ( based on Material Type ), which means you need your code based on Plant Entities & not Material Entity.

*get material data
io_changed_data->read_data(EXPORTING
i_entity = 'MATERIAL'
i_struct = io_model->gc_struct_key_attrIMPORTING
er_t_data_ins = lr_t_ins
er_t_data_upd = lr_t_upd )

lr_t_ins & lr_t_upd are always be blank as you are doing changes in Plant entity.

If you need to read the Material Type use below code:-

lo_model->create_data_reference( EXPORTING i_fieldname = IF_MDG_BS_MAT_GEN_C=>GC_FIELDNAME_MATERIAL

i_struct = if_usmd_model_ext=>gc_struct_key_attr
it_attribute = VALUE #( ( fieldname = 'MTART' ) )
if_table = abap_true
i_tabtype = if_usmd_model_ext=>gc_tabtype_sorted
IMPORTING er_data = DATA(lo_data) ).

FIELD-SYMBOLS : <lt_mat> TYPE SORTED TABLE.

ASSIGN lo_data->* TO <lt_mat>.

* Read the Attribute Data

DATA : lv_matnr TYPE MATNR. " Your existing Material Number
lo_model->read_char_value( EXPORTING i_fieldname = IF_MDG_BS_MAT_GEN_C=>GC_FIELDNAME_MATERIAL

it_sel = VALUE #( FOR line IN lt_object ( sign = 'I' option = 'EQ' fieldname = IF_MDG_BS_MAT_GEN_C=>GC_FIELDNAME_MATERIAL low = = lv_matnr ) )

if_use_edtn_slice = abap_false
IMPORTING et_data = <lt_mat> ).

Now after reading Material Type ( in <lt_mat>), you can work on derivation of you MARC entities, by checking the data using io_changed_data->read_data for your MARC entities.

Cheers,

Rohit

Share
10 |10000 characters needed characters left characters exceeded