Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3353

Re: Converting internal table to xlsx and downloading to application server

$
0
0

Dear Abin,

 

Even I have faced this issue..Hope the below sample code will help you...

 

DATA : STRING1 TYPE C LENGTH 1024,

          STRING2 TYPE C LENGTH 21000,

          V1      TYPE C LENGTH 40.

   FIELD-SYMBOLS: <FS_TABLE>  TYPE TABLE,

                  <WA_FIELD>  TYPE ANY.

   IF SY-SYSID = 'JEP'.

     CONCATENATE '/sapmnt/JEP/tmp/abap_backgrnd_reports/' 'MM_CONSUMPTION' SY-DATUM SY-UZEIT '.txt' INTO L_FILENAME.

   ELSE.

     CONCATENATE '/usr/sap/tmp/abap_backgrnd_reports/' 'MM_CONSUMPTION' SY-DATUM SY-UZEIT '.txt' INTO L_FILENAME.

   ENDIF.

 

   LOOP AT FIELDTAB INTO W_FCAT.

     CONCATENATE STRING2 W_FCAT-SELTEXT_M INTO STRING2 SEPARATED BY '|'.

   ENDLOOP.

 

   DATA : P_WTAB1 LIKE LINE OF IMSEG1.

 

   OPEN DATASET L_FILENAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

   IF SY-SUBRC NE 0.

     MESSAGE E000(ZFI01) WITH 'CAN NOT OPEN FILE: ' L_FILENAME.

   ENDIF.

   TRANSFER STRING2 TO L_FILENAME.

 

   CLEAR STRING2.

   LOOP AT IMSEG1 INTO P_WTAB1.

     LOOP AT FIELDTAB INTO W_FCAT.

       ASSIGN COMPONENT W_FCAT-FIELDNAME OF STRUCTURE P_WTAB1 TO <WA_FIELD>.

       V1 <WA_FIELD>.

       CONDENSE V1.

       CONCATENATE STRING2 V1 INTO STRING2 SEPARATED BY '|'.

     ENDLOOP.

     REPLACE ALL OCCURRENCES OF '#' IN STRING2 WITH SPACE.

     REPLACE ALL OCCURRENCES OF '"' IN STRING2 WITH SPACE.

     TRANSFER STRING2 TO L_FILENAME.

     CLEAR STRING2.

   ENDLOOP.

   CLOSE DATASET L_FILENAME.


Sending the path in mail.. after completion of background job.


FORM MAILSEND .

   DATA: PEMAIL TYPE ADR6-SMTP_ADDR.

   DATA: W_DOCUMENT_DATA TYPE  SODOCCHGI1,

         GD_SUBJECT   LIKE SODOCCHGI1-OBJ_DESCR,

         IT_MESS_BOD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

         W_SENT_ALL(1) TYPE C,

         T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

         T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

 

   SELECT SINGLE ADR6~SMTP_ADDR INTO PEMAIL

                             FROM ADR6 INNER JOIN USR21

                             ON  ADR6~ADDRNUMBER = USR21~ADDRNUMBER

                             AND ADR6~PERSNUMBER = USR21~PERSNUMBER

                             WHERE USR21~BNAME = SY-UNAME.

   CHECK NOT ( PEMAIL IS INITIAL ).

 

   IF X1 = 0.

     W_DOCUMENT_DATA-OBJ_NAME  = 'REPORT COMPLETION'.

     W_DOCUMENT_DATA-OBJ_DESCR = 'Report Completed in background'.

     W_DOCUMENT_DATA-OBJ_LANGU  = SY-LANGU.

     W_DOCUMENT_DATA-DOC_SIZE = 0.

 

     IT_MESS_BOD        = 'Dear Sir,'.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = ' '.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = 'Please find the below application server path to download the file'.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = ' '.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = L_FILENAME.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = ' '.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = 'Please download the same using the Tcode ZSAPDIRDOWNLD'.

     APPEND IT_MESS_BOD.

 

   ELSE.

     W_DOCUMENT_DATA-OBJ_NAME  = 'REPORT COMPLETION'.

     W_DOCUMENT_DATA-OBJ_DESCR = 'Report Completed in background'.

     W_DOCUMENT_DATA-OBJ_LANGU  = SY-LANGU.

     W_DOCUMENT_DATA-DOC_SIZE = 0.

 

     IT_MESS_BOD        = 'Dear Sir,'.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = ' '.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = 'There is no data available for your selection'.

     APPEND IT_MESS_BOD.

     IT_MESS_BOD        = ' '.

 

   ENDIF.

 

   CLEAR T_PACKING_LIST.

   REFRESH T_PACKING_LIST.

   T_PACKING_LIST-TRANSF_BIN = 'X'.

   T_PACKING_LIST-HEAD_START = 1.

   T_PACKING_LIST-HEAD_NUM   = 0.

   T_PACKING_LIST-BODY_START = 1.

   DESCRIBE TABLE IT_MESS_BOD LINES T_PACKING_LIST-BODY_NUM.

   T_PACKING_LIST-DOC_TYPE   = 'RAW'.

   APPEND T_PACKING_LIST.

 

   CLEAR T_RECEIVERS.

   REFRESH T_RECEIVERS.

   T_RECEIVERS-RECEIVER    = PEMAIL.

   T_RECEIVERS-REC_TYPE    = 'U'.

   T_RECEIVERS-COM_TYPE    = 'INT'.

   T_RECEIVERS-EXPRESS     = 'X'.

   APPEND T_RECEIVERS.

 

   CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

     EXPORTING

       DOCUMENT_DATA              = W_DOCUMENT_DATA

       DOCUMENT_TYPE              = 'RAW'

       PUT_IN_OUTBOX              = 'X'

       COMMIT_WORK                = 'X'

     IMPORTING

       SENT_TO_ALL                = W_SENT_ALL

     TABLES

       OBJECT_CONTENT             = IT_MESS_BOD

       RECEIVERS                  = T_RECEIVERS

     EXCEPTIONS

       TOO_MANY_RECEIVERS         = 1

       DOCUMENT_NOT_SENT          = 2

       DOCUMENT_TYPE_NOT_EXIST    = 3

       OPERATION_NO_AUTHORIZATION = 4

       PARAMETER_ERROR            = 5

       X_ERROR                    = 6

       ENQUEUE_ERROR              = 7

       OTHERS                     = 8.

   IF SY-SUBRC = 0.

     COMMIT WORK.

     SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.

   ENDIF.

 

Message was edited by: G.V.S Praveen Kumar     OPEN DATASET dset FOR INPUT IN TEXT MODE ENCODING DEFAULT.     IF sy-subrc NE 0.       MESSAGE i140 WITH  'File ' dset ' cannot be opened'.       EXIT.     ENDIF. *create internal table containing file text     DO.       READ DATASET dset   INTO rec.       IF sy-subrc NE 0.         EXIT.       ENDIF.       REPLACE ALL OCCURRENCES OF '#' IN rec WITH space.       REPLACE ALL OCCURRENCES OF '"' IN rec WITH space.       APPEND rec.     ENDDO.     CALL FUNCTION 'GUI_DOWNLOAD'       EXPORTING         filename                = p_pcnam_n         WRITE_FIELD_SEPARATOR   = 'X' *       FILETYPE                = 'ASC'       TABLES         data_tab                = rec       EXCEPTIONS         file_write_error        = 1         no_batch                = 2         gui_refuse_filetransfer = 3         invalid_type            = 4         no_authority            = 5         unknown_error           = 6         header_not_allowed      = 7         separator_not_allowed   = 8         filesize_not_allowed    = 9         header_too_long         = 10         dp_error_create         = 11         dp_error_send           = 12         dp_error_write          = 13         unknown_dp_error        = 14         access_denied           = 15         dp_out_of_memory        = 16         disk_full               = 17         dp_timeout              = 18         file_not_found          = 19         dataprovider_exception  = 20         control_flush_error     = 21         OTHERS                  = 22.     CASE sy-subrc.       WHEN 0.         MESSAGE i140 WITH 'File' dset                           ' successfully transferred to ' p_pcnam.         EXIT.       WHEN 1.         MESSAGE i140 WITH 'File' p_pcnam ' Cannot be opened'.         EXIT.       WHEN OTHERS.         MESSAGE i140 WITH 'File' p_pcnam ' Reading error'.         EXIT.     ENDCASE.


Viewing all articles
Browse latest Browse all 3353

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>