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: 

Reading file from CV03N and send as email attachment

ashish_goyal2
Participant
0 Kudos

Hi Team,

Requirement :- While Creating/Changing sales order, an output type "BA00" will trigger for medium '5' (mail) which will read the file present in CV03N and send this file as email attachment.

1. I have done codding in Driver program. This driver program is executing in update task.


Sequence of FM's Used:-


CALL FUNCTION 'CV115_DOC_OPEN_DISPLAY'

CALL FUNCTION 'CRM_EMAIL_SPLIT_FILENAME'

CALL FUNCTION 'CV120_FTP_OPEN'

CALL FUNCTION 'CV120_GET_FRONTEND_TYPE'

CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW

CALL FUNCTION 'GUI_UPLOAD'


For this i have created one stand alone  FM.

Question :-  While executing this FM stand alone through se37 all the steps are working fine.

Query :-  While applying this FM in Driver program(which is executing in update task) CALL FUNCTION 'GUI_UPLOAD' is not reading file data

Please help me ...

Code :-

CALL FUNCTION 'CV115_DOC_OPEN_DISPLAY'

       EXPORTING

*       PF_API_FLAG  = ' '

         pf_dokar     = gse1_draw-dokar

         pf_doknr     = gse1_draw-doknr

         pf_doktl     = gse1_draw-doktl

         pf_dokvr     = gse1_draw-dokvr

         pf_read_drat = 'X'

         pf_read_drad = 'X'

         pf_read_comp = 'X'

         pf_read_kpro = 'X'

         pf_read_drap = 'X'

       IMPORTING

         psx_draw     = gse_draw

       TABLES

         ptx_drat     = gte_drat

         ptx_draz     = gte_draz

         ptx_drad     = gte_drad

         ptx_drap     = gte_drap

         ptx_files    = gte_files.

*************************************************************

LOOP AT gte_files INTO gse_file.

           gse_dmsfiles-mark        = 'X'.

           gse_dmsfiles-lo_index    = gse_file-lo_index.      "file no. index

           gte_phios = gse_file-tbl_phios.                    "file object numbers

           READ TABLE gte_phios INTO gse_phios WITH KEY lo_index = gse_file-lo_index.

           IF sy-subrc = 0.

             IF gse_phios-filename IS NOT INITIAL.

               CLEAR : iv_path, ev_filename, ev_extension.

               iv_path = gse_phios-filename.

               CALL FUNCTION 'CRM_EMAIL_SPLIT_FILENAME'

                 EXPORTING

                   iv_path      = iv_path

                 IMPORTING

                   ev_filename  = ev_filename

                   ev_extension = ev_extension.

               gse_dmsfiles-filename  = ev_filename.

               gse_dmsfiles-file_type = ev_extension.

               APPEND gse_dmsfiles TO gte_dmsfiles.

             ENDIF.

           ENDIF.

ENDLOOP.

***************************************************

LOOP AT gte_dmsfiles INTO gse_dmsfiles WHERE mark = 'X'.

           CLEAR : gte_phios[].

           READ TABLE gte_files INTO gse_file WITH KEY lo_index = gse_dmsfiles-lo_index.

           IF sy-subrc = 0.

             gte_phios = gse_file-tbl_phios.                    "file object numbers

             READ TABLE gte_phios INTO gse_phios WITH KEY lo_index = gse_file-lo_index.

             IF sy-subrc = 0.

               CLEAR : gve_file,gse_phio,gse_doc_file,gse_cout_def.

               gse_cout_def-kpro_use  = 'X'.

               gse_cout_def-comp_get  = 'X'.

               gse_doc_file-langu     = 'EN'.

               gse_doc_file-dappl     = gse_file-dappl.

               gse_phio-lo_index        = gse_file-lo_index.

               gse_phio-lo_objid        = gse_file-lo_objid.

               gse_phio-ph_objid        = gse_phios-ph_objid.

               gse_phio-ph_index        = gse_phios-ph_index.

               gse_phio-langu           = gse_phios-langu.

               gse_phio-status_nr       = gse_phios-status_nr.

               gse_phio-filename        = gse_phios-filename.

               gse_phio-active_version  = gse_phios-active_version.

               gse_phio-delete_flag     = gse_phios-delete_flag.

               gse_phio-protected       = gse_phios-protected.

               gse_phio-default_langu   = gse_phios-default_langu.

               gse_phio-file_id         = gse_phios-file_id.

               gse_phio-storage_cat     = gse_phios-storage_cat.

               gse_phio-created_by      = gse_phios-created_by.

               gse_phio-created_at      = gse_phios-created_at.

               gse_phio-changed_by      = gse_phios-changed_by.

               gse_phio-changed_at      = gse_phios-changed_at.

*********************************************************

CALL FUNCTION 'CV120_FTP_OPEN'

            EXPORTINGpf_show_progress = ''

            EXCEPTIONS: error            = 1

                        OTHERS           = 2.

****************************************************

CALL FUNCTION 'CV120_GET_FRONTEND_TYPE'

         EXPORTING: pf_batch          = c_x "'X'

                    pf_host           = ' '

         IMPORTING: pfx_frontend_type = gs_frontend-frontend_type

                    pfx_host          = gs_frontend-hostname

                    pfx_winsys        = gs_frontend-winsys.

**************************************************************

"This FM will create a temporaray file at location GVE_FILE

               CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW

                 EXPORTING

                   ps_cout_def = gse_cout_def

                   pf_tcode    = 'CV03N'

                   ps_doc_file = gse_doc_file

                   ps_draw     = gse1_draw

                   ps_phio     = gse_phio

                   ps_frontend   = gs_frontend

                 IMPORTING

                   pfx_file    = gve_file

******************************************************************

***upload the temp file in internal table

                 CALL FUNCTION 'GUI_UPLOAD'

                   EXPORTING

                     filename                = gv_filename

                     filetype                = 'BIN'

                     no_auth_check                 = 'X'

                   TABLES

                     data_tab                = gte_solix

                   EXCEPTIONS

                     file_open_error         = 1

                     file_read_error         = 2

                     no_batch                = 3

                     gui_refuse_filetransfer = 4.

*******************************************************************

Exception is coming :-  gui_refuse_filetransfer = 4.

Regards

Shashank Jain


1 ACCEPTED SOLUTION

ashish_goyal2
Participant
0 Kudos

It's done now.

Approach

Sequence of FM's Used


CALL FUNCTION 'CV115_DOC_OPEN_DISPLAY'

CALL FUNCTION 'CRM_EMAIL_SPLIT_FILENAME'

CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW'

CALL FUNCTION 'GUI_UPLOAD'

Basically GUI_UPLOAD was failing since the driver program is running in update task.

So i have used the Sequence of FM's in User exit of Sales order i.e MV45AFZZ

After that Transporting the content in binary format to Driver program which is running in update task...

Cheers

12 REPLIES 12

Former Member
0 Kudos

Hi Ashish/Shashank ,

GUI_UPLOAD is a front end service and doesn't work in update task or background task.

Use file from application server instead(AL11) and then retrieve using open data set and close data set commands.

Cheers

0 Kudos

Hi Ashish,

But i need to read file present in CV03N and send as email attachment not from AL11

Please suggest...

0 Kudos

Try placing COMMIT WORK AND WAIT before GUI_UPLOAD.

Let me know if it does not work.

0 Kudos

I cannot use Commit WORK and Wait since my driver program is running in update task hence commit is giving me DUMP..

I am trying another approach , but stuck in one step . please help...

Step 1.

CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'

     EXPORTING

       documenttype    = 'XYZ'

       documentnumber  = '0000000000000255200001206'

       documentpart    = '000'

       documentversion = '00'

       getdocfiles     = 'X'

     IMPORTING

       return          = ls_return

     TABLES

       documentfiles   = lt_files2.

   READ TABLE lt_files2 INTO ls_files2 INDEX 1.

   CALL FUNCTION 'SCMS_DOC_READ'

     EXPORTING

       stor_cat    = 'DMS_C1_ST'

       doc_id      =    c_docid      

       PHIO_ID     c_phio

     TABLES

       access_info = lt_inf

       content_bin = lt_bin.


I am not able to understand what to pass  in  stor_cat ,doc_id   , PHIO_ID  in  these three parameters.

0 Kudos

Hi,

Check if this is helpful.

CALL FUNCTION 'SCMS_DOC_READ' "CMS: Read Document

  EXPORTING

* mandt = SY-MANDT " sy-mandt Client

  stor_cat = " sdokstca-stor_cat Category

* crep_id = SPACE " c Repository (Only Allowed if Category = SPACE)

  doc_id = " c Document ID

* phio_id = " sdok_phid PHIO ID if Known, May Be Shorter than DocID

* signature = 'X' " c Sign URL for Access to Document ("X" Yes, SPACE No)

* no_cache = SPACE " sy-datar Screens, display user entry

* raw_mode = SPACE " sy-datar Screens, display user entry

  IMPORTING

  status = " scms_docst CMS: Document status

  . " SCMS_DOC_READ

0 Kudos

Hello Ashish,

Your BAPI returns.. table of type BAPI_DOC_FILES2

use field  storagecategory and  file_id respectively...

0 Kudos

Where i can see the storage category in CV03N (or say in some table)...

I am able to get details(like name etc) of attached PDF of CV03N. Now last step is using FM " SCMS_DOC_READ" . In this FM i am getting Error message ""

"Error during import of physical document (DMS_C1, ) from cluster table"

stor_cat    = 'DMS_C1_ST'

doc_id      space

PHIO_ID     =  52148311E6321E50E10080000A2DB84A (getting from above FM)

Please suggest where i can see document category...

I just want to cross check whether config is correct or not.

0 Kudos

Hello Ashish,

Your BAPI  "BAPI_DOCUMENT_GETDETAIL2" returns.. table of type BAPI_DOC_FILES2

use field  storagecategory and  file_id respectively...

0 Kudos

Yes I have used the same ...

stor_cat    = DMS_C1_ST  (storagecategory getting from BAPI_DOCUMENT_GETDETAIL2 )

PHIO_ID   file_id (getting from BAPI_DOCUMENT_GETDETAIL2)

doc_id      space


Even same error :- "

"Error during import of physical document (DMS_C1, ) from cluster table"

I have also checked the config in DC10 Transaction increasing the file size to '100000'.

Also i have assigned the storage category in CV02N as "DMS_C1_ST"


I don't know why " SCMS_DOC_READ" is failed 






0 Kudos

Dear Ashish,

This means that the document is not saved correctly in the Content Server / CV03n. you will not be able to read document from CV03n.

Regards

S S B

ashish_goyal2
Participant
0 Kudos

It's done now.

Approach

Sequence of FM's Used


CALL FUNCTION 'CV115_DOC_OPEN_DISPLAY'

CALL FUNCTION 'CRM_EMAIL_SPLIT_FILENAME'

CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW'

CALL FUNCTION 'GUI_UPLOAD'

Basically GUI_UPLOAD was failing since the driver program is running in update task.

So i have used the Sequence of FM's in User exit of Sales order i.e MV45AFZZ

After that Transporting the content in binary format to Driver program which is running in update task...

Cheers

0 Kudos

Hi,

I require to attach DMS file in RFQ.

Please suggest place of code.