Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
Read only

Delete characteristic values with batch input - MM02

umtyzc
Participant
0 Likes
2,120

Hi all, i want to mass deletion for materials characteristic value. I use the following batch program to change or add characteristic value for materials. But I can't delete with the same method.



How can i delete  characteristic value using SHDB session?





type-pools: slis.

data : begin of itab occurs 0 ,

         bismt(18)             , " Malzeme

         maktx(40)             , " Tanımı

         karakteristik_degeri(70)             ,

         karakteristik_grubu(30)            ,

        end of itab            .

data : bdctab like bdcdata occurs 0 with header line.

data : messtab like bdcmsgcoll occurs 0 with header line.

data : begin of returntab occurs 0    ,

         matnr   like mara-matnr       ,

         message like bapiret2-message ,

        end of returntab               .

data : gv_mode(1) .

selection-screen begin of block b1 with frame title text-001 .

parameters : p_backg radiobutton group bb ,

              p_foreg radiobutton group bb default 'X' ,

              p_error radiobutton group bb .

selection-screen end of block b1 .

selection-screen begin of block b2 with frame title text-002 .

parameters : p_fname like rlgrap-filename obligatory .

selection-screen end of block b2 .

at selection-screen on value-request for p_fname .

   perform query_filename changing p_fname .

start-of-selection .

   perform get_data .

   if returntab[] is initial .

     perform batch .

   endif .

   perform display_message .

*&---------------------------------------------------------------------*

*&      Form  QUERY_FILENAME

*&---------------------------------------------------------------------*

form query_filename changing def_path .

   data: lt_file type filetable,

         lv_rc   like sy-subrc,

         ls_file like line of lt_file.

   call method cl_gui_frontend_services=>file_open_dialog

     changing

       file_table              = lt_file

       rc                      = lv_rc

     exceptions

       file_open_dialog_failed = 1

       cntl_error              = 2

       error_no_gui            = 3

       others                  = 4.

   if sy-subrc eq 0.

     read table lt_file into ls_file index 1.

     def_path = ls_file-filename.

   else.

     message e002(z01) with 'Dosya bulunamadı.' .

   endif.

endform.                    " QUERY_FILENAME

*&---------------------------------------------------------------------*

*&      Form  GET_DATA

*&---------------------------------------------------------------------*

form get_data .

   data : begin of lt_mtab occurs 0 ,

           bismt like mara-bismt    ,

           index type int4          ,

          end of lt_mtab            .

   data : rawdata(4096) type c occurs 0 ,

          lv_atinn1 like cawn-atinn .

   if p_backg = 'X' .

     gv_mode = 'N' .

   elseif p_foreg = 'X' .

     gv_mode = 'A' .

   elseif p_error = 'X' .

     gv_mode = 'E' .

   endif .

   call function 'SAPGUI_PROGRESS_INDICATOR'

     exporting

       text = 'Excel dosyası iƧeri okunuyor...'.

   call function 'TEXT_CONVERT_XLS_TO_SAP'

     exporting

       i_tab_raw_data       = rawdata

       i_filename           = p_fname

     tables

       i_tab_converted_data = itab

     exceptions

       conversion_failed    = 1

       others               = 2.

   if sy-subrc <> 0 .

     message e002(z01) with 'Dosya hatalı, SAP iƧine alınamadı.' .

   endif.

   do 1 times .

     delete itab index 1 .

   enddo .

   delete itab where bismt = space .

   loop at itab .

** Kontroller

** 1. Eski malzeme no

     select single bismt from mara

       into itab-bismt

      where bismt = itab-bismt

        and lvorm = space .

     if sy-subrc ne 0 .

       returntab-matnr = itab-bismt .

       returntab-message = text-004 .

       append returntab .

       clear  returntab .

     endif .

   endloop .

endform.                    " GET_DATA

*&---------------------------------------------------------------------*

*&      Form  BATCH

*&---------------------------------------------------------------------*

form batch .

   loop at itab .

     perform fill_bdctab .

     perform call_transaction.

     perform move_messtab .

     clear : bdctab, bdctab[].

   endloop.

endform.                    " BATCH

*&---------------------------------------------------------------------*

*&      Form  CALL_TRANSACTION

*&---------------------------------------------------------------------*

form call_transaction .

   call transaction 'MM02' using bdctab mode gv_mode update 'S'

                                         messages into messtab .

endform.                    " CALL_TRANSACTION

*&---------------------------------------------------------------------*

*&      Form  MOVE_MESSAGE

*&---------------------------------------------------------------------*

form move_message .

   data lv_text(480) .

   loop at messtab .

     if messtab-msgtyp = 'S' .

       check not messtab-msgv1 is initial .

     endif .

     clear lv_text .

     select single text from t100

       into lv_text

      where sprsl = messtab-msgspra

        and arbgb = messtab-msgid

        and msgnr = messtab-msgnr.

     check not lv_text is initial .

     if lv_text cs '&1'.

       replace '&1' with messtab-msgv1 into lv_text .

       replace '&2' with messtab-msgv2 into lv_text .

       replace '&3' with messtab-msgv3 into lv_text .

       replace '&4' with messtab-msgv4 into lv_text .

     else.

       replace '&' with messtab-msgv1 into lv_text .

       replace '&' with messtab-msgv2 into lv_text .

       replace '&' with messtab-msgv3 into lv_text .

       replace '&' with messtab-msgv4 into lv_text .

     endif.

     condense lv_text .

     returntab-message = lv_text .

     collect returntab .

     clear   returntab .

   endloop .

   clear : messtab, messtab[].

endform.                    " MOVE_MESSAGE

*&---------------------------------------------------------------------*

*&      Form  DISPLAY_MESSAGE

*&---------------------------------------------------------------------*

form display_message .

** ALV iƧin tanımlamalar

   data : lv_repid    like sy-repid            ,

          lt_fieldcat type slis_t_fieldcat_alv ,

          ls_layout   type slis_layout_alv     ,

          ls_fieldcat type slis_fieldcat_alv   .

   check not returntab[] is initial .

* Listelenecek alan katalogu olusturulur

   lv_repid = sy-repid .

   call function 'REUSE_ALV_FIELDCATALOG_MERGE'

     exporting

       i_program_name     = lv_repid

       i_internal_tabname = 'RETURNTAB'

       i_inclname         = lv_repid

     changing

       ct_fieldcat        = lt_fieldcat[].

   loop at lt_fieldcat into ls_fieldcat .

     case ls_fieldcat-fieldname.

       when 'MESSAGE' .

         ls_fieldcat-seltext_l  = 'İletiler'(003).

     endcase .

     ls_fieldcat-seltext_s = ls_fieldcat-seltext_m

               = ls_fieldcat-seltext_l .

     ls_fieldcat-ddictxt = 'L'.

     modify lt_fieldcat from ls_fieldcat index sy-tabix .

   endloop .

   ls_layout-zebra             = 'X' .    " Ƈizgili desen

   ls_layout-cell_merge        = 'X' .    " Hücreleri birleştir

   ls_layout-colwidth_optimize = 'X' .    " Sütun optimizasyonu

   ls_layout-detail_popup      = 'X' .

** Display

   call function 'REUSE_ALV_GRID_DISPLAY'

     exporting

       i_callback_program = lv_repid

       is_layout          = ls_layout

       it_fieldcat        = lt_fieldcat[]

     tables

       t_outtab           = returntab[]

     exceptions

       program_error      = 1

       others             = 2.

endform.                    " DISPLAY_MESSAGE

*&---------------------------------------------------------------------*

*&      Form  FILL_BDCTAB

*&---------------------------------------------------------------------*

form fill_bdctab .

   perform bdc_dynpro using 'SAPLMGMM'         '0060'.

   perform bdc_field  using 'RMMG1-MATNR'      itab-bismt.

   perform bdc_field  using 'BDC_OKCODE'       '=ENTR'.

   perform bdc_dynpro using 'SAPLMGMM'         '0070'.

   perform bdc_field  using 'BDC_CURSOR'  'MSICHTAUSW-DYTXT(03)'.

   perform bdc_field  using 'MSICHTAUSW-KZSEL(03)'  'X'.

   perform bdc_field  using 'BDC_OKCODE'   '=ENTR'.

*-> Sınıflandırma

   perform bdc_dynpro using 'SAPLCLCA'         '0602'.

   perform bdc_field  using 'BDC_CURSOR'       'RMCLF-KLART'.

   perform bdc_field  using 'RMCLF-KLART'      '001'.

   perform bdc_field  using 'BDC_OKCODE'       '=ENTE' .

   perform bdc_dynpro using 'SAPLCLFM'         '0500'.

   perform bdc_field  using 'BDC_CURSOR'       'RMCLF-CLASS(01)' .

   perform bdc_field  using 'BDC_OKCODE'       '=AUSW' .

   perform bdc_dynpro using 'SAPLCTMS'         '0109'.

   perform bdc_field  using 'RCTMS-MNAME(01)'  itab-karakteristik_grubu .

   perform bdc_field  using 'RCTMS-MWERT(01)'  itab-karakteristik_degeri

   .

   perform bdc_field  using 'BDC_OKCODE'       '=BACK' .

   perform bdc_dynpro using 'SAPLCLFM'         '0500'.

   perform bdc_field  using 'BDC_OKCODE'       '=SAVE' .

endform.                    " FILL_BDCTAB

*&---------------------------------------------------------------------*

*&      Form  BDC_DYNPRO

*&---------------------------------------------------------------------*

form bdc_dynpro using program dynpro.

   clear bdctab.

   bdctab-program = program.

   bdctab-dynpro = dynpro.

   bdctab-dynbegin = 'X'.

   append bdctab.

endform.                               " BDC_DYNPRO

*&---------------------------------------------------------------------*

*&      Form  BDC_FIELD

*&---------------------------------------------------------------------*

form bdc_field using fnam fval.

   clear bdctab.

   bdctab-fnam = fnam.

   bdctab-fval = fval.

   append bdctab.

endform.                               " BDC_FIELD

*&---------------------------------------------------------------------*

*&      Form  MOVE_MESSTAB

*&---------------------------------------------------------------------*

form move_messtab .

   data : lv_text(480) ,

          lv_matnr like mara-matnr .

   loop at messtab where msgtyp = 'E' or msgtyp = 'S' .

     if messtab-msgtyp = 'S' .

       check not messtab-msgv1 is initial .

     endif .

     clear lv_text .

     select single text from t100

       into lv_text

      where sprsl = messtab-msgspra

        and arbgb = messtab-msgid

        and msgnr = messtab-msgnr.

     check not lv_text is initial .

     if lv_text cs '&1'.

       replace '&1' with messtab-msgv1 into lv_text .

       replace '&2' with messtab-msgv2 into lv_text .

       replace '&3' with messtab-msgv3 into lv_text .

       replace '&4' with messtab-msgv4 into lv_text .

     else.

       replace '&' with messtab-msgv1 into lv_text .

       replace '&' with messtab-msgv2 into lv_text .

       replace '&' with messtab-msgv3 into lv_text .

       replace '&' with messtab-msgv4 into lv_text .

     endif.

     condense lv_text .

     if messtab-msgtyp = 'S' and

        messtab-msgspra = 'T' and

        messtab-msgid = 'M3' and

        messtab-msgnr = '800' and

        not messtab-msgv1 is initial .

       call function 'CONVERSION_EXIT_MATN1_INPUT'

         exporting

           input        = messtab-msgv1

         importing

           output       = returntab-matnr

         exceptions

           length_error = 1

           others       = 2.

     endif .

     returntab-message = lv_text .

     collect returntab .

     clear   returntab .

   endloop .

   clear : messtab, messtab[].

endform.                    " MOVE_MESSTAB

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,562

Hi,

Did you consider using FM BAPI_OBJCL_DELETE? BDC can be very very painful.

R

4 REPLIES 4
Read only

Former Member
0 Likes
1,563

Hi,

Did you consider using FM BAPI_OBJCL_DELETE? BDC can be very very painful.

R

Read only

0 Likes
1,562

Hi Rudra, How can i do mass change using BAPI_OBJCL_DELETE?

Can you give an example code?

Read only

0 Likes
1,562

Here you go.

Just tested it. Works like a charm.

DATA : lta_allocvaluesnum  TYPE TABLE OF bapi1003_alloc_values_num,

        lta_allocvalueschar TYPE TABLE OF bapi1003_alloc_values_char,

        lta_allocvaluescurr TYPE TABLE OF bapi1003_alloc_values_curr,

        lwa_allocvalueschar TYPE bapi1003_alloc_values_char,

        lta_return_code     TYPE TABLE OF bapiret2.

CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'

   EXPORTING

     objectkey              = <Material internal format>

     objecttable            = 'MARA'

     classnum               = <Class name> as you see in MM03

     classtype              = '001'

   TABLES

     allocvaluesnum         = lta_allocvaluesnum

     allocvalueschar        = lta_allocvalueschar

     allocvaluescurr        = lta_allocvaluescurr

     return                 = lta_return_code

           .

READ TABLE lta_return_code TRANSPORTING NO FIELDS WITH KEY type = 'E'.

CHECK sy-subrc NE 0.

REFRESH lta_return_code.

CALL FUNCTION 'BAPI_OBJCL_DELETE'

   EXPORTING

     objectkey    = <Material internal format>

     objecttable  = 'MARA'

     classnum     = <Class name> as you see in MM03

     classtype    = '001'

   TABLES

     return       = lta_return_code.

READ TABLE lta_return_code TRANSPORTING NO FIELDS WITH KEY type = 'E'.

CHECK sy-subrc NE 0.

DELETE lta_allocvalueschar WHERE charact = <Characteristic>. "Delete the characteristic we don't want. For multple use loop or any condition

CALL FUNCTION 'BAPI_OBJCL_CREATE'

   EXPORTING

     objectkeynew            = <Material internal format>

     objecttablenew          = 'MARA'

     classnumnew             = <Class name> as you see in MM03

     classtypenew            = '001'    "<- '001' for mat class , '023' for batch class

   TABLES

     allocvaluesnum         = lta_allocvaluesnum

     allocvalueschar        = lta_allocvalueschar

     allocvaluescurr        = lta_allocvaluescurr

     return                 = lta_return_code

           .

READ TABLE lta_return_code TRANSPORTING NO FIELDS WITH KEY type = 'E'.

CHECK sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.


R

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,562

Hint: Post only relevant part of the code related to problem (we don't need the upload part, and the definition of the good old BDC form is widely known)

Did you perform some search on available BAPI/IDOC

  • material specific as ALE type CLFMAS
  • generic characteristics: BAPI_OBJCL_GETDETAIL_KEY,  BAPI_OBJCL_DELETE

There are already some threads/documents available at scn.

Regards,

Raymond