‎2007 May 24 10:39 AM
hello friends,
i am making a module program which has table name as a input field,
and when i press enter my internal table gets generated dynamically,
i select the data into the table,
and then it gets converted into a flat file.
and then this flat file data is displayed in the text editor.
for converting my table in to a flat file i am using a function module 'SAP_CONVERT_TO_TEX_FORMAT'.
now for this function module all the fields of the table should be in the charachter format,
and if i am gererating a dynamic table, it will contain also integer fields,
nd it gives an dump in the function module -
' The current statement is defined for character-type data objects only.'
so how to correct this error or is there any other way to convert internal table
into a flat file and other way to upload the file in the application server.
My code:
&----
*& Module pool ZSUR_FTP1
*&
&----
*&
*&
&----
INCLUDE zsur_ftp1top . " global Data
INCLUDE ZSUR_FTP1O01 . " PBO-Modules
INCLUDE ZSUR_FTP1I01 . " PAI-Modules
INCLUDE ZSUR_FTP1F01 . " FORM-Routines
&----
*& Module status_0100 OUTPUT
&----
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
IF lr_editor IS INITIAL.
l_repid = sy-repid.
CREATE OBJECT lr_custom_container
EXPORTING
container_name = 'CUSTOM1'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
Create obejct for the TextEditor control
CREATE OBJECT lr_editor
EXPORTING
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = l_line_length
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
parent = lr_custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5
OTHERS = 6.
ENDIF.
ENDMODULE. " status_0100 OUTPUT
&----
*& Module user_command_0100 INPUT
&----
text
----
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK' OR 'CANCEL'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'B1'.
PERFORM ('GET_DATA') IN PROGRAM (prog) IF FOUND.
WHEN 'SEND'.
PERFORM send.
ENDCASE.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM flat_file USING text1.
PERFORM fill_container.
ENDMODULE. " user_command_0100 INPUT
&----
*& Form get_structure
&----
GET THE STRUCTURE OF THE TABLE.
----
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr,
ref_table_des TYPE REF TO cl_abap_structdescr.
REFRESH : ifc,ifc_char.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( text1 ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
&----
*& Form create_dynamic_itab
&----
1) CREATE DYNAMIC INTERNAL TABLE AND ASSIGN TO
FS
2) CREATE DYNAMIC WORK AREA AND ASSIGN TO FS
----
FORM create_dynamic_itab.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM. "create_dynamic_itab
&----
*& Form get_data
&----
Select Data From the Table
----
FORM get_data.
DATA : l_struc_index LIKE sy-index,
string TYPE string..
SELECT * FROM (text1)
INTO CORRESPONDING FIELDS OF TABLE
<dyn_table> UP TO 20 ROWS.
ENDFORM. "get_data
&----
*& Form flat_file
&----
Select Data From the Table
----
FORM flat_file USING text1.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
i_field_seperator = '#'
TABLES
i_tab_sap_data = <dyn_table>
CHANGING
i_tab_converted_data = i_text
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
ENDFORM. "flat_file
&----
*& Form fill_container
&----
FORM fill_container .
IF lr_custom_container IS INITIAL.
CREATE OBJECT lr_custom_container
EXPORTING
container_name = 'CUSTOM1'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF lr_editor IS INITIAL.
CREATE OBJECT lr_editor
EXPORTING
wordwrap_mode = cl_gui_textedit=>wordwrap_off
parent = lr_custom_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5
OTHERS = 6.
ENDIF.
Set toolbar of the textedit to inactive
CALL METHOD lr_editor->set_toolbar_mode
EXPORTING
toolbar_mode = 0
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 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.
Switch off the status line
CALL METHOD lr_editor->set_statusbar_mode
EXCEPTIONS
error_cntl_call_method = 1
invalid_parameter = 2
OTHERS = 3.
ENDIF.
CALL METHOD lr_editor->set_text_as_r3table
EXPORTING
table = i_text
EXCEPTIONS
error_dp = 1
error_dp_create = 2
OTHERS = 3.
ENDFORM. " fill_container
&----
*& Form SEND
&----
FORM send .
DATA : string TYPE string.
DATA: wa_text TYPE i_text.
OPEN DATASET d1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT i_text INTO wa_text.
MOVE wa_text TO string.
TRANSFER string TO d1.
ENDLOOP.
MESSAGE 'Data Send' TYPE 'S' .
*message i001('data sent').
CLOSE DATASET d1.
ENDFORM. " SEND
please reply ASAP
‎2007 May 24 10:42 AM
Hi
Before converting to a flat file see that All fields in the internal table are of data type CHAR.
So declare another Internal table with all CHAR fields and move the data into it and use that ITAB to convert data into file.
Reward points if useful
Regards
Anji
‎2007 May 24 11:36 AM
thanx anji,
i m creating the table dynamically,
nd even tried to do wat you said dynamically
but it is talking all the integer fields as #.
waiting for ur reply
‎2007 May 24 11:44 AM
hello anji,
the solution wat i used was :
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
MOVE xfc TO xfc_char.
IF xfc_char-datatype NE 'C'.
xfc_char-datatype = 'C'.
ENDIF.
IF xfc_char-inttype NE 'C'.
xfc_char-inttype = 'C'.
ENDIF.
APPEND xfc_char TO ifc_char.
ENDLOOP.
ENDFORM.
i created 2 dynamic structures (ifc , ifc_char) 1 with all the fields as in the Table and in the other i
converted all the fields that are not of type Char into char field.
then thru perform create_dynamic_table i created both the tables as per the Structures gernetaed (IFC, IFC_CHAR)
then in the form get_data,
this is wat i did:
FORM get_data.
DATA : l_struc_index LIKE sy-index,
string TYPE string..
SELECT * FROM (text1)
INTO CORRESPONDING FIELDS OF TABLE
<dyn_table> UP TO 20 ROWS.
MOVE <dyn_table> TO <dyn_table_char>.
but in this case it is making all my integer fields '#'
‎2007 May 24 10:43 AM
OPEN DATASET <Data source name> FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT <internal table name>
IF sy-subrc EQ 0.
TRANSFER <internal table name> TO <Data source name>
ENDIF..
ENDLOOP.
CLOSE DATASET <Data source name>.
<b>Error in your case is
DATA : string TYPE string.
Declare it as TYPE C instead of string.</b>
I guess it will help to solve your problem.
Reward to all useful answers.
Regards,
SaiRam
‎2007 May 24 11:37 AM
Hello Dear,
thanx for your reply
but as of now i m not facing ny problem in the data set
the problem is i m not able to convert my internal table in to a flat file
‎2007 May 24 10:57 AM
‎2007 May 24 11:51 AM
HI,
try
<b> p_file_tmp type string.</b>
p_file_tmp = p_file. " generates type error if p_file used
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = p_file_tmp
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = gt_file
FIELDNAMES =
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.
regards,
Sooness.