Skip to Content

This brief document explains about Standard behavior of SAP to Sort Unit of Measurement at MM03 screen level and Idoc Segment Level  , As Idoc function Module uses ‘MASTERIDOC_CREATE_MATMAS to create Materials, and if we check the Sorting format of Unit of Measurement at Idoc Level then it’s sorted as per table MARM sorting format.

However, Sometimes customer can ask to use same Sorting Format as they see it in MM03 Transaction Code. So to achieve this similar functionality to be implemented in standard SAP behavior, we need to add custom ABAP code. Hence this document illustrates these custom code and existing behavior.

Existing Sorting Format:

MMR (Material Master Display- MM03):

            Below screen shows the Sorting format of Unit of Measurement at MMR level.

Idoc_sdn_1.JPG

Table MARM:

Below screen shows the Sorting format of Unit of Measurement at dictionary level.

Idoc_sdn_2.JPG

          Now, Sort the segments concerning the logistic formats (MMR level) of a material in Idoc Segment E1MARMM and its sub-segments in the same logic as at the time of display of these logistic formats in the transaction MM03 / Additional data / Unit of measure, i.e. sort in ascending order.

         In the E1MARMM segments and their sub-segments, we should have the picture of the transaction MM03 (PCE, CAR, S02, S03 & LOT).

          As per standard process existing in SAP, We use Idoc function Module MASTERIDOC_CREATE_MATMAS to capture the Material Master in Idoc Segment. SAP reads the unit of Measure data in below loop using Function Module ‘MARM_SINGLE_READ’ based on Material Number.

    
Idoc_sdn_3.JPG

The above logic adds the unit of measure to T_IDOC_DATA from the MARM table, based on their order available in the database.   Ie: CAR, LOT, S02, S03, and ST (ref above Screen Shot).           

We have no development point available for above Idoc, only we can use the FUNCTION-CLIENT « 002 » Customer Exit; it is there where we can change the order of the unit of measure.

Idoc_sdn_4.JPG

In the CUSTOMER-FUNCTION ‘002’, we need to write below code.

Idoc_cimtype = ‘ZMATMAS03 ’.   Your Extension

CASE : idoc_data-segnam. «  Idoc Segment

  WHEN ‘E1MARMM’.

     CLEAR zlarm01.

     DATA: BEGIN OF meinh OCCURS 0.

             INCLUDE STRUCTURE smeinh                         .

     DATA: END   OF meinh.

     DATA: BEGIN OF meinh_orig OCCURS 0.

             INCLUDE STRUCTURE smeinh.

     DATA: END   OF meinh_orig.

     DATA: mara TYPE STANDARD TABLE OF mara WITH HEADER LINE,

           lv_mesub TYPE marm-mesub,

           sort_tab TYPE STANDARD TABLE OF smeinh,

           wa_meinh TYPE smeinh,

           n_meinh TYPE smeinh,

           hmeinh TYPE STANDARD TABLE OF smeinh.

     DATA: tabix TYPE sy-tabix,

           insert_index LIKE sy-tabix,

           counter TYPE i,

           lineTYPE i,

           doppeleintrag(1) TYPE c,

           l_fname(50) TYPE c,

           lv_tabix TYPE sy-tabix.

     DATA: it_t006a TYPE STANDARD TABLE OF t006a

                     INITIAL SIZE 0 WITH HEADER LINE.

     CLEAR lv_tabix.

     SELECT * FROM marm

              INTO CORRESPONDING FIELDS OF TABLE meinh

WHERE matnr = f_marm-matnr.

     IF sy-subrc = 0.

       meinh_orig[] = meinh[].

     ENDIF.

     SELECT * FROM mara

              INTO CORRESPONDING FIELDS OF TABLE mara

WHERE matnr = f_marm-matnr.

     READ TABLE mara INDEX 1.

     READ TABLE meinh WITH KEY mara-meins.

     IF sy-subrc = 0.

       meinh-kzbme = ‘x’.

       MODIFY meinh INDEX sy-tabix.

     ENDIF.

     READ TABLE meinh WITH KEY kzbme = ‘x’.

     IF sy-subrc = 0.

       lv_mesub = meinh-meinh.

     ENDIF.

     LOOP AT meinh.

       lv_tabix = sy-tabix.

       IF meinh-mesub EQ space.

         meinh-mesub = lv_mesub.

         MODIFY meinh INDEX lv_tabix.

       ENDIF.

     ENDLOOP.

     READ TABLE meinh WITH KEY kzbme = ‘x’ INTO wa_meinh.

     CHECK sy-subrc = 0.

     APPEND wa_meinh TO sort_tab.

     LOOP AT sort_tab INTO wa_meinh.

       insert_index = sy-tabix + 1.

       REFRESH hmeinh.

       LOOP AT meinh INTO n_meinh WHERE mesub = wa_meinh-meinh.

         CHECK n_meinh-meinh NE wa_meinh-meinh.     

         n_meinh-azsub = n_meinh-umrez / n_meinh-umren.

         APPEND n_meinh TO hmeinh.

       ENDLOOP.

       SORT hmeinh BY azsub ASCENDING meinh.

       INSERT LINES OF hmeinh INTO sort_tab INDEX insert_index.

       wa_meinh-kzsub = ‘x’.

       READ TABLE meinh WITH KEY meinh = wa_meinh-meinh.

       counter = 0.

       LOOP AT meinh WHERE meinh = wa_meinh-meinh.

         counter = counter + 1.

         line = sy-tabix.

       ENDLOOP.

       IF counter = 1.

         MODIFY meinh FROM wa_meinh INDEX line.

       ELSE.

         doppeleintrag = ‘x’.

         EXIT.

       ENDIF.

     ENDLOOP.

     IF doppeleintrag IS INITIAL.

       LOOP AT meinh INTO wa_meinh WHERE kzsub IS initial.

         APPEND wa_meinh TO sort_tab.

       ENDLOOP.

       REFRESH meinh.

       meinh[] = sort_tab.

     ELSE.

* sind Eintraege doppelt, wird nicht sortierte meinh zurueckgegeben

       LOOP AT meinh INTO wa_meinh WHERE kzsub = ‘x’.

         CLEAR wa_meinh-kzsub.

         MODIFY meinh FROM wa_meinh.

       ENDLOOP.

     ENDIF.

     IF NOT meinh IS INITIAL.

       SELECT * FROM t006a

                  INTO TABLE it_t006a

                  FOR ALL ENTRIES IN meinh

                   WHERE  spras = sy-langu

                      AND msehi = meinh-meinh.

     ENDIF.

     READ TABLE meinh_orig WITH KEY meinh = f_marm-meinh

TRANSPORTING NO FIELDS.

     IF sy-subrc = 0.

       tabix = sy-tabix.

       READ TABLE meinh INDEX tabix.

       IF sy-subrc = 0.

         READ TABLE it_t006a WITH KEY msehi = meinh-meinh.

         IF sy-subrc = 0.

           DATA: lv_sdata(1000) TYPE c.

           DATA: lv_iso_meinh LIKE marm-meinh,

                 lv_iso_meabm LIKE marm-meabm,

                 lv_iso_voleh LIKE marm-voleh,

                 lv_iso_gewei LIKE marm-gewei,

                 lv_iso_mesub LIKE marm-mesub.

           DATA: record TYPE sy-tabix.

           DATA: lv_mean_meinh TYPE marm-meinh.

           CLEAR: lv_mean_meinh, lv_iso_meabm, lv_iso_voleh,

                  lv_iso_gewei, lv_iso_mesub.

           lv_mean_meinh = meinh-meinh.

           zlarm01-meinh = meinh-meinh.

*ISO code of Sorted Unit of Measurement

           CALL FUNCTION ‘UNIT_OF_MEASURE_SAP_TO_ISO’

                EXPORTING

sap_code    = meinh-meinh

                IMPORTING

                     iso_code    = lv_iso_meinh

                EXCEPTIONS

not_found   = 01

                     no_iso_code = 02.

           IF sy-subrc <> 0.

           ENDIF.

           meinh-meinh = lv_iso_meinh.

« Note : In the same way, Convert Unit of measurement to ISO using abobe Function Module for meabm, voleh, gewei, mesub«

           DESCRIBE TABLE idoc_data LINES record.

           READ TABLE idoc_data INDEX record.

           IF sy-subrc = 0.

             MOVE-CORRESPONDING meinh TO e1marmm.

             CONDENSE:  e1marmm-msgfn,

e1marmm-meinh,

e1marmm-umrez,

e1marmm-umren,

e1marmm-ean11,

e1marmm-numtp,

e1marmm-laeng,

e1marmm-breit,

e1marmm-hoehe,

e1marmm-meabm,

e1marmm-volum,

e1marmm-voleh,

e1marmm-brgew,

e1marmm-gewei,

e1marmm-mesub.

             e1marmm-msgfn = idoc_data-sdata(3).

             idoc_data-sdata = e1marmm.

             MODIFY idoc_data INDEX record.

           ENDIF.

           idoc_data-segnam = ‘ZLARM01’.

           idoc_data-sdata  = zlarm01.

           APPEND idoc_data.

The above explanation is to Sort Unit of Measurement at Idoc level.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply