云服务器价格_云数据库_云主机【优惠】最新活动-搜集站云资讯

网站空间_6元虚拟主机_免费领

小七 141 0

网站空间_6元虚拟主机_免费领

Scenario:

Many times there is a business requirement of linking documents, entering notes, sending notes or linking an internet address to various SAP objects. These external  attachments can be reference documents, pictures, Email attachments, design , diagrams or related spreadsheets. To meet this requirement SAP has provided a tool bar called ‘Generic Service Toolbar'(GOS).

Recently, I came across a requirement where i had to create a attachment for existing sales order (va02) through report. in this requirement i have created a Custom report.

By using this report, You can attach a wide range of documents like Word Document, Excel Sheets, PDF and Text files and many more, including pictures.

Go to transaction SE38 and create report .

Here is the Source Code.

*Declarations

*Structure Declarations

TYPES : BEGIN OF ty_table,    "Structure for FileName

fname(128) TYPE c,

END OF ty_table.

*Data Declarations

DATA: w_prog                TYPE sy-repid,         "Current Program Name

w_dynnr              TYPE sy-dynnr,        "Current Dynpro Number

w_attachement   TYPE borident,         "Work Area for BOR object identifier

ws_borident        TYPE borident,         "Work Area for BOR object identifier

w_document       TYPE sood4,            "Interface for send screen and MOM

folder_id             TYPE soodk,             "Definition of Object Key

w_h_data           TYPE sood2,             "Object Definition Workarea

w_fol_data         TYPE sofm2,             "Folder Contents Work area

w_rec_data        TYPE soos6,             "Transfer Information of folder Work area

ws_files              TYPE ty_table,

wt_files               TYPE TABLE OF ty_table.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

*Parameter Declarations

PARAMETER: p_mandt TYPE sy-mandt,                                                      " Client Number

p_vbeln TYPE vbeln,                                                                            " Sales Order Number

p_path  TYPE ibipparms-path  MEMORY ID ad_local_path,               " File Path

p_name(30).                                                                                          " Name of attachement.

SELECTION-SCREEN END OF BLOCK b1.

*Initialization Event

INITIALIZATION .

w_prog = sy-repid .

w_dynnr = sy-dynnr .

*/ Selection Screen  For File Path Selection

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path .

*/ F4 Help for file selection

CALL FUNCTION ‘F4_FILENAME’

EXPORTING

program_name        = w_prog

dynpro_number       = w_dynnr

field_name               = ‘P_PATH’

IMPORTING

file_name                 = p_path .

*Start of selection Evvent

START-OF-SELECTION .

*/Client Validations

IF sy-mandt NE p_mandt .

WRITE ‘Mandt Error’ .

EXIT .

ENDIF .

*/ Assign Object Keys to the Structure BOR

ws_borident-objkey      = p_vbeln.             "SalesOrder Number

ws_borident-objtype     = ‘EQUI’.               "Object Type

ws_borident-objtype     = ‘BUS2032’.        "BUS Number

*/ Filename Assign to the Structure

ws_files-fname = p_path .               "Path

APPEND ws_files TO wt_files .

*/ Folder Root

CALL FUNCTION ‘SO_FOLDER_ROOT_ID_GET’

EXPORTING

region    = ‘B’

IMPORTING

folder_id = folder_id

EXCEPTIONS

OTHERS    = 1.

*/ Append data to the MOM Structure

w_document-foltp   = folder_id-objtp.

w_document-folyr   = folder_id-objyr .

w_document-folno   = folder_id-objno .

w_document-objdes  = p_name .           "Name of file

w_document-objnam  = p_name .          "Name of file

*/ Attachment FileName Assignment

w_h_data-objdes = p_name .                 "Name of file

*/ Using this function module to read FILE from Presentation server

CALL FUNCTION ‘SO_DOCUMENT_REPOSITORY_MANAGER’

EXPORTING

method                  = ‘IMPORTFROMPC’

ref_document        = w_document

TABLES

files                       = wt_files

CHANGING

document              = w_document

header_data          = w_h_data

folmem_data         = w_fol_data

receive_data         = w_rec_data .

*/ File Creation OkCodes

IF w_document-okcode = ‘CREA’ OR w_document-okcode = ‘CHNG’.

w_attachement-objtype = ‘MESSAGE’.

w_attachement-objkey  = w_document(34).

CALL FUNCTION ‘BINARY_RELATION_CREATE_COMMIT’

EXPORTING

obj_rolea            = ws_borident

obj_roleb            = w_attachement

relationtype         = ‘ATTA’

EXCEPTIONS

no_model             = 1

internal_error       = 2

unknown              = 3

OTHERS             = 4.

*/Error Handling

IF sy-subrc 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF .

Before Execution:

Go to the transaction VA03 (Sales Order Display ) in system as shown in the below screen shot.

There is no attachment existed for this sales order. Now go to report and execute it following selection screen will be display.

Give the inputs Client Number, Sales  order number , File path and file name as shown in below.

In this i have given a text document for attachment.

When click on execute button it will create a sales order attachment.

Testing:

Now go to transaction VA03 and check whether the attachment is added or not.

Attachment is added.

Table Storage:

The Content of file converted to binary and it stores in tables like SOOD and SRGBTBREL.

SOOD Table stores the information of attached Object info.

SRGBTBREL table stores the information of Relationships in GOS Environment.

I hope this Blog would help many ABAP’ers in attaching files.

Thanks&Regards,

Harikrishna M.

Good attempt Hari .Thanks for sharing.

Thank you very much jayakumar

Good job..

Thanks Mohammed

Thank you so much for the information

Thanks Sarkar....

Good Information

Thankyou Nara ....

Hello HariKrishna,

Good Information,

Just need to know if we can attach multiple files using this FM

Thankyou Hardika,you can attach only single attachment by using this function module.

If you want to attach multiple files, then you can loop this function module.

Sure Thanks, One more info i needed, the files attached are stored in the database server by using the above method. Is there a way we can store the files on the content server?

Like Archiving the files?

,物联网的,老虎淘客,网站服务器租用,2018世界人工智能大会,啥是大数据