Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft word

david_fryda2
Participant
0 Kudos

Hi everyone,

I've been asking to create a document word using ABAP programming.

I am using the interface I_OI_DOCUMENT_PROXY.

The question is how can I insert a "new page" in the document word ?

Thanks a lot.

Regards.

8 REPLIES 8

ferry_lianto
Active Contributor
0 Kudos

Hi David,

Please check transaction code <b>OLE</b> and click on Start (Word) or execute program <b>RSOLETT1</b>.

Hope this will help.

Regards,

Ferry Lianto

0 Kudos

Hi Ferry,

I am trying to create a document word dynamically from a program ABAP. I do not know in advance which text I will have. I have to insert this text in a table and pass it to the interface I mentionned earlier.

What I am trying to do is to insert a new page.

Thanks.

Former Member
0 Kudos

Hi

Herewith i am sending one report,i hope this will help you to solve your probelm.

1 ----


2 * INCLUDE ZIOIEXCEL *

3 ----


4 * Instantiates the control framework using i_oi_document factory.

5 * Excapsulates SAP Office Integration specific functionality. Uses the

6 * i_oi_document_proxy class to create the document link then

7 * uses the i_oi_table collection for transporting SAP internal tables

8 * from the server to the client for display in the active document

9 * server.

10

11 INCLUDE <CTLDEF>. "General Definitions For Controls (CET)

12 * Platform- and application-indep. Office integration

13 INCLUDE OFFICEINTEGRATIONINCLUDE.

14

15 CLASS COIEXCEL DEFINITION. "Excel DOI wrapper class

16 PUBLIC SECTION.

17

18 * Create the control framework and returns a document proxy interface

19 METHODS: CONSTRUCTOR,

20 * Clean up routine

21 DESTROY.

22 * Catch the on_close event to process cleanup

23 METHODS: ON_CLOSE_DOCUMENT

24 FOR EVENT ON_CLOSE_DOCUMENT OF I_OI_DOCUMENT_PROXY.

25 METHODS: CREATEDOCUMENT "Not used

26 IMPORTING S_DOCTITLE TYPE C

27 EXPORTING RETCODE TYPE T_OI_RET_STRING.

28 METHODS: OPENDOCUMENT

29 IMPORTING FILEURL TYPE C

30 EXPORTING RETCODE TYPE T_OI_RET_STRING.

31 METHODS: TRANSFERTABLE

32 IMPORTING S_TABLENAME TYPE C

33 EXPORTING RETCODE TYPE T_OI_RET_STRING

34 CHANGING I_TAB TYPE TABLE.

35 METHODS: LAUNCHSE16 IMPORTING C_TBLNAME TYPE C

36 C_FILEPATH TYPE C

37 CHANGING TBL_TAB TYPE TABLE.

38 PRIVATE SECTION.

39 DATA:

40 H_FACTORY TYPE REF TO I_OI_DOCUMENT_FACTORY,

41 H_TABLES TYPE REF TO I_OI_TABLE_COLLECTION,

42 H_DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY,

43 S_RETCODE TYPE T_OI_RET_STRING,

44 S_FILEURL(256) TYPE C,

45 S_DOCURL(256) TYPE C.

46

47 ENDCLASS.

48

49 CLASS COIEXCEL IMPLEMENTATION.

50 METHOD CONSTRUCTOR.

51 *----


52 * For external execution we simply use the factory class. (vs 4.5)

53 *

54 *----


55 DATA: DOCUMENT_EXCEL TYPE SOI_DOCUMENT_TYPE

56 VALUE SOI_DOCTYPE_EXCEL97_SHEET.

57

58 CALL FUNCTION 'CONTROL_INIT' "Initialize the control framework

59 EXCEPTIONS

60 CONTROL_INIT_ERROR = 1

61 OTHERS = 2.

62 * Starting point - get a reference to the control framework

63 call method c_oi_factory_creator=>get_document_factory

64 exporting factory_type = 'OLE'

65 IMPORTING FACTORY = H_FACTORY

66 RETCODE = S_RETCODE.

67 call method c_oi_errors=>show_message exporting type = 'E'.

68 * DOI Container object creation

69 CALL METHOD H_FACTORY->START_FACTORY

70 EXPORTING R3_APPLICATION_NAME = 'SAP-Excel DOI'

71 REGISTER_ON_CLOSE_EVENT = 'X'

72 IMPORTING RETCODE = S_RETCODE.

73 * Get a reference to the document proxy

74 CALL METHOD H_FACTORY->GET_DOCUMENT_PROXY

75 EXPORTING DOCUMENT_TYPE = DOCUMENT_EXCEL

76 IMPORTING DOCUMENT_PROXY = H_DOCUMENT

77 RETCODE = S_RETCODE.

78 CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE

79 EXPORTING TYPE = 'E'.

80 * Register the on_close event

81 SET HANDLER ME->ON_CLOSE_DOCUMENT FOR H_DOCUMENT.

82

83 ENDMETHOD. " Constructor.. COIExcel

84

85 * Cleanup

86 METHOD DESTROY.

87

88 IF NOT H_TABLES IS INITIAL.

89 CALL METHOD H_TABLES->REMOVE_ALL_TABLES

90 IMPORTING RETCODE = S_RETCODE.

91 FREE H_TABLES.

92 ENDIF.

93

94 IF NOT H_FACTORY IS INITIAL.

95 CALL METHOD H_FACTORY->STOP_FACTORY.

96 FREE H_FACTORY.

97 ENDIF.

98

99 FREE H_DOCUMENT.

100 CALL FUNCTION 'CONTROL_EXIT'.

101

102 ENDMETHOD. " Destructor.... COIExcel

103

104 METHOD ON_CLOSE_DOCUMENT.

105 * for event on_close_document of i_oi_document_proxy.

106 IF NOT H_DOCUMENT IS INITIAL.

107 CALL METHOD H_DOCUMENT->CLOSE_DOCUMENT

108 IMPORTING RETCODE = S_RETCODE.

109 CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE

110 EXPORTING TYPE = 'E'.

111 ENDIF.

112

113 * Cleanup the DOI allocations and the control framework.

114 CALL METHOD ME->DESTROY.

115 * message id 'mo' type 'S' number '001' with 'Enter selection table.'.

116 ENDMETHOD.

117

118 METHOD CREATEDOCUMENT.

119 * importing s_doctitle type c

120 * exporting s_retcode type t_oi_ret_string.

121

122 IF NOT H_DOCUMENT IS INITIAL.

123 CALL METHOD H_DOCUMENT->CREATE_DOCUMENT

124 EXPORTING OPEN_INPLACE = ' '

125 DOCUMENT_TITLE = S_DOCTITLE

126 IMPORTING RETCODE = S_RETCODE.

127 CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.

128 ENDIF.

129

130 ENDMETHOD.

131

132 * Parameters are set to open the document specified by fileurl,

133 * opened externally, and run the startup macro that resides

134 * inside the Excel document.

135 METHOD OPENDOCUMENT.

136 * importing fileurl type c

137 * exporting s_retcode type t_oi_ret_string.

138

139 CALL METHOD H_DOCUMENT->OPEN_DOCUMENT

140 EXPORTING

141 DOCUMENT_URL = FILEURL

142 OPEN_INPLACE = ' '

143 STARTUP_MACRO = 'Module1.LoadR3Data'

144 IMPORTING RETCODE = S_RETCODE.

145

146 CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE ='E'.

147

148 ENDMETHOD.

149

150 METHOD TRANSFERTABLE.

151 * importing s_tblname type c

152 * exporting retcode type t_oi_ret_string

153 * changing i_tab type table

154

155 IF H_TABLES IS INITIAL.

156 CALL METHOD H_FACTORY->GET_TABLE_COLLECTION

157 IMPORTING TABLE_COLLECTION = H_TABLES

158 RETCODE = S_RETCODE.

159 CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.

160 ENDIF.

161

162 *transfer data to presentation server

163 CALL METHOD H_TABLES->ADD_TABLE

164 EXPORTING TABLE_NAME = 'ITAB'

165 TABLE_TYPE = H_TABLES->TABLE_TYPE_OUTPUT

166 DDIC_NAME = S_TABLENAME

167 DESCRIPTION = 'Block Data'

168 IMPORTING

169 RETCODE = S_RETCODE

170 CHANGING DATA_TABLE = I_TAB.

171 RETCODE = S_RETCODE.

172 ENDMETHOD.

173

174 * Specific method for use in the ZBTableListGeneration program.

175 * Simplifies the dynamic program creation

176 METHOD LAUNCHSE16.

177 * importing c_tblname type c

178 * c_filepath type c

179 * changing tbl_tab type table

180

181 CALL METHOD ME->TRANSFERTABLE

182 EXPORTING S_TABLENAME = C_TBLNAME

183 IMPORTING RETCODE = S_RETCODE

184 CHANGING I_TAB = TBL_TAB.

185

186 CALL METHOD ME->OPENDOCUMENT

187 EXPORTING FILEURL = C_FILEPATH.

188 ENDMETHOD.

189

190 ENDCLASS. "COIEXCEL Implemetation

Thanks

Mrutyunjaya Tripathy

0 Kudos

Hi,

Thanks for the code.

Can you please tell me where in your code I can find what precisely I am looking for.

Thanks a lot (nice program).

Former Member
0 Kudos

Hi David,

**The question is how can I insert a "new page" in the document word ?

Can you just tell us what you want?Is it that you want a new document to be created just like New document creation in MS Word ? Or you want to create new page in an existing word document like the NEW-PAGE command?

If it is creating a new document, then it is easy.

In the interface I_OI_DOCUMENT_PROXY, there is no facility for creating new documents . So what I think is create a new class which has I_OI_DOCUMENT_PROXY as interface and create a new method in the class. Then you can use OLE Methodology to create new documents.

Code to create a new Word document

-


Declarations

-


INCLUDE ole2incl .

DATA gs_word TYPE ole2_object . "OLE object handle

DATA gs_documents TYPE ole2_object . "Documents

For the particular Function Code

-


CREATE OBJECT gs_word 'WORD.APPLICATION' .

IF sy-subrc NE 0 .

MESSAGE s000(su) WITH 'Error while creating OLE object!'.

LEAVE PROGRAM .

ENDIF .

*--Setting object's visibility property

SET PROPERTY OF gs_word 'Visible' = '1' .

*--Opening a new document

GET PROPERTY OF gs_word 'Documents' = gs_documents .

CALL METHOD OF gs_documents 'Add' .

0 Kudos

Hi,

I know how to create a document word.

What I am asking is : when creating the document, I want to transfer to it text using a table. How can I pass to this docuemnt a NEW PAGE code ( in order to make the docuemnt create a new page) ?

That's all.

I hope I made myself more understable and sorry if I wasn't.

Thanks.

0 Kudos

Hi David,

Tell me if this is your requirement.

You have going to create a document. In that document, you have number of pages. You have certain values of a table to be printed and the data can be dynamic. You want that data to be print in a separate page of the document.

Tell me if this is not exactly your requirement.

My mail-id is sylendra.prasad@wipro.com.You can contact me in this id so that we can discuss this matter.

Regards,

SP.

Rashid_Javed
Contributor
0 Kudos

Hi

Since you are already using I_OI_DOCUMENT_PROXY, i assume you are familiar with the classes and interfaces provided by sap for office integration. They are all part of development class sofficeintegration.

Anyways, there is a class in the same development class called C_OI_AUTOMATION_OBJECT. It has a method which can be used to call methods for the intance objects. It is CALL_OBJECT_METHOD. You can use this to call the insert method of Word. The method is "InsertBreak" and should be with parameter "wdPageBreak"

Hope this is helpful.

RJv