Application Development and Automation 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: 
Read only

open dataset

Former Member
0 Likes
922

Hi all,

My code like this when i try to upload .txt .

txt file will be poplulating in Wa but not moving into itab.

OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING UTF-8.

IF SY-SUBRC = 0.

DO.

READ DATASET P_FILE INTO WA_ITAB.

IF SY-SUBRC = 0.

SPLIT WA_ITAB AT '#' INTO ITAB-WERKS

ITAB-MATNR

ITAB-EKGRP

ITAB-LIFNR

ITAB-EVERS

L_MENGE.

ITAB-MENGE = L_MENGE.

APPEND ITAB.

CLEAR ITAB.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET P_FILE.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
896

Hi Devender,

May be '#' represents Horizontal tab, so do as follows.

OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING UTF-8.

IF SY-SUBRC = 0.

DO.

READ DATASET P_FILE INTO WA_ITAB.

IF SY-SUBRC = 0.

SPLIT WA_ITAB AT <b>CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB</b> INTO ITAB-WERKS

ITAB-MATNR

ITAB-EKGRP

ITAB-LIFNR

ITAB-EVERS

L_MENGE.

ITAB-MENGE = L_MENGE.

APPEND ITAB.

CLEAR ITAB.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET P_FILE.

Thanks,

Vinay

10 REPLIES 10
Read only

Former Member
0 Likes
896

Hello,

Change the code like this:


OPEN DATASET P_FILE FOR OUTPUT  " CHECK HERE
 IN TEXT MODE ENCODING UTF-8.
IF SY-SUBRC = 0.
DO.
READ DATASET P_FILE INTO WA_ITAB.
IF SY-SUBRC = 0.
SPLIT WA_ITAB AT '#' INTO ITAB-WERKS
ITAB-MATNR
ITAB-EKGRP
ITAB-LIFNR
ITAB-EVERS
L_MENGE.
ITAB-MENGE = L_MENGE.
APPEND ITAB.
CLEAR ITAB.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET P_FILE. 

Vasanth

Read only

Former Member
0 Likes
896

I presume you have debugged it and nothing is being passed into itab from the split statement.

Read only

0 Likes
896

yes, i debugged it and nothing passing to itab.

Read only

0 Likes
896

Hello,

I think the '#' symbol u r seeing here is not actually hash.

Please check the delimiter of the file. The split command can't able to identiy the '#'symbel.

Vasanth

Read only

0 Likes
896

use cl_abap_char_utilities=>HORIZONTAL_TAB instead of # in split

split wa at cl_abap_char_utilities=>HORIZONTAL_TAB into....

Read only

Former Member
0 Likes
897

Hi Devender,

May be '#' represents Horizontal tab, so do as follows.

OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING UTF-8.

IF SY-SUBRC = 0.

DO.

READ DATASET P_FILE INTO WA_ITAB.

IF SY-SUBRC = 0.

SPLIT WA_ITAB AT <b>CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB</b> INTO ITAB-WERKS

ITAB-MATNR

ITAB-EKGRP

ITAB-LIFNR

ITAB-EVERS

L_MENGE.

ITAB-MENGE = L_MENGE.

APPEND ITAB.

CLEAR ITAB.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET P_FILE.

Thanks,

Vinay

Read only

0 Likes
896

THANKS VINAY. YOU ARE STAR.

WHAT IS UR EMAIL ADDRESS

Read only

0 Likes
896

Hi Devender,

remeber ther is no splitting # .For a tab delimited file you see # symbol.

If you want to split

use the following syntax

for >= 4.6 c version

constants: con_tab type x value '09'

split xyz_file at con_tab into ---

for versions <= 4.7

constants: con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

split xyz_file at con_tab into ---

hope you are clear.

Thanks

venki

Read only

0 Likes
896

Hi Devender,

Thanks for your words and You can find my email address on business card.

Thanks,

Vinay

Read only

Former Member
0 Likes
896

Hi,

split the value into work area and then append it into internal table:

SPLIT WA_ITAB AT '#' INTO <b>WA_ITAB-WERKS</b>

-


-


<b>append WA_ITAB to ITAB.</b>

Regards,

Chanadn