Skip to Content
Technical Articles
Author's profile photo Mohamed Helfaya

How to Export CO46/MD04 to Spreadsheet

Some of the most important T-codes and views in SAP Production planning module are CO46 & MD04 We always need to extract them to Excel to check the planned orders and production order numbers and we cannot extract them directly to Excel so I will explain how to extract it:

First, you need to active BADI (MD_EXPORT_TREE) 

Got T-code: SE18

BADI

Click on Display

 

Then Click on Create BADI Implementation

After Creation just double-click on the created enhancement implementation

Expand Z_MD_EXPORT_TREE and double-click Implementing Class to modify the created implementation class:

Double-click the method IF_EX_MD_EXPORT_TREE~EXPORT_TREE or click the change button to implement this method

 

Then you have to add this code to this class as follows “Keep in mind that you have to take a copy from the standard code”:

METHOD IF_EX_MD_EXPORT_TREE~EXPORT_TREE.

* This example implementation creates a small ALV table based on
* the content of the order report tree. This table is printed using the


* type including fields to be printed
  TYPES: BEGIN OF table_type,
           node TYPE lvc_nkey,
           parent_node TYPE lvc_nkey,
           matnr TYPE matnr,
           berid TYPE berid,
           werks TYPE werks_d,
           bbdat TYPE dat00,
           delb0 TYPE delb0,
           delnr TYPE del12,
           delps TYPE delps,
           rcdat TYPE dat00,
           rceb0 TYPE delb0,
           rcenr TYPE del12,
           rceps TYPE delps,
           err01 TYPE aussl,
           msgxx TYPE msgxx,
    maktx TYPE makt-maktx,
         END OF table_type.

* table type including fields to be printed
  TYPES: t_table_type TYPE STANDARD TABLE OF table_type.

* local references to objects
  DATA: lr_table TYPE REF TO cl_salv_table,
        lr_columns TYPE REF TO cl_salv_columns,
        lr_print_obj TYPE REF TO cl_salv_print.

* local internal tables
  DATA: lt_fieldcat TYPE lvc_t_fcat,
        lt_tree_lines TYPE md_t_tree_struc,
        lt_tree_small TYPE t_table_type.


* local structures
  DATA: ls_tree_lines TYPE mdtreestruc,
        ls_tree_small TYPE table_type.



* transfer imported tables into local tables
  lt_fieldcat[] = it_fieldcat[].
  lt_tree_lines[] = it_tree_lines[].

* don't print all columns of the tree; create smaller table
select SINGLE maktx from makt INTO ls_tree_lines WHERE matnr = ls_tree_lines-matnr and spras = 'E'.
  LOOP AT lt_tree_lines INTO ls_tree_lines.
    MOVE-CORRESPONDING ls_tree_lines TO ls_tree_small.
    APPEND ls_tree_small TO lt_tree_small.
  ENDLOOP.


    DATA :
 GD_REPID     LIKE SY-REPID,
      G_SAVE TYPE C VALUE 'X',
      G_VARIANT TYPE DISVARIANT,
      GX_VARIANT TYPE DISVARIANT,
      G_EXIT TYPE C.
    data : wa_layout type slis_layout_alv.
       DATA : FIELD_CAT TYPE SLIS_FIELDCAT_ALV.
DATA : IT TYPE SLIS_T_FIELDCAT_ALV.
DATA : ls_tree_small2 TYPE TABLE OF table_type .


LOOP AT lt_tree_small ASSIGNING FIELD-SYMBOL(<fs>).
  APPEND <fs> TO ls_tree_small2 .


  ENDLOOP.


FIELD_CAT-FIELDNAME = 'NODE'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Sorting'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.

FIELD_CAT-FIELDNAME = 'PARENT_NODE'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'reference'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.

FIELD_CAT-FIELDNAME = 'MATNR'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Material'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.


FIELD_CAT-FIELDNAME = 'MAKTX'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'DESC.'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.

FIELD_CAT-FIELDNAME = 'BERID'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Planing Plant'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.


FIELD_CAT-FIELDNAME = 'WERKS'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Production Plant'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.

FIELD_CAT-FIELDNAME = 'DELB0'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'REQ Type'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.


FIELD_CAT-FIELDNAME = 'DELNR'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Sales order/REQ'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.


FIELD_CAT-FIELDNAME = 'DELPS'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Sales order item'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.


FIELD_CAT-FIELDNAME = 'RCEB0'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Item Type'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.


FIELD_CAT-FIELDNAME = 'RCENR'.
FIELD_CAT-TABNAME = 'ls_tree_small2'.
FIELD_CAT-SELTEXT_L = 'Order Number'.
APPEND FIELD_CAT TO IT.
CLEAR FIELD_CAT.




  GD_REPID = SY-REPID.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
is_layout = wa_layout
      I_CALLBACK_PROGRAM      = GD_REPID
*      I_CALLBACK_TOP_OF_PAGE  = 'TOP-OF-PAGE'  "see FORM
      I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
      IT_FIELDCAT             = IT[]
      I_SAVE                  = 'A'
      IS_VARIANT              = G_VARIANT

*IT_SORT = IT_SORT
    TABLES
      T_OUTTAB                = ls_tree_small2
    EXCEPTIONS
      PROGRAM_ERROR           = 1
      OTHERS                  = 2.
  IF SY-SUBRC <> 0.
  ENDIF.

ENDMETHOD.

Then you can open CO46 

Click on Export order tree 

You will be navigated to the created screen as follows:

Then you can export it to Excel

 

Hope this helps you,

Thanks to Mahmoud Elsherbiny, Alaa Azazi for helping me on this case. 

 

Thanks, 

 

 

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mahmoud Elsherbiny
      Mahmoud Elsherbiny

      Good Job

      Author's profile photo Mohamed Helfaya
      Mohamed Helfaya
      Blog Post Author

      Thanks Bro.

       

      Author's profile photo Kareem Hany
      Kareem Hany

      Very useful information Mohamed, thanks for sharing.

      Author's profile photo Mohamed Helfaya
      Mohamed Helfaya
      Blog Post Author

      Many thanks Eng. Kareem 🙏