cancel
Showing results for 
Search instead for 
Did you mean: 

Fill Cost Center Medium text automatically using BADI

matias_z
Participant
0 Kudos

Hi All,

I'm trying to fill the Cost Center Medium Text (TXTMI) automatically based on the short text entered.

I'm using method IF_EX_USMD_RULE_SERVICE2~DERIVE for entity CCTR.

I noticed that method io_write_data->write_data will change the medium text ONLY when that field was already populated.

BUT if the medium text is blank and I want to fill it...then it does nothing!

Do you know how can I solve this?

Thanks in advance!

Matias

Accepted Solutions (0)

Answers (2)

Answers (2)

sreenu_b2
Explorer
0 Kudos

Hi Matias,

Could you share the  screen shot of CR .


Regards

Bandi

matias_z
Participant
0 Kudos

Here are all the fields I need to populate...then hit CHECK or ENTER and the Medium Text should be filled with the description of the Short Text ("Test Short Text" in this case). But it's not happening, unless I enter previously something inside the Medium Text...

I tried to change the fields in the code so that the Medium Text fills the Short Text and the same thing is happeing...it just changes it if that field had some value previously...not when it's initial from scratch.

matias_z
Participant
0 Kudos

The process I follow is:

1-Fill all those fields shown in the screenshot

2-Hit Check...nothing happens to the Middle Text

3-Enter some value in the Middle Text and hit check

4-Remove that value of the Middle Text to leave it blank again and hit Check....NOW YES, the Short Text is entered in the Middle Text field.

sreenu_b2
Explorer
0 Kudos

Hi Matias,

Could you p-lease set the break-point and send the screen shot of io_changed_data return values.

The code as pointed by uday works when you have text translations in different tab. In your screen i see the short and medium text is along with entity details. So i am interested to see the changed data when you hit enter or check with short text entered.

IN debug what data is populated in lr_text_transl_table ,send that screen shot??

io_changed_data->read_data(

    EXPORTING

      i_entity               =  l_entity  " Entity Type

      i_struct               = if_usmd_model=>gc_struct_key_txt_langu   " Type of Data Structure

    IMPORTING

      er_t_data_mod          =   lr_text_transl_table  " "Modified" Data Records

  ).

Regards

Srinivasulu bandi

matias_z
Participant
0 Kudos

When using i_struct = 'KTXT' or 'KLTXT' I got nothing as result, empty table.

When not using any struct in in the read_data method I got the entire register, which is the one I'm trying to update, as this is the one which comes with values:

But not updating the TXTMI anyway

0 Kudos

Hi Matias,

The best way to update the medium text based on the short text is in the method IF_EX_USMD_RULE_SERVICE2~DERIVE of the BAdI: Derivations Across Entity Types

You can do this by create a BAdI implementation for the the BAdI definition USMD_RULE_SERVICE_CROSS_ET

Code snippet:

CALL METHOD io_changed_data->get_entity_types

    IMPORTING

      et_entity = lt_entity.

  CLEAR ls_entity.

  READ TABLE lt_entity INTO ls_entity INDEX 1.

  IF sy-subrc EQ 0.

    l_entity = ls_entity.

    lv_field = l_entity.

  ENDIF.

io_model->create_data_reference(

      EXPORTING

        i_fieldname = lv_field

        i_struct    = if_usmd_model=>gc_struct_key_txt_langu

        if_table    = 'X'

        i_tabtype   = if_usmd_model=>gc_tabtype_standard

      IMPORTING

        er_data     = lr_text_transl_table ).

  io_changed_data->read_data(

    EXPORTING

      i_entity               =  l_entity  " Entity Type

      i_struct               = if_usmd_model=>gc_struct_key_txt_langu   " Type of Data Structure

    IMPORTING

      er_t_data_mod          =   lr_text_transl_table  " "Modified" Data Records

  ).

  ASSIGN lr_text_transl_table->* TO <lt_data_mod>.

  LOOP AT <lt_data_mod> ASSIGNING <ls_data_ins>.

    ASSIGN COMPONENT 'TXTMI' OF STRUCTURE <ls_data_ins> TO <ls_mod> .

    IF sy-subrc IS INITIAL.

*Check =medium text maintained by user

      IF <ls_mod> IS NOT INITIAL.

        CONTINUE.

      ELSE.

        ASSIGN COMPONENT 'TXTSH' OF STRUCTURE <ls_data_ins> TO <ls_mod_ins> .

        IF sy-subrc IS INITIAL.

          <ls_mod> = <ls_mod_ins>.

          lv_update = abap_true.

        ENDIF.

      ENDIF.

    ENDIF.

  ENDLOOP.

  IF lv_update IS NOT INITIAL.

*Update the data back to context

    CALL METHOD io_write_data->write_data

      EXPORTING

        i_entity = l_entity

        it_data  = <lt_data_mod>.

  ENDIF.

Below is the MDGIMG node from where you can proceed to create a BAdI Implementation for derivation across entity types.

Best Regards

matias_z
Participant
0 Kudos

Hi Uday,

Thank's for the answer.

That's almost the exact code I already have in my system. And it does not work (I even tried using your code....same result).

Somehow it is not updating the Middle Text, if it is not entered previously.

Does it work in your system?

What the user enters are all the mandatory fields, except for the middle text...which is suppose to be filled automatically using the text entered in the Short Text field.

Thanks!

Matias

0 Kudos

Hi Matias,

That is interesting. For me it works when I follow below steps:

1. User opens Single Processing for Cost Center.

2. User enters the shot description in the tab Object Description

3. User clicks on Basic Data tab

4. User enters the mandatory fields - This is optional step (that is, does not affect the derivation)

5. Click on Check button

After step 5 if you navigate to the Object Description you will see the medium description populated (derived) with the same value as short description.

Thanks

Uday