SHARE
TWEET

Untitled

a guest Nov 25th, 2019 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *&---------------------------------------------------------------------*
  2. *& Report  ZTS_HG_SANDBOX
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  zts_hg_sandbox.
  10.  
  11. INCLUDE ole2incl.
  12.  
  13. TABLES sscrfields.
  14.  
  15.  
  16. SELECTION-SCREEN:
  17. BEGIN OF SCREEN 1,
  18.  PUSHBUTTON 2(10)  but1 USER-COMMAND cli1 VISIBLE LENGTH 10.
  19. SELECTION-SCREEN: END OF SCREEN 1.
  20.  
  21. DATA:  count TYPE i,
  22.        application TYPE ole2_object,
  23.        workbook TYPE ole2_object,
  24.        excel     TYPE ole2_object,
  25.        sheet TYPE ole2_object,
  26.        cells TYPE ole2_object.
  27. CONSTANTS: row_max TYPE i VALUE 256.
  28. DATA index TYPE i.
  29.  
  30. FIELD-SYMBOLS:  <itab1> TYPE ANY TABLE.
  31. *DATA: BEGIN OF itab1 OCCURS 0, first_name(10), END OF itab1.
  32. DATA: BEGIN OF itab2 OCCURS 0, last_name(10), END OF itab2.
  33. DATA: BEGIN OF itab3 OCCURS 0, place(50), END OF itab3.
  34.  
  35.  
  36. ************************************************************************
  37. *START-OF-SELECTION
  38. START-OF-SELECTION.
  39.  
  40.   but1 = 'Exportação'.
  41.  
  42.   CALL SCREEN 1.
  43.  
  44. AT SELECTION-SCREEN.
  45.   CASE sscrfields.
  46.     WHEN 'CLI1'.
  47.  
  48.       PERFORM zf_excel_export.
  49.  
  50.     WHEN 'CLI2'.
  51.  
  52.   ENDCASE.
  53.  
  54.  
  55. *&---------------------------------------------------------------------*
  56. *&      Form  zf_excel_export
  57. *&---------------------------------------------------------------------*
  58. *       text
  59. *----------------------------------------------------------------------*
  60. FORM zf_excel_export.
  61. *  APPEND: 'roshani' TO itab1,           'jain'   TO itab2,         'worli'      TO itab3,
  62. *          'nehal'   TO itab1,           'shah'   TO itab2,         'chowpatty'  TO itab3,
  63. *          'saad'    TO itab1,           'sheikh' TO itab2,         'versova'    TO itab3,
  64. *          'sushilnath' TO itab1,        'shukla' TO itab2,         'grant road' TO itab3,
  65. *          'ajju'    TO itab1,           'ratna'  TO itab2,         'gaon'       TO itab3,
  66. *          'sanant'  TO itab1,           'R.'     TO itab2,         'mahim'      TO itab3.
  67.  
  68.   DATA: v_hr_inicio TYPE sy-uzeit,
  69.         v_hr_fim    TYPE sy-uzeit.
  70.  
  71.   v_hr_inicio =  sy-uzeit.
  72.  
  73.   DATA lt_sflight TYPE SORTED TABLE OF sflight WITH UNIQUE KEY mandt carrid connid fldate.
  74.   ASSIGN lt_sflight TO <itab1>.
  75.  
  76.   SELECT *
  77.     FROM sflight
  78.     INTO TABLE <itab1>.
  79.  
  80.   CREATE OBJECT excel 'EXCEL.APPLICATION'.
  81.  
  82.   IF sy-subrc NE 0.
  83.     WRITE: / 'No EXCEL creation possible'.
  84.     STOP.
  85.   ENDIF.
  86.  
  87.   SET PROPERTY OF excel 'DisplayAlerts' = 0.
  88.  
  89.   CALL METHOD OF excel 'WORKBOOKS' = workbook .
  90.  
  91.   SET PROPERTY OF excel 'VISIBLE' = 1.
  92.  
  93.  
  94. *  Create worksheet
  95.   SET PROPERTY OF excel 'SheetsInNewWorkbook' = 1.
  96.   CALL METHOD OF workbook 'ADD'.
  97.  
  98.  
  99.   DO 30 TIMES.
  100.     IF sy-index GT 1.
  101.       CALL METHOD OF excel 'WORKSHEETS' = sheet.
  102.       CALL METHOD OF sheet 'ADD'.
  103.       FREE OBJECT sheet.
  104.     ENDIF.
  105.   ENDDO.
  106.  
  107.   count = 1.
  108.   DO 3 TIMES.
  109.  
  110.     CALL METHOD OF excel 'WORKSHEETS' = sheet
  111.       EXPORTING
  112.       #1 = count.
  113.  
  114.     FIELD-SYMBOLS <fs_line> TYPE sflight.
  115.  
  116. *    perform get_sheet_name using scnt sname.
  117.     CASE count.
  118.       WHEN '1'.
  119.         SET PROPERTY OF sheet 'NAME' = 'firstName'.
  120.         CALL METHOD OF sheet 'ACTIVATE'.
  121. *        <itab1>-carrid = 'FIRST NAME'.
  122.  
  123.         FIELD-SYMBOLS: <fs_value> TYPE ANY.
  124.         DATA l_index LIKE sy-index.
  125.  
  126.         LOOP AT <itab1> ASSIGNING <fs_line>.
  127.           index =  sy-tabix + 1. " 1 - column name
  128. *          index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
  129.           DO.
  130.             ASSIGN COMPONENT sy-index OF STRUCTURE <fs_line> TO <fs_value>.
  131.             l_index = sy-index.
  132.             IF sy-subrc IS NOT INITIAL.
  133.               EXIT.
  134.             ENDIF.
  135.  
  136.  
  137.  
  138.             CALL METHOD OF sheet 'Cells' = cells
  139.               EXPORTING #1 = index
  140.               #2 = l_index.
  141.  
  142.             SET PROPERTY OF cells 'Formula' = <fs_value>.
  143.             SET PROPERTY OF cells 'Value' = <fs_value>.
  144.  
  145.           ENDDO.
  146.  
  147.         ENDLOOP.
  148.  
  149.       WHEN '2'.
  150.         SET PROPERTY OF sheet 'NAME' = 'LastName'.
  151.         CALL METHOD OF sheet 'ACTIVATE'.
  152.         LOOP AT itab2.
  153.           index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
  154.           CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
  155.           SET PROPERTY OF cells 'Formula' = itab2-last_name.
  156.           SET PROPERTY OF cells 'Value' = itab2-last_name.
  157.  
  158.         ENDLOOP.
  159.  
  160.       WHEN '3'.
  161.         SET PROPERTY OF sheet 'NAME' = 'place'.
  162.         CALL METHOD OF sheet 'ACTIVATE'.
  163.         LOOP AT itab3.
  164.           index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
  165.           CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
  166.           SET PROPERTY OF cells 'Formula' = itab3-place.
  167.           SET PROPERTY OF cells 'Value' = itab3-place.
  168.  
  169.         ENDLOOP.
  170.  
  171.  
  172.     ENDCASE.
  173.     count = count + 1.
  174.  
  175.  
  176. **
  177.  
  178.   ENDDO.
  179.  
  180.   break 3j_abap.
  181.  
  182.   v_hr_fim =  sy-uzeit.
  183.  
  184.   WRITE: 'Hora Início' , v_hr_inicio.
  185.   WRITE: 'Hora fim' , v_hr_fim.
  186.  
  187. * Save excel speadsheet to particular filename
  188.  
  189.   GET PROPERTY OF excel 'ActiveSheet' = sheet.
  190.   CALL METHOD OF sheet 'SaveAs'
  191.                    EXPORTING #1 = 'C:\TEMP\tempexceldoc1.xls'     "filename
  192.                              #2 = 1.                          "fileFormat
  193.  
  194.  
  195.  
  196.  
  197.  
  198. ENDFORM.                    "zf_excel_export
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top