2010 Jan 07 10:42 PM
Hi Everyone,
I need little help, I have a requirement to extract table content with columns names as the header.
After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through
a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can
write to the file.
REPORT zlab_tbl_export.
DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
DATA v_file(100) VALUE 'c:\sap_export.txt'.
DATA line(1000).
DATA: o_data TYPE REF TO data.
CREATE DATA o_data TYPE TABLE OF (table_name).
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN o_data->* TO <table>.
SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
>>>>>>> LOOP at <table> into line. >>>>>>>>>>>> " Here the code breaks and fail
TRANSFER line to v_file.
WRITE :/ line.
ENDLOOP.
CLOSE DATASET v_file.Exception Message
----------------------------------------------------------------------------------------------------
|Error analysis |
| You attempted to move one data object to another. |
| This is not possible here because the conversion of a data object |
| of type "v" to type "C" is not supported. |
| |
| List of internal ABAP types: |
| |
| C Text (Character) |
| N Numerical text |
| D Date (YYYYMMDD) |
| T Time (HHMMSS) |
| X Hexadecimal |
| I Integer |
| P Packed number |
| F Floating point number |
| |
| h Internal table |
| r Object reference |
| l Data reference |
| g String of type C |
| y String of type X |
| s 2-byte integer with plus/minus sign |
| b 1-byte integer without plus/minus sign |
| u Structure (flat structure) |
| v Structure (deep structure) |
----------------------------------------------------------------------------------------------------
Hi Everyone,
I need little help, I have a requirement to extract table content with columns names as the header.
After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through
a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can
write to the file.
REPORT zlab_tbl_export.
DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
DATA v_file(100) VALUE 'c:\sap_export.txt'.
DATA line(1000).
DATA: o_data TYPE REF TO data.
CREATE DATA o_data TYPE TABLE OF (table_name).
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN o_data->* TO <table>.
SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
>>>>>>> LOOP at <table> into line. >>>>>>>>>>>> " Here the code breaks and fail
TRANSFER line to v_file.
WRITE :/ line.
ENDLOOP.
CLOSE DATASET v_file.Exception Message
----------------------------------------------------------------------------------------------------
|Error analysis |
| You attempted to move one data object to another. |
| This is not possible here because the conversion of a data object |
| of type "v" to type "C" is not supported. |
| |
| List of internal ABAP types: |
| |
| C Text (Character) |
| N Numerical text |
| D Date (YYYYMMDD) |
| T Time (HHMMSS) |
| X Hexadecimal |
| I Integer |
| P Packed number |
| F Floating point number |
| |
| h Internal table |
| r Object reference |
| l Data reference |
| g String of type C |
| y String of type X |
| s 2-byte integer with plus/minus sign |
| b 1-byte integer without plus/minus sign |
| u Structure (flat structure) |
| v Structure (deep structure) |
----------------------------------------------------------------------------------------------------
2010 Jan 07 10:46 PM
Hi Everyone, I need little help, I have a requirement to extract table content with columns names as the header. After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can write to the file.
thie is the code
REPORT zlab_tbl_export.
DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
DATA v_file(100) VALUE 'c:\sap_export.txt'.
DATA line(1000).
DATA: o_data TYPE REF TO data.
CREATE DATA o_data TYPE TABLE OF (table_name).
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN o_data->* TO <table>.
SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP at <table> into line. " Fail here
TRANSFER line to v_file.
WRITE :/ line.
ENDLOOP.
CLOSE DATASET v_file.and this is the exception:
Error analysis
You attempted to move one data object to another.
This is not possible here because the conversion of a data object
of type v to type C is not supported.
Edited by: Misbah on Jan 7, 2010 11:50 PM
2010 Jan 07 11:33 PM
Hi Misbah,
A DATASET oprnFOR OUTPUT IN TEXT MODE can be filled with character-like data only.
Yo can never use a string as a work area of an internal table except for a table of strings.
Try something like this:
field-symbols:
<rec> type any,
<fld> type any.
<out> type any.
data:
lv_rec type string,
lr_data type ref to data,
lv_len type sy-linsz.
LOOP at <table> assigning <rec>.
do.
assign component sy-index of structure <rec> to <fld>.
if sy-subrc <> 0.
exit."do
endif.
describe field <fld> output-length lv_len.
create data lr_data type c length lv_len.
assign lr_data->* to <out>.
write <fld> to <out>.
concatenate lv_rec <out> into lv_rec.
enddo.
TRANSFER lv_rec to v_file.
WRITE :/ lv_rec.
ENDLOOP.
Regards,
Clemens
2010 Jan 07 11:43 PM
Thanks Clemens,
I modified my code based on the code you posted, but unfortunately the program just write empty lines (number of lines = number of records) .. can you please help me further to fix this ?
Misbah
2010 Jan 07 11:51 PM
Hi Misbah,
check in debugger what the contents of the selected table data is, what is the content of all field-symbols in all step and what is finally transferred.
I can't help you from here. And I'll go to bed right now.
Regards,
Clemens
2010 Jan 07 11:53 PM
It is working now ..
I just changed this line
if sy-subrc 0.to
if sy-subrc NE 0Thanks a lot for you help Clemens.
for some reason when you apply the code tag , the <> disappear !
Misbah
Edited by: Misbah on Jan 8, 2010 12:53 AM
Edited by: Misbah on Jan 8, 2010 12:54 AM
2010 Jan 08 10:56 AM
Hi Misbah,
oh, yes, sorry. I always encourage people to use the preview tab and control the posting and I did not, at least not accurately. The characters < and > together are interpreted as a html tag and thus ignored. This is maybe one of the advantages of ABAP that you can write NE for this
Now I know that you can use html tags like & lt ; (without spaces between) to display NE in
my preferred way as <> here in the forum.
Hopefully someone adds this to the FAQs.
Regards,
Clemens
2010 Jan 08 4:20 PM
you are right , hopefully this problem with the forum will be fixed soon
Thanks again.
Misbah
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |