You are on page 1of 12

*&---------------------------------------------------------------------*

*& Include
ZWWWFILLFORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FillExcelForm
*&---------------------------------------------------------------------*
FORM FillExcelForm
using it_Val type table
Doc
type OLE2_OBJECT.
Types:
tt_Sort_Val type standard table of ZWWW_VALUES.
Field-symbols:
<it_Values> type ZWWW_VALUES,
<it_SortVal> type tt_Sort_Val.
Data:
Cnt
type i,
RowsCount type i value 1,
VAR_Error type sy-subrc,
CharValue(2048),
FORM_NAME
TempDir
FileData
w_FileName

type
type
type
type

WWWDATATAB-OBJID value 'ZWWW',


RLGRAP-FILENAME,
RLGRAP-FILENAME,
RLGRAP-FILENAME.

Data:
App
Range
Find
Offset
Cell
RangeTempl
QTables
QTable

type
type
type
type
type
type
type
type

OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT.

Get property of Doc 'Application' = App.


Assign it_Val[] to <it_Sortval>.
Loop at <it_Sortval> assigning <it_Values>.
At New VAR_NAME.
Cnt = 0.
If not <it_Values>-VAR_NAME is initial.
Call method of App 'Range' = Range
EXPORTING
#1 = <it_Values>-VAR_NAME.
Call method of Range 'Rows' = Find.
Get property of Find 'Count' = RowsCount.
*
CALL FUNCTION 'FLUSH'.

*
*

Call method of Range 'Offset' = Offset


EXPORTING
#1 = RowsCount.
Call method of Offset 'Select'.
CALL FUNCTION 'FLUSH'.
EndIf.
EndAt.

At End of VAR_NAME.
If Cnt > 0.
Cnt = Cnt * RowsCount.
Call method of Range 'Copy'.
Call method of Offset 'Resize' = Offset
EXPORTING
#1 = Cnt.
Call method of Offset 'Insert'.
EndIf.
Continue.
EndAt.
At End of VAR_NUM.
If not <IT_VALUES>-VAR_NAME is initial.
Cnt = Cnt + 1.
EndIf.
EndAt.
EndLoop.
Var_Error = 0.
Loop at <it_SortVal> assigning <IT_VALUES>.
CharValue = <IT_VALUES>-VALUE.

Set property of App 'DisplayAlerts' = 0.


At New VAR_NAME.
RowsCount = 1.
If <IT_VALUES>-VAR_NAME is initial.
Call method of App 'Cells' = Range.
Else.
Call method of App 'Range' = Range
EXPORTING
#1 = <IT_VALUES>-VAR_NAME.
Call method of Range 'Rows' = Find.
Get property of Find 'Count' = RowsCount.
EndIf.
Var_Error = sy-subrc.
check sy-subrc = 0.

*
*

Call method of Range 'Select'.


CALL FUNCTION 'FLUSH'.
EndAt.
check Var_Error = 0.

If <IT_VALUES>-FIND_TEXT is initial.
Set property of Find 'Value' = CharValue.
"<IT_VALUES>-VALUE.
Case <IT_VALUES>-VAL_TYPE.
when space or 'S' or 'T' or 'R'.
Call method of Range 'Cells' = Cell
EXPORTING
#1 = 1
#2 = 1.
Set property of Cell 'Value' = CharValue.
Call method of Cell 'TextToColumns'
EXPORTING
#1 = Cell
#2 = 1. "xlDelimited
when 'V'.

*
*
*

Call method of App 'Range' = RangeTempl


EXPORTING
#1 = <IT_VALUES>-VALUE.
If sy-subrc = 0.
Call method of RangeTempl 'Copy'
EXPORTING
#1 = Range.
EndIf.
when 'M'.
Call method of App 'Run'
EXPORTING
#1 = <IT_VALUES>-VALUE
#2 = Range.
If sy-subrc <> 0.
Call method of App 'Run'
EXPORTING
#1 = <IT_VALUES>-VALUE.
EndIf.
CALL FUNCTION 'FLUSH'.
EndCase.
Else.
If not <IT_VALUES>-VALUE cs Char_TAB or
( <IT_VALUES>-VAL_TYPE = space or
<IT_VALUES>-VAL_TYPE = 'S' ).
Call method of Range 'Replace'
EXPORTING
#1 = <IT_VALUES>-FIND_TEXT
#2 = <IT_VALUES>-VALUE.
ElseIf not <IT_VALUES>-VALUE cs Char_0D or
<IT_VALUES>-VAL_TYPE = 'R'. "Row
Call method of Range 'Find' = Find
EXPORTING
#1 = <IT_VALUES>-FIND_TEXT.
Set property of Find 'Value' = CharValue.
CALL FUNCTION 'FLUSH'.
Call method of Find 'Replace'
exporting #1 = <IT_VALUES>-FIND_TEXT
#2 = <IT_VALUES>-VALUE.
Call method of Find 'TextToColumns'
EXPORTING
#1 = Find
#2 = 1. "xlDelimited
ElseIf <IT_VALUES>-VAL_TYPE = 'T'. "Table
Concatenate TempDir '\' FORM_NAME '-' sy-TIMLO '.txt'
into FileData.
Perform ValueAsFile
using <IT_VALUES>-Value FileData Cnt.
Cnt = Cnt - 1.
If Cnt > 0.
Cnt = Cnt * RangeHeight.
Call method of Range 'Copy'.
Call method of Offset 'Resize' = Offset
EXPORTING
#1 = Cnt.
Call method of Offset 'Insert'.
EndIf.
Call method of Range 'Find' = Find
EXPORTING
#1 = <IT_VALUES>-FIND_TEXT.

Call method of Range 'WorkSheet' = QTables.


Call method of QTables 'QueryTables' = QTables.
Concatenate 'TEXT;' FileData into w_FileName.
Call method of QTables 'Add' = QTable
EXPORTING
#1 = w_FileName
#2 = Find.
Set property of QTable 'AdjustColumnWidth' = 0.
Set property of QTable 'RefreshStyle' = 0.
Call method of QTable 'Refresh'.
Call method of QTable 'Delete'.
CALL FUNCTION 'FLUSH'.
*

w_FileName = FileData.
Call function 'GUI_DELETE_FILE'
EXPORTING
FILE_NAME = FileData
EXCEPTIONS
others
= 1.
EndIf.
EndIf.

At End of VAR_NUM.
If not <IT_VALUES>-VAR_NAME is initial.
Call method of Range 'Offset' = Range
EXPORTING
#1 = RowsCount.
*
Call method of Range 'Select'.
EndIf.
EndAt.
EndLoop.
Loop at <it_SortVal> assigning <IT_VALUES>
where VAL_TYPE = 'V' or VAL_TYPE = 'D' .
Case <IT_VALUES>-VAL_TYPE.
when 'V'.
Call method of App 'Range' = Range
EXPORTING
#1 = <IT_VALUES>-VALUE.
Call method of Range 'Delete'.
when 'D'.
Call method of App 'Range' = Range
EXPORTING
#1 = <IT_VALUES>-VAR_NAME.
Call method of Range 'Delete'.
EndCase.
EndLoop.
ENDFORM.

" FillExcelForm

*&---------------------------------------------------------------------*
*&
Form FillWordForm
*&---------------------------------------------------------------------*
FORM FillWordForm
using it_Val type table
Doc
type OLE2_OBJECT.

Types:
tt_Sort_Val type standard table of ZWWW_VALUES.
Field-symbols:
<it_Values> type ZWWW_VALUES,
<it_SortVal> type tt_Sort_Val.
Data:
VAR_Error type sy-subrc,
CharValue(2048).
Data:
RangeStart type i,
RangeEnd type i,
RangeSize type i.
Data:
NewStart type i,
NewEnd type i,
NewSize type i.
Data:
App
Item
Range
RangeTempl
CurrRange
Find
Bookmark
Duplicate
Cell

type
type
type
type
type
type
type
type
type

OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT,
OLE2_OBJECT.

Call method of Doc 'Application' = App.


Call method of App 'ActiveDocument' = Item.
Assign it_Val[] to <it_Sortval>.
Var_Error = 0.
Loop at <it_SortVal> assigning <IT_VALUES>.
CharValue = <IT_VALUES>-VALUE.
At New VAR_NAME.
If <IT_VALUES>-VAR_NAME is initial.
Call method of Item 'Range' = Range.
Call method of Range 'Find' = Find.
Else.
Call method of Item 'Bookmarks' = Bookmark
EXPORTING
#1 = <IT_VALUES>-VAR_NAME.
Call method of Bookmark 'Range' = Range.
Call method of Bookmark 'Range' = CurrRange.
Call method of Range 'Copy'.

Call method of Range 'Find' = Find.


EndIf.
check sy-subrc = 0.
Var_Error = sy-subrc.
Get property of Range 'Start' = RangeStart.
Get property of Range 'End' = RangeEnd.

RangeSize = RangeEnd - RangeStart.


EndAt.
check Var_Error = 0.

*
*

At new VAL_TYPE.
At new VAR_NUM.
If not <IT_VALUES>-VAR_NUM is initial.
Call method of Range 'Move'
EXPORTING
#1 = '10'
#2 = '1'.
Call method of Range 'Select'.
CALL FUNCTION 'FLUSH'.
If <IT_VALUES>-VAL_TYPE = 'V'.
Call method of Item 'Bookmarks' = RangeTempl
EXPORTING
#1 = <IT_VALUES>-VALUE.
If sy-subrc = 0.
Call method of RangeTempl 'Range' = RangeTempl.
Get property of RangeTempl 'Start' = NewStart.
Get property of RangeTempl 'End' = NewEnd.
Call method of RangeTempl 'Copy'.
Call method of Range 'Paste'.

NewSize = NewEnd - NewStart.


Get property of Range 'Start' = NewStart.
NewEnd = NewStart + NewSize.
Set property of Range 'End' = NewEnd.
EndIf.
Else.
Call method of Bookmark 'Range' = RangeTempl.
RangeTempl = CurrRange.
Call method of RangeTempl 'Copy'.
Call method of Range 'Paste'.
Get property of Range 'Start' = NewStart.
NewEnd = NewStart + RangeSize.
Set property of Range 'End' = NewEnd.
EndIf.

*
*
*

Call method of Range 'Select'.


CALL FUNCTION 'FLUSH'.
EndIf.
EndAt.
EndAt.
If <IT_VALUES>-FIND_TEXT is initial.
Case <IT_VALUES>-VAL_TYPE.
when space or 'S'.
Set property of Range 'Text' = CharValue.
"<IT_VALUES>-VALUE.
when 'M'.
Call method of Range 'Duplicate' = Duplicate.
Call method of App 'Run'
EXPORTING
#1 = <IT_VALUES>-VALUE
#2 = Duplicate.

If sy-subrc <> 0.
Call method of App 'Run'
EXPORTING
#1 = <IT_VALUES>-VALUE.
EndIf.
*

*
*
*
*
*
*

*
*
*

Set property of App 'ScreenUpdating' = ScreenUpdating.


CALL FUNCTION 'FLUSH'.
EndCase.
Else.
Case <IT_VALUES>-VAL_TYPE.
when space or 'S'.
Call method of Find 'Execute'
EXPORTING
#1 = <IT_VALUES>-FIND_TEXT
#2 = '0'
#3 = '0'
#4 = '0'
#5 = '0'
#6 = '0'
#7 = '1'
#8 = '0'
#9 = '0'
#10 = <IT_VALUES>-VALUE
#11 = '2'.
EndCase.
EndIf.
At End of VAR_NUM.
If not <IT_VALUES>-VAR_NAME is initial.
Call method of Range 'Move'
exporting #1 = '10'
#2 = '1'.
Call method of Range 'Select'.
CALL FUNCTION 'FLUSH'.
At End of VAR_NAME.
If not <IT_VALUES>-VAR_NAME is initial and
not <IT_VALUES>-VAR_NUM is initial .
Call method of Item 'Bookmarks' = Bookmark
exporting #1 = <IT_VALUES>-VAR_NAME.
Call method of Bookmark 'Range' = Range.
Range = CurrRange.
Call method of Range 'Delete'.
Range = CurrRange.
Call method of Bookmark 'Range' = Range.
Call method of Range 'Cells' = Cell.
Call method of Cell 'Delete'.
EndIf.
Continue.
EndAt.
Call method of Range 'Paste'.
EndIf.
EndAt.
EndLoop.
Loop at <it_SortVal> assigning <IT_VALUES>

where VAL_TYPE = 'V' or VAL_TYPE = 'D'.

Case <IT_VALUES>-VAL_TYPE.
when 'V'.
Call method of Item 'Bookmarks' = Bookmark
EXPORTING
#1 = <IT_VALUES>-VALUE.
Call method of Bookmark 'Range' = Range.
Call method of Range 'Delete'.
CALL FUNCTION 'FLUSH'.
Call method of Bookmark 'Range' = Range.
Call method of Range 'Cells' = Cell.
Call method of Cell 'Delete'.
CALL FUNCTION 'FLUSH'.
when 'D'.
Call method of Item 'Bookmarks' = Bookmark
EXPORTING
#1 = <IT_VALUES>-VAR_NAME.
Call method of Bookmark 'Range' = Range.
Call method of Range 'Delete'.
CALL FUNCTION 'FLUSH'.
Call method of Bookmark 'Range' = Range.
Call method of Range 'Cells' = Cell.
Call method of Cell 'Delete'.
CALL FUNCTION 'FLUSH'.
EndCase.
EndLoop.
CALL FUNCTION 'FLUSH'.

ENDFORM.

" FillWordForm

Form FUNCTION_ZBDS_OPENFORM2.
*"-------------------------------------------------------------------*"*" :
*" IMPORTING
*"
REFERENCE(DESCRIPTION) TYPE C
*"
REFERENCE(DOC_CLASSNAME) TYPE SBDST_CLASSNAME
*"
REFERENCE(DOC_CLASSTYPE) TYPE SBDST_CLASSTYPE
*"
REFERENCE(DOC_OBJECT) TYPE SBDST_OBJECT_KEY
*"
VALUE(OPTIMIZE) TYPE N DEFAULT 300
*"
VALUE(DECIMAL_SEPARATOR) TYPE C DEFAULT '.'
*"
VALUE(PRINTDIALOG) TYPE C DEFAULT 'X'
*"
VALUE(PROTECT) TYPE C DEFAULT 'X'
*"
VALUE(DEBUG_MODE) TYPE C DEFAULT ''
*" TABLES
*"
IT_VALUES OPTIONAL
*"-------------------------------------------------------------------Data:
bds_instance type ref to cl_bds_document_set,
*
doc_classname type sbdst_classname,
*
doc_classtype type sbdst_classtype,
*
doc_object
type sbdst_object_key,
control
TYPE REF TO i_oi_container_control,
AppStr(80),
document
TYPE REF TO i_oi_document_proxy,
r_doc_signature type line of sbdst_signature,
t_doc_signature type sbdst_signature with header line,
t_doc_component TYPE sbdst_components,
t_doc_uri
TYPE sbdst_uri,
r_doc_uri
TYPE LINE OF sbdst_uri,

item_url(256)
TYPE c,
Hnd type CNTL_HANDLE,
Doc type OLE2_OBJECT,
App type OLE2_OBJECT,
Item type OLE2_OBJECT,
Dialogs
type OLE2_OBJECT,
ItemDlg
type OLE2_OBJECT,
Res(250),
ScreenUpdating type i,
FileType(30),
Ext(255),
Begin of AppParam,
DecimalSeparator,
ThousandsSeparator,
UseSystemSeparators(10),
End of AppParam.
Perform AssignCharX.
CHECK control IS INITIAL.
CALL METHOD c_oi_container_control_creator=>get_container_control
IMPORTING
control = control.

*
*
*
*
*

CALL METHOD control->init_control


EXPORTING
parent
= cl_gui_container=>default_screen
r3_application_name
= ''.
inplace_enabled
= '' "'X'
inplace_scroll_documents = 'X'
register_on_close_event = '' "'X'
register_on_custom_event = 'X'
no_flush
= 'X'.
r_doc_signature-prop_name = 'DESCRIPTION'.
r_doc_signature-prop_value = description.
APPEND r_doc_signature TO t_doc_signature.
CREATE OBJECT bds_instance.
CALL METHOD bds_instance->get_info
EXPORTING
classname
= doc_classname
classtype
= doc_classtype
object_key
= doc_object
CHANGING
components
= t_doc_component
signature
= t_doc_signature[]
EXCEPTIONS
nothing_found = 1
error_kpro
= 2
internal_error = 3
parameter_error = 4
not_authorized = 5
not_allowed
= 6
OTHERS
= 0.
CHECK sy-subrc = 0.

CALL METHOD bds_instance->get_with_url


EXPORTING
classname
= doc_classname
classtype
= doc_classtype
object_key
= doc_object
CHANGING
uris
= t_doc_uri
signature
= t_doc_signature[]
EXCEPTIONS
nothing_found = 1
error_kpro
= 2
internal_error = 3
parameter_error = 4
not_authorized = 5
not_allowed
= 6
OTHERS
= 0.
*
*
*
*
*
*
*
*
*
*
*
*
*
*

Data: fls type SBDST_FILES with header line.


fls-directory = 'C:\'.
fls-filename = 'kuku'.
Append fls.
Call method bds_instance->GET_WITH_FILES
EXPORTING
classname
= doc_classname
classtype
= doc_classtype
object_key
= doc_object
CHANGING
files
= fls[]
signature
= t_doc_signature[]
EXCEPTIONS
OTHERS
= 1.
FREE bds_instance.
Loop at t_doc_signature
where PROP_NAME = 'BDS_DOCUMENTCLASS'.
Ext = t_doc_signature-PROP_VALUE.
Exit.
EndLoop.
check sy-subrc = 0.
READ TABLE t_doc_uri INTO r_doc_uri INDEX 1.
item_url = r_doc_uri-uri.
Translate Ext to upper case.
Case Ext.
when 'XLS'.
FileType = 'EXCEL'.
when 'DOC'.
FileType = 'WORD'.
when others.
Exit.
EndCase.
Concatenate FILETYPE '.Application' into AppStr.
CALL METHOD control->get_document_proxy
EXPORTING
document_type
= AppStr
register_container = 'X'

IMPORTING
document_proxy

= document.

CALL METHOD document->open_document


EXPORTING
open_inplace = 'X'
document_url = item_url.
Call method document->GET_DOCUMENT_HANDLE
importing
HANDLE = Hnd.
Call method of Hnd-Obj 'Application' = App.
************************************************
Set property of App 'DisplayAlerts' = 0.
CALL FUNCTION 'FLUSH'.
If DEBUG_MODE = 'X'.
Set property of App 'Visible' = 1.
ScreenUpdating = 1.
Else.
Set property of App 'Visible' = 0.
ScreenUpdating = 0.
EndIf.
Set property of App 'ScreenUpdating' = ScreenUpdating.
CALL FUNCTION 'FLUSH'.
Case FILETYPE.
when 'EXCEL'.
Data: CurSeparator.
Perform Get_Excel_Decimal_Separator
using CurSeparator.
If CurSeparator <> DECIMAL_SEPARATOR.
Get property of App
'DecimalSeparator' = AppParam-DecimalSeparator.
Get property of App
'ThousandsSeparator' = AppParam-ThousandsSeparator.
Get property of App
'UseSystemSeparators' = AppParam-UseSystemSeparators.
Set property of App 'UseSystemSeparators' = 0.
Set property of App 'DecimalSeparator' = DECIMAL_SEPARATOR.
Set property of App 'ThousandsSeparator' = ' '.
CALL FUNCTION 'FLUSH'.
EndIf.
*
Call method of App 'Workbooks' = Doc.
Call function 'ZWWW_FILLFORM'
exporting
DOC = Doc
OPTIMIZE = OPTIMIZE
FILE_TYPE = FILETYPE
tables
IT_VALUES = IT_VALUES.
*
If CurSeparator <> DECIMAL_SEPARATOR.
Set property of App
'DecimalSeparator' = AppParam-DecimalSeparator.
Set property of App
'ThousandsSeparator' = AppParam-ThousandsSeparator.

Set property of App


'UseSystemSeparators' = AppParam-UseSystemSeparators.
EndIf.
CALL FUNCTION 'FLUSH'.
If not PROTECT is initial.
Data: Sht
type OLE2_OBJECT,
ItmSht type OLE2_OBJECT,
CntSht type i,
Num type i.
Num = 0.
Call method of Item 'Worksheets' = Sht.
Get property of Sht 'Count' = CntSht.
Do CntSht times.
Num = Num + 1.
Call method of Sht 'Item' = ItmSht
exporting #1 = Num.
Call method of ItmSht 'Protect'
exporting #1 = sy-timlo " Password
#2 = 1 " DrawingObjects = True
#3 = 1 " Contents = True
#4 = 1." Scenarios = True
EndDo.
CALL FUNCTION 'FLUSH'.
EndIf.
*

Call method of Item 'Save'.


CALL FUNCTION 'FLUSH'.
Set property of App 'DisplayAlerts' = 1.
Set property of App 'ScreenUpdating' = 1.
Set property of App 'Visible' = 1.
CALL FUNCTION 'FLUSH'.
If not PRINTDIALOG is initial.
Call method of App 'Dialogs' = Dialogs.
Call method of Dialogs 'Item' = ItemDlg
EXPORTING
#1 = '8'. "xlDialogPrint
Call method of ItemDlg 'Show' = Res.
CALL FUNCTION 'FLUSH'.

*
*
*
*

If Res = -1.
return_code = 0.
EndIf.
CALL FUNCTION 'FLUSH'.
EndIf.

EndCase.
Endform. "ENDFUNCTION.

You might also like