Application Development and Automation 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: 
Read only

Write MS Word Document into Internal Table

Former Member
0 Likes
2,086

Hi,

I have to upload an ms word document into an internal table, change its contents and write the internal table to word document again. I am able to do this with .txt file but not with .doc. Any suggestions?

Thnx in advance!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,402

To upload data from doc file to internal table you can use the function module GUI_UPLOAD ....

declare P_DATA as :

P_DATA(255) type c.

and give the file location in it

for example : P_DATA = 'C:\text.doc'

or you can say

constant : P_DATA(255) type c value 'C:\text.doc'.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = P_DATA

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = IT_TAB

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Please do not forget to mention HAS_FIELD_SEPARATOR = 'X'

This is the one which should solve your problem.

10 REPLIES 10
Read only

Former Member
0 Likes
1,402

Refer

Read only

rainer_hbenthal
Active Contributor
0 Likes
1,402

Open you worddocument with notepad and have a look at the mess you're getting. You cant do meaninggful changes to this. What you can see in notepad is what you're getting in your ABAP.

Read only

0 Likes
1,402

Thanks for your reply.

Well my requirement is actually to modify and save a word document using ABAP code. Using internal table was the one started with. If that is not posible can you suggest any other method ?

Read only

Former Member
0 Likes
1,403

To upload data from doc file to internal table you can use the function module GUI_UPLOAD ....

declare P_DATA as :

P_DATA(255) type c.

and give the file location in it

for example : P_DATA = 'C:\text.doc'

or you can say

constant : P_DATA(255) type c value 'C:\text.doc'.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = P_DATA

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = IT_TAB

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Please do not forget to mention HAS_FIELD_SEPARATOR = 'X'

This is the one which should solve your problem.

Read only

0 Likes
1,402

I tried the same code but it did not work. The text was still gibberish. Is there any other way to modify and save a word document using ABAP Code.

Edited by: tshouri on Apr 9, 2010 6:52 PM

Read only

0 Likes
1,402

Hello

See this example: SAPRDEMO_FORM_INTERFACE

Kleber Santos

Read only

0 Likes
1,402

Hi Kleber,

thanks for the reply.I tried the program but am not able to understand how to link the program parameters to word file parameters.Please help me out with this.Thank you.

Read only

0 Likes
1,402

Thanks for the help.

Problemo Solvedo!

Read only

0 Likes
1,402

>

> Thanks for the help.

>

> Problemo Solvedo!

Can you please provide the solution..It would be of kind help for me.

Thanks

Abhisek

Read only

0 Likes
1,402

See this example: SAPRDEMO_FORM_INTERFACE