Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

VF02 - attach an file

Former Member
0 Kudos

HI all

What is the FM of BAPI to upload an attachement to billing document?

Thanks in advance

9 REPLIES 9

Former Member
0 Kudos

Hi DB,

You can use the function module BDS_BUSINESSDOCUMENT_CREA_TAB to attach the documents for any transactions.

Find the below code which i have done to attach the documents to QM02 transaction.

function zfm_attach_documents .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_QMNUM) LIKE  VIQMEL-QMNUM
*"     VALUE(I_FENUM) LIKE  VIQMFE-FENUM
*"     VALUE(I_FILETYPE) LIKE  BAPICOMPON-MIMETYPE
*"     VALUE(I_FILENAME) LIKE  BAPISIGNAT-PROP_NAME
*"  TABLES
*"      T_CONTENT STRUCTURE  BAPICONTEN
*"----------------------------------------------------------------------
  data: lv_object_key type sbdst_object_key,
        lv_logsys type tbdls-logsys.

  data: lit_signature type table of bapisignat,
        lwa_signature like line of lit_signature,
        lit_components type table of  bapicompon,
        lwa_components like line of lit_components,
        lit_content TYPE TABLE OF bapiconten,
        lwa_content LIKE LINE OF lit_content.

  data: ls_sdokmime type sdokmime.

  constants: c_classname type sbdst_classname value 'QMFE',
             c_classtype type sbdst_classtype value 'BO',
             c_logsys type tbdls-logsys value 'EC1CLNT800',
             c_clnt(2) TYPE c VALUE 'CL'.

  CLEAR: lwa_signature, lv_logsys.
  REFRESH: lit_signature.
  CONCATENATE sy-sysid c_clnt sy-mandt INTO lv_logsys.

  concatenate i_qmnum i_fenum into lv_object_key.


  case i_filetype.

    when 'DOC'.

      lwa_signature-doc_count = 1.
      lwa_signature-doc_ver_no = 1.
      lwa_signature-doc_var_id = 1.
      lwa_signature-doc_var_tg = 'OR'.
      lwa_signature-comp_count = 1.

      lwa_signature-prop_name  = 'BDS_DOCUMENTTYPE'.
      lwa_signature-prop_value = 'BDS_ATTACH'.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  = 'BDS_DOCUMENTCLASS'.
      lwa_signature-prop_value = 'DOC'.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  =	'DESCRIPTION'.
      lwa_signature-prop_value = i_filename.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  =	'LANGUAGE'.
      lwa_signature-prop_value = 'E'.
      append lwa_signature to lit_signature.
      clear lwa_signature.

*Entering values for table components
      lwa_components-doc_count = 1.
      lwa_components-comp_count = 1.
      lwa_components-comp_id   = i_filename.
      lwa_components-mimetype = 'APPLICATION/MSWORD'.

      append lwa_components to lit_components.
      clear lwa_components.

    when 'XLS'.
      lwa_signature-doc_count = 1.
      lwa_signature-doc_ver_no = 1.
      lwa_signature-doc_var_id =	1.
      lwa_signature-doc_var_tg = 'OR'.
      lwa_signature-comp_count =	1.

      lwa_signature-prop_name  = 'BDS_DOCUMENTTYPE'.
      lwa_signature-prop_value = 'BDS_SHEET'.
      append lwa_signature to lit_signature.


      lwa_signature-prop_name  = 'BDS_DOCUMENTCLASS'.
      lwa_signature-prop_value = 'XLS'.
      append lwa_signature to lit_signature.


      lwa_signature-prop_name  = 'DESCRIPTION'.
      lwa_signature-prop_value = i_filename.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  = 'LANGUAGE'.
      lwa_signature-prop_value = 'E'.
      append lwa_signature to lit_signature.
      clear lwa_signature.

*Entering values for table components
      lwa_components-doc_count = 1.
      lwa_components-comp_count = 1.
      lwa_components-comp_id   = i_filename.
      lwa_components-mimetype = 'APPLICATION/VND.MS-EXCEL'.

      append lwa_components to lit_components.
      clear lwa_components.

    when 'PDF'.
      lwa_signature-doc_count = 1.
      lwa_signature-doc_ver_no = 1.
      lwa_signature-doc_var_id =	1.
      lwa_signature-doc_var_tg = 'OR'.
      lwa_signature-comp_count =	1.

      lwa_signature-prop_name  = 'BDS_DOCUMENTTYPE'.
      lwa_signature-prop_value = 'ZFSCMPDF'.
      append lwa_signature to lit_signature.


      lwa_signature-prop_name  = 'BDS_DOCUMENTCLASS'.
      lwa_signature-prop_value = 'PDF'.
      append lwa_signature to lit_signature.


      lwa_signature-prop_name  = 'DESCRIPTION'.
      lwa_signature-prop_value = i_filename.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  = 'LANGUAGE'.
      lwa_signature-prop_value = 'E'.
      append lwa_signature to lit_signature.
      clear lwa_signature.

*Entering values for table components
      lwa_components-doc_count = 1.
      lwa_components-comp_count = 1.
      lwa_components-comp_id   = i_filename.
      lwa_components-mimetype = 'APPLICATION/PDF'.

      append lwa_components to lit_components.
      clear lwa_components.

    when 'RTF'.

      lwa_signature-doc_count = 1.
      lwa_signature-doc_ver_no = 1.
      lwa_signature-doc_var_id = 1.
      lwa_signature-doc_var_tg = 'OR'.
      lwa_signature-comp_count = 1.

      lwa_signature-prop_name  = 'BDS_DOCUMENTTYPE'.
      lwa_signature-prop_value = 'BDS_ATTACH'.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  = 'BDS_DOCUMENTCLASS'.
      lwa_signature-prop_value = 'RTF'.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  =	'DESCRIPTION'.
      lwa_signature-prop_value = i_filename.
      append lwa_signature to lit_signature.

      lwa_signature-prop_name  =	'LANGUAGE'.
      lwa_signature-prop_value = 'E'.
      append lwa_signature to lit_signature.
      clear lwa_signature.

*Entering values for table components
      lwa_components-doc_count = 1.
      lwa_components-comp_count = 1.
      lwa_components-comp_id   = i_filename.
      lwa_components-mimetype = 'APPLICATION/RTF'.

      append lwa_components to lit_components.
      clear lwa_components.

    when others.
      exit.
  endcase.

  LOOP AT t_content INTO lwa_content.
    APPEND lwa_content TO lit_content.
  ENDLOOP.

  call function 'BDS_BUSINESSDOCUMENT_CREA_TAB'
    exporting
      logical_system = c_logsys
      classname      = c_classname
      classtype      = c_classtype
      client         = sy-mandt
      object_key     = lv_object_key
      binary_flag    = 'X'
    tables
      signature      = lit_signature
      components     = lit_components
      content        = lit_content.
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

endfunction.

Reward for useful answers.

Cheers,

Satish

0 Kudos

HI thanks for the coding, Where did you find teh values for classname, classtyp etc etc?

I want to attach a PDF file in VF02

JB

Former Member
0 Kudos

Hi J B,

in your case Class name is BUS2037 and Class type is same 'BO'.

Pls. reward if it helps.

Cheers,

Satish

0 Kudos

I get alwas an error when I try to open the file in the attachement list:

Attachement list error while loading document -> Can you send me the coding before you call the Z function module.

DO you know also the classname and classtype for FB02?

Thanks in advance

J

0 Kudos

Hi Satish ,

   I want to add PDF attachment in FK02 transaction . What will be the class name as well as class type?

Thanks ain advance.

Samrat

former_member314998
Participant
0 Kudos

Hi Satish ,

   I want to add PDF attachment in FK02 transaction . What will be the class name as well as class type?

Thanks ain advance.

Samrat

0 Kudos

Open a new question, don't use a previous question

0 Kudos

You want it via FK02 transaction or via any other program?

It can be done directly from FK02 tcode.

Ref-

0 Kudos

Hi Satyabrata,

    I want to attah it by program, by transaction directly I can do that but according to my requirement that file should be stored with vendor by means of program calling any function module.

Samrat