Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

GOS LINK Attachment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

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

*& Report ZTEST_VENU3


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

REPORT

ZTEST_VENU3.

PARAMETERS:
p_type TYPE
p_file TYPE
p_desc TYPE

p_key TYPE swo_typeid OBLIGATORY,


swo_objtyp OBLIGATORY,
c LENGTH 100 OBLIGATORY LOWER CASE,
so_obj_des OBLIGATORY.

DATA: ls_fol_id TYPE soodk,


ls_obj_id TYPE soodk,
ls_obj_data TYPE sood1,
ls_folmem_k TYPE sofmk,
ls_note TYPE borident,
ls_object TYPE borident,
lv_ep_note TYPE borident-objkey,
lv_offset TYPE i.
DATA: it_objhead TYPE STANDARD TABLE OF soli,
it_content LIKE STANDARD TABLE OF soli,
wa_content LIKE soli.
ls_object-objkey = p_key.
ls_object-objtype = p_type.
TRY.
OPEN DATASET p_file FOR INPUT IN BINARY MODE.
WHILE sy-subrc = 0.
READ DATASET p_file INTO wa_content.
APPEND wa_content TO it_content.
ENDWHILE.
CLOSE DATASET p_file.
CATCH cx_sy_file_access_error.
MESSAGE 'Error reading file' TYPE 'E'.
ENDTRY.
CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
EXPORTING
it_contents_bin = it_content[]
IMPORTING
et_contents_bin = it_content[].
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING

folder_id = ls_fol_id
EXCEPTIONS
OTHERS = 1.
ls_obj_data-objsns = 'O'.
ls_obj_data-objla = sy-langu.
ls_obj_data-objdes = p_desc.
lv_offset = STRLEN( p_file ) - 3.
ls_obj_data-file_ext = p_file+lv_offset(3).
ls_obj_data-objlen = LINES( it_content ) * 255.
CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
folder_id = ls_fol_id
object_type = 'EXT'
object_hd_change = ls_obj_data
IMPORTING
object_id = ls_obj_id
TABLES
objhead = it_objhead
objcont = it_content
EXCEPTIONS
active_user_not_exist = 35
folder_not_exist = 6
object_type_not_exist = 17
owner_not_exist = 22
parameter_error = 23
OTHERS = 1000.
IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.
ls_folmem_k-foltp = ls_fol_id-objtp.
ls_folmem_k-folyr = ls_fol_id-objyr.
ls_folmem_k-folno = ls_fol_id-objno.
ls_folmem_k-doctp = ls_obj_id-objtp.
ls_folmem_k-docyr = ls_obj_id-objyr.
ls_folmem_k-docno = ls_obj_id-objno.
lv_ep_note = ls_folmem_k.
ls_note-objtype = 'MESSAGE'.
ls_note-objkey = lv_ep_note.
CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
EXPORTING
obj_rolea = ls_object
obj_roleb = ls_note
relationtype = 'ATTA'
EXCEPTIONS
OTHERS = 1.
ELSE.
MESSAGE 'Not OK' TYPE 'I'.
RETURN.
ENDIF.
IF sy-subrc = 0.
MESSAGE 'OK' TYPE 'I'.

ELSE.
MESSAGE 'Not OK' TYPE 'I'.
ENDIF.

METHOD if_ex_mb_document_badi~mb_document_before_update.
* Internal table declaration
DATA: it_otf
TYPE STANDARD TABLE OF itcoo,
it_docs
TYPE STANDARD TABLE OF docs,
it_lines
TYPE STANDARD TABLE OF tline.
* Declaration of local variables.
DATA:
st_job_output_info
TYPE ssfcrescl,
st_document_output_info TYPE ssfcrespd,
st_job_output_options
TYPE ssfcresop,
st_output_options
TYPE ssfcompop,
st_control_parameters
TYPE ssfctrlop,
v_len_in
TYPE so_obj_len,
*
v_language
TYPE sflangu VALUE 'E',
v_e_devtype
TYPE rspoptype,
v_bin_filesize
TYPE i,
v_name
TYPE string,
v_path
TYPE string,
v_fullpath
TYPE string,
v_filter
TYPE string,
v_uact
TYPE i,
v_guiobj
TYPE REF TO cl_gui_frontend_services,
v_filename
TYPE string,
v_fm_name
TYPE rs38l_fnam.

DATA:bank_contact TYPE char50,


our_contact TYPE char50,
our_reference TYPE char20,
test_number TYPE char10,
transfer_date TYPE datum,
bank_account TYPE t012k,
bank_master_data TYPE bnka,
company_code TYPE bukrs,
tel_no TYPE char50,
fax_no TYPE char50.
DATA: it_ftr
it_adr

TYPE
TYPE

CONSTANTS c_formname

ztr_ftr_t,
ztr_adr_t.
TYPE tdsfname VALUE 'ZTR_FTLETTER01'.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'


EXPORTING
i_language
= 'E'
*
i_application = 'SAPDEFAULT'
IMPORTING
e_devtype
= v_e_devtype.
st_output_options-tdprinter = v_e_devtype.
st_control_parameters-no_dialog = 'X'.
st_control_parameters-getotf = 'X'.
*.................GET SMARTFORM FUNCTION MODULE NAME.................*
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname
= c_formname
IMPORTING
fm_name
= v_fm_name
EXCEPTIONS
no_form
= 1
no_function_module = 2
OTHERS
= 3.
*...........................CALL SMARTFORM............................*
CALL FUNCTION v_fm_name
EXPORTING
control_parameters
= st_control_parameters
output_options
= st_output_options
bank_contact
= bank_contact
our_contact
= our_contact
our_reference
= our_reference
test_number
= test_number
transfer_date
= transfer_date
bank_account
= bank_account
bank_master_data
= bank_master_data
company_code
= company_code
tel_no
= tel_no
fax_no
= fax_no

IMPORTING
document_output_info
job_output_info
job_output_options
TABLES
it_ftr
it_adr
EXCEPTIONS
formatting_error
internal_error
send_error
user_canceled
OTHERS
IF sy-subrc <> 0.
* Implement suitable error
ENDIF.

= st_document_output_info
= st_job_output_info
= st_job_output_options
= it_ftr
= it_adr
=
=
=
=
=

1
2
3
4
5.

handling here

*.........................CONVERT TO OTF TO PDF.......................*


CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize
= v_bin_filesize
TABLES
otf
= st_job_output_info-otfdata
doctab_archive
= it_docs
lines
= it_lines
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS
= 3.

DATA:lv_objlen
ls_string

TYPE so_obj_len,
TYPE string.

DATA:lt_objcont TYPE soli_tab.


lv_objlen = v_bin_filesize.
* Convert OTF format to String
CALL FUNCTION 'SWA_STRING_FROM_TABLE'
EXPORTING
character_table
= it_lines
IMPORTING
character_string
= ls_string
EXCEPTIONS
no_flat_charlike_structure = 1
OTHERS
= 2.
IF sy-subrc NE 0.
ENDIF.
* Convert String to Sap Office table
CALL FUNCTION 'SWA_STRING_TO_TABLE'
EXPORTING
character_string
= ls_string

IMPORTING
character_table
= lt_objcont
EXCEPTIONS
no_flat_charlike_structure = 1
OTHERS
= 2.
IF sy-subrc NE 0.
ENDIF.
*Create Folder id.
DATA:ls_folder_id
TYPE soodk.
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region
= 'B'
IMPORTING
folder_id = ls_folder_id
EXCEPTIONS
OTHERS
= 1.
IF sy-subrc NE 0.
ENDIF.
* Now Create Attachment.
DATA:
ls_object_id
ls_object_hd_change

TYPE soodk,
TYPE sood1.

ls_object_id = ls_folder_id.
ls_object_hd_change-objlen = lv_objlen.
ls_object_hd_change-objla = sy-langu.
ls_object_hd_change-objdes = 'GRN'.
ls_object_hd_change-file_ext = 'PDF'.
ls_object_hd_change-objnam = 'GRNTEST'.
* Extract object description and extention from filename
DATA:
lv_attach_type
lv_uname

TYPE so_obj_tp VALUE 'EXT',


TYPE soud-usrnam.

DATA:ls_attach_id
TYPE soodk.
DATA:lt_objhead
TYPE soli_tab.
MOVE sy-uname TO lv_uname.
CALL FUNCTION 'SO_ATTACHMENT_INSERT'
EXPORTING
object_id
= ls_object_id
object_hd_change
= ls_object_hd_change
attach_type
= lv_attach_type
owner
= lv_uname
IMPORTING
attach_id
= ls_attach_id
TABLES

objcont
objhead
EXCEPTIONS
active_user_not_exist
object_type_not_exist
operation_no_authorization
owner_not_exist
parameter_error
substitute_not_active
substitute_not_defined
x_error
system_failure
communication_failure
OTHERS
IF sy-subrc NE 0.
ENDIF.

= lt_objcont
= lt_objhead
=
=
=
=
=
=
=
=
=
=
=

1
2
3
4
5
6
7
8
9
10
11.

* Create link between object and attachment


DATA: ls_obj_rolea
TYPE borident,
ls_obj_roleb
TYPE borident.
DATA:lv_relationtype

TYPE binreltyp VALUE 'ATTA'.

DATA:ls_mkpf TYPE mkpf.


READ TABLE xmkpf INTO ls_mkpf INDEX 1.
CONCATENATE ls_folder_id ls_attach_id
ls_obj_roleb-objtype = 'MESSAGE'.

INTO ls_obj_roleb-objkey.

CONCATENATE ls_mkpf-mblnr ls_mkpf-mjahr INTO


ls_obj_rolea-objtype = 'BUS2017'.

ls_obj_rolea-objkey .

CALL FUNCTION 'BINARY_RELATION_CREATE'


EXPORTING
obj_rolea
= ls_obj_rolea
obj_roleb
= ls_obj_roleb
relationtype = lv_relationtype
EXCEPTIONS
OTHERS
= 1.
IF sy-subrc NE 0.
ENDIF.
DATA: lv_key TYPE sweinstcou-objkey.

CONCATENATE ls_mkpf-mblnr ls_mkpf-mjahr INTO lv_key.


CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype
= 'BUS2017'
objkey
= lv_key
event
= 'CREATED'
*
creator
= sy-uname

*
*
*
*
*
*
*
*
*
*
*

take_workitem_requester = ' '


start_with_delay
= ' '
start_recfb_synchron
= ' '
no_commit_for_queue
= ' '
debug_flag
= ' '
no_logging
= ' '
ident
=
importing
event_id
=
tables
event_container
=
exceptions
objtype_not_found
= 1
others
= 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF..
ENDMETHOD.

You might also like