‎2007 Jul 05 3:11 PM
I want to store the flat file data for temporary purpose and as a backup also, but its size is so huge that processing them at one instance is a difficult task. Is there any 'Z' program that will split the records puts it in a new file. Anyone please give an idea and your answer ll b rewarded with maximum points if it helps me on this issue.
‎2007 Jul 05 3:25 PM
Hi Manjula,
Check out the below program this will help you solve your requirement, you split the records as per the limit specified and puts them in a new file. Think so it help you.
REPORT zc1_split_file MESSAGE-ID ztestmsg.
TABLES: mara.
DATA: BEGIN OF input,
mandt LIKE mara-mandt,
matnr LIKE mara-matnr,
ersda LIKE mara-ersda,
ernam LIKE mara-ernam,
matkl LIKE mara-matkl,
END OF input.
DATA: i_mara_tab LIKE TABLE OF input WITH HEADER LINE,
i_mara_temp LIKE TABLE OF input,
w_mara_tab LIKE LINE OF i_mara_tab,
v_newfile(120) TYPE c,
v_no_lines TYPE i,
v_split(4) TYPE n VALUE 1,
v_count(4) TYPE n VALUE 1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE rlgrap-filename MEMORY ID file,
p_count(4) TYPE n.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Diplaying the dialog box for opening the file ************
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = '.,..'
IMPORTING
filename = p_file.
START-OF-SELECTION.
IF p_file IS INITIAL. " check to ensure file.
MESSAGE i001.
EXIT.
ENDIF.
IF p_count IS INITIAL. " check to ensure file.
MESSAGE i002.
EXIT.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = i_mara_tab
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT i_mara_tab INTO w_mara_tab.
IF v_count < p_count.
APPEND w_mara_tab TO i_mara_temp.
v_count = v_count + 1.
ELSE.
APPEND w_mara_tab TO i_mara_temp.
v_count = v_count + 1.
PERFORM split_records.
REFRESH i_mara_temp.
v_count = 1.
v_split = v_split + 1.
ENDIF.
ENDLOOP.
IF v_count NE 1.
PERFORM split_records.
ENDIF.
--> p1 text
<-- p2 text
----
FORM split_records.
CONCATENATE p_file v_split INTO v_newfile.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = v_newfile
filetype = 'DAT'
mode = 'A'
TABLES
data_tab = i_mara_temp
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE:/'Data has been written into:' , v_newfile.
ENDFORM.
**Reward points if found useful....
Regards,
Manikandan.A
‎2007 Jul 05 3:25 PM
Hi Manjula,
Check out the below program this will help you solve your requirement, you split the records as per the limit specified and puts them in a new file. Think so it help you.
REPORT zc1_split_file MESSAGE-ID ztestmsg.
TABLES: mara.
DATA: BEGIN OF input,
mandt LIKE mara-mandt,
matnr LIKE mara-matnr,
ersda LIKE mara-ersda,
ernam LIKE mara-ernam,
matkl LIKE mara-matkl,
END OF input.
DATA: i_mara_tab LIKE TABLE OF input WITH HEADER LINE,
i_mara_temp LIKE TABLE OF input,
w_mara_tab LIKE LINE OF i_mara_tab,
v_newfile(120) TYPE c,
v_no_lines TYPE i,
v_split(4) TYPE n VALUE 1,
v_count(4) TYPE n VALUE 1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE rlgrap-filename MEMORY ID file,
p_count(4) TYPE n.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Diplaying the dialog box for opening the file ************
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = '.,..'
IMPORTING
filename = p_file.
START-OF-SELECTION.
IF p_file IS INITIAL. " check to ensure file.
MESSAGE i001.
EXIT.
ENDIF.
IF p_count IS INITIAL. " check to ensure file.
MESSAGE i002.
EXIT.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = i_mara_tab
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT i_mara_tab INTO w_mara_tab.
IF v_count < p_count.
APPEND w_mara_tab TO i_mara_temp.
v_count = v_count + 1.
ELSE.
APPEND w_mara_tab TO i_mara_temp.
v_count = v_count + 1.
PERFORM split_records.
REFRESH i_mara_temp.
v_count = 1.
v_split = v_split + 1.
ENDIF.
ENDLOOP.
IF v_count NE 1.
PERFORM split_records.
ENDIF.
--> p1 text
<-- p2 text
----
FORM split_records.
CONCATENATE p_file v_split INTO v_newfile.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = v_newfile
filetype = 'DAT'
mode = 'A'
TABLES
data_tab = i_mara_temp
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE:/'Data has been written into:' , v_newfile.
ENDFORM.
**Reward points if found useful....
Regards,
Manikandan.A
‎2007 Jul 05 6:57 PM