【轉載】傳送SAP附件到 WEBSERVICE介面(二進位制)

hubaichun發表於2018-10-13

原文地址:https://archive.sap.com/discussions/thread/59572

TXT檔案傳輸有問題。

*"*"本地介面:
*"  IMPORTING
*"     VALUE(IS_OBJECT) TYPE  SIBFLPORB
*"  TABLES
*"      DOCUMENT_DATA1 STRUCTURE  SOFOLENTI1
*"      OBJECT_HEADER STRUCTURE  SOLISTI1
*"      OBJECT_CONTENT STRUCTURE  SOLISTI1
*"      CONTENTS_HEX1 STRUCTURE  SOLIX
*"      ATTACHMENT_LIST STRUCTURE  SOATTLSTI1
*"      RECEIVER_LIST STRUCTURE  SORECLSTI1
*"      OBJECT_PARA STRUCTURE  SOPARAI1
*"      OBJECT_PARB STRUCTURE  SOPARBI1
*"  EXCEPTIONS
*"      EXCEPTION_STRING
*"      ICX_OBL_PARAMETER_ERROR
*"----------------------------------------------------------------------

  DATA : P_BOTYPE LIKE TOJTB-NAME,
         V_TBX    LIKE SY-TABIX.

  DATA:ET_LINKS_S TYPE OBL_S_LINK,
       ET_LINKS   TYPE  OBL_T_LINK.

  DATA:CONTENTS_HEX TYPE TABLE OF SOLIX.

  DATA: DOCUMENT_ID   LIKE SOFOLENTI1-DOC_ID,
        DOCUMENT_DATA TYPE SOFOLENTI1.

*include: RSSOCONS.

  CLASS CL_GOS_DOCUMENT_SERVICE DEFINITION LOAD.

*  CREATE OBJECT RF.

  IS_OBJECT-INSTID = '4500000000'. "訂單號
  IS_OBJECT-TYPEID = 'BUS2012'.  "業務型別 SWO1裡面查詢
  IS_OBJECT-CATID = 'BO'.

  REFRESH ET_LINKS.

  DATA: ICX_OBL_PARAMETER_ERROR TYPE REF TO IF_MESSAGE.

  TRY.

      CALL METHOD CL_BINARY_RELATION=>READ_LINKS_OF_BINREL
        EXPORTING
          IS_OBJECT   = IS_OBJECT
          IP_RELATION = 'ATTA'
        IMPORTING
          ET_LINKS    = ET_LINKS.
*
*    CATCH
*
*    CX_OBL_PARAMETER_ERROR INTO ICX_OBL_PARAMETER_ERROR.
*
*      EXCEPTION_STRING = ICX_OBL_PARAMETER_ERROR->GET_LONGTEXT( ).
*
*    CATCH CX_OBL_INTERNAL_ERROR INTO ICX_OBL_INTERNAL_ERROR .
*
*      EXCEPTION_STRING = ICX_OBL_INTERNAL_ERROR->GET_LONGTEXT( ).
*
*    CATCH CX_OBL_MODEL_ERROR INTO ICX_OBL_MODEL_ERROR.
*
*      EXCEPTION_STRING = ICX_OBL_MODEL_ERROR->GET_LONGTEXT( ).

  ENDTRY.

  LOOP AT ET_LINKS INTO ET_LINKS_S.

    V_TBX = SY-TABIX.

    DOCUMENT_ID = ET_LINKS_S-INSTID_B.

    CALL FUNCTION 'SO_DOCUMENT_READ_API1'
      EXPORTING
        DOCUMENT_ID                = DOCUMENT_ID
*       FILTER                     = 'X '
      IMPORTING
        DOCUMENT_DATA              = DOCUMENT_DATA
      TABLES
        OBJECT_HEADER              = OBJECT_HEADER
        OBJECT_CONTENT             = OBJECT_CONTENT
        OBJECT_PARA                = OBJECT_PARA
        OBJECT_PARB                = OBJECT_PARB
        ATTACHMENT_LIST            = ATTACHMENT_LIST
        RECEIVER_LIST              = RECEIVER_LIST
        CONTENTS_HEX               = CONTENTS_HEX
      EXCEPTIONS
        DOCUMENT_ID_NOT_EXIST      = 1
        OPERATION_NO_AUTHORIZATION = 2
        X_ERROR                    = 3
        OTHERS                     = 4.

    IF SY-SUBRC <> 0.

      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    APPEND LINES OF CONTENTS_HEX TO CONTENTS_HEX1.
    APPEND DOCUMENT_DATA TO DOCUMENT_DATA1.

相關文章