Routing Creation(CA01) - SAP Upload Tool - Using BDC.


Routing defines the sequence of activities performed at the work center. Routing plays an important role in calculating production cost, machine time, and labor time.

A routing is a description of which operations or list of activities has to be carried out during the production and planning process.
It also tells what order or sequence the activities/operations needs to be carried out at work centers or machines.

This program can be used for routing creation. Its a simple program which takes care of multiple options. This program also helps to generate the file format, which will remove the dependency on the file format all the time. 


SAMPLE PROGRAM:

REPORT zpp_routing_creation.
*&---------------------------------------------------------------------*
*& Report ZTEST
*&---------------------------------------------------------------------*
*& Report Name        : ZPP_ROUTING_CREATION
*& Report Title       : <Title>
*& Created By         : <Developer_Name>
*& Created On         : <Creation Date (DD/MM/YYYY)>
*& Module             : <MM, PP, SD, FI, etc.>
*& Object ID          : <Dev ID(As Per Tracker)>
*& TR No.             : <Transport Req. No.>
*& Description        : <What Is Report All About>
*&---------------------------------------------------------------------*
* Change Log:
*&---------------------------------------------------------------------*
*& No.       Date       Transport Request No.       Change Description
*&---------------------------------------------------------------------*


*Type Declaration

TYPES: BEGIN OF gty_rout,
         bom_count    TYPE i,
         matnr(40),
         werks(4),
         sttag(10),
         ktext(40),
         verwe(3),
         statu(1),
         losvn(16),
         losbs(16),
         plnme(4),
         slwbez(4),
         itm_count(4),
         arbpl(18),
         steus(4),
         ltxa1(40),
         bmsch(16),
         vgw01(16),
         vge01(5),
         vgw02(16),
         vge02(5),
         vgw03(16),
         vge03(5),
         vgw04(16),
         vge04(5),
         vgw05(16),
         vge05(5),
         usr00(20),
       END OF gty_rout.

TYPES: BEGIN OF gty_msg,
         msgtyp(1),
         matnr(18)   TYPE c,
         plnal(1),
         fldname(30),
         msgv1(100)  TYPE c,
       END OF gty_msg.

DATA: gwa_messtab TYPE bdcmsgcoll,
      gt_messtab  TYPE TABLE OF bdcmsgcoll,
      gwa_bdcdata TYPE bdcdata,
      gt_bdcdata  TYPE TABLE OF bdcdata.
DATA: gwa_msg TYPE gty_msg,
      gt_msg  TYPE TABLE OF gty_msg.

TYPES: BEGIN OF gty_mapl,
         matnr TYPE mapl-matnr,
         werks TYPE mapl-werks,
         plnty TYPE mapl-plnty,
         plnnr TYPE mapl-plnnr,
         plnal TYPE mapl-plnal,
         zkriz TYPE mapl-zkriz,
         zaehl TYPE mapl-zaehl,
         datuv TYPE mapl-datuv,
         loekz TYPE mapl-loekz,
       END OF gty_mapl.

DATA: gt_mapl   TYPE TABLE OF gty_mapl,
      gwa_mapl  TYPE gty_mapl,
      gt_rout   TYPE TABLE OF gty_rout,
      gwa_rout  TYPE gty_rout,
      gt_rout1  TYPE TABLE OF gty_rout,
      gwa_rout1 TYPE gty_rout,
      gwa_rout2 TYPE gty_rout.

DATA: lv_text(100)      TYPE c,
      lv_bomcount       TYPE i,
      lv_count          TYPE i,
      gv_count(2)       TYPE n,
      gv_field_name(25) TYPE c.


TYPES: BEGIN OF gty_rout_format,
         bom_count(40),
         matnr(40),
         werks(20),
         sttag(40),
         ktext(40),
         verwe(40),
         statu(40),
         losvn(40),
         losbs(40),
         plnme(40),
         slwbez(40),
         itm_count(40),
         arbpl(40),
         steus(40),
         ltxa1(40),
         bmsch(40),
         vgw01(40),
         vge01(40),
         vgw02(40),
         vge02(40),
         vgw03(40),
         vge03(40),
         vgw04(40),
         vge04(40),
         vgw05(40),
         vge05(40),
         usr00(40),
       END OF gty_rout_format.

DATA: gt_rout_format  TYPE TABLE OF gty_rout_format,
      gwa_rout_format TYPE gty_rout_format.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY LOWER CASE.
PARAMETERS: p_mode TYPE ctu_params-dismode DEFAULT 'N' NO-DISPLAY.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN: BEGIN OF LINE,
PUSHBUTTON 1(15) TEXT-002 USER-COMMAND form,
END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM get_file_name USING p_file.

AT SELECTION-SCREEN.
  IF sy-ucomm EQ 'FORM'.
    PERFORM download_format.
  ENDIF.

START-OF-SELECTION.

  PERFORM read_input_file.
  PERFORM fetch_data.

  SORT gt_rout BY bom_count itm_count.
  READ TABLE gt_rout INTO gwa_rout INDEX sy-tfill.
  lv_bomcount = gwa_rout-bom_count.

  lv_count = 1.
  WHILE lv_count <= lv_bomcount.
    CLEAR gwa_rout.
    CLEAR gwa_rout1.
    CLEAR gt_rout1.
    LOOP AT gt_rout INTO gwa_rout WHERE bom_count = lv_count.
      MOVE gwa_rout TO gwa_rout1.
      APPEND gwa_rout1 TO gt_rout1.
    ENDLOOP.
    PERFORM call_bdc.
    lv_count = lv_count + 1.
  ENDWHILE.

  PERFORM display_status.

*&---------------------------------------------------------------------*
*&      Form  get_file_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FILE  text
*----------------------------------------------------------------------*

FORM get_file_name USING pfile.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = ' '
    IMPORTING
      file_name     = pfile.
ENDFORM. " get_file_name

*&---------------------------------------------------------------------*
*&      Form  read_input_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM read_input_file.
  CLEAR: gwa_rout, gt_rout.

  DATA : lv_fname   TYPE localfile,
         i_raw_data TYPE truxs_t_text_data.

  MOVE  p_file TO lv_fname.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = ''
      i_line_header        = 'X'
      i_tab_raw_data       = i_raw_data
      i_filename           = lv_fname
    TABLES
      i_tab_converted_data = gt_rout
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  CALL_BDC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM call_bdc.
  CLEAR gwa_rout1.
  CLEAR gwa_rout2.
  gv_count = 1.
  READ TABLE gt_rout1 INTO gwa_rout2 INDEX 1.
  LOOP AT gt_rout1 INTO gwa_rout1.

** Inserting the Bom Header
    AT FIRST.
      PERFORM insert_header.
    ENDAT.

** Inserting the line item
*****************************************************************************
**For first Line item

    PERFORM bdc_dynpro      USING 'SAPLCPDI' '1400'.

    CONCATENATE 'PLPOD-VGE03('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING 'BDC_CURSOR' gv_field_name.
    PERFORM bdc_field       USING 'BDC_OKCODE' '/00'.

    CONCATENATE 'PLPOD-ARBPL('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-arbpl.                  "'TFWC0001'.

    CONCATENATE 'PLPOD-STEUS('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-steus.                  "'pp01'.

    CONCATENATE 'PLPOD-LTXA1('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-ltxa1.                  "'TCO Loading + Hand Seamer + Laser #1'.

    CONCATENATE 'PLPOD-BMSCH('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-bmsch.                  "'5'.

    CONCATENATE 'PLPOD-VGW01('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-vgw01.                   "'2'.

    CONCATENATE 'PLPOD-VGE01('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name 'MIN'.                  "'min'.

    CONCATENATE 'PLPOD-VGW02('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-vgw02.                  "'2'.

    CONCATENATE 'PLPOD-VGE02('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name 'MIN'.                  "'min'.

    CONCATENATE 'PLPOD-VGW03('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-vgw03.                  "'2'.

    CONCATENATE 'PLPOD-VGE03('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name 'KWH'.                  "'min'.

    CONCATENATE 'PLPOD-VGW04('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-vgw04.                  "'2'.

    CONCATENATE 'PLPOD-VGE04('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name 'MIN'.                  "'min'.

    CONCATENATE 'PLPOD-VGW05('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name gwa_rout1-vgw05.                  "'2'.

    CONCATENATE 'PLPOD-VGE05('  gv_count  ')' INTO gv_field_name.
    PERFORM bdc_field       USING gv_field_name 'PC'.                  "'pc'.

    IF gwa_rout1-steus = 'ZP99'.
      CLEAR gv_field_name.
      CONCATENATE 'RC27X-FLG_SEL('  gv_count  ')' INTO gv_field_name.

      PERFORM bdc_dynpro      USING 'SAPLCPDI' '1400'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'PLPOD-VORNR(01)'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=VOD1'.
      PERFORM bdc_field       USING 'RC27X-ENTRY_ACT'
                                    '1'.

      CLEAR gv_field_name.
      CONCATENATE 'RC27X-FLG_SEL('  gv_count  ')' INTO gv_field_name.

      PERFORM bdc_field       USING gv_field_name          " 'RC27X-FLG_SEL(01)'
                                    'X'.

      PERFORM bdc_dynpro      USING 'SAPLCPDO' '1200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'PLPOD-SLWID'.
      PERFORM bdc_field       USING 'PLPOD-SLWID'
                                    '0000001'.

      PERFORM bdc_dynpro      USING 'SAPLCPDO' '1200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '/00'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'PLPOD-USR00'.
      PERFORM bdc_field       USING 'PLPOD-SLWID'
                                    '0000001'.
      PERFORM bdc_field       USING 'PLPOD-USR00'
                                    gwa_rout1-usr00.          "'5'.

      PERFORM bdc_dynpro      USING 'SAPLCPDO' '1200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.

    ENDIF.

** To insert the new line item (if items are more than 26 in 1 BOM)
    IF gv_count = 26.
      PERFORM bdc_dynpro      USING 'SAPLCPDI' '1400'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'PLPOD-ARBPL(15)'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=P+'.
      PERFORM bdc_field       USING 'RC27X-ENTRY_ACT'
                                    '1'.
      gv_count = 1.
    ENDIF.

    gv_count = gv_count + 1.

    AT LAST.
      PERFORM bdc_dynpro      USING 'SAPLCPDI' '1400'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RC27X-ENTRY_ACT'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BU'.
      PERFORM bdc_field       USING 'RC27X-ENTRY_ACT'
                                    '1'.

      CALL TRANSACTION 'CA01' USING gt_bdcdata
                                              MODE p_mode
                                             UPDATE 'S'
                                             MESSAGES INTO gt_messtab.
**    For saving error message
      LOOP AT gt_messtab INTO gwa_messtab.

        gwa_msg-matnr = gwa_rout2-matnr.

        CALL FUNCTION 'FORMAT_MESSAGE'
          EXPORTING
            id        = gwa_messtab-msgid
            lang      = 'EN'
            no        = gwa_messtab-msgnr
            v1        = gwa_messtab-msgv1
            v2        = gwa_messtab-msgv2
            v3        = gwa_messtab-msgv3
            v4        = gwa_messtab-msgv4
          IMPORTING
            msg       = lv_text
          EXCEPTIONS
            not_found = 1
            OTHERS    = 2.

        gwa_msg-msgtyp  = gwa_messtab-msgtyp.
        gwa_msg-fldname = gwa_messtab-fldname.
        gwa_msg-msgv1 = lv_text .

        APPEND gwa_msg TO gt_msg.
        CLEAR: lv_text, gwa_msg.
      ENDLOOP.

      CLEAR: gt_bdcdata[].
      CLEAR gt_messtab.
    ENDAT.
  ENDLOOP.

ENDFORM. " CALL_BDC
*&---------------------------------------------------------------------*
*&      Form  insert_header
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM insert_header .
  DATA: lv_sttag TYPE sy-datum,
        lv_flag.

  CLEAR: lv_sttag, lv_flag.

  IF gt_rout IS NOT INITIAL.
    SELECT matnr werks plnty plnnr plnal zkriz zaehl datuv loekz
      FROM mapl
      INTO TABLE gt_mapl
      FOR ALL ENTRIES IN gt_rout
      WHERE matnr = gt_rout-matnr
      AND werks = gt_rout-werks
      AND plnty = 'N'.
  ENDIF.

  DELETE gt_mapl WHERE loekz IS NOT INITIAL.
  SORT gt_mapl BY matnr werks ASCENDING datuv ASCENDING.

  DELETE ADJACENT DUPLICATES FROM gt_mapl COMPARING matnr werks.

  PERFORM bdc_dynpro      USING 'SAPLCPDI' '1010'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'RC271-STTAG'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM bdc_field       USING 'RC27M-MATNR'
                                gwa_rout2-matnr.          "'T9500000001'.
  PERFORM bdc_field       USING 'RC27M-WERKS'
                                gwa_rout2-werks.          "'1000'.
  PERFORM bdc_field       USING 'RC271-STTAG'
                                gwa_rout2-sttag.          "'25.03.2009'.
  PERFORM bdc_field       USING 'RC271-PLNNR'
                              ''.

  LOOP AT gt_mapl INTO gwa_mapl WHERE matnr = gwa_rout2-matnr
                                  AND werks = gwa_rout2-werks.
    lv_flag = 'X'.
  ENDLOOP.

  IF lv_flag IS NOT INITIAL.
    PERFORM bdc_dynpro      USING 'SAPLCPDI' '1200'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RC27X-ENTRY_ACT'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ANLG'.
    PERFORM bdc_field       USING 'RC27X-ENTRY_ACT'
                                  '1'.

    PERFORM bdc_dynpro      USING 'SAPLCPDA' '1200'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM bdc_field       USING 'PLKOD-KTEXT'
                                  gwa_rout2-ktext.
    PERFORM bdc_field       USING 'PLKOD-WERKS'
                                  gwa_rout2-werks.
    PERFORM bdc_field       USING 'PLKOD-VERWE'
                                  gwa_rout2-verwe.
    PERFORM bdc_field       USING 'PLKOD-STATU'
                                  gwa_rout2-statu.
    PERFORM bdc_field       USING 'PLKOD-LOSVN'
                                  gwa_rout2-losvn.
    PERFORM bdc_field       USING 'PLKOD-LOSBS'
                                  gwa_rout2-losbs.
*    PERFORM bdc_field       USING 'PLKOD-PLNME'
*                                  gwa_rout2-plnme.

    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'PLKOD-SLWBEZ'.
    PERFORM bdc_field       USING 'PLKOD-SLWBEZ'
                                  gwa_rout2-slwbez.
  ENDIF.

  PERFORM bdc_dynpro      USING 'SAPLCPDA' '1200'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=VOUE'.

  PERFORM bdc_field       USING 'PLKOD-KTEXT'
                                gwa_rout2-ktext.          "'Thin Film 1/4 Module * 200 W'.
  PERFORM bdc_field       USING 'PLKOD-WERKS'
                                gwa_rout2-werks.          "'1000'.
  PERFORM bdc_field       USING 'PLKOD-VERWE'
                                gwa_rout2-verwe.          "'1'.
  PERFORM bdc_field       USING 'PLKOD-STATU'
                                gwa_rout2-statu.          "'4'.
  PERFORM bdc_field       USING 'PLKOD-LOSVN'
                                gwa_rout2-losvn.          "'1'.
  PERFORM bdc_field       USING 'PLKOD-LOSBS'
                                gwa_rout2-losbs.          "'99,999,999'.
  PERFORM bdc_field       USING 'PLKOD-PLNME'
                                gwa_rout2-plnme.          "'EA'.

  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'PLKOD-SLWBEZ'.
  PERFORM bdc_field       USING 'PLKOD-SLWBEZ'
                                gwa_rout2-slwbez.         "'100'.

ENDFORM. " insert_header


*&---------------------------------------------------------------------*
*&      Form  bdc_dynpro
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0294   text
*      -->P_0295   text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR gwa_bdcdata.
  gwa_bdcdata-program  = program.
  gwa_bdcdata-dynpro   = dynpro.
  gwa_bdcdata-dynbegin = 'X'.
  APPEND gwa_bdcdata TO gt_bdcdata.
  CLEAR gwa_bdcdata.
ENDFORM. "BDC_DYNPRO
*&---------------------------------------------------------------------*
*&      Form  bdc_field
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0299   text
*      -->P_0300   text
*----------------------------------------------------------------------*

FORM bdc_field USING fnam fval.
  CLEAR gwa_bdcdata.
  gwa_bdcdata-fnam = fnam.
  gwa_bdcdata-fval = fval.
  APPEND gwa_bdcdata TO gt_bdcdata.
  CLEAR: gwa_bdcdata.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  display_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_status .
  LOOP AT gt_msg INTO gwa_msg.
    WRITE: / gwa_msg-msgtyp ,' ', gwa_msg-matnr,' ',gwa_msg-plnal,' ',gwa_msg-fldname,' ', gwa_msg-msgv1.
  ENDLOOP.
ENDFORM. " display_status
*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fetch_data .

  LOOP AT gt_rout INTO gwa_rout.
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input  = gwa_rout-matnr
      IMPORTING
        output = gwa_rout-matnr.

    MODIFY gt_rout FROM gwa_rout.
  ENDLOOP.

  IF gt_rout IS NOT INITIAL.
    SELECT matnr werks plnty plnnr plnal zkriz zaehl datuv loekz
      FROM mapl
      INTO TABLE gt_mapl
      FOR ALL ENTRIES IN gt_rout
      WHERE matnr = gt_rout-matnr
      AND werks = gt_rout-werks
      AND plnty = 'N'.
  ENDIF.

  DELETE gt_mapl WHERE loekz IS NOT INITIAL.
  SORT gt_mapl BY matnr werks ASCENDING datuv ASCENDING.

  DELETE ADJACENT DUPLICATES FROM gt_mapl COMPARING matnr werks.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_FORMAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM download_format .
  DATA: gv_file  TYPE string VALUE 'C:\Users\ABCD\Documents\Routing_Creation.xls',
        lv_tabix TYPE sy-tabix.

  TYPES: var(1500) TYPE c,
         ty_excel  TYPE TABLE OF var.

  DATA: gt_excel          TYPE ty_excel WITH HEADER LINE,
        gv_sheet_name(20) TYPE c.

  DATA: w_cell1 TYPE ole2_object,
        w_cell2 TYPE ole2_object.

  DATA: gv_excel     TYPE ole2_object,
        gv_workbooks TYPE ole2_object,
        gv_sheet     TYPE ole2_object,
        worksheet    TYPE ole2_object,
        range        TYPE ole2_object,
        h_column     TYPE ole2_object.

  DATA: gv_delimiter(1) TYPE c,
        gv_rc           TYPE i.

  REFRESH: gt_excel.
  CLEAR: gv_delimiter, gv_rc, gt_excel.

  DATA: cells TYPE ole2_object,
        cell1 TYPE ole2_object,
        cell2 TYPE ole2_object,
        font  TYPE ole2_object.

  gv_delimiter = cl_abap_char_utilities=>horizontal_tab.

  REFRESH: gt_rout_format, gt_excel[].
  CLEAR: gwa_rout_format, gt_excel.

  gwa_rout_format-bom_count = 'Count'.
  gwa_rout_format-matnr = 'Material'.
  gwa_rout_format-werks = 'Plant'.
  gwa_rout_format-sttag = 'Key Date(DD.MM.YYYY)'.
  gwa_rout_format-ktext = 'Task List Description'.
  gwa_rout_format-verwe = 'Task List Usage'.
  gwa_rout_format-statu = 'Status'.
  gwa_rout_format-losvn = 'From Lot Size'.
  gwa_rout_format-losbs = 'To Lot Size'.
  gwa_rout_format-plnme = 'Task List Unit Of Measure'.
  gwa_rout_format-slwbez = 'Inspection Point'.
  gwa_rout_format-itm_count = 'Operation Number'.
  gwa_rout_format-arbpl = 'Work Center'.
  gwa_rout_format-steus = 'Control Key'.
  gwa_rout_format-ltxa1 =  'Operation Short Text'.
  gwa_rout_format-bmsch = 'Base Quantity'.
  gwa_rout_format-vgw01 = 'Machine'.
  gwa_rout_format-vge01 = 'UoM Machine'.
  gwa_rout_format-vgw02 = 'Labour'.
  gwa_rout_format-vge02 = 'UoM Labour'.
  gwa_rout_format-vgw03 = 'Power'.
  gwa_rout_format-vge03 = 'UoM Power'.
  gwa_rout_format-vgw04 = 'Repair & OH'.
  gwa_rout_format-vge04 = 'UoM Repair & OH'.
  gwa_rout_format-vgw05 = 'Cont. Labour'.
  gwa_rout_format-vge05 = 'UoM Cont. Labour'.
  gwa_rout_format-usr00 = 'Cavity'.
  INSERT gwa_rout_format INTO gt_rout_format INDEX 1.

  LOOP AT gt_rout_format INTO gwa_rout_format.
    CONCATENATE gwa_rout_format-bom_count
                gwa_rout_format-matnr gwa_rout_format-werks gwa_rout_format-sttag gwa_rout_format-ktext
                gwa_rout_format-verwe gwa_rout_format-statu gwa_rout_format-losvn gwa_rout_format-losbs
                gwa_rout_format-plnme gwa_rout_format-slwbez gwa_rout_format-itm_count gwa_rout_format-arbpl
                gwa_rout_format-steus gwa_rout_format-ltxa1 gwa_rout_format-bmsch gwa_rout_format-vgw01
                gwa_rout_format-vge01 gwa_rout_format-vgw02 gwa_rout_format-vge02 gwa_rout_format-vgw03
                gwa_rout_format-vge03 gwa_rout_format-vgw04 gwa_rout_format-vge04 gwa_rout_format-vgw05
                gwa_rout_format-vge05 gwa_rout_format-usr00
                INTO gt_excel SEPARATED BY gv_delimiter.
    APPEND gt_excel.
    CLEAR gt_excel.
  ENDLOOP.


  CREATE OBJECT gv_excel 'EXCEL.APPLICATION'.

  CALL METHOD OF gv_excel 'Workbooks' = gv_workbooks.
  CALL METHOD OF gv_workbooks 'Add' = gv_sheet.

  SET PROPERTY OF gv_excel 'Visible' = 1.

  gv_sheet_name = 'Routing Creation'.

  GET PROPERTY OF gv_excel   'ACTIVESHEET' = worksheet.
  SET PROPERTY OF worksheet 'Name'        = gv_sheet_name .

  CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
      data                 = gt_excel[]
    CHANGING
      rc                   = gv_rc
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.

  CALL METHOD OF gv_excel 'Cells' = cell1
    EXPORTING
      #1 = 1     "down
      #2 = 1.    "across

  CALL METHOD OF gv_excel 'Cells' = cell2
    EXPORTING
      #1 = 1     "down
      #2 = 27.   "across

  CALL METHOD OF gv_excel 'Range' = range
    EXPORTING
    #1 = cell1
    #2 = cell2.

  GET PROPERTY OF range 'Font' = font.
  SET PROPERTY OF font 'Bold' = 1.

  CALL METHOD OF gv_excel 'Cells' = cell1
    EXPORTING
    #1 = 2
    #2 = 1.

  CALL METHOD OF gv_excel 'Cells' = cell2
    EXPORTING
    #1 = 65535
    #2 = 11.

  CALL METHOD OF gv_excel 'Range' = range
    EXPORTING
    #1 = cell1
    #2 = cell2.

  SET PROPERTY OF range 'NumberFormat' = '@'.

  CALL METHOD OF gv_excel 'Cells' = w_cell1
    EXPORTING
    #1 = 1
    #2 = 1.
  CALL METHOD OF gv_excel 'Cells' = w_cell2
    EXPORTING
    #1 = 1
    #2 = 1.
  CALL METHOD OF gv_excel 'Range' = range
    EXPORTING
    #1 = w_cell1
    #2 = w_cell2.

  CALL METHOD OF range 'Select'.
  CALL METHOD OF worksheet 'Paste' NO FLUSH.

  CALL METHOD OF gv_excel 'Columns' = h_column.
  CALL METHOD OF h_column 'Autofit'.
  FREE OBJECT h_column.

  CALL METHOD OF worksheet 'SAVEAS'
    EXPORTING
      #1 = gv_file
      #2 = 1.

  CALL METHOD OF worksheet 'CLOSE'.
  CALL METHOD OF gv_excel 'CLOSE'.
  CALL METHOD OF gv_workbooks 'CLOSE'.
  CALL METHOD OF gv_workbooks 'QUIT'.
  CALL METHOD OF gv_excel 'QUIT'.
  CALL METHOD OF worksheet 'QUIT'.

  FREE OBJECT: gv_workbooks,
               gv_sheet,
               gv_excel.

ENDFORM.





Comments

Also Read...