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 code for XLS file or csv file??

Former Member
0 Likes
923

Hi

Please let me know the code to read a xls or csv file from the SAP application unix server.I had written the code,but in case of xls file the output is junk values.

OUTPUT:###########3 OK &&&&&&&&&&&&&

is coming like this.

code:

DATA:BEGIN OF itab OCCURS 0,

matl_type(4) TYPE c,

matl_group(9) TYPE c,

matl_desc(40) TYPE c,

char_prof(18) TYPE c,

END OF itab.

DATA:wa LIKE itab.

DATA file TYPE string VALUE `/sap/inbound/master.xls`.

BREAK-POINT.

OPEN DATASET file FOR INPUT IN binary MODE.

IF sy-subrc = 0.

WRITE:'ok'.

ENDIF.

DO.

READ DATASET file INTO wa.

IF sy-subrc = 0.

itab = wa.

WRITE: / wa-matl_type,

wa-matl_group,

wa-matl_desc,

wa-char_prof.

APPEND itab.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET file.

please help me to correct this error.

in case of cvs file,when i comes to read dataset,my subrc = 4.

regds

vipin

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
570

Hi Vipin ,

I have made some changes tour code , now please check this code - -

DATA:BEGIN OF itab OCCURS 0,
matl_type(4) TYPE c,
matl_group(9) TYPE c,
matl_desc(40) TYPE c,
char_prof(18) TYPE c,
END OF itab.

DATA:wa LIKE itab.

DATA file TYPE string VALUE `/sap/inbound/master.xls`.



OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
BREAK-POINT.
IF sy-subrc = 0.
*  WRITE:'ok'.


DO.
  READ DATASET file INTO wa.
  IF sy-subrc = 0.
    itab = wa.
    WRITE: / wa-matl_type,
    wa-matl_group,
    wa-matl_desc,
    wa-char_prof.
    APPEND itab.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET file.

Regards

Pinaki

Hi

Please let me know the code to read a xls or csv file from the SAP application unix server.I had written the code,but in case of xls file the output is junk values.

OUTPUT:###########3 OK &&&&&&&&&&&&&

is coming like this.

code:

DATA:BEGIN OF itab OCCURS 0,

matl_type(4) TYPE c,

matl_group(9) TYPE c,

matl_desc(40) TYPE c,

char_prof(18) TYPE c,

END OF itab.

DATA:wa LIKE itab.

DATA file TYPE string VALUE `/sap/inbound/master.xls`.

BREAK-POINT.

OPEN DATASET file FOR INPUT IN binary MODE.

IF sy-subrc = 0.

WRITE:'ok'.

ENDIF.

DO.

READ DATASET file INTO wa.

IF sy-subrc = 0.

itab = wa.

WRITE: / wa-matl_type,

wa-matl_group,

wa-matl_desc,

wa-char_prof.

APPEND itab.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET file.

please help me to correct this error.

in case of cvs file,when i comes to read dataset,my subrc = 4.

regds

vipin

2 REPLIES 2
Read only

former_member242255
Active Contributor
0 Likes
570

after reading the dataset,you have to SPLIT the data that is got from the file so that the fields

are placed correctly into the corresponding fields..

Read only

Former Member
0 Likes
571

Hi Vipin ,

I have made some changes tour code , now please check this code - -

DATA:BEGIN OF itab OCCURS 0,
matl_type(4) TYPE c,
matl_group(9) TYPE c,
matl_desc(40) TYPE c,
char_prof(18) TYPE c,
END OF itab.

DATA:wa LIKE itab.

DATA file TYPE string VALUE `/sap/inbound/master.xls`.



OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
BREAK-POINT.
IF sy-subrc = 0.
*  WRITE:'ok'.


DO.
  READ DATASET file INTO wa.
  IF sy-subrc = 0.
    itab = wa.
    WRITE: / wa-matl_type,
    wa-matl_group,
    wa-matl_desc,
    wa-char_prof.
    APPEND itab.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET file.

Regards

Pinaki