在采购订单屏幕的左上角有个特殊的按钮,可以通过它创建、查看或删除采购订单的附件。这个按钮是使用GOS(Generic Object Service)工具实现的,可以把GOS理解为一个连接文档和SAP内各种对象的一个工具,包括,采购订单(me23n),会计凭证(FB03)等等都用到了GOS。
下面就是me22n修改采购订单时的GOS,可以看到能为这个PO创建附件,也能查看附件清单。
下面的例子程序是用来读取PO附件文档的名称和内容,其中用到了2个FM BDS_GOS_CONNECTIONS_GET SO_DOCUMENT_READ_API1。
BDS_GOS_CONNECTIONS_GET:用来获取GOS的连接
SO_DOCUMENT_READ_API1:用来通过GOS连接读取具体的附件文档名称、内容等相关信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
REPORT ytest_gos_export_attachment. PARAMETERS:p_ebeln TYPE ekko-ebeln. DATA:lv_logical_system LIKE bapibds01-log_system, classname LIKE bapibds01-classname, gos_objkey LIKE swotobjid-objkey, lt_gos_connections LIKE bdn_con OCCURS 1 WITH HEADER LINE. DATA:lv_id TYPE sofolenti1-doc_id, ls_doc_data TYPE sofolenti1, lt_object_header TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE, lt_object_content TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE, lt_hex TYPE STANDARD TABLE OF solix WITH HEADER LINE. CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET' IMPORTING own_logical_system = lv_logical_system EXCEPTIONS own_lv_logical_system_not_defined = 1 OTHERS = 2. . gos_objkey = p_ebeln. "采购订单 CALL FUNCTION 'BDS_GOS_CONNECTIONS_GET' EXPORTING logical_system = lv_logical_system classname = 'BUS2012' "用来标识采购订单 objkey = gos_objkey client = sy-mandt TABLES gos_connections = lt_gos_connections EXCEPTIONS no_objects_found = 1 internal_error = 2 internal_gos_error = 3 OTHERS = 4. LOOP AT lt_gos_connections. lv_id = lt_gos_connections-loio_id. CALL FUNCTION 'SO_DOCUMENT_READ_API1' EXPORTING document_id = lv_id IMPORTING document_data = ls_doc_data TABLES object_header = lt_object_header object_content = lt_object_content contents_hex = lt_hex EXCEPTIONS document_id_not_exist = 1 operation_no_authorization = 2 x_error = 3 OTHERS = 4. BREAK-POINT. ENDLOOP. |
程序里加了个断点,运行时能看到 lt_object_content和 lt_object_header中的内容,一个保存了附件名字(BaiduSAP.txt)和类型(ASC),另外一个保存了内容。
txt文件的内容:
me23n采购订单中查看到的文档清单:
以上。
发表评论