Пример макроса
*&———————————————————————*
*& Report Z_TEST_MACROS_NIK
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT z_test_macros_nik.
DATA: result TYPE i,
n1 TYPE i VALUE 5,
n2 TYPE i VALUE 6.
DEFINE operation.
result = &1 &2 &3.
output &1 &2 &3 result.
END-OF-DEFINITION.
DEFINE output.
WRITE: / ‘The result of &1 &2 &3 is’, &4.
END-OF-DEFINITION.
operation 4 + 3.
operation 2 ** 7.
operation n2 – n1.
Объекты блокировки
REPORT z_test_block_nik.
DATA: lv_block TYPE c,
lv_name TYPE zavto–name.
lv_name = ‘car1’.
DATA lv_user_block LIKE sy–uname.
CALL FUNCTION ‘ENQUEUE_EZ_TEST_BLOCK’
EXPORTING
name = lv_name
EXCEPTIONS
OTHERS = 1.
IF sy–subrc <> 0.
WRITE : ‘Заблокировать не удалось’.
ELSE.
CALL FUNCTION ‘DEQUEUE_EZ_TEST_BLOCK’
EXPORTING
name = lv_name.
ENDIF.
OLE MS WORD
*&———————————————————————*
*& Report ZOLE_TEST_NIK
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT zole_test_nik.
INCLUDE ole2incl.
DATA: word TYPE ole2_object,
documents TYPE ole2_object,
actdoc TYPE ole2_object,
application TYPE ole2_object,
options TYPE ole2_object,
actwin TYPE ole2_object,
actpan TYPE ole2_object,
view TYPE ole2_object,
selection TYPE ole2_object,
font TYPE ole2_object,
parformat TYPE ole2_object,
tables TYPE ole2_object,
range TYPE ole2_object,
table TYPE ole2_object,
table_border TYPE ole2_object,
cell TYPE ole2_object,
paragraph TYPE ole2_object.
DATA position(5) TYPE n.
START-OF-SELECTION.
CREATE OBJECT word ‘WORD.APPLICATION’.
IF sy-subrc NE 0 .
MESSAGE s000(su) WITH ‘ERROR creating OLE obj!’.
LEAVE PROGRAM.
ENDIF.
SET PROPERTY OF word ‘Visible’ = ‘1’.
GET PROPERTY OF word ‘DOcuments’ = documents.
GET PROPERTY OF application ‘Options’ = options.
SET PROPERTY OF options ‘MeasurmentUnit’ = ‘1’.
GET PROPERTY OF application ‘Selection’ = selection.
GET PROPERTY OF selection ‘Font’ = font.
GET PROPERTY OF selection ‘ParagraphFormat’ = parformat.
SET PROPERTY OF font ‘Name’ = ‘Arial’.
SET PROPERTY OF font ‘Size’ = ’10’.
SET PROPERTY OF font ‘Bold’ = ‘0’.
SET PROPERTY OF font ‘Italic’ = ‘1’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
SET PROPERTY OF parformat ‘Aligment’ = ‘2’.
CALL METHOD OF selection ‘TypeText’
EXPORTING
#1 = ‘This is OLE Example!’.
SET PROPERTY OF view ‘SeekView’ = ‘0’.
“——SET HEADER TEXT
SET PROPERTY OF font ‘Name’ = ‘Times New Roman’.
SET PROPERTY OF font ‘Size’ = ’16’.
SET PROPERTY OF font ‘Bold’ = ‘1’.
SET PROPERTY OF font ‘Italic’ = ‘0’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
SET PROPERTY OF parformat ‘Aligment’ = ‘1’.
CALL METHOD OF selection ‘TypeText’
EXPORTING
#1 = text-000.
“———–cursor to the new line
CALL METHOD OF selection ‘TypeParagraph’.
“———–write the title
SET PROPERTY OF font ‘Name’ = ‘Times New Roman’.
SET PROPERTY OF font ‘Size’ = ’12’.
SET PROPERTY OF font ‘Bold’ = ‘0’.
SET PROPERTY OF font ‘Italic’ = ‘0’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
SET PROPERTY OF parformat ‘Aligment’ = ‘3’.
CALL METHOD OF selection ‘TypeText’
EXPORTING
#1 = text-001.
“———–SKIP 4 lines
DO 4 TIMES.
CALL METHOD OF selection ‘TypeParagraph’.
ENDDO.
“———–INSERT TABLE
GET PROPERTY OF actdoc ‘Tables’ = tables.
GET PROPERTY OF selection ‘Range’ = range.
“———–ADD 3 Rows INTO TABLE
CALL METHOD OF
tables
‘Add’ = table
EXPORTING
#1 = range “HANDLE for range entity
#2 = ‘3’ “Num of rows
#3 = ‘2’. “Num columns
“————SET Border Attrib
GET PROPERTY OF table ‘Borders’ = table_border.
SET PROPERTY OF table_border ‘Enable’ = ‘1’.
“————Filling table
“————Reset attr for table content
SET PROPERTY OF font ‘Name’ = ‘Garamond’.
SET PROPERTY OF font ‘Size’ = ’11’.
SET PROPERTY OF font ‘Bold’ = ‘0’.
SET PROPERTY OF font ‘Italic’ = ‘0’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
“————ѕолучение координат ¤чеек
CALL METHOD OF table ‘Cell’ = cell
EXPORTING
#1 = ‘1’
#2 = ‘1’.
“————ѕолучение диапазона дл¤ записи текста
GET PROPERTY OF cell ‘Range’ = range.
“————«аполнение ¤чейки
SET PROPERTY OF range ‘Text’ = ‘OLE’.
“———–ѕолучение координаты ¤чейки
CALL METHOD OF table ‘Cell’ = cell
EXPORTING
#1 = ‘3’
#2 = ‘2’.
“———–RESET ATTRIB
SET PROPERTY OF font ‘Name’ = ‘Times New Roman’.
SET PROPERTY OF font ‘Size’ = ’12’.
SET PROPERTY OF font ‘Bold’ = ‘0’.
SET PROPERTY OF font ‘Italic’ = ‘0’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
“———-SET paragraph format
SET PROPERTY OF parformat ‘Aligment’ = ‘3’.
“———табул¤ци¤ отступ от абзаца один раз
GET PROPERTY OF selection ‘Paragraph’ = paragraph.
CALL METHOD OF paragraph ‘Indent’.
CALL METHOD OF selection ‘TypeText’
EXPORTING
#1 = text-002.
“———FREELING Object WORD
FREE OBJECT word.
Простой пример
REPORT zole_test_nik.
INCLUDE ole2incl.
DATA: word TYPE ole2_object,
documents TYPE ole2_object,
document TYPE ole2_object,
selection TYPE ole2_object,
actdoc TYPE ole2_object,
application TYPE ole2_object,
options TYPE ole2_object,
actwin TYPE ole2_object,
actpan TYPE ole2_object,
view TYPE ole2_object,
font TYPE ole2_object,
parformat TYPE ole2_object,
tables TYPE ole2_object,
range TYPE ole2_object,
table TYPE ole2_object,
table_border TYPE ole2_object,
cell TYPE ole2_object,
paragraph TYPE ole2_object.
START-OF-SELECTION.
CREATE OBJECT word ‘WORD.APPLICATION’.
IF sy–subrc NE 0 .
MESSAGE s000(su) WITH ‘ERROR creating OLE obj!’.
LEAVE PROGRAM.
ENDIF.
SET PROPERTY OF word ‘Visible’ = ‘1’.
GET PROPERTY OF word ‘Documents’ = documents.
CALL METHOD OF documents ‘Add’ = document.
CALL METHOD OF word ‘Selection’ = selection.
GET PROPERTY OF selection ‘Font’ = font.
SET PROPERTY OF font ‘Name’ = ‘Arial’.
SET PROPERTY OF font ‘Size’ = ’10’.
SET PROPERTY OF font ‘Bold’ = ‘0’.
SET PROPERTY OF font ‘Italic’ = ‘1’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
CALL METHOD OF selection ‘TypeText’
EXPORTING
#1 = ‘This is OLE Example!’.
“———–cursor to the new line
CALL METHOD OF selection ‘TypeParagraph’.
“——SET HEADER TEXT
SET PROPERTY OF font ‘Name’ = ‘Times New Roman’.
SET PROPERTY OF font ‘Size’ = ’16’.
SET PROPERTY OF font ‘Bold’ = ‘1’.
SET PROPERTY OF font ‘Italic’ = ‘0’.
SET PROPERTY OF font ‘Underline’ = ‘0’.
CALL METHOD OF selection ‘TypeText’
EXPORTING
#1 = ‘bla bla bla text2’.
“———–SKIP 4 lines
DO 4 TIMES.
CALL METHOD OF selection ‘TypeParagraph’.
ENDDO.
“———FREELING Object WORD
FREE OBJECT word.
EXCEL OLE Example
*&———————————————————————*
*& Report ZOLE_TEST_NIK
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT zole_test_nik.
INCLUDE ole2incl.
DATA: excel TYPE ole2_object,
active_window TYPE ole2_object,
work_books TYPE ole2_object,
work_book TYPE ole2_object,
active_cell TYPE ole2_object.
DATA : lv_row TYPE i,
lv_col TYPE i,
i_val TYPE string,
l_prop TYPE i.
START-OF-SELECTION.
CREATE OBJECT excel ‘EXCEL.APPLICATION’.
SET PROPERTY OF EXCEL ‘Visible’ = ‘1’.
GET PROPERTY OF excel ‘Workbooks’ = work_books.
CALL METHOD OF work_books ‘Add’ = work_book.
lv_row = 1.
lv_col = 1.
CALL METHOD OF excel ‘Cells’ = active_cell
EXPORTING
#1 = lv_row
#2 = lv_col.
i_val = ‘Country code’.
SET PROPERTY OF active_cell ‘FormulaR1C1’ = i_val.
lv_row = 1.
lv_col = 2.
CALL METHOD OF excel ‘Cells’ = active_cell
EXPORTING
#1 = lv_row
#2 = lv_col.
i_val = ‘Country Name’.
SET PROPERTY OF active_cell ‘FormulaR1C1’ = i_val.
CALL METHOD OF excel ‘Cells’ = active_cell
EXPORTING
#1 = lv_row
#2 = lv_col.
“—-заполнение тест
DO 2 TIMES.
lv_col = sy-index.
DO 20 TIMES.
lv_row = sy-index + 1.
CALL METHOD OF excel ‘Cells’ = active_cell
EXPORTING
#1 = lv_row
#2 = lv_col.
IF lv_col = 1.
i_val = ‘val’ && sy-index.
ELSE.
i_val = ‘city’ && sy-index.
ENDIF.
SET PROPERTY OF active_cell ‘FormulaR1C1’ = i_val.
ENDDO.
ENDDO.
“————————————————————–
“————————————————————–
CALL METHOD OF work_books ‘SaveAs’
EXPORTING
#1 = ‘H:1.xls’.
GET PROPERTY OF excel ‘ActiveWindow’ = active_window.
CALL METHOD OF active_window ‘Close’.
FREE OBJECT excel.