Skip to Content
avatar image
Former Member

Tax Classification has to be defaulted to '0' in SAP MDG

tax-classification.pngHello All,

I have requirement that the Tax classification for material master has to be defaulted to ZERO according to material type.

what is the best procedure to achieve this.please its very urgent for me.

Thank you

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Feb 26 at 11:05 PM

    Hi Vidya,

    Again, you can use the Cross Entity Derivation BADI & on the trigger of new entries for your Tax. You can derive the Tax Classification value to '0' for each row.

    Whenever you are trying to add Distribution Channel to your Material, then Tax entries will automatically going to ( with tax type) add in the UIBB. You just need to read those entries by below code. And then use the lo_mlansales_tax reference to write the data to the entity.

    " Read Tax Classification

    CALL METHOD io_changed_data->read_data

    EXPORTING i_entity = if_mdg_bs_mat_gen_c=>gc_entity_mlansales

    IMPORTING er_t_data_upd = DATA(lo_mlansales_tab).


    Cheers,

    Rohit

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 28 at 10:27 AM

    Hi Rohit,

    Thanks for the quick response.

    im facing a small issue.can u check the below code.

    *get MLANSALES data
    io_changed_data->read_data(
    EXPORTING
    i_entity = 'MLANSALES'
    i_struct = io_model->gc_struct_key_attr
    IMPORTING
    er_t_data_mod = lr_t_mod ).

    ASSIGN lr_t_mod->* TO <lt_mod>.
    *Proceed only if data is returned
    IF <lt_mod> IS NOT ASSIGNED OR <lt_mod> IS INITIAL.
    RETURN.
    ELSE.
    READ TABLE <lt_mod> ASSIGNING <ls_data> INDEX 1.
    IF sy-subrc = 0.
    ASSIGN COMPONENT 'TATYP' OF STRUCTURE <ls_data> TO <l_var1>.
    ASSIGN COMPONENT 'USMDX_S_UPDATE' OF STRUCTURE <ls_data> TO <l_var2>.
    *Proceed only if MATERIAL has value
    IF <l_var2> IS INITIAL.
    RETURN.
    ENDIF.
    ENDIF.
    ENDIF.
    *create data reference for entity type MLANSALES
    CALL METHOD io_model->create_data_reference
    EXPORTING
    i_fieldname = 'MLANSALES'
    i_struct = 'KATTR' "Keys + Attributes According to IT_ATTRIBUTE
    i_tabtype = if_usmd_model_ext=>gc_tabtype_standard
    IMPORTING
    er_data = lrt_entity_data.

    *assign entity to table . This table if populated will be used to write data
    ASSIGN lrt_entity_data->* TO <lt_table>.
    *assign entity to table . This table if populated will be used to delete data
    ASSIGN 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_attributes
    IMPORTING
    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 Material number from io_model->read_data above
    CALL METHOD io_model->read_char_value
    EXPORTING
    i_fieldname = usmd0_cs_fld-crequest
    it_sel = lt_sel
    if_use_edtn_slice = abap_false
    IMPORTING
    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.

    CALL METHOD io_model->read_char_value
    EXPORTING
    i_fieldname = 'MLANSALES'
    it_sel = lt_sel
    IMPORTING
    et_data = <lt_table1>.


    * Here we can enter further logic to assign a different MRP Profile based on Material Type
    CLEAR wa_tab.
    wa_tab-material = lv_matnr.

    IF <l_var1> = 'UTX2' OR
    <l_var1> = 'UTX3' OR
    <l_var1> = 'UTXJ' OR
    <l_var1> = 'ZCRT'.
    wa_tab-TAXSALTAX = '0'.
    ENDIF.

    APPEND Wa_tab to lT_tab.
    CLEAR wa_tab.

    gs_comp-name = 'MATERIAL'.
    gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'MATNR' ).
    APPEND gs_comp TO gt_comp.
    *
    gs_comp-name = 'TAXSALTAX'.
    gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'TAXKM' ).
    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 data
    LOOP AT lt_tab INTO wa_tab.
    MOVE-CORRESPONDING wa_tab TO <lv_system>.
    APPEND <lv_system> TO <lt_table>.
    ENDLOOP.

    *populating attribute table
    CREATE 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.


    IF <lt_table> IS NOT INITIAL.
    TRY.
    io_write_data->write_data(
    EXPORTING
    i_entity = 'MLANSALES'
    it_attribute = lt_attribute
    it_data = <lt_table> ).
    CATCH cx_usmd_write_error. " Error During Write Access
    RETURN.
    ENDTRY.
    ENDIF.

    I debugged the code lot of times but till write_data into the entity the data im able to see but its not reflecting in the UI as expected.

    Add comment
    10|10000 characters needed characters exceeded