gos link attachment

Upload: venu

Post on 06-Oct-2015

12 views

Category:

Documents


0 download

DESCRIPTION

GOS LINK Attachment

TRANSCRIPT

*&---------------------------------------------------------------------**&ReportZTEST_VENU3*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*

REPORTZTEST_VENU3.

PARAMETERS:p_keyTYPEswo_typeidOBLIGATORY,p_typeTYPEswo_objtypOBLIGATORY,p_fileTYPEcLENGTH100OBLIGATORYLOWERCASE,p_descTYPEso_obj_desOBLIGATORY.

DATA:ls_fol_idTYPEsoodk,ls_obj_idTYPEsoodk,ls_obj_dataTYPEsood1,ls_folmem_kTYPEsofmk,ls_noteTYPEborident,ls_objectTYPEborident,lv_ep_noteTYPEborident-objkey,lv_offsetTYPEi.

DATA:it_objheadTYPESTANDARDTABLEOFsoli,it_contentLIKESTANDARDTABLEOFsoli,wa_contentLIKEsoli.

ls_object-objkey=p_key.ls_object-objtype=p_type.

TRY.OPENDATASETp_fileFORINPUTINBINARYMODE.WHILEsy-subrc=0.READDATASETp_fileINTOwa_content.APPENDwa_contentTOit_content.ENDWHILE.CLOSEDATASETp_file.CATCHcx_sy_file_access_error.MESSAGE'Errorreadingfile'TYPE'E'.ENDTRY.

CALLFUNCTION'SO_CONVERT_CONTENTS_BIN'EXPORTINGit_contents_bin=it_content[]IMPORTINGet_contents_bin=it_content[].

CALLFUNCTION'SO_FOLDER_ROOT_ID_GET'EXPORTINGregion='B'IMPORTINGfolder_id=ls_fol_idEXCEPTIONSOTHERS=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.

CALLFUNCTION'SO_OBJECT_INSERT'EXPORTINGfolder_id=ls_fol_idobject_type='EXT'object_hd_change=ls_obj_dataIMPORTINGobject_id=ls_obj_idTABLESobjhead=it_objheadobjcont=it_contentEXCEPTIONSactive_user_not_exist=35folder_not_exist=6object_type_not_exist=17owner_not_exist=22parameter_error=23OTHERS=1000.

IFsy-subrc=0ANDls_object-objkeyISNOTINITIAL.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.CALLFUNCTION'BINARY_RELATION_CREATE_COMMIT'EXPORTINGobj_rolea=ls_objectobj_roleb=ls_noterelationtype='ATTA'EXCEPTIONSOTHERS=1.ELSE.MESSAGE'NotOK'TYPE'I'.RETURN.ENDIF.

IFsy-subrc=0.MESSAGE'OK'TYPE'I'.ELSE.MESSAGE'NotOK'TYPE'I'.ENDIF.

METHODif_ex_mb_document_badi~mb_document_before_update.*InternaltabledeclarationDATA:it_otfTYPESTANDARDTABLEOFitcoo,it_docsTYPESTANDARDTABLEOFdocs,it_linesTYPESTANDARDTABLEOFtline.

*Declarationoflocalvariables.DATA:st_job_output_infoTYPEssfcrescl,st_document_output_infoTYPEssfcrespd,st_job_output_optionsTYPEssfcresop,st_output_optionsTYPEssfcompop,st_control_parametersTYPEssfctrlop,v_len_inTYPEso_obj_len,*v_languageTYPEsflanguVALUE'E',v_e_devtypeTYPErspoptype,v_bin_filesizeTYPEi,v_nameTYPEstring,v_pathTYPEstring,v_fullpathTYPEstring,v_filterTYPEstring,v_uactTYPEi,v_guiobjTYPEREFTOcl_gui_frontend_services,v_filenameTYPEstring,v_fm_nameTYPErs38l_fnam.

DATA:bank_contactTYPEchar50,our_contactTYPEchar50,our_referenceTYPEchar20,test_numberTYPEchar10,transfer_dateTYPEdatum,bank_accountTYPEt012k,bank_master_dataTYPEbnka,company_codeTYPEbukrs,tel_noTYPEchar50,fax_noTYPEchar50.

DATA:it_ftrTYPEztr_ftr_t,it_adrTYPEztr_adr_t.

CONSTANTSc_formnameTYPEtdsfnameVALUE'ZTR_FTLETTER01'.

CALLFUNCTION'SSF_GET_DEVICE_TYPE'EXPORTINGi_language='E'*i_application='SAPDEFAULT'IMPORTINGe_devtype=v_e_devtype.

st_output_options-tdprinter=v_e_devtype.st_control_parameters-no_dialog='X'.st_control_parameters-getotf='X'.*.................GETSMARTFORMFUNCTIONMODULENAME.................*CALLFUNCTION'SSF_FUNCTION_MODULE_NAME'EXPORTINGformname=c_formnameIMPORTINGfm_name=v_fm_nameEXCEPTIONSno_form=1no_function_module=2OTHERS=3.

*...........................CALLSMARTFORM............................*CALLFUNCTIONv_fm_nameEXPORTINGcontrol_parameters=st_control_parametersoutput_options=st_output_optionsbank_contact=bank_contactour_contact=our_contactour_reference=our_referencetest_number=test_numbertransfer_date=transfer_datebank_account=bank_accountbank_master_data=bank_master_datacompany_code=company_codetel_no=tel_nofax_no=fax_noIMPORTINGdocument_output_info=st_document_output_infojob_output_info=st_job_output_infojob_output_options=st_job_output_optionsTABLESit_ftr=it_ftrit_adr=it_adrEXCEPTIONSformatting_error=1internal_error=2send_error=3user_canceled=4OTHERS=5.IFsy-subrc0.*ImplementsuitableerrorhandlinghereENDIF.

*.........................CONVERTTOOTFTOPDF.......................*CALLFUNCTION'CONVERT_OTF_2_PDF'IMPORTINGbin_filesize=v_bin_filesizeTABLESotf=st_job_output_info-otfdatadoctab_archive=it_docslines=it_linesEXCEPTIONSerr_conv_not_possible=1err_otf_mc_noendmarker=2OTHERS=3.

DATA:lv_objlenTYPEso_obj_len,ls_stringTYPEstring.

DATA:lt_objcontTYPEsoli_tab.lv_objlen=v_bin_filesize.*ConvertOTFformattoStringCALLFUNCTION'SWA_STRING_FROM_TABLE'EXPORTINGcharacter_table=it_linesIMPORTINGcharacter_string=ls_stringEXCEPTIONSno_flat_charlike_structure=1OTHERS=2.IFsy-subrcNE0.

ENDIF.

*ConvertStringtoSapOfficetableCALLFUNCTION'SWA_STRING_TO_TABLE'EXPORTINGcharacter_string=ls_stringIMPORTINGcharacter_table=lt_objcontEXCEPTIONSno_flat_charlike_structure=1OTHERS=2.IFsy-subrcNE0.

ENDIF.

*CreateFolderid.DATA:ls_folder_idTYPEsoodk.CALLFUNCTION'SO_FOLDER_ROOT_ID_GET'EXPORTINGregion='B'IMPORTINGfolder_id=ls_folder_idEXCEPTIONSOTHERS=1.IFsy-subrcNE0.

ENDIF.

*NowCreateAttachment.

DATA:ls_object_idTYPEsoodk,ls_object_hd_changeTYPEsood1.

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'.*Extractobjectdescriptionandextentionfromfilename

DATA:lv_attach_typeTYPEso_obj_tpVALUE'EXT',lv_unameTYPEsoud-usrnam.

DATA:ls_attach_idTYPEsoodk.DATA:lt_objheadTYPEsoli_tab.MOVEsy-unameTOlv_uname.

CALLFUNCTION'SO_ATTACHMENT_INSERT'EXPORTINGobject_id=ls_object_idobject_hd_change=ls_object_hd_changeattach_type=lv_attach_typeowner=lv_unameIMPORTINGattach_id=ls_attach_idTABLESobjcont=lt_objcontobjhead=lt_objheadEXCEPTIONSactive_user_not_exist=1object_type_not_exist=2operation_no_authorization=3owner_not_exist=4parameter_error=5substitute_not_active=6substitute_not_defined=7x_error=8system_failure=9communication_failure=10OTHERS=11.IFsy-subrcNE0.ENDIF.

*CreatelinkbetweenobjectandattachmentDATA:ls_obj_roleaTYPEborident,ls_obj_rolebTYPEborident.

DATA:lv_relationtypeTYPEbinreltypVALUE'ATTA'.

DATA:ls_mkpfTYPEmkpf.

READTABLExmkpfINTOls_mkpfINDEX1.CONCATENATEls_folder_idls_attach_idINTOls_obj_roleb-objkey.ls_obj_roleb-objtype='MESSAGE'.

CONCATENATEls_mkpf-mblnrls_mkpf-mjahrINTOls_obj_rolea-objkey.ls_obj_rolea-objtype='BUS2017'.

CALLFUNCTION'BINARY_RELATION_CREATE'EXPORTINGobj_rolea=ls_obj_roleaobj_roleb=ls_obj_rolebrelationtype=lv_relationtypeEXCEPTIONSOTHERS=1.IFsy-subrcNE0.ENDIF.

DATA:lv_keyTYPEsweinstcou-objkey.

CONCATENATEls_mkpf-mblnrls_mkpf-mjahrINTOlv_key.

CALLFUNCTION'SWE_EVENT_CREATE'EXPORTINGobjtype='BUS2017'objkey=lv_keyevent='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=exceptionsobjtype_not_found=1others=2.IFsy-subrc0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ENDIF..ENDMETHOD.