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: 

Downloading data containing different line types

Former Member
0 Kudos
180

Hi,

Any help would be greatly appreciated.

I have a requirement of downloading customer statement (open line items) on the presentation server or application server (user specified). The format of data is as follows:

Company code & address

Customer code and address

Line items data

The user can select multiple customers and a page break is required between two customer statements.

Q1) If I have to download on the presentation server, how do I consolidate the header and item data into one internal table to be passed to GUI_Download?

Q2) To insert a page break, which format can be used? I doubt if excel and text file allow to do it? Also, what is the limit on the number of lines for MS word?

Thanks and Regards,

Shyam K

1 ACCEPTED SOLUTION

Former Member
0 Kudos
80

Hi,

<b>Q1 ..Download data twice...first header and then data in append mode ..find the Code</b>


FORM f9000_save_detail_report
                       TABLES xt_det_report  STRUCTURE ls_det_report
                        USING xv_sum_fp      TYPE      char255
                              xv_det_fp      TYPE      char255.
  CONSTANTS :
         lc_file_type  TYPE char10 VALUE 'DAT'.

  DATA : lit_head_det  TYPE TABLE OF ty_head_det,
         wa_head_det   LIKE LINE  OF lit_head_det,

         lit_head_sum  TYPE TABLE OF ty_head_sum,
         wa_head_sum   LIKE LINE  OF lit_head_sum,

         lv_file_name  TYPE string.

  CLEAR: lit_head_det[],
         wa_head_det,
         lv_file_name.

*----------------Column Header for Detail Report----------------------*
*  wa_head_det-create_date    = text-023 .
  wa_head_det-partner        = text-046 .
*  wa_head_det-bpext          = text-047 .
  wa_head_det-leg_sp_id      = text-047 .
  wa_head_det-nomship_ref    = text-024 .
  wa_head_det-offer          = text-025 .
  wa_head_det-conf_ref_no    = text-026 .
  wa_head_det-con_eff_date   = text-027 .
  wa_head_det-activity_date  = text-028 .
  wa_head_det-rej_text       = text-029 .
  wa_head_det-trf_date       = text-030 .
  wa_head_det-mprn           = text-031 .
  wa_head_det-mprn_status    = text-032 .
  wa_head_det-mam_app        = text-036 .
  wa_head_det-open_read      = text-010 .
  APPEND wa_head_det TO lit_head_det.

*----------------Column Header for Summary Report----------------------*
  wa_head_sum-date           = text-023 .
  wa_head_sum-count          = text-051 .
  APPEND wa_head_sum TO lit_head_sum.


*----------------Progress Indicator For the User----------------------*
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = 100
      text       = text-053
    EXCEPTIONS
      OTHERS     = 1.

*   SY-SUBRC Check Not Required


*----------------Download Detail Report to Excel----------------------*
*---Assign Detail File Path
  lv_file_name = xv_det_fp.

*---Load Header Data of Detail Report
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = lv_file_name
      filetype                = lc_file_type
      write_field_separator   = lc_true
      codepage                = '4103'
    TABLES
      data_tab                = lit_head_det
    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.

*----Load Detail Report Data to Excel File
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = lv_file_name
        filetype                = lc_file_type
        append                  = lc_true
        write_field_separator   = lc_true
        codepage                = '4103'
      TABLES
        data_tab                = xt_det_report
      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.

  ENDIF.
  IF sy-subrc <> 0.
*   202 : Error Occurred while writing data to the file.
    MESSAGE e202(zusm_gen) .
    EXIT.
  ELSE.
    WRITE 😕 text-042 , lv_file_name.
  ENDIF.

Regards

Mark Helpful Answers

3 REPLIES 3

Former Member
0 Kudos
80

Why don´t you use the 'MS_EXCEL_OLE_STANDARD_DAT' function? It helps you to bring the results into excel format with headers. Instead of using the GUI_DOWNLOAD function you can use it.

I Hope this helps you.

An example would be;

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = fich

DATA_SHEET_NAME = 'Title'

PASSWORD_OPTION = 0

TABLES

DATA_TAB = t_data_table

FIELDNAMES = t_headers

EXCEPTIONS

FILE_NOT_EXIST = 1

FILENAME_EXPECTED = 2

COMMUNICATION_ERROR = 3

OLE_OBJECT_METHOD_ERROR = 4

OLE_OBJECT_PROPERTY_ERROR = 5

INVALID_PIVOT_FIELDS = 6

DOWNLOAD_PROBLEM = 7

OTHERS = 8.

endif.

Former Member
0 Kudos
80

I hope this could help you too.

REPORT zdownempdata .

INFOTYPES: 0000, 0001, 0007, 0008, 0121, 0615.

NODES: pernr.

TABLES: t001p.

TYPES: BEGIN OF t_employee,

  • INCLUDE STRUCTURE hrms_biw_io_occupancy.

begda TYPE begda,

endda TYPE endda,

pernr TYPE pernr_d,

rfpnr TYPE rfpnr,

bukrs TYPE bukrs,

werks TYPE persa,

btrtl TYPE btrtl,

persg TYPE persg,

persk TYPE persk,

orgeh TYPE orgeh,

stell TYPE stell,

plans TYPE plans,

kokrs TYPE mast_coar,

kostl TYPE mast_cctr,

abkrs TYPE abkrs,

molga TYPE molga,

trfar TYPE trfar,

trfgb TYPE trfgb,

trfkz TYPE trfkz,

trfgr TYPE trfgr,

trfst TYPE trfst,

bsgrd TYPE bsgrd,

ansal TYPE ansal_15,

ancur TYPE ancur,

empct TYPE empct,

stat2 TYPE stat2,

ncsdate TYPE hiredate,

sltyp TYPE p_sltyp,

slreg TYPE p_slreg,

slgrp TYPE p_slgrp,

sllev TYPE p_sllvl,

ansvh TYPE ansvh,

vdsk1 TYPE vdsk1,

sname TYPE smnam,

END OF t_employee.

DATA: it_employee TYPE STANDARD TABLE OF t_employee INITIAL SIZE 0,

wa_employee TYPE t_employee.

TYPES: BEGIN OF t_emptexts,

  • INCLUDE STRUCTURE hrms_bw_txt_employee.

DATEFROM TYPE RSDATEFROM,

DATETO TYPE RSDATETO,

PERNR TYPE PERSNO,

TXTMD TYPE EMNAM,

END OF t_emptexts.

DATA: it_emptexts TYPE STANDARD TABLE OF t_emptexts INITIAL SIZE 0,

wa_emptexts TYPE t_emptexts.

TYPES: BEGIN OF t_contract,

  • INCLUDE STRUCTURE pa0615.

pernr TYPE p0615-pernr,

begda TYPE p0615-begda,

endda TYPE p0615-endda,

aedtm TYPE p0615-aedtm,

ctype TYPE p0615-ctype,

cbeg TYPE p0615-cbeg,

cend TYPE p0615-cend,

END OF t_contract.

DATA: it_contract TYPE STANDARD TABLE OF t_contract INITIAL SIZE 0,

wa_contract TYPE t_contract.

DATA: it_tabemp TYPE filetable,

gd_subrcemp TYPE i,

it_tabempt TYPE filetable,

gd_subrcempt TYPE i,

it_tabcont TYPE filetable,

gd_subrccont TYPE i.

DATA: gd_downfile TYPE string.

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

PARAMETERS: p_emp LIKE rlgrap-filename,

p_empt LIKE rlgrap-filename,

p_cont LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK block1.

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

*at selection-screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_emp.

REFRESH: it_tabemp.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'Select File'

default_filename = '*.xls'

initial_directory = 'C:\'

multiselection = ' ' "No multiple selection

CHANGING

file_table = it_tabemp

rc = gd_subrcemp.

LOOP AT it_tabemp INTO p_emp.

ENDLOOP.

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

*at selection-screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_empt.

REFRESH: it_tabemp.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'Select File'

default_filename = '*.xls'

initial_directory = 'C:\'

multiselection = ' ' "No multiple selection

CHANGING

file_table = it_tabempt

rc = gd_subrcempt.

LOOP AT it_tabempt INTO p_empt.

ENDLOOP.

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

*at selection-screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_cont.

REFRESH: it_tabcont.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'Select File'

default_filename = '*.xls'

initial_directory = 'C:\'

multiselection = ' ' "No multiple selection

CHANGING

file_table = it_tabcont

rc = gd_subrccont.

LOOP AT it_tabcont INTO p_cont.

ENDLOOP.

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

*START-OF-SELECTION.

START-OF-SELECTION.

GET pernr.

  • Selecting the latest infotype record

rp_provide_from_last p0000 space pn-begda pn-endda.

rp_provide_from_last p0001 space pn-begda pn-endda.

rp_provide_from_last p0007 space pn-begda pn-endda.

rp_provide_from_last p0008 space pn-begda pn-endda.

rp_provide_from_last p0121 space pn-begda pn-endda.

rp_provide_from_last p0615 space pn-begda pn-endda.

MOVE-CORRESPONDING p0001 TO wa_employee.

wa_employee-rfpnr = p0121-rfp01. "?????

MOVE-CORRESPONDING p0007 TO wa_employee.

MOVE-CORRESPONDING p0008 TO wa_employee.

MOVE-CORRESPONDING p0000 TO wa_employee.

SELECT SINGLE molga

FROM t001p

INTO wa_employee-molga

WHERE werks EQ p0001-werks AND

btrtl EQ p0001-btrtl.

SELECT SINGLE trfkz

FROM t503

INTO wa_employee-trfkz

WHERE persg EQ p0001-persg AND

persk EQ p0001-persk.

CALL FUNCTION 'HR_ENTRY_DATE'

EXPORTING

persnr = pernr-pernr

  • RCLAS =

  • BEGDA = '18000101'

  • ENDDA = '99991231'

  • VARKY =

IMPORTING

entrydate = wa_employee-ncsdate

  • TABLES

  • ENTRY_DATES =

EXCEPTIONS

ENTRY_DATE_NOT_FOUND = 1

PERNR_NOT_ASSIGNED = 2

OTHERS = 3

.

IF sy-subrc <> 0.

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

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

ENDIF.

  • append employee data

APPEND wa_employee TO it_employee.

CLEAR: wa_employee.

wa_emptexts-datefrom = p0001-begda.

wa_emptexts-dateto = p0001-endda.

wa_emptexts-pernr = p0001-pernr.

wa_emptexts-txtmd = p0001-ename.

  • append employee texts data

APPEND wa_emptexts TO it_emptexts.

CLEAR: wa_emptexts.

MOVE-CORRESPONDING p0615 TO wa_contract.

  • append employee contract data

APPEND wa_contract TO it_contract.

CLEAR: wa_contract.

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

*END-OF-SELECTION.

END-OF-SELECTION.

  • download employee data

IF NOT p_emp IS INITIAL.

gd_downfile = p_emp.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = gd_downfile

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = it_employee.

IF sy-subrc EQ 0.

WRITE:/ 'Employee file downloaded to',

gd_downfile.

ELSE.

WRITE:/ 'There was an error downloading Employee file to',

gd_downfile.

ENDIF.

ENDIF.

  • download employee texts data

IF NOT p_empt IS INITIAL.

gd_downfile = p_empt.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = gd_downfile

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = it_emptexts.

IF sy-subrc EQ 0.

WRITE:/ 'Employee text file downloaded to',

gd_downfile.

ELSE.

WRITE:/ 'There was an error downloading Employee text file to',

gd_downfile.

ENDIF.

ENDIF.

  • download contract data

IF NOT p_cont IS INITIAL.

gd_downfile = p_cont.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = gd_downfile

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = it_contract.

IF sy-subrc EQ 0.

WRITE:/ 'Employee contract file downloaded to',

gd_downfile.

ELSE.

WRITE:/ 'There was an error downloading Employee contract file to',

gd_downfile.

ENDIF.

ENDIF.

Former Member
0 Kudos
81

Hi,

<b>Q1 ..Download data twice...first header and then data in append mode ..find the Code</b>


FORM f9000_save_detail_report
                       TABLES xt_det_report  STRUCTURE ls_det_report
                        USING xv_sum_fp      TYPE      char255
                              xv_det_fp      TYPE      char255.
  CONSTANTS :
         lc_file_type  TYPE char10 VALUE 'DAT'.

  DATA : lit_head_det  TYPE TABLE OF ty_head_det,
         wa_head_det   LIKE LINE  OF lit_head_det,

         lit_head_sum  TYPE TABLE OF ty_head_sum,
         wa_head_sum   LIKE LINE  OF lit_head_sum,

         lv_file_name  TYPE string.

  CLEAR: lit_head_det[],
         wa_head_det,
         lv_file_name.

*----------------Column Header for Detail Report----------------------*
*  wa_head_det-create_date    = text-023 .
  wa_head_det-partner        = text-046 .
*  wa_head_det-bpext          = text-047 .
  wa_head_det-leg_sp_id      = text-047 .
  wa_head_det-nomship_ref    = text-024 .
  wa_head_det-offer          = text-025 .
  wa_head_det-conf_ref_no    = text-026 .
  wa_head_det-con_eff_date   = text-027 .
  wa_head_det-activity_date  = text-028 .
  wa_head_det-rej_text       = text-029 .
  wa_head_det-trf_date       = text-030 .
  wa_head_det-mprn           = text-031 .
  wa_head_det-mprn_status    = text-032 .
  wa_head_det-mam_app        = text-036 .
  wa_head_det-open_read      = text-010 .
  APPEND wa_head_det TO lit_head_det.

*----------------Column Header for Summary Report----------------------*
  wa_head_sum-date           = text-023 .
  wa_head_sum-count          = text-051 .
  APPEND wa_head_sum TO lit_head_sum.


*----------------Progress Indicator For the User----------------------*
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = 100
      text       = text-053
    EXCEPTIONS
      OTHERS     = 1.

*   SY-SUBRC Check Not Required


*----------------Download Detail Report to Excel----------------------*
*---Assign Detail File Path
  lv_file_name = xv_det_fp.

*---Load Header Data of Detail Report
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = lv_file_name
      filetype                = lc_file_type
      write_field_separator   = lc_true
      codepage                = '4103'
    TABLES
      data_tab                = lit_head_det
    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.

*----Load Detail Report Data to Excel File
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = lv_file_name
        filetype                = lc_file_type
        append                  = lc_true
        write_field_separator   = lc_true
        codepage                = '4103'
      TABLES
        data_tab                = xt_det_report
      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.

  ENDIF.
  IF sy-subrc <> 0.
*   202 : Error Occurred while writing data to the file.
    MESSAGE e202(zusm_gen) .
    EXIT.
  ELSE.
    WRITE 😕 text-042 , lv_file_name.
  ENDIF.

Regards

Mark Helpful Answers