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: 

How do we write header and item data to a file from program?

Former Member
0 Kudos

I need to write data from R/3 to flat file.It is in format of level1 - header

level2 - items

5 REPLIES 5

Former Member
0 Kudos

Use the GUI_DOWNLOAD FM.

Option1.

Download Header details into one Flat file and Item details into one flat file

Option2.

Declare a data type like below:

data: begin of i_data occurs 0,

column1 type char50,

column2 type char50,

.

.

.

.

.

end of i_data.

loop at header.

*append header to i_data.

loop at item where item's = header-key.

*apppend item to i_data.

endloop.

endloop.

Use the GUI_DOWNLOAD FM to download the I_DATA.

Sample code:

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename =

'C:\Documents and Settings\P.Ramu\Desktop\RDI1.xls'

TABLES

data_tab = i_data

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.

Message was edited by: Prakash Ramu

former_member189629
Active Contributor
0 Kudos

HI Adi,

First create an internal table (IT_FINAL) with all fields of header(IT_HDR) and item(IT_ITM) and use the first field of IT_FINAL as an indicator to differentiate header & items.

I mean, while appending the final tab with header items, assign '0' to the first field to indicate it as header and while you append the items use '1' in the first field so that they can be easily identified as items.

below is a code snippet

*--- Fill header

IT_FINAL-FIELD1 = '0'.

IT_FINAL-FIELD2 = header field value 1

IT_FINAL-FIELDn = header field value n

append it_final.

clear it_final.

*--- Fill items

IT_FINAL-FIELD1 = '1'.

IT_FINAL-FIELD2 = item field value 1

IT_FINAL-FIELDn = item field value n

append it_final.

clear it_final.

and ofcourse use GUI_DOWNLOAD to get it on a flat file

I am sure this will help. Pl reward accordingly if it does

K

Message was edited by: Karthik Potharaju

Former Member
0 Kudos

hi,

Declare an internal table with header and another with item fields.

declare another internal table (it_char)with a single field of character type with large size that can accomodate your header as well as item data say 500.

loop at it_header.
 at new it_header-field1.
  "append all header fields to it_char
 endat.
 read table it_item with key field.
  " append all item fields to it_char.
endloop.

Download the table it_char using GUI_DOWNLOAD Function module.

Regards,

Richa

Former Member
0 Kudos

It depends on how you wish to transfer the data...lets say want header data and than the corresponding item data.

loop at iheader.

move iheader data to itext.

append itext.

clear idetail.

loop at idetail where key = iheader-key.

move idetail data to itext.

append itext.

endloop.

endloop.

call function 'gui_download'

exporting

filename = 'C:\test.txt'

tables

data_tab = itext.