Application Development and Automation 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: 
Read only

download error

Former Member
0 Likes
2,588

Hi guys i need your help badly .

i am downloading data using function module ws_download or gui_download .datas are getting downloaded , but few columns are blank . on those blank columns data are getting populated from next column. it doesnt take any blank space. actually internal table doesnt have any data corresponding to that field.

solution pls.

Hi guys i need your help badly .

i am downloading data using function module ws_download or gui_download .datas are getting downloaded , but few columns are blank . on those blank columns data are getting populated from next column. it doesnt take any blank space. actually internal table doesnt have any data corresponding to that field.

solution pls.

30 REPLIES 30
Read only

Abhijit74
Active Contributor
0 Likes
2,493

Hello,

Have you specified any field separator ? WRITE_FIELD_SEPARATOR .

-------------------------------------------------------------------------------------------------------------

data:begin of it occurs 0,

       grp type c,

       val type i,

      end of it.

data:begin of heading occurs 0,

       TEXT(10) type c,

      end of heading.

      it-grp = 'A'.

      it-val = 100.

      append it.

      it-grp = 'B'.

      it-val = 200.

      append it.

*     heading-text = 'GROUP'.

*     append heading.

*     heading-text = 'VALUE'.

*     append heading.

      call function 'GUI_DOWNLOAD'

        exporting

          filename                        = 'C:\text.xls'

          FILETYPE                        = 'DAT'

          WRITE_FIELD_SEPARATOR           = '#'

          SHOW_TRANSFER_STATUS            = 'X'

        tables

          data_tab                        = it[]

*        FIELDNAMES                      = heading[]

       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

                .

      if sy-subrc <> 0.

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

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

      endif.

-----------------------------------------------------------------------------------------------------------------------

Thanks,

Abhijit

Read only

Former Member
0 Likes
2,493

hi Abhijit,

              i have used write_field_separator , it doesnt make any differencr in the output. Any other solutions

regards

kaushik

Read only

Former Member
0 Likes
2,493

Hello.

Could you post ur code (the download part) so we can have a look and help you?.

Regards

Read only

0 Likes
2,493

Hi Miguel Sure ...

REPORT zmbcrp0081 NO STANDARD PAGE HEADING LINE-SIZE 900 LINE-COUNT 90.

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

* Program Title       : Download data in Excel and Send mail

* Program Description : Download data from ZMSD_LOP_OUT table into Excel

*                       format and Send an mail with attachment if Send

*                       mail checkbox is selected.

*

* SAP R/3   Module    : SD

* SAP R/3   Release   : 4.6c

* Development Log

*  ---------------

*  Name            Date       Description

*--------------- ---------- --------------------------------------------

*-----------------------------------------------------------------------

*TYPE-POOLS DECLARATION

*-----------------------------------------------------------------------

TYPE-POOLS:slis.

*-----------------------------------------------------------------------

*TABLES DECLARATION

*-----------------------------------------------------------------------

TABLES: zmsd_lop_out.

**----------------------------------------------------------------------

** RANGES

**----------------------------------------------------------------------

*RANGES : r_chrcode FOR zmsd_lop_out-zchrcode.

*

*r_chrcode-low = '2*'.

*r_chrcode-high = ' '.

*r_chrcode-sign = 'I'.

*r_chrcode-option = 'CP'.

*APPEND r_chrcode.

*CLEAR r_chrcode.

*-----------------------------------------------------------------------

* TYPES DECLARATIONS

*-----------------------------------------------------------------------

TYPES: BEGIN OF ty_lopout,

       zvkorg           TYPE   zmsd_lop_out-zvkorg,

       zfcode           TYPE   zmsd_lop_out-zfcode,

       zinvno           TYPE   zmsd_lop_out-zinvno,

       zfdate           TYPE   zmsd_lop_out-zfdate,

       zchrcode         TYPE   zmsd_lop_out-zchrcode,

       zhawb            TYPE   zmsd_lop_out-zhawb,

       z_cntr_type      TYPE   zmsd_lop_out-z_cntr_type,

       zmawb            TYPE   zmsd_lop_out-zmawb,

       zshipmod         TYPE   zmsd_lop_out-zshipmod,

       zdpport          TYPE   zmsd_lop_out-zdpport,

       zdsport          TYPE   zmsd_lop_out-zdsport,

       zqty             TYPE   zmsd_lop_out-zqty,

       zpr_uom          TYPE   zmsd_lop_out-zpr_uom,

       zf_cur           TYPE   zmsd_lop_out-zf_cur,

       zexrate          TYPE   zmsd_lop_out-zexrate,

       zamount          TYPE   zmsd_lop_out-zamount,

       zgst_amt         TYPE   zmsd_lop_out-zgst_amt,

       ztot_amt         TYPE   zmsd_lop_out-ztot_amt,

       zccode           TYPE   zmsd_lop_out-zccode,

       zccp_no          TYPE   zmsd_lop_out-zccp_no,

       z_cif_val        TYPE   zmsd_lop_out-z_cif_val,

       z_tax_inv        TYPE   zmsd_lop_out-z_tax_inv,

       z_tax_inv_dt     TYPE   zmsd_lop_out-z_tax_inv_dt,

       z_rem_1          TYPE   zmsd_lop_out-z_rem_1,

       zbtvol           TYPE   zmsd_lop_out-zbtvol,

       zbrgew           TYPE   zmsd_lop_out-zbrgew,

       z_no_of_cntr     TYPE   zmsd_lop_out-z_no_of_cntr,

       zfnum1           TYPE   zmsd_lop_out-zfnum1,

       zvessel          TYPE   zmsd_lop_out-zvessel,

       zatd             TYPE   zmsd_lop_out-zatd,

       zeta             TYPE   zmsd_lop_out-zeta,

       zrate            TYPE   zmsd_lop_out-zrate,

       zrate_cur        TYPE   zmsd_lop_out-zrate_cur,

       zdpport_nm       TYPE   zmsd_lop_out-zdpport_nm,

       zdsport_nm       TYPE   zmsd_lop_out-zdsport_nm,

       zcc_pp           TYPE   zmsd_lop_out-zfpstatus,

       zrate_type       TYPE   zmsd_lop_out-z_rate_type,

       END OF ty_lopout.

*-----------------------------------------------------------------------

* INTERNAL TABLES

*-----------------------------------------------------------------------

DATA: t_lopout TYPE TABLE OF ty_lopout,

      w_lopout TYPE ty_lopout,

      t_head    TYPE STANDARD TABLE OF slis_fieldcat_alv,

      w_head    TYPE slis_fieldcat_alv.

*-----------------------------------------------------------------------

* VARIABLES DECLARATION

*-----------------------------------------------------------------------

DATA: v_file TYPE rlgrap-filename.

*-----------------------------------------------------------------------

* SELECT-OPTIONS AND PARAMETERS

*-----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_zvkorg   FOR zmsd_lop_out-zvkorg NO INTERVALS,

                 s_zfcode   FOR zmsd_lop_out-zfcode NO INTERVALS,

                 s_crdate   FOR zmsd_lop_out-creation_date.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_zsts     TYPE zzsts DEFAULT 'T' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.

PARAMETERS     : p_file     TYPE rlgrap-filename.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_mail     AS   CHECKBOX.

SELECTION-SCREEN END OF BLOCK b.

*-----------------------------------------------------------------------

* INITIALIZATION

*-----------------------------------------------------------------------

*-----------------------------------------------------------------------

* AT SELECTION-SCREEN

*-----------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'

       EXPORTING

            program_name  = syst-cprog

            dynpro_number = syst-dynnr

            field_name    = ' '

       IMPORTING

            file_name     = p_file.

*-----------------------------------------------------------------------

* START OF SELECTION

*-----------------------------------------------------------------------

START-OF-SELECTION.

  PERFORM get_data.

  PERFORM fetch_header.

  PERFORM downld_excel.

*&---------------------------------------------------------------------*

*&      Form  get_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data.

  SELECT *

         FROM zmsd_lop_out

         INTO CORRESPONDING FIELDS OF TABLE t_lopout

         WHERE zvkorg        IN   s_zvkorg

         AND   zfcode        IN   s_zfcode

         AND   creation_date IN   s_crdate

         AND   zsts          =    p_zsts

         AND   zchrcode      <>   space.

ENDFORM.                    " get_data

*&---------------------------------------------------------------------*

*&      Form  downld_excel

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM downld_excel.

  DATA: lv_chrcode TYPE z_chcd.

  LOOP AT t_lopout INTO w_lopout.

    lv_chrcode = w_lopout-zchrcode.

    lv_chrcode = lv_chrcode+0(1).

    IF lv_chrcode <> '2'.

      DELETE t_lopout.

    ENDIF.

  ENDLOOP.

  IF sy-subrc = 0.

    v_file = p_file.

  ENDIF.

  CALL FUNCTION 'WS_DOWNLOAD'

       EXPORTING

            filename   = v_file

            filetype   = 'DAT'

       TABLES

            data_tab   = t_lopout

            fieldnames = t_head.

ENDFORM.                    " downld_excel

*&---------------------------------------------------------------------*

*&      Form  fetch_header

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fetch_header.

  w_head = 'Company Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Forwarder Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Invoice Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Invoice Date'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Charge Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Ref Doc No'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Container Type'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'MAWB'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Transport'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Departure Port'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Destination City'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Charges Incuured'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Pricing Unit'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Currency Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Exchange Rate'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Amount'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'GST Amount'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Total Amount'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Carrier Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'CCP Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'CIF Value'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Tax Invoice Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Tax Invoice Date'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Remarks 1'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Remarks 2'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Remarks 3'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Volume(M3)'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Weight'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'No. of Container'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Flight Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Vessel'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'ATD'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'ETA'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Rate'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Rate Currency'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Departure Port Name'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Destination Port Name'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Freight Paid Status'.

  APPEND w_head TO t_head.

  CLEAR w_head.

  w_head = 'Rate Type'.

  APPEND w_head TO t_head.

  CLEAR w_head.

ENDFORM.                    " fetch_header

Read only

Rushikesh_Yeole
Contributor
0 Likes
2,493

Best way to use GUI_DOWNLOAD...as suggested above

WS_DOWNLOAD is obsolete now

Read only

0 Likes
2,493

Hi rushikesh

                  i have even used GUI download. it doesnt make any difference, and it is throwing dump in gui download that the reason i used ws_download

Read only

0 Likes
2,493

hi ,

Suggest i am really having no clue now tried all possibilities

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

Hi Kaushik,

I tried simulating your scenario by preparing an internal table which has some columns blank. Then, I used FM GUI_DOWNLOAD to download the contents into an excel. I see the contents in the excel as in the internal table i.e. the blank columns remain blank in the excel.

I would suggest have a real close look at the contents of your internal table just before the call to GUI_DOWNLOAD. Also, I am posting an excerpt from my sample code below.

CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filename                = 'C:\test.xls'
     filetype                = 'DAT'
     write_field_separator   = '#'
     show_transfer_status    = 'X'
   TABLES
     data_tab                = lt_prod
   EXCEPTIONS
     OTHERS                  = 99.

Read only

0 Likes
2,493

try to use GUI_DOWNLOAD

and in the fieldname use gt_xlsfield as a table you can download the file

Read only

0 Likes
2,493

hi kumar ,

           gui download is throwing dump when i use filetypw dat. and it is not fetching the header as there are some functionality like fieldnames is not available in this server

Read only

0 Likes
2,493

Hi Kumar when i use gui download with file type 'asc' data are populating right but header is not coming.

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

I don't think you are using the correct table type to pass data to fieldnames parameter for GUI_DOWNLOAD. Check this link and try the approach described - https://scn.sap.com/message/6743229

Read only

0 Likes
2,493

Hi kumar i am using 4.6c there is no functionality of fieldnames in gui download fm

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

Then, why don't you simply add the column names to your internal table?

By the way, the link I shared a while ago talks about the 4.6C scenario also. They say something about calling the function twice. Please check.

Message was edited by: Kumar Akshat

Read only

0 Likes
2,493

how to perform that

Read only

0 Likes
2,493

hi kumar

REPORT zmbcrp0081 NO STANDARD PAGE HEADING LINE-SIZE 900 LINE-COUNT 90.

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

* Program Title       : Download data in Excel and Send mail

* Program Description : Download data from ZMSD_LOP_OUT table into Excel

*                       format and Send an mail with attachment if Send

*                       mail checkbox is selected.

*

* SAP R/3   Module    : SD

* SAP R/3   Release   : 4.6c

* Development Log

*  ---------------

*  Name            Date       Description

*--------------- ---------- --------------------------------------------

*-----------------------------------------------------------------------

*TYPE-POOLS DECLARATION

*-----------------------------------------------------------------------

TYPE-POOLS:slis.

*-----------------------------------------------------------------------

*TABLES DECLARATION

*-----------------------------------------------------------------------

TABLES: zmsd_lop_out.

*-----------------------------------------------------------------------

* TYPES DECLARATIONS

*-----------------------------------------------------------------------

TYPES: BEGIN OF ty_lopout,

       zvkorg           TYPE   zmsd_lop_out-zvkorg,

       zfcode           TYPE   zmsd_lop_out-zfcode,

       zinvno           TYPE   zmsd_lop_out-zinvno,

       zfdate           TYPE   zmsd_lop_out-zfdate,

       zchrcode         TYPE   zmsd_lop_out-zchrcode,

       zhawb            TYPE   zmsd_lop_out-zhawb,

       z_cntr_type      TYPE   zmsd_lop_out-z_cntr_type,

       zmawb            TYPE   zmsd_lop_out-zmawb,

       zshipmod         TYPE   zmsd_lop_out-zshipmod,

       zdpport          TYPE   zmsd_lop_out-zdpport,

       zdsport          TYPE   zmsd_lop_out-zdsport,

       zqty             TYPE   zmsd_lop_out-zqty,

       zpr_uom          TYPE   zmsd_lop_out-zpr_uom,

       zf_cur           TYPE   zmsd_lop_out-zf_cur,

       zexrate          TYPE   zmsd_lop_out-zexrate,

       zamount          TYPE   zmsd_lop_out-zamount,

       zgst_amt         TYPE   zmsd_lop_out-zgst_amt,

       ztot_amt         TYPE   zmsd_lop_out-ztot_amt,

       zccode           TYPE   zmsd_lop_out-zccode,

       zccp_no          TYPE   zmsd_lop_out-zccp_no,

       z_cif_val        TYPE   zmsd_lop_out-z_cif_val,

       z_tax_inv        TYPE   zmsd_lop_out-z_tax_inv,

       z_tax_inv_dt     TYPE   zmsd_lop_out-z_tax_inv_dt,

       z_rem_1          TYPE   zmsd_lop_out-z_rem_1,

       zbtvol           TYPE   zmsd_lop_out-zbtvol,

       zbrgew           TYPE   zmsd_lop_out-zbrgew,

       z_no_of_cntr     TYPE   zmsd_lop_out-z_no_of_cntr,

       zfnum1           TYPE   zmsd_lop_out-zfnum1,

       zvessel          TYPE   zmsd_lop_out-zvessel,

       zatd             TYPE   zmsd_lop_out-zatd,

       zeta             TYPE   zmsd_lop_out-zeta,

       zrate            TYPE   zmsd_lop_out-zrate,

       zrate_cur        TYPE   zmsd_lop_out-zrate_cur,

       zdpport_nm       TYPE   zmsd_lop_out-zdpport_nm,

       zdsport_nm       TYPE   zmsd_lop_out-zdsport_nm,

       zcc_pp           TYPE   zmsd_lop_out-zfpstatus,

       zrate_type       TYPE   zmsd_lop_out-z_rate_type,

       END OF ty_lopout.

types:begin of ty_head,

      col_name(30) type c,

      end of ty_head.

*-----------------------------------------------------------------------

* INTERNAL TABLES

*-----------------------------------------------------------------------

DATA: t_lopout TYPE TABLE OF ty_lopout,

      w_lopout TYPE ty_lopout,

*      t_head    TYPE STANDARD TABLE OF slis_fieldcat_alv,

*      w_head    TYPE slis_fieldcat_alv.

t_head type table of ty_head,

w_head type ty_head.

*-----------------------------------------------------------------------

* VARIABLES DECLARATION

*-----------------------------------------------------------------------

DATA: v_file TYPE string.

*-----------------------------------------------------------------------

* SELECT-OPTIONS AND PARAMETERS

*-----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_zvkorg   FOR zmsd_lop_out-zvkorg NO INTERVALS,

                 s_zfcode   FOR zmsd_lop_out-zfcode NO INTERVALS,

                 s_crdate   FOR zmsd_lop_out-creation_date.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_zsts     TYPE zzsts DEFAULT 'T' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.

PARAMETERS     : p_file     TYPE rlgrap-filename.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_mail     AS   CHECKBOX.

SELECTION-SCREEN END OF BLOCK b.

*-----------------------------------------------------------------------

* INITIALIZATION

*-----------------------------------------------------------------------

*-----------------------------------------------------------------------

* AT SELECTION-SCREEN

*-----------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'

       EXPORTING

            program_name  = syst-cprog

            dynpro_number = syst-dynnr

            field_name    = ' '

       IMPORTING

            file_name     = p_file.

*-----------------------------------------------------------------------

* START OF SELECTION

*-----------------------------------------------------------------------

START-OF-SELECTION.

  PERFORM get_data.

  PERFORM fetch_header.

  PERFORM downld_excel.

*&---------------------------------------------------------------------*

*&      Form  get_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data.

  SELECT *

         FROM zmsd_lop_out

         INTO CORRESPONDING FIELDS OF TABLE t_lopout

         WHERE zvkorg        IN   s_zvkorg

         AND   zfcode        IN   s_zfcode

         AND   creation_date IN   s_crdate

         AND   zsts          =    p_zsts

         AND   zchrcode      <>   space.

ENDFORM.                    " get_data

*&---------------------------------------------------------------------*

*&      Form  downld_excel

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM downld_excel.

  DATA: lv_chrcode TYPE z_chcd.

  LOOP AT t_lopout INTO w_lopout.

    lv_chrcode = w_lopout-zchrcode.

    lv_chrcode = lv_chrcode+0(1).

    IF lv_chrcode <> '2'.

      DELETE t_lopout.

    ENDIF.

  ENDLOOP.

  IF sy-subrc = 0.

    v_file = p_file.

  ENDIF.

  CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

*   BIN_FILESIZE                  =

      filename                      = v_file

     filetype                      = 'ASC'

*   append                        = 'X'

     write_field_separator         = 'X'

    TABLES

      data_tab                      = t_head

            .

*

  CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

      filename                      = v_file

     filetype                      = 'ASC'

   APPEND                        = 'X'

     write_field_separator         = 'X'

    TABLES

      data_tab                      = t_lopout

            .

ENDFORM.

"downld_excel

*&---------------------------------------------------------------------*

*&      Form  fetch_header

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fetch_header.

*  w_head-col_pos   = '1'.

*  w_head-fieldname = 'Company Code'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '2'.

*  w_head-fieldname = 'Forwarder Code'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '3'.

*  w_head-fieldname = 'Invoice Number'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*  w_head-col_pos  = '4'.

*  w_head-fieldname = 'Invoice Date'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '5'.

*  w_head-fieldname = 'Charge Code'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '6'.

*  w_head-fieldname = 'Ref Doc No'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '7'.

*  w_head-fieldname = 'Container Type'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '8'.

*  w_head-fieldname = 'MAWB'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '9'.

*  w_head-fieldname = 'Transport'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '10'.

*  w_head-fieldname = 'Departure Port'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '11'.

*  w_head-fieldname = 'Destination City'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '12'.

*  w_head-fieldname = 'Charges Incuured'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '13'.

*  w_head-fieldname = 'Pricing Unit'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '14'.

*  w_head-fieldname = 'Currency Code'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '15'.

*  w_head-fieldname = 'Exchange Rate'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '16'.

*  w_head-fieldname = 'Amount'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '17'.

*  w_head-fieldname = 'GST Amount'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '18'.

*  w_head-fieldname = 'Total Invoice Amount'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '19'.

*  w_head-fieldname = 'Carrier Code'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '20'.

*  w_head-fieldname = 'CCP Number'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '21'.

*  w_head-fieldname = 'CIF Value'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '22'.

*  w_head-fieldname = 'Tax Invoice Number'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '23'.

*  w_head-fieldname = 'Tax Invoice Date'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '24'.

*  w_head-fieldname = 'Remarks 1'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '25'.

*  w_head-fieldname = 'Volume(M3)'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '26'.

*  w_head-fieldname = 'Weight'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '27'.

*  w_head-fieldname = 'No. of Container'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '28'.

*  w_head-fieldname = 'Flight Number'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '29'.

*  w_head-fieldname = 'Vessel'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '30'.

*  w_head-fieldname = 'ATD'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '31'.

*  w_head-fieldname = 'ETA'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '32'.

*  w_head-fieldname = 'Rate'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '33'.

*  w_head-fieldname = 'Rate Currency'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '34'.

*  w_head-fieldname = 'Departure Port Name'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '35'.

*  w_head-fieldname = 'Destination Port Name'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '36'.

*  w_head-fieldname = 'Freight Paid Status'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

*

*  w_head-col_pos  = '37'.

*  w_head-fieldname = 'Rate Type'.

*  APPEND w_head TO t_head.

*  CLEAR w_head.

ENDFORM.

" fetch_header

this is d code. can u tell in brief .

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

You need to call GUI_DOWNLOAD twice. The first time you call it, pass it a table containing one row with all the column names. The second you call it, pass the actual table data and with the APPEND parameter set to 'X'.

Something like this:

CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filename              = 'C:\test.xls'
     filetype              = 'DAT'
     write_field_separator = '#'
     show_transfer_status  = 'X'
   TABLES
     data_tab              = lt_fieldname
*    fieldnames            = lt_fieldname
   EXCEPTIONS
     OTHERS                = 99.

CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filename              = 'C:\test.xls'
     filetype              = 'DAT'
     write_field_separator = '#'
     show_transfer_status  = 'X'
     append                = 'X'
   TABLES
     data_tab              = lt_prod
*    fieldnames            = lt_fieldname
   EXCEPTIONS
     OTHERS                = 99.

Message was edited by: Kumar Akshat

Read only

0 Likes
2,493

i tried this header is getting populated in this manner

company code

invoice number

f code

date etc.

why?

Read only

0 Likes
2,493

hi kumar i tried it again now it is fetching header ... but after column X . again it is fetching data from previous column but actually internal table that field data is empty.

pls can u help me on this?

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

Sorry, I didn't understand your problem. Can you post a screenshot of the excel and point out what is the issue?

Read only

0 Likes
2,493

THANKS KUMAR I HAVE RESOLVED IT. NOW I HAVE DOWNLOADED THE DATA INTO EXCEL SHEET . HOW CAN I ATTACH IT SEND MAIL . PLEASE HELP ME WITH SOME CODE IN INPUT PARAMTERS THE PATH IS D:/TEST.XLS. HOW CAN I ATTACH THIS FILE.

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

This is a pretty standard requirement. Please check this link - http://saptechnical.com/Tips/ABAP/email/Anyformat.htm

Read only

0 Likes
2,493

Hi akshat,

                      thanks but in 4.6c the class called cl_bcs_document is not available. is there any other program u ve.. i have downloaded the data its in file c:/test.xls

i need to attach this file if the user choose send mail option

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,493

There are other posts on SCN which deal with this requirement in 4.6c. I guess you would have FM SO_NEW_DOCUMENT_ATT_SEND_API1 in your system. Check how to use it for your purpose.

Read only

0 Likes
2,493

Hi Akshat,

concatenate 'PERNR' 'PERSG' 'PERSK' 'PLANS' 'STELL'

         into  w_attachment

separated by  con_tab.

  concatenate con_cret

              w_attachment

         into w_attachment.

  append w_attachment to i_attachment.

  clear  w_attachment.

  loop at i_emp_data into w_emp_data.

    concatenate w_emp_data-pernr

                w_emp_data-persg

                w_emp_data-persk

                w_emp_data-plans

                w_emp_data-stell

           into w_attachment

   separated by con_tab.

    concatenate con_cret w_attachment

           into w_attachment.

    append w_attachment to i_attachment.

    clear  w_attachment.

  endloop.

can u tell me is dis the way to attach . i am not able to understand i need to attach c:/test.txt

Read only

0 Likes
2,493

REPORT zmbcrp0081 NO STANDARD PAGE HEADING LINE-SIZE 900 LINE-COUNT 90.

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

* Program Title       : Download data in Excel and Send mail

* Program Description : Download data from ZMSD_LOP_OUT table into Excel

*                       format and Send an mail with attachment if Send

*                       mail checkbox is selected.

*

* SAP R/3   Module    : SD

* SAP R/3   Release   : 4.6c

* Development Log

*  ---------------

*  Name            Date       Description

*--------------- ---------- --------------------------------------------

*-----------------------------------------------------------------------

*TYPE-POOLS DECLARATION

*-----------------------------------------------------------------------

TYPE-POOLS:slis.

*-----------------------------------------------------------------------

*TABLES DECLARATION

*-----------------------------------------------------------------------

TABLES: zmsd_lop_out, somlreci1.

*-----------------------------------------------------------------------

* TYPES DECLARATIONS

*-----------------------------------------------------------------------

TYPES: BEGIN OF ty_lopout,

       zvkorg           TYPE   zmsd_lop_out-zvkorg,

       zfcode           TYPE   zmsd_lop_out-zfcode,

       zinvno           TYPE   zmsd_lop_out-zinvno,

       zfdate           TYPE   zmsd_lop_out-zfdate,

       zchrcode         TYPE   zmsd_lop_out-zchrcode,

       zhawb            TYPE   zmsd_lop_out-zhawb,

       z_cntr_type      TYPE   zmsd_lop_out-z_cntr_type,

       zmawb            TYPE   zmsd_lop_out-zmawb,

       zshipmod         TYPE   zmsd_lop_out-zshipmod,

       zdpport          TYPE   zmsd_lop_out-zdpport,

       zdsport          TYPE   zmsd_lop_out-zdsport,

       zqty             TYPE   zmsd_lop_out-zqty,

       zpr_uom          TYPE   zmsd_lop_out-zpr_uom,

       zf_cur           TYPE   zmsd_lop_out-zf_cur,

       zexrate          TYPE   zmsd_lop_out-zexrate,

       zamount          TYPE   zmsd_lop_out-zamount,

       zgst_amt         TYPE   zmsd_lop_out-zgst_amt,

       ztot_amt         TYPE   zmsd_lop_out-ztot_amt,

       zccode           TYPE   zmsd_lop_out-zccode,

       zccp_no          TYPE   zmsd_lop_out-zccp_no,

       z_cif_val        TYPE   zmsd_lop_out-z_cif_val,

       z_tax_inv        TYPE   zmsd_lop_out-z_tax_inv,

       z_tax_inv_dt     TYPE   zmsd_lop_out-z_tax_inv_dt,

       z_rem_1          TYPE   zmsd_lop_out-z_rem_1,

       zbtvol           TYPE   zmsd_lop_out-zbtvol,

       zbrgew           TYPE   zmsd_lop_out-zbrgew,

       z_no_of_cntr     TYPE   zmsd_lop_out-z_no_of_cntr,

       zfnum1           TYPE   zmsd_lop_out-zfnum1,

       zvessel          TYPE   zmsd_lop_out-zvessel,

       zatd             TYPE   zmsd_lop_out-zatd,

       zeta             TYPE   zmsd_lop_out-zeta,

       zrate            TYPE   zmsd_lop_out-zrate,

       zrate_cur        TYPE   zmsd_lop_out-zrate_cur,

       zdpport_nm       TYPE   zmsd_lop_out-zdpport_nm,

       zdsport_nm       TYPE   zmsd_lop_out-zdsport_nm,

       zcc_pp           TYPE   zmsd_lop_out-zfpstatus,

       zrate_type       TYPE   zmsd_lop_out-z_rate_type,

       END OF ty_lopout.

TYPES: BEGIN OF ty_lopout1,

      zvkorg           TYPE   zmsd_lop_out-zvkorg,

      zfcode           TYPE   zmsd_lop_out-zfcode,

      zinvno           TYPE   zmsd_lop_out-zinvno,

      zfdate(10)       TYPE   c,

      zchrcode         TYPE   zmsd_lop_out-zchrcode,

      zhawb            TYPE   zmsd_lop_out-zhawb,

      z_cntr_type      TYPE   zmsd_lop_out-z_cntr_type,

      zmawb            TYPE   zmsd_lop_out-zmawb,

      zshipmod         TYPE   zmsd_lop_out-zshipmod,

      zdpport          TYPE   zmsd_lop_out-zdpport,

      zdsport          TYPE   zmsd_lop_out-zdsport,

      zqty             TYPE   zmsd_lop_out-zqty,

      zpr_uom          TYPE   zmsd_lop_out-zpr_uom,

      zf_cur           TYPE   zmsd_lop_out-zf_cur,

      zexrate          TYPE   zmsd_lop_out-zexrate,

      zamount          TYPE   zmsd_lop_out-zamount,

      zgst_amt         TYPE   zmsd_lop_out-zgst_amt,

      ztot_amt         TYPE   zmsd_lop_out-ztot_amt,

      zccode           TYPE   zmsd_lop_out-zccode,

      zccp_no          TYPE   zmsd_lop_out-zccp_no,

      z_cif_val        TYPE   zmsd_lop_out-z_cif_val,

      z_tax_inv        TYPE   zmsd_lop_out-z_tax_inv,

      z_tax_inv_dt     TYPE   zmsd_lop_out-z_tax_inv_dt,

      z_rem_1          TYPE   zmsd_lop_out-z_rem_1,

      zbtvol           TYPE   zmsd_lop_out-zbtvol,

      zbrgew           TYPE   zmsd_lop_out-zbrgew,

      z_no_of_cntr     TYPE   zmsd_lop_out-z_no_of_cntr,

      zfnum1           TYPE   zmsd_lop_out-zfnum1,

      zvessel          TYPE   zmsd_lop_out-zvessel,

      zatd             TYPE   zmsd_lop_out-zatd,

      zeta             TYPE   zmsd_lop_out-zeta,

      zrate            TYPE   zmsd_lop_out-zrate,

      zrate_cur        TYPE   zmsd_lop_out-zrate_cur,

      zdpport_nm       TYPE   zmsd_lop_out-zdpport_nm,

      zdsport_nm       TYPE   zmsd_lop_out-zdsport_nm,

      zcc_pp           TYPE   zmsd_lop_out-zfpstatus,

      zrate_type       TYPE   zmsd_lop_out-z_rate_type,

      END OF ty_lopout1.

TYPES: BEGIN OF ty_head,

       zvkorg(20)        TYPE     c,

       zfcode(20)        TYPE     c,

       zinvno(20)        TYPE     c,

       zfdate(20)        TYPE     c,

       zchrcode(20)      TYPE     c,

       zhawb(20)         TYPE     c,

       zcntr_type(20)    TYPE     c,

       zmawb(20)         TYPE     c,

       zshipmod(20)      TYPE     c,

       zdpport(25)       TYPE     c,

       zdsport(25)       TYPE     c,

       zqty(20)          TYPE     c,

       zpr_uom(20)       TYPE     c,

       zf_cur(25)        TYPE     c,

       zexrate(25)       TYPE     c,

       zamount(25)       TYPE     c,

       zgst_amt(20)      TYPE     c,

       ztot_amt(20)      TYPE     c,

       zccode(20)        TYPE     c,

       zccp_no(20)       TYPE     c,

       zcif_val(20)      TYPE     c,

       ztax_invnr(20)    TYPE     c,

       ztax_invdat(20)   TYPE     c,

       remarks(20)       TYPE     c,

       zbtvol(20)        TYPE     c,

       zbrgew(20)        TYPE     c,

       zno_of_cntr(20)   TYPE     c,

       zfnum1(20)        TYPE     c,

       zvessel(20)       TYPE     c,

       zatd(20)          TYPE     c,

       zeta(20)          TYPE     c,

       zrate(20)         TYPE     c,

       zrate_cur(20)     TYPE     c,

       zdpport_nm(20)    TYPE     c,

       zdsport_nm(20)    TYPE     c,

       zfpstatus(20)     TYPE     c,

       zrate_type(20)    TYPE     c,

       END OF ty_head.

*-----------------------------------------------------------------------

* INTERNAL TABLES

*-----------------------------------------------------------------------

DATA: t_lopout TYPE TABLE OF ty_lopout,

      w_lopout TYPE ty_lopout,

      t_lopout1 TYPE TABLE OF ty_lopout1,

      w_lopout1 TYPE ty_lopout1,

      t_head TYPE TABLE OF ty_head,

      w_head TYPE ty_head.

* To Send Email with an Excel attachment

DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER

LINE,

      lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER

LINE,

      lt_attachment      TYPE STANDARD TABLE OF solisti1  WITH HEADER

LINE,

      lt_mailsubject     TYPE sodocchgi1,

      lt_packing_list    TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER

LINE,

      gv_cnt             TYPE i.

*-----------------------------------------------------------------------

* VARIABLES DECLARATION

*-----------------------------------------------------------------------

DATA: v_file TYPE string.

*-----------------------------------------------------------------------

* SELECT-OPTIONS AND PARAMETERS

*-----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_zvkorg   FOR zmsd_lop_out-zvkorg NO INTERVALS,

                 s_zfcode   FOR zmsd_lop_out-zfcode NO INTERVALS,

                 s_crdate   FOR zmsd_lop_out-creation_date.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_zsts     TYPE zzsts DEFAULT 'T' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.

PARAMETERS     : p_file     TYPE rlgrap-filename.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_mail     AS   CHECKBOX.

SELECTION-SCREEN END OF BLOCK b.

SELECTION-SCREEN:BEGIN OF SCREEN 1001.

SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.

SELECT-OPTIONS:s_email FOR somlreci1-receiver NO INTERVALS.

SELECTION-SCREEN:END OF BLOCK b1.

SELECTION-SCREEN:END OF SCREEN 1001.

*-----------------------------------------------------------------------

* AT SELECTION-SCREEN

*-----------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'

       EXPORTING

            program_name  = syst-cprog

            dynpro_number = syst-dynnr

            field_name    = ' '

       IMPORTING

            file_name     = p_file.

*-----------------------------------------------------------------------

* START OF SELECTION

*-----------------------------------------------------------------------

START-OF-SELECTION.

  PERFORM fetch_header.

  PERFORM get_data.

  PERFORM downld_excel.

  IF p_mail = 'X'.

    CALL SELECTION-SCREEN 1001 STARTING AT 30 5.

    IF NOT s_email IS INITIAL.

      PERFORM send_mail.

    ENDIF.

  ENDIF.

*&---------------------------------------------------------------------*

*&      Form  get_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data.

  DATA: lv_chrcode TYPE z_chcd.

  DATA: lv_date(12) TYPE c.

  SELECT *

         FROM zmsd_lop_out

         INTO CORRESPONDING FIELDS OF TABLE t_lopout

         WHERE zvkorg        IN   s_zvkorg

         AND   zfcode        IN   s_zfcode

         AND   creation_date IN   s_crdate

         AND   zsts          =    p_zsts

         AND   zchrcode      <>   space.

  LOOP AT t_lopout INTO w_lopout.

    IF NOT w_lopout-zfdate IS INITIAL.

      CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT'

           EXPORTING

                input  = w_lopout-zfdate

           IMPORTING

                output = lv_date.

      MOVE-CORRESPONDING w_lopout TO w_lopout1.

      MOVE lv_date TO w_lopout1-zfdate.

      APPEND w_lopout1 TO t_lopout1.

    ENDIF.

  ENDLOOP.

  LOOP AT t_lopout1 INTO w_lopout1.

    IF NOT w_lopout1-zchrcode IS INITIAL.

      lv_chrcode = w_lopout1-zchrcode.

      lv_chrcode = lv_chrcode+0(1).

      IF lv_chrcode <> '2'.

        DELETE t_lopout1.

      ENDIF.

    ENDIF.

  ENDLOOP.

ENDFORM.                    " get_data

*&---------------------------------------------------------------------*

*&      Form  downld_excel

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM downld_excel.

  IF sy-subrc = 0.

    v_file = p_file.

  ENDIF.

  CALL FUNCTION 'GUI_DOWNLOAD'

       EXPORTING

            filename              = v_file

            filetype              = 'ASC'

            write_field_separator = 'X'

       TABLES

            data_tab              = t_head.

  CALL FUNCTION 'GUI_DOWNLOAD'

       EXPORTING

            filename              = v_file

            filetype              = 'ASC'

            append                = 'X'

            write_field_separator = 'X'

       TABLES

            data_tab              = t_lopout1.

ENDFORM.                       "downld_excel

*&---------------------------------------------------------------------*

*&      Form  fetch_header

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fetch_header.

  w_head-zvkorg      = 'Company Code'.

  w_head-zfcode      = 'Forwarder Code'.

  w_head-zinvno      = 'Invoice Number'.

  w_head-zfdate      = 'Forwarder Date'.

  w_head-zchrcode    = 'Charge Code'.

  w_head-zhawb       = 'HAWB'.

  w_head-zcntr_type  = 'Container Type'.

  w_head-zmawb       = 'MAWB'.

  w_head-zshipmod    = 'Transport'.

  w_head-zdpport     = 'Departure Port Code'.

  w_head-zdsport     = 'Destination City Code'.

  w_head-zqty        = 'Quantity'.

  w_head-zpr_uom     = 'Pricing Unit'.

  w_head-zf_cur      = 'Forwarder Currency Code'.

  w_head-zexrate     = 'Forwarder Exchange Rate'.

  w_head-zamount     = 'Forwarder Amount'.

  w_head-zgst_amt    = 'GST Amount'.

  w_head-ztot_amt    = 'Total Invoice Amount'.

  w_head-zccode      = 'Carrier Code'.

  w_head-zccp_no     = 'CCP Number'.

  w_head-zcif_val    = 'CIF Value'.

  w_head-ztax_invnr  = 'Tax Invoice Number'.

  w_head-ztax_invdat = 'Tax Invoice Date'.

  w_head-remarks     = 'Remarks'.

  w_head-zbtvol      = 'Volume in M3'.

  w_head-zbrgew      = 'Chargeable Weight'.

  w_head-zno_of_cntr = 'No. of Container'.

  w_head-zfnum1      = 'Flight Number'.

  w_head-zvessel     = 'Vessel'.

  w_head-zatd        = 'ATD Departure'.

  w_head-zeta        = 'ETA/ATA Arrival'.

  w_head-zrate       = 'Rate per Unit'.

  w_head-zrate_cur   = 'Rate Currency'.

  w_head-zdpport_nm  = 'Departure Port Name'.

  w_head-zdsport_nm  = 'Destination Port Name'.

  w_head-zfpstatus   = 'Freight Paid Status'.

  w_head-zrate_type  = 'Rate Type'.

  APPEND w_head TO t_head.

  CLEAR w_head.

ENDFORM.                    " fetch_header

*&---------------------------------------------------------------------*

*&      Form  send_mail

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM send_mail.

*Add recepients

  lt_mailrecipients-rec_type  = 'U'.

  lt_mailrecipients-com_type  = 'INT'.

  lt_mailrecipients-receiver  = s_email.

  APPEND lt_mailrecipients .

  CLEAR lt_mailrecipients .

*Put in mail Contents

lt_mailtxt = 'Dpwnloaded data from msd_lop_out'.

APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'test mail'. APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Thanks'.              APPEND lt_mailtxt. CLEAR lt_mailtxt.

*Create attachment

  CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode

               con_tab TYPE x VALUE '09'.   "OK for non Unicode

  CONCATENATE 'Company Code' 'Forwarder Code' 'Invoice number'

'Invoice Date' 'Charge Code' 'HAWB' 'Container Type' INTO lt_attachment

  SEPARATED BY con_tab.

  CONCATENATE con_cret lt_attachment INTO lt_attachment.

  APPEND lt_attachment.

  CLEAR lt_attachment.

  LOOP AT t_lopout INTO w_head.

    CONCATENATE w_head-zvkorg w_head-zfcode w_head-zinvno w_head-zfdate

    INTO lt_attachment SEPARATED BY con_tab.

    CONCATENATE con_cret lt_attachment INTO lt_attachment.

    APPEND lt_attachment.

    CLEAR lt_attachment.

  ENDLOOP.

*Pack the mail contents and attachments

  lt_packing_list-transf_bin  = space.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 0.

  lt_packing_list-body_start  = 1.

  DESCRIBE TABLE lt_mailtxt LINES lt_packing_list-body_num.

*  lt_packing_list-body_num    = LINES( lt_mailtxt ).

  lt_packing_list-doc_type    = 'RAW'.

  APPEND lt_packing_list. CLEAR lt_packing_list.

  lt_packing_list-transf_bin  = 'X'.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 1.

  lt_packing_list-body_start  = 1.

*  lt_packing_list-body_num    = LINES( lt_attachment ).

  DESCRIBE TABLE lt_attachment LINES lt_packing_list-body_num.

  lt_packing_list-doc_type    = 'XLS'. " You c raw data

  lt_packing_list-obj_name    = 'data.xls'.

  lt_packing_list-obj_descr   = 'data.xls'.

  lt_packing_list-doc_size    = lt_packing_list-body_num * 255.

  APPEND lt_packing_list. CLEAR lt_packing_list.

  lt_mailsubject-obj_name     = 'MAILATTCH'.

  lt_mailsubject-obj_langu    = sy-langu.

  lt_mailsubject-obj_descr    = 'You have got mail'.

  lt_mailsubject-sensitivty   = 'F'.

*  gv_cnt = LINES( lt_attachment ).

  lt_mailsubject-doc_size     = ( gv_cnt - 1 ) * 255 + STRLEN(

  lt_attachment ).

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      document_data                    = lt_mailsubject

*   PUT_IN_OUTBOX                    = ' '

* IMPORTING

*   SENT_TO_ALL                      =

*   NEW_OBJECT_ID                    =

    TABLES

      packing_list                     = lt_packing_list

*   OBJECT_HEADER                    =

     contents_bin                     = lt_attachment

     contents_txt                     = lt_mailtxt

*   CONTENTS_HEX                     =

*   OBJECT_PARA                      =

*   OBJECT_PARB                      =

      receivers                        = lt_mailrecipients

* 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.

ENDFORM.                    " send_mail

Read only

Former Member
0 Likes
2,493

Hi Kaushik Chand,

                         Have you tested your internal table which you downloading?

if the table is having empty column then the download file will be the same.

Could you please give the code what you are using for the download?

it may help us to help you soon..

Read only

0 Likes
2,493

REPORT zmbcrp0081 NO STANDARD PAGE HEADING LINE-SIZE 900 LINE-COUNT 90.

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

* Program Title       : Download data in Excel and Send mail

* Program Description : Download data from ZMSD_LOP_OUT table into Excel

*                       format and Send an mail with attachment if Send

*                       mail checkbox is selected.

*

* SAP R/3   Module    : SD

* SAP R/3   Release   : 4.6c

* Development Log

*  ---------------

*  Name            Date       Description

*--------------- ---------- --------------------------------------------

*-----------------------------------------------------------------------

*TYPE-POOLS DECLARATION

*-----------------------------------------------------------------------

TYPE-POOLS:slis.

*-----------------------------------------------------------------------

*TABLES DECLARATION

*-----------------------------------------------------------------------

TABLES: zmsd_lop_out.

*-----------------------------------------------------------------------

* TYPES DECLARATIONS

*-----------------------------------------------------------------------

TYPES: BEGIN OF ty_lopout,

       zvkorg           TYPE   zmsd_lop_out-zvkorg,

       zfcode           TYPE   zmsd_lop_out-zfcode,

       zinvno           TYPE   zmsd_lop_out-zinvno,

       zfdate           TYPE   zmsd_lop_out-zfdate,

       zchrcode         TYPE   zmsd_lop_out-zchrcode,

       zhawb            TYPE   zmsd_lop_out-zhawb,

       z_cntr_type      TYPE   zmsd_lop_out-z_cntr_type,

       zmawb            TYPE   zmsd_lop_out-zmawb,

       zshipmod         TYPE   zmsd_lop_out-zshipmod,

       zdpport          TYPE   zmsd_lop_out-zdpport,

       zdsport          TYPE   zmsd_lop_out-zdsport,

       zqty             TYPE   zmsd_lop_out-zqty,

       zpr_uom          TYPE   zmsd_lop_out-zpr_uom,

       zf_cur           TYPE   zmsd_lop_out-zf_cur,

       zexrate          TYPE   zmsd_lop_out-zexrate,

       zamount          TYPE   zmsd_lop_out-zamount,

       zgst_amt         TYPE   zmsd_lop_out-zgst_amt,

       ztot_amt         TYPE   zmsd_lop_out-ztot_amt,

       zccode           TYPE   zmsd_lop_out-zccode,

       zccp_no          TYPE   zmsd_lop_out-zccp_no,

       z_cif_val        TYPE   zmsd_lop_out-z_cif_val,

       z_tax_inv        TYPE   zmsd_lop_out-z_tax_inv,

       z_tax_inv_dt     TYPE   zmsd_lop_out-z_tax_inv_dt,

       z_rem_1          TYPE   zmsd_lop_out-z_rem_1,

       zbtvol           TYPE   zmsd_lop_out-zbtvol,

       zbrgew           TYPE   zmsd_lop_out-zbrgew,

       z_no_of_cntr     TYPE   zmsd_lop_out-z_no_of_cntr,

       zfnum1           TYPE   zmsd_lop_out-zfnum1,

       zvessel          TYPE   zmsd_lop_out-zvessel,

       zatd             TYPE   zmsd_lop_out-zatd,

       zeta             TYPE   zmsd_lop_out-zeta,

       zrate            TYPE   zmsd_lop_out-zrate,

       zrate_cur        TYPE   zmsd_lop_out-zrate_cur,

       zdpport_nm       TYPE   zmsd_lop_out-zdpport_nm,

       zdsport_nm       TYPE   zmsd_lop_out-zdsport_nm,

       zcc_pp           TYPE   zmsd_lop_out-zfpstatus,

       zrate_type       TYPE   zmsd_lop_out-z_rate_type,

       END OF ty_lopout.

*-----------------------------------------------------------------------

* INTERNAL TABLES

*-----------------------------------------------------------------------

DATA: t_lopout TYPE TABLE OF ty_lopout,

      w_lopout TYPE ty_lopout,

      t_head    TYPE STANDARD TABLE OF slis_fieldcat_alv,

      w_head    TYPE slis_fieldcat_alv.

*-----------------------------------------------------------------------

* VARIABLES DECLARATION

*-----------------------------------------------------------------------

DATA: v_file TYPE rlgrap-filename.

*-----------------------------------------------------------------------

* SELECT-OPTIONS AND PARAMETERS

*-----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_zvkorg   FOR zmsd_lop_out-zvkorg NO INTERVALS,

                 s_zfcode   FOR zmsd_lop_out-zfcode NO INTERVALS,

                 s_crdate   FOR zmsd_lop_out-creation_date.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_zsts     TYPE zzsts DEFAULT 'T' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.

PARAMETERS     : p_file     TYPE rlgrap-filename.

SELECTION-SCREEN SKIP.

PARAMETERS     : p_mail     AS   CHECKBOX.

SELECTION-SCREEN END OF BLOCK b.

*-----------------------------------------------------------------------

* INITIALIZATION

*-----------------------------------------------------------------------

*-----------------------------------------------------------------------

* AT SELECTION-SCREEN

*-----------------------------------------------------------------------

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'

       EXPORTING

            program_name  = syst-cprog

            dynpro_number = syst-dynnr

            field_name    = ' '

       IMPORTING

            file_name     = p_file.

*-----------------------------------------------------------------------

* START OF SELECTION

*-----------------------------------------------------------------------

START-OF-SELECTION.

  PERFORM get_data.

  PERFORM fetch_header.

  PERFORM downld_excel.

*&---------------------------------------------------------------------*

*&      Form  get_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data.

  SELECT *

         FROM zmsd_lop_out

         INTO CORRESPONDING FIELDS OF TABLE t_lopout

         WHERE zvkorg        IN   s_zvkorg

         AND   zfcode        IN   s_zfcode

         AND   creation_date IN   s_crdate

         AND   zsts          =    p_zsts

         AND   zchrcode      <>   space.

ENDFORM.                    " get_data

*&---------------------------------------------------------------------*

*&      Form  downld_excel

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM downld_excel.

  DATA: lv_chrcode TYPE z_chcd.

  LOOP AT t_lopout INTO w_lopout.

    lv_chrcode = w_lopout-zchrcode.

    lv_chrcode = lv_chrcode+0(1).

    IF lv_chrcode <> '2'.

      DELETE t_lopout.

    ENDIF.

  ENDLOOP.

  IF sy-subrc = 0.

    v_file = p_file.

  ENDIF.

* break-point.

*

*  CALL FUNCTION 'GUI_DOWNLOAD'

*    EXPORTING

**   BIN_FILESIZE                  =

*      filename                      = v_file

*     filetype                      = 'ASC'

**   APPEND                        = ' '

*     write_field_separator         = 'X'

*    TABLES

*      data_tab                      = t_head

*            .

*

*  CALL FUNCTION 'GUI_DOWNLOAD'

*    EXPORTING

*

*      filename                      = v_file

*     filetype                      = 'ASC'

**   APPEND                        = ' '

*     write_field_separator         = 'X'

*    TABLES

*      data_tab                      = t_lopout

*            .

  CALL FUNCTION 'WS_DOWNLOAD'

       EXPORTING

            filename   = v_file

            filetype   = 'DAT'

       TABLES

            data_tab   = t_lopout

            fieldnames = t_head.

ENDFORM.

"     downld_excel

*&---------------------------------------------------------------------*

*&      Form  fetch_header

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fetch_header.

*  w_head-col_pos   = '1'.

  w_head-fieldname = 'Company Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '2'.

  w_head-fieldname = 'Forwarder Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '3'.

  w_head-fieldname = 'Invoice Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '4'.

  w_head-fieldname = 'Invoice Date'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '5'.

  w_head-fieldname = 'Charge Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '6'.

  w_head-fieldname = 'Ref Doc No'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '7'.

  w_head-fieldname = 'Container Type'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '8'.

  w_head-fieldname = 'MAWB'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '9'.

  w_head-fieldname = 'Transport'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '10'.

  w_head-fieldname = 'Departure Port'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '11'.

  w_head-fieldname = 'Destination City'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '12'.

  w_head-fieldname = 'Charges Incuured'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '13'.

  w_head-fieldname = 'Pricing Unit'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '14'.

  w_head-fieldname = 'Currency Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '15'.

  w_head-fieldname = 'Exchange Rate'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '16'.

  w_head-fieldname = 'Amount'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '17'.

  w_head-fieldname = 'GST Amount'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '18'.

  w_head-fieldname = 'Total Invoice Amount'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '19'.

  w_head-fieldname = 'Carrier Code'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '20'.

  w_head-fieldname = 'CCP Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '21'.

  w_head-fieldname = 'CIF Value'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '22'.

  w_head-fieldname = 'Tax Invoice Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '23'.

  w_head-fieldname = 'Tax Invoice Date'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '24'.

  w_head-fieldname = 'Remarks 1'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '25'.

  w_head-fieldname = 'Volume(M3)'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '26'.

  w_head-fieldname = 'Weight'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '27'.

  w_head-fieldname = 'No. of Container'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '28'.

  w_head-fieldname = 'Flight Number'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '29'.

  w_head-fieldname = 'Vessel'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '30'.

  w_head-fieldname = 'ATD'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '31'.

  w_head-fieldname = 'ETA'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '32'.

  w_head-fieldname = 'Rate'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '33'.

  w_head-fieldname = 'Rate Currency'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '34'.

  w_head-fieldname = 'Departure Port Name'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '35'.

  w_head-fieldname = 'Destination Port Name'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '36'.

  w_head-fieldname = 'Freight Paid Status'.

  APPEND w_head TO t_head.

  CLEAR w_head.

*  w_head-col_pos  = '37'.

  w_head-fieldname = 'Rate Type'.

  APPEND w_head TO t_head.

  CLEAR w_head.

ENDFORM.

" fetch_header

pls help asap

Read only

0 Likes
2,493

i dont have the functionality of fieldnames in gui_download is there any way to populate header?

Read only

0 Likes
2,493

Hi Kaushik,

1)Use field symble value    = '|'.

This will seprate the field tab into different column.

2) if you want to add header and you don't habe the functionality of field name then you do one thing... append or insert field name manually into the internal table at first first row.

Then it will download as a header into the excel.

Hope it works.

Regards,

RAvi Pratap Singh