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: 

How to add multiple Documents to GOS at a time in a Transaction

venkat_aileni
Contributor
0 Kudos
2,837

Hi Experts,

I want to add multiple documents to a transaction say (PO).

I know by using GOS Customization we can add multiple documents one after the other but i want to add Multiple documents at a single shot.

My logic is i have created a class(ZCL_MUL_ATTACHMENTS) whose super class is CL_GOS_SERVICE

I have redefined the execute method of my z class using

call method cl_gui_frontend_services=>file_open_dialog

exporting multiselection = 'X'

"file_filter = '.'

changing file_table = file_tab

rc = return

exceptions others = 0.

By the above method(multiselection = 'X') we can select multiple files at a time.

Then i have looped internal table which conists of multiple file paths into workarea.

In the loop i have used CALL FUNCTION 'GUI_UPLOAD' where i have passed file path from the workarea.

By this logic iam able to select multiple files but unable to attach them.

By using method create_attachment we can create attachment but how to get the is_object fields for these multiple paths??

CALL METHOD lo_attachment->create_attachment

EXPORTING is_object = ls_object

IMPORTING ep_attachment = lp_attachment.

Thanks in advance.

Venkat

7 REPLIES 7

Former Member
0 Kudos
1,284

Hi Venkat,

I have a similar requirement from the client,

Were you able to achieve the desired result?

Regards

Siva

1,284

Hi Friends,

The sollution for your issus is :

1. Create implementation ZGOS_SRV_REQUEST in BAPI : GOS_SRV_REQUEST

2. Put filter : PCATTA_CREA in ZGOS_SRV_REQUEST

3. Create Module Function ot Methode ZGOS_MULTI_ATTACHEMENT

IMPUT PARAMETERE - IS_LPOR type SIBFLPORB and EV_MSG type MSGTX.

4. Call MF or METHOD in implementation method
IF_EX_GOS_SRV_REQUEST~START_SERVICE

5. Put this code in MF or METHOD and activate implementation.
***************************************************************************

DATA:
lt_binary_tab TYPE solix_tab,
lt_objcont TYPE soli_tab,
ls_folder_id TYPE soodk,
ls_obj_id TYPE soodk,
ls_obj_data TYPE sood1,
lt_objhead TYPE STANDARD TABLE OF soli,
ls_objhead TYPE soli,
ls_obj_rolea TYPE borident,
ls_obj_roleb TYPE borident,
ls_sofmk TYPE sofmk,
lv_ep_note TYPE borident-objkey,
lv_rc TYPE i,
lv_path TYPE string,
lv_filename TYPE string,
lv_fname TYPE string,
lv_ext TYPE char4,
lv_msg TYPE char50,
lv_text_path TYPE string,
lt_bin TYPE STANDARD TABLE OF solix,
lv_root TYPE string,
ls_content TYPE soli,
lt_file_table TYPE filetable,
lv_filelength TYPE i,
ls_buffer TYPE xstring,
lo_manager TYPE REF TO cl_gos_manager,
ls_obj TYPE borident.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
initial_directory = 'C:\Temp\'
multiselection = 'X'
CHANGING
file_table = lt_file_table[]
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4.

IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
lv_msg = 'File_open_dialog_failed'.
WHEN 2.
lv_msg = 'Cntl_error'.
WHEN 3.
lv_msg = 'Error_no_gui '.
WHEN 4.
lv_msg = 'Other open dialog error'.
ENDCASE.

MESSAGE lv_msg TYPE 'E' DISPLAY LIKE 'I'.
ELSE.

LOOP AT lt_file_table INTO DATA(ls_file_table).
* Should match both windows frontend and application server paths
FREE : lv_root, lv_path, lv_filename, lv_fname, lv_ext.
FIND REGEX '^(.:\\|\/\/)(.+\\|.+\/)*(.+)\.(.+)' IN ls_file_table-filename
SUBMATCHES lv_root lv_path lv_fname lv_ext.

lv_text_path = lv_path.
MOVE ls_file_table-filename TO lv_filename.
TRANSLATE lv_ext TO UPPER CASE.
TRANSLATE lv_filename TO UPPER CASE.

* Upload file and convert contents into BIN format
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_filename
filetype = 'BIN'
IMPORTING
filelength = lv_filelength
CHANGING
data_tab = lt_bin
EXCEPTIONS
OTHERS = 1.

IF sy-subrc = 0.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_filelength
IMPORTING
buffer = ls_buffer
TABLES
binary_tab = lt_bin
EXCEPTIONS
failed = 1
OTHERS = 2.

IF sy-subrc = 0.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = ls_buffer
TABLES
binary_tab = lt_binary_tab.

CALL FUNCTION 'SO_SOLIXTAB_TO_SOLITAB'
EXPORTING
ip_solixtab = lt_binary_tab
IMPORTING
ep_solitab = lt_objcont.

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING
folder_id = ls_folder_id
EXCEPTIONS
OTHERS = 1.

IF sy-subrc = 0.

ls_obj_data-objsns = 'O'.
ls_obj_data-objla = sy-langu.
ls_obj_data-objdes = lv_fname.
ls_obj_data-file_ext = lv_ext.
ls_obj_data-objlen = lv_filelength.

FREE : lt_objhead.
CONCATENATE '&SO_FILENAME=' lv_fname '.' lv_ext INTO ls_content. "lv_filename
APPEND ls_content TO lt_objhead.
FREE : ls_content.
ls_content = '&SO_FORMAT=BIN'.
APPEND ls_content TO lt_objhead.

CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
folder_id = ls_folder_id
object_type = 'EXT'
object_hd_change = ls_obj_data
IMPORTING
object_id = ls_obj_id
TABLES
objhead = lt_objhead
objcont = lt_objcont
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
dl_name_exist = 4
folder_not_exist = 5
folder_no_authorization = 6
object_type_not_exist = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
OTHERS = 15.

IF sy-subrc = 0.

ls_sofmk-foltp = ls_folder_id-objtp.
ls_sofmk-folyr = ls_folder_id-objyr.
ls_sofmk-folno = ls_folder_id-objno.
ls_sofmk-doctp = ls_obj_id-objtp.
ls_sofmk-docyr = ls_obj_id-objyr.
ls_sofmk-docno = ls_obj_id-objno.
lv_ep_note = ls_sofmk.

ls_obj_roleb-objtype = 'MESSAGE'.
ls_obj_roleb-objkey = lv_ep_note.

ls_obj_rolea-objkey = is_lpor-instid.
ls_obj_rolea-objtype = is_lpor-objtype-typeid.
ls_obj_rolea-logsys = 'OB'.

IF sy-dynnr NE '0200'.
* Create relation between object & document
CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
EXPORTING
obj_rolea = ls_obj_rolea
obj_roleb = ls_obj_roleb
relationtype = 'ATTA'
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
OTHERS = 4.

IF sy-subrc = 0.
COMMIT WORK AND WAIT.
ENDIF.
ELSE.
CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = ls_obj_rolea
obj_roleb = ls_obj_roleb
relationtype = 'ATTA'
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
OTHERS = 4.
ENDIF.

ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.

CREATE OBJECT lo_manager
EXPORTING
is_object = ls_obj_rolea
ip_no_commit = space
EXCEPTIONS
OTHERS = 1.

CALL METHOD lo_manager->unpublish.
FREE lo_manager.

CREATE OBJECT lo_manager
EXPORTING
is_object = ls_obj_rolea
ip_no_commit = space
EXCEPTIONS
OTHERS = 1.

ENDIF.

************************************************

I hope to solve your problem.

Best Regards
Romulus C.

0 Kudos
1,284

Hi,

Can you please explain it briefly, by using your code I can able to select the files but not able to attach, only one file gets attached.

0 Kudos
1,284

Hello Jerald,

In your implementation you have this elements :

And in interface : IF_EX_GOS_SRV_REQUEST~START_SERVICE you put the code.

I hope to help you
Romulus

0 Kudos
1,284

Hi,

I did like this, but it's taking only first record and adding it as attachment.

0 Kudos
1,284

Hi Romulus,

Whether I need to change this code or just copy paste this one.

0 Kudos
1,284

Hello Jackson,

Did you find any solution regarding to adding only one file as attachment problem ?

I have tried the code snipped on my system which Romulus shared and it is only adding one files as attachment.