Skip to Content
avatar image
Former Member

Have problem when generate Web Service from bapi function

Dear all,

Please kindly help me about generating Web Service from BAPI function, It does not success only this attached function.

I have done so many function without any problems.

I found 1 case that I use specific variable to be an import/ export then, it can't create as well.

As for this one, I try so many changes but I can't success it as well.

This is my function on R/3 4.6C, Dot net connector 2.0, Dot net Frame Work 1.1.

FUNCTION Z_BAPI_ATTACHMENT_CREATE.

*"----


""Local interface: Type: Remote-enabled module

*" IMPORTING

*" VALUE(P_BOTYPE) LIKE BORIDENT-OBJTYPE

*" VALUE(P_BO_ID) LIKE BORIDENT-OBJKEY

*" VALUE(P_MSGTYP) LIKE SOFM-DOCTP

*" VALUE(P_DOCTY) LIKE BORIDENT-OBJTYPE

*" VALUE(P_RELTYP) LIKE BRELTYP-RELTYPE

*" VALUE(P_FNAME) LIKE RLGRAP-FILENAME

*" VALUE(P_OBJDES) TYPE SO_OBJ_DES

*" EXPORTING

*" VALUE(RETURNMESSAGE) TYPE CHAR50

*"----


INCLUDE : <cntn01>.

  • P_BOTYPE TYPE BORIDENT-OBJTYPE DEFAULT 'BUS2105'

  • P_BO_ID TYPE BORIDENT-OBJKEY

  • P_MSGTYPE TYPE SOFM-DOCTP DEFAULT 'URL'

  • P_DOCTY TYPE BORIDENT-OBJTYPE DEFAULT 'MESSAGE'

  • P_RELTYP TYPE BRELTYP-RELTYPE DEFAULT 'ATTA'

  • P_FNAME TYPE RLGRAP-FILENAME

  • P_OBJDES TYPE SO_OBJ_DES

TYPES: BEGIN OF ty_message_key,

foltp TYPE so_fol_tp,

folyr TYPE so_fol_yr,

folno TYPE so_fol_no,

doctp TYPE so_doc_tp,

docyr TYPE so_doc_yr,

docno TYPE so_doc_no,

fortp TYPE so_for_tp,

foryr TYPE so_for_yr,

forno TYPE so_for_no,

END OF ty_message_key.

DATA : lv_message_key TYPE ty_message_key.

DATA : lo_message TYPE swc_object.

DATA : lt_doc_content TYPE STANDARD TABLE OF soli-line

WITH HEADER LINE.

----


  • First derive the Attachment's ( MESSAGE )document type.

p_docty = 'MESSAGE'.

CASE p_reltyp.

  • In case of URls

WHEN 'URL'.

p_msgtyp = 'URL'.

  • In case of Notes / Private Notes

WHEN 'NOTE' OR 'PNOT'.

p_msgtyp = 'RAW'.

WHEN 'ATTA'.

  • Take given parameter e.g. 'DOC', 'PDF' etc.

  • P_MSGTYP = 'EXT'.

WHEN OTHERS.

  • ....exit

EXIT.

ENDCASE.

----


  • Create an initial instance of BO 'MESSAGE' - to call the

  • instance-independent method 'Create'.

swc_create_object lo_message 'MESSAGE' lv_message_key.

  • define container to pass the parameter values to the method call

  • in next step.

swc_container lt_message_container.

  • Populate container with parameters for method

swc_set_element lt_message_container 'DOCUMENTTITLE' p_objdes.

swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.

swc_set_element lt_message_container 'NO_DIALOG' 'X'.

swc_set_element lt_message_container 'DOCUMENTNAME' p_docty.

swc_set_element lt_message_container 'DOCUMENTTYPE' p_msgtyp.

  • In case of URLs..it should be concatenated with &KEY& in the begining.

CASE p_msgtyp.

WHEN 'URL'.

CONCATENATE '&KEY&' p_fname INTO lt_doc_content.

APPEND lt_doc_content.

  • In case of Notes or Private Notes, get the data from files on appl

  • server or from wherever(? - remember background).

WHEN 'RAW'.

lt_doc_content = p_fname.

APPEND lt_doc_content.

  • In case of PC File attachments

WHEN OTHERS.

OPEN DATASET p_fname FOR INPUT IN BINARY MODE.

IF sy-subrc EQ 0.

DO.

READ DATASET p_fname INTO lt_doc_content. "2 of 27

IF sy-subrc EQ 0.

APPEND lt_doc_content.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET p_fname.

ENDIF.

ENDCASE.

  • 'DocumentContent' is a multi-line element ( itab ).

swc_set_table lt_message_container 'DocumentContent' lt_doc_content.

  • Size is required in case of File attachments

DATA : lv_doc_size TYPE i.

DATA : l_file_lines TYPE i.

DESCRIBE TABLE lt_doc_content LINES l_file_lines.

READ TABLE lt_doc_content INDEX l_file_lines.

lv_doc_size = ( 255 * ( l_file_lines - 1 ) ) +

STRLEN( lt_doc_content ).

swc_set_element lt_message_container 'DOCUMENTSIZE' lv_doc_size .

  • Refresh to get the reference of create 'MESSAGE' object for attachment

swc_refresh_object lo_message.

swc_call_method lo_message 'CREATE' lt_message_container.

  • Get Key of new object

swc_get_object_key lo_message lv_message_key.

  • Now we have attachment as a business object instance. We can now

  • attach it to our main business object instance.

  • Create main BO object_a

  • data: LO_IS_OBJECT_A type SIBFLPORB. "type SIBFLPORB is unknown, so I

DATA: lo_is_object_a TYPE borident.

lo_is_object_a-objkey = p_bo_id.

lo_is_object_a-objtype = p_botype.

  • LO_IS_OBJECT_A-CATID = 'BO'.

  • Create attachment BO object_b

  • data: LO_IS_OBJECT_B type SIBFLPORB. "type SIBFLPORB is unknown

DATA: lo_is_object_b TYPE borident.

lo_is_object_b-objkey = lv_message_key.

lo_is_object_b-objtype = p_docty.

  • LO_IS_OBJECT_B-CATID = 'BO'.

*TRY.

*CALL METHOD CL_BINARY_RELATION=&gtCREATE_LINK

  • EXPORTING

  • IS_OBJECT_A = LO_IS_OBJECT_A

  • IS_OBJECT_B = LO_IS_OBJECT_B

  • IP_RELTYPE = P_RELTYP.

CALL FUNCTION 'BINARY_RELATION_CREATE'

EXPORTING

obj_rolea = lo_is_object_a

obj_roleb = lo_is_object_b

relationtype = p_reltyp

EXCEPTIONS

OTHERS = 1.

  • Check if everything OK...who cares!!

COMMIT WORK.

if sy-subrc = 0.

RETURNMESSAGE = 'S-Success'.

else.

RETURNMESSAGE = 'E-Error'.

endif.

ENDFUNCTION.

Thanks in advance,

Benjawan

Edited by: Nitipat Chadchavalpanichaya on Oct 20, 2008 9:02 AM

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 20, 2008 at 12:51 PM

    what is the error you are getting?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      There is no any error message show up. It just the class

      Z_BAPI_ATTACHMENT_CREATE doesn't create autometically as normal. I showed you as below.

      That means I can't call class z_bapi_attachment_create.

      '----


      ' <autogenerated>

      ' This code was generated by a SAP. NET Connector Proxy Generator Version 2.0

      ' Created at 21/10/2551

      ' Created from Windows

      '

      ' Changes to this file may cause incorrect behavior and will be lost if

      ' the code is regenerated.

      ' </autogenerated>

      '----


      Imports System

      Imports System.Text

      Imports System.Collections

      Imports System.ComponentModel

      Imports System.Runtime.InteropServices

      Imports System.Xml.Serialization

      Imports System.Web.Services

      Imports System.Web.Services.Description

      Imports System.Web.Services.Protocols

      Imports SAP.Connector

      '@ <summary>

      '@ Client SAP proxy class

      '@ </summary>

      <WebServiceBinding(Name:="dummy.Binding", Namespace:="urn:sap-com:document:sap:rfc:functions")> _

      Public Class PRAttachment

      Inherits SAPClient

      '@ <summary>

      '@ Initializes a new PRAttachment.

      '@ </summary>

      Public Sub New()

      End Sub

      '@ <summary>

      '@ Initializes a new PRAttachment with a new connection based on the specified connection string.

      '@ </summary>

      '@ <param name="connectionString">A connection string (e.g. RFC or URL) specifying the system where the proxy should connect to.</param>

      Public Sub New(ByVal ConnectionString As String)

      MyBase.New(ConnectionString)

      End Sub

      '@ <summary>

      '@ Initializes a new PRAttachment and adds it to the given container.

      '@ This allows automated connection mananged by VS component designer:

      '@ If container is disposed, it will also dispose this SAPClient instance,

      '@ which will dispose a contained connection if needed.

      '@ </summary>

      '@ <param name="Cont">The container where the new SAPClient instance is to be added.</param>

      Public Sub New(ByVal Cont As Container)

      MyBase.New(Cont)

      End Sub

      End Class