11-23-2007 4:57 PM
How do I create a Word document in a Custom Container, save in SAP, and later maintain it. Please recommend how to save the data in a custom table.
david
11-23-2007 5:23 PM
You can make a Text container in the SAP with help of the Custome Control.
Then you can save your data using SAVE_TEXT FM. But you need to maintian the Text ID, Text Class.
Regards,
Naimesh Patel
11-23-2007 5:23 PM
You can make a Text container in the SAP with help of the Custome Control.
Then you can save your data using SAVE_TEXT FM. But you need to maintian the Text ID, Text Class.
Regards,
Naimesh Patel
11-24-2007 7:40 AM
11-26-2007 2:45 PM
> have you seen this demo program
>
> SAPRDEMODOCUMENTCONTAINER2
Using program SAPRDEMODOCUMENTCONTAINER2 to create a Word document, can the contents be saved in the SAP database for later retrieval into the word application in this program? I don't want to save it in the PC
Thanks for the prompt response.
david
11-28-2007 8:04 AM
Look at Document Managment System. I think that U can using fictitious DMS document for attach and save Word document in internal repository.
FM BAPI_DOCUMENT_CREATE2, BAPI_DOCUMENT_CHANGE2 - for create\change and attach files. FM BAPI_DOCUMENT_GETDETAIL2 - for get files.
FM CV120* - for maintain files in DMS.
Added:
Also U can using application server for saving and store files (if your hardware is permited). FM WS_UPLOAD, WS_DOWNLOAD - for this target.
Message was edited by:
Andrey Markin
11-28-2007 5:16 PM
> Look at Document Managment System. I think that U can
> using fictitious DMS document for attach and save
> Word document in internal repository.
> FM BAPI_DOCUMENT_CREATE2, BAPI_DOCUMENT_CHANGE2 - for
> create\change and attach files. FM
> BAPI_DOCUMENT_GETDETAIL2 - for get files.
> FM CV120* - for maintain files in DMS.
>
> Added:
> Also U can using application server for saving and
> store files (if your hardware is permited). FM
> WS_UPLOAD, WS_DOWNLOAD - for this target.
>
> Message was edited by:
> Andrey Markin
I am using the FCKeditor to copy text from Word and save into the SAP database. I am able to save a 20 page document. I will investigate your suggestions in the near future in case we need to save larger documents. Thanks for your prompt response, and I will post the results.
david
11-30-2007 11:22 AM
Easy Peasy
1) Extend WORKITEM Business Object to ZWORKITEM (and delegate)
2) Add a method to the ZWORKITEM Business Object ZCALLATTACH. This method will create the appropriate attachment WITHOUT PRESENTING A DIALOG so can also be run in Batch:
Import parameters : ZFILEANDPATH (file and path name of the attachment°
: ZWIID : Work Item number çleave blank)o;
3) use Function module SAP_WAPI_START_WORKFLOW with the following parameters:
TASK number of task defined below. Note Synchronous Task. TS9XXXXXXX
Input_container contains 2 elements
ZWIID with work item number (leave blank)
ZFILEANDPATH complete file and path name 9with file extension e.g xls, doc, ppt, pdf etc
Agents: Fill with whoever needs to execute the workitem
5) A work item will be created; Now run FM SAP_WAPI_EXECUTE_WORKITEM with the following parameters
WORKITEMID self explanatory
This now creates the attachment. In your inbox you can double click on the .doc, .xls,.ppt,.pdf or whateever document you like and the appropriate Windows application will be started.
You can save / delete / modify the attachment.
When you are don finish the workflow by chqnging the Work item´s stqtus --set complete or whatever.
Here´s the technical implemetation details
Method ZCALLATTACH which sets up the environment (passes the file name and workitem id) and method AttachFileWithoutDialog which actually does the work.
ZCALLATTCH is quite simple :
BEGIN_METHOD ZCALLATTACH CHANGING CONTAINER.
data: zworkitem like swwwihead-wi_id.
data: zfileandpath like rlgrap-filename.
data: lt_container like swcont occurs 0 with header line.
get data into container of new object note that the workitem ID
we want to attach the file to is NOT the work item of the task we
are running under. The function module will create a NEW instance
and then execute the method AttachfileWithoutDialog with the correct
work item ID.
swc_get_element container 'Zwiid' zworkitem.
swc_set_element lt_container 'Zwiid' zworkitem.
swc_get_element container 'Zfileandpath' zfileandpath.
swc_set_element lt_container 'Zfileandpath' zfileandpath.
set new container to persistent -- need to keep it for
non dialog execution.
swc_container_to_persistent lt_container.
CALL FUNCTION 'Z_CREATE_ATTACHMENT'
TABLES
LT_CONTAINER = lt_container.
.
now free up container.
swc_release_container lt_container.
END_METHOD.
This simply retrieves the values for the work item and file name and path and transfers them to a new container. This has to be defined as PERSISTENT since it is passed via a function module. This function module will actually call a method in THIS SAME BUSINESS OBJECT -- ZWORKITEM. Now in order to do that we need to create a new instance of the work item (the work item we are attaching the file to) and call the method to create the attachment for THAT WORK ITEM and not the current instance otherwise we will get recursion and unpredictable results. We cant use any of the generic SELFITEM methods since we need the NEW INSTANCE of the object which is what the function module does.
Code of the function module Z_CREATE_ATTACHMENT
function z_create_attachment.
*"----
-
""Local Interface:
*" TABLES
*" LT_CONTAINER STRUCTURE SWCONT
*"----
-
data: p_bus like tojtb-name,
p_key like swotobjid-objkey,
p_attrib like swotra-attribute,
p_method(32). " default 'AttachFileWithoutDialog'.
constants: c_attrib value 'A',
c_method value 'M'.
data zworkitem like swwwihead-wi_id.
data: begin of return.
include structure swotreturn.
data end of return.
data: l_invoke like swotinvoke.
data: w_prog like tojtb-progname,
w_runname like tojtb-progname,
w_super like tojtb-parent,
w_type(1) type c.
data: object like swotrtime-object.
data: zfileandpath like rlgrap-filename.
data: w_object like swotobjid.
swc_get_element lt_container 'Zwiid' zworkitem.
swc_get_element lt_container 'Zfileandpath' zfileandpath.
p_bus = 'ZWORKITEM'.
p_method = 'ATTACHFILEWITHOUTDIALOG'.
p_key = q_key.
p_key = zworkitem.
if p_method = ' '.
w_type = c_method.
else.
w_type = c_method.
endif.
w_object-objkey = p_key.
w_object-objtype = p_bus.
w_runname = 'ZWORKITEM'.
get actual program name where method / attribute
exists.
If verb is not in the object type
then use the supertype.
case p_method.
when ' '.
Method not entered so attribute required.
call function 'SWO_PROPERTY_GET'
exporting
object = w_object
attribute = p_attrib
changing
value = return.
EXCEPTIONS
ERROR_CREATE = 1
ERROR_INVOKE = 2
ERROR_C޾NTAINER = 3
OTHERS = 4
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
when others.
Method required.
1 ) Must instantiate the object first.
call function 'SWO_CREATE'
exporting
objtype = p_bus
objkey = p_key
importing
object = object
return = return.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Execute the method.
*
*
for swo invoke -- access type 'G' ====> get attribute
access type 'C' ====> execute a method
this function is executed internally.
in the perform (p_method) statement the sap kernel knows
that the program is actually a business object type of program
not a "Normal" abap so the perform gets handled a little
differently than the usual perform statement.
You cannot execute the BOR program via SE38.
set any input and output parameters
for your method.
*
You will have to code them here
l_invoke-object = object.
l_invoke-lobjtype = p_method.
l_invoke-verb = p_method.
l_invoke-objkey = p_key.
l_invoke-reftype = 'D'.
l_invoke-synchron = 'X'.
*
w_runname = 'ZWORKITEM'.
perform (p_method) in program (w_runname) tables lt_container
changing
l_invoke.
endcase.
endfunction.
Method ATTACHFILEWITHOUTDIALOG
BEGIN_METHOD ATTACHFILEWITHOUTDIALOG CHANGING CONTAINER.
This method adds a file to a work item
without presenting dialogs so it can be run from XI.
Complicated method so change WITH CARE.
constants: reference_type_kpro value 'K'. "KPro reference
constants:crea like sy-ucomm value 'CREA'. " Create
constants: ok like sy-subrc value '00'.
constants: so_format(11) value '&SO_FORMAT='.
constants : object_type_not_exist like sy-subrc value '0017'.
data: result_object type swc_object.
data: folder_id like soodk.
data new_objtype like sood-objtp.
data: folder_id_api1 like soobjinfi1-object_id.
data: object_id like soodk.
data: workitem like SWWWIHEAD-WI_ID.
data: old_object_id like soodk.
data: cont_size like sy-tabix.
data: object_dat like sofolenti1.
data: object_dat_cha like sodocchgi2.
data: parent_id like sofolenti1-doc_id.
data: objhead like soli occurs 0 with header line.
data: folder_key like sofdk.
data: folder_data like sofdd.
data: folder_region like sofd-folrg.
data: objects like sood4 occurs 0 with header line.
data: objcont like soli occurs 0 with header line.
data: h_objcont like soli occurs 0 with header line.
data: ok_code_out like sy-ucomm.
data: ok_code like sy-ucomm.
data: save_object like object-key.
data: parent_obj like swotobjid.
data: object_fl_display like sofm2.
data: object_fl_change like sofm1.
data: object_hd_display like sood2.
data: object_hd_change like sood1.
data: object_rc_display like soos6.
data: act_objtype like SOODK-OBJTP.
data: owner LIKE SOUD-USRNAM.
data f_cancelled type c.
data: act_filetype like rlgrap-filetype.
data : act_filename type string.
data: done type c.
data h_filename type file_table-filename.
data file_path_xl type file_table-filename.
data: delimiter type c value '.'.
data tab_size like sy-tabix.
data split_tab type string occurs 0 with header line.
data f_obj_change_global like sonv-flag.
data returncode like sonv-rcode.
data tsotd_data like soxot.
data current_line like sy-tabix.
constants:
swfco_attach_contelem_name type swc_elem value '_ATTACH_OBJECTS',
ext type c value 'EXT'.
data:
attach_contelem_name type swc_elem value swfco_attach_contelem_name.
data:
BEGIN OF sobject-key,
FOLDERTYPE LIKE SOFM-FOLTP,
FOLDERYEAR LIKE SOFM-FOLYR,
FOLDERNUMBER LIKE SOFM-FOLNO,
TYPE LIKE SOFM-DOCTP,
YEAR LIKE SOFM-DOCYR,
NUMBER LIKE SOFM-DOCNO,
FORWARDERNAME LIKE SOUB-USRNAM,
END OF sobject-key.
data: z_line(255) type c.
data: LO_ATTACH_OBJECT TYPE SWC_OBJECT,
LO_ATTACH_HANDLE LIKE SWOTOBJID,
LS_RETURN LIKE SWOTRETURN,
LT_ATTACH_CONTAINER LIKE SWCONT OCCURS 0 WITH HEADER LINE,
LC_METHOD(32) TYPE C,
LC_FUNC_NAME(30) TYPE C,
LC_STATUSTEXT LIKE SWWSTATEXT-STATUSTEXT.
data: wiheader like swwwihead.
data doc_length like SOXWD-DOC_LENGTH.
data: zfileandpath like rlgrap-filename.
swc_get_element container 'Zfileandpath' zfileandpath.
workitem = object-key.
Move 'B' to folder_region.
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
REGION = folder_region
IMPORTING
FOLDER_ID = folder_id
EXCEPTIONS
COMMUNICATION_FAILURE = 1
OWNER_NOT_EXIST = 2
SYSTEM_FAILURE = 3
X_ERROR = 4
OTHERS = 5
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
move: folder_id-objtp to objects-foltp,
folder_id-objyr to objects-folyr,
folder_id-objno to objects-folno,
folder_data-folrg to objects-folrg.
read table objects index 1.
if sy-subrc eq 0.
modify objects index 1.
else.
append objects.
current_line = 1.
endif.
CALL FUNCTION 'SO_WIND_OBJECT_HEADER'
EXPORTING
FOLDER_ID = folder_id
FOLDER_REGION = folder_region
MULTIPLE_OBJECTS = 'X'
NO_DIALOG = 'X'
OBJECT_ID = OBJECT_ID
OK_CODE_CALLER = ' '
OK_CODE_IN = 'CREA'
OWNER = 'JHAW'
IMPORTING
CHANGE_FLAG =
FOLDER_ID = folder_id
FOLDER_REGION = folder_region
OBJECT_FL_DISPLAY_OUT = object_fl_display
OBJECT_HD_DISPLAY_OUT = object_hd_display
OBJECT_ID = object_id
OK_CODE_OUT = OK_CODE
.
ok_code = 'IMPO'.
CALL FUNCTION 'SO_OBJECT_UPLOAD'
EXPORTING
DEFAULT_FILENAME = '.'
FILETYPE = 'RAW'
PATH_AND_FILE = zfileandpath
NO_DIALOG = 'X'
IMPORTING
FILELENGTH = doc_length
F_CANCELLED = f_cancelled
ACT_FILETYPE = act_filetype
ACT_FILENAME = act_filename
ACT_OBJTYPE = act_objtype
FILE_PUT_TO_KPRO = done
TABLES
OBJCONT = h_objcont
EXCEPTIONS
FILE_READ_ERROR = 1
INVALID_TYPE = 2
X_ERROR = 3
OBJECT_TYPE_NOT_ALLOWED = 4
KPRO_INSERT_ERROR = 5
OTHERS = 6 .
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
move doc_length to object_hd_display-objlen.
message id 'SO' type 'S' number 109.
object_hd_display-extct = reference_type_kpro.
clear new_objtype.
split act_filename at delimiter into table split_tab.
describe table split_tab lines tab_size.
if tab_size gt 1.
read table split_tab index tab_size.
if split_tab ca '/'.
clear object_hd_display-file_ext.
else.
move split_tab(3) to new_objtype.
translate new_objtype to upper case.
endif.
else.
move ext to new_objtype.
clear object_hd_display-file_ext.
endif.
move doc_length to object_hd_display-objlen.
objcont[] = h_objcont[].
call function 'SO_TSOTD_READ'
exporting
object_type = new_objtype
importing
object_type_data = tsotd_data
exceptions
object_type_not_exist = 17
others = 999.
case sy-subrc.
when ok.
if not tsotd_data-nocrea is initial and new_objtype ne 'EXT'.
clear new_objtype.
exit.
endif.
when object_type_not_exist.
move: new_objtype to object_hd_display-file_ext,
'EXT' to object_id-objtp,
'EXT' to objects-objtp.
modify objects index current_line.
when others.
endcase.
call function 'SO_SPLIT_FILE_AND_PATH'
exporting
full_name = act_filename
importing
stripped_name = h_filename.
if object_id-objtp eq ext or object_id-objtp eq 'BIN'.
clear objhead. refresh objhead.
move h_filename to objhead. insert objhead index 1.
move so_format to objhead-line.
move act_filetype to objhead-line+11(3).
append objhead.
append objhead.
endif.
if object_hd_display-objdes is initial.
perform so_split_file_and_extension(saplso30)
using h_filename
object_hd_display-objdes
act_filetype.
move object_hd_display-objdes to objects-objdes.
endif.
move-corresponding: object_hd_display to object_hd_change,
object_fl_display to object_fl_change.
if object_id-objtp ne 'FOL'.
move object_id to old_object_id.
if parent_object-objtp is initial.
call function 'SO_OBJECT_INSERT'
exporting
folder_id = folder_id
object_fl_change = object_fl_change
object_type = object_id-objtp
object_hd_change = object_hd_change
owner = owner
importing
object_id = object_id
object_fl_display = object_fl_display
object_hd_display = object_hd_display
tables
objcont = objcont
objhead = objhead
objpara = objpara
objparb = objparb
exceptions
active_user_not_exist = 35
communication_failure = 71
component_not_available = 1
dl_name_exist = 3
folder_no_authorization = 5
folder_not_exist = 6
object_type_not_exist = 17
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72.
if sy-subrc eq ok.
message id 'SO' type 'S' number 109.
endif.
move: object_id-objtp to objects-objtp,
object_id-objyr to objects-objyr,
object_id-objno to objects-objno,
object_hd_display-objnam to objects-objnam,
object_hd_display-objdes to objects-objdes,
object_hd_display-file_ext to objects-file_ext,
crea to objects-okcode.
modify objects index current_line.
call function 'DB_COMMIT'.
move: objects-foltp to sobject-key-foldertype,
objects-folno to sobject-key-foldernumber,
objects-objtp to sobject-key-type,
objects-objyr to sobject-key-year,
objects-objno to sobject-key-number,
objects-folyr to sobject-key-folderyear,
objects-fornam to sobject-key-forwardername.
if not objects-file_ext is initial.
write objects-objdes to z_line.
write '.'to z_line+240.
write objects-file_ext to z_line+241.
condense z_line no-gaps.
objects-objdes = z_line.
modify objects index current_line.
endif.
swc_create_object result_object 'SOFM' sobject-key.
swc_set_element container result result_object.
swc_set_element container 'DOCUMENTNAME' objects-objnam.
swc_set_element container 'DOCUMENTTITLE' objects-objdes.
move object-key to save_object.
endif.
lo_attach_object = result_object.
swc_container lt_container.
lt_container[] = container[].
SWC_OBJECT_TO_PERSISTENT LO_ATTACH_OBJECT LO_ATTACH_HANDLE.
CALL FUNCTION 'SWW_WI_OBJECTHANDLE_ADD'
exporting
wi_id = workitem
OBJECT_ID = LO_ATTACH_HANDLE
ELEMENT_NAME = ATTACH_CONTELEM_NAME
DO_COMMIT = 'X'
CHANGING
WI_HEADER = WIHEADER
wi_container_handle = swlc_workitem-container_handle
EXCEPTIONS
UPDATE_FAILED = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
endif.
message id 'SO' type 'S' number 182.
END_METHOD.
Task definition (PFTC)
Set up as a Synchronous task (general) TS9XXXXXXXX
CALL METHOD ZCALLATTACH in Bus Obj ZWORKITEM
parameters ZIID (work item)
ZFILEANDPATH complete file and path name
You could probably tidy these bits up into a more user friendly option but this method was cobbled using an XI system.
Cheers
Jimbo
11-30-2007 3:40 PM