02-12-2007 10:19 PM
Basically I would like to fill an internal table. How I could do the oposite of:
check not filename is initial.
open dataset filename for output in text mode encoding non-unicode.
if sy-subrc ne 0.
write: / msg, filename.
exit.
endif.
loop at t_download.
transfer t_download to filename.
endloop.
close dataset filename.
02-12-2007 10:55 PM
Hi,
Try this..
DATA: BEGIN OF itab OCCURS 0,
knumv type konv-knumv,
kposn type konv-kposn,
stunr type konv-stunr,
kschl type konv-kschl,
kwert type konv-kwert,
END OF itab.
DATA: v_string type string.
DATA:
dsn(20) VALUE '/usr/test.dat'.
OPEN DATASET dsn.
IF sy-subrc = 0.
DO.
READ DATASET dsn INTO v_string.
IF sy-subrc <> 0.
EXIT.
ELSE.
SPLIT v_string AT cl_abap_char_utilities=>horizontal_tab
INTO itab-knumv itab-kposn itab-stunr itab-kschl
itab-kwert.
APPEND itab.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET dsn.
Thanks,
Naren
02-12-2007 10:22 PM
Hi,
Do you want to read the file data??
DATA:
dsn(20) VALUE '/usr/test.dat',
t_data type string occurs 0 with header line.
OPEN DATASET dsn.
IF sy-subrc = 0.
DO.
READ DATASET dsn INTO t_data.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND t_data.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET dsn.
LOOP AT t_data.
WRITE: / t_data.
ENDLOOP.
Thanks,
Naren
02-12-2007 10:49 PM
Thank you Narren
i assigned you points. Do you know how I could perform oposite of this complete part. Knowing the sturcture.of internal table result. Basically(after your preavious answer I have the string but how coud I de-concatenate it). Actually the opposite of:
loop at result.
CONCATENATE v_download result-knumv INTO v_download .
CONCATENATE v_download result-kposn INTO v_download SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE v_download result-stunr INTO v_download SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE v_download result-kschl INTO v_download SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE v_download result-kwert INTO v_download SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
append v_download to t_download. clear v_download.
endloop.
check not filename is initial.
open dataset filename for output in text mode encoding non-unicode.
if sy-subrc ne 0.
write: / msg, filename.
exit.
endif.
loop at t_download.
transfer t_download to filename.
endloop.
close dataset filename.
02-12-2007 10:52 PM
Hi,
Once you have the entire records in a single line of the internal table.
You can split the line at the horizontal tab and store them into separate fields and append it into another internal table.
Since you are appending the horizontal_tab as the delimiter, i used the same to split it.
Regards
Subramanian
02-12-2007 10:55 PM
Hi,
Try this..
DATA: BEGIN OF itab OCCURS 0,
knumv type konv-knumv,
kposn type konv-kposn,
stunr type konv-stunr,
kschl type konv-kschl,
kwert type konv-kwert,
END OF itab.
DATA: v_string type string.
DATA:
dsn(20) VALUE '/usr/test.dat'.
OPEN DATASET dsn.
IF sy-subrc = 0.
DO.
READ DATASET dsn INTO v_string.
IF sy-subrc <> 0.
EXIT.
ELSE.
SPLIT v_string AT cl_abap_char_utilities=>horizontal_tab
INTO itab-knumv itab-kposn itab-stunr itab-kschl
itab-kwert.
APPEND itab.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET dsn.
Thanks,
Naren
02-14-2007 9:55 AM
Great answer. I gave you maximum points.
only
OPEN DATASET dsn for input in text mode encoding non-unicode.
was needed