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

Errors in reading Fields Value while uploading data from CSV file

Former Member
0 Likes
1,766

Dear ABAP Guru

I am facing a problem in which the values of the fields gets truncated while reading the data from CSV File

as per below given details:

009,000000000019214,OMC1,TEST-BIN-1

009,000000000019215,OMC1,TEST-BIN-2

009,000000000019216,OMC1,TEST-BIN-3

          • ABAP PROGRAM ********

REPORT ZUPDATE_BIN.

  • Data declarations for later use

TABLES MARD.

PARAMETERS FILENAME(128) DEFAULT 'c:\testfile.csv'

LOWER CASE.

DATA: MSG_TEXT(50),ws_mandt(4),ws_matnr(18),ws_werks(4),ws_lgort(4),ws_bin(10).

Data : BEGIN OF idetail occurs 0, "This is a temp-table where SELECT data is to be stored

mandt type c, "Client char(3)

comma_1(1) type c, "Comma

matnr(18) type c, "Material char(18)

comma_2(1) type c, "Comma

werks(4) type c, "plant char(4)

comma_3(1) type c, "Comma

lgort(4) type c, "storage location char(4)

comma_4(1) type c, "Comma

bin(10) type c. "Storage bin char(10)

data : END OF idetail.

OPEN DATASET FILENAME FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE MSG_TEXT.

IF SY-SUBRC NE 0.

WRITE: 'File cannot be opened. Reason:', MSG_TEXT.

EXIT.

ENDIF.

DO.

READ DATASET FILENAME INTO idetail.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND idetail.

ENDDO.

CLOSE DATASET FILENAME.

LOOP AT IDETAIL.

WRITE: / IDETAIL.

write : / idetail-matnr , idetail-bin.

ENDLOOP.

RESULTS

009,000000000019214,OMC1,TEST-BIN-1

9,000000000019214, IN-1

009,000000000019215,OMC1,TEST-BIN-2

9,000000000019215, IN-2

Note : Please note that my fields values are being truncated

Edited by: Anil Bedi on May 9, 2010 10:14 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,267

Dear Mr Asik Shameen

Thanks for taking pains.

I would be highly thankful if you provide us the solution of reading data from CSV file and updating master records

thru that,as it would be of great help for us.

As suggested I created a TEST-Program as per code given by you,but system gives DUMP Error

when it reaches at line -->

"TRANSFER TEXT1 to FNAME"

showing file is not opened. I tried with full path also ie.

DATA: FNAME(60) VALUE 'c:\myfile'.

but still gives same dump error.

My dear we are on SAP ERP2005 with ECC 6.0 on windows/mssql plateform.

with best regards

Anil bedi

6 REPLIES 6
Read only

asik_shameem
Active Contributor
0 Likes
1,267

Hello Anil,

This is not the conventional way of uploading the data. You have the character comma as a delimiter, use SPLIT command to get the data in each field. And remove the field comma_* from the internal table IDETAIL.

Do something like below.

TYPES: BEGIN OF ty_tab,
         line TYPE string,
       END OF ty_tab.

DATA: gt_tab  TYPE TABLE OF ty_tab,
      gwa_tab TYPE ty_tab.

DO.
READ DATASET FILENAME INTO gwa_tab.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
APPEND gwa_tab TO gt_tab.
ENDDO.

LOOP AT gt_tab INTO gwa_tab.

  SPLIT gwa_tab
      AT ','
      INTO  idetail-mandt
            idetail-matnr
            ...
  APPEND IDETAIL.

ENDLOOP.

Read only

Former Member
0 Likes
1,267

Dear Mr.Asik Shameen

Thanks for taking up my problem.

I have made the changes as suggested by you.

But system gives Syntax error at line :

"read dataset filename into gwa_tab"

Error is "gwa_tab" cannot be a table,a reference,a string or contain any of these objects".

Please help

regards

Anil

Read only

0 Likes
1,267

Hello Anil,

That means [READ DATASET|http://help.sap.com/saphelp_470/helpdata/en/fc/eb3d42358411d1829f0000e829fbfe/content.htm] does not accept STRING data type it seems. Just change the STRING type into CHARACTER type as below.

What version of SAP you have? STRING is acceptable in ECC 6.0. How ever, use the sample code below if you still face any problem.

DATA: FNAME(60) VALUE 'myfile'.
DATA: TEXT1(255) VALUE '009,000000000019214'.
DATA: BEGIN OF IDETAIL OCCURS 10,
       mandt TYPE mandt,
       matnr TYPE matnr,
      END OF IDETAIL.

TYPES: BEGIN OF ty_tab,
         line TYPE c length 255,
       END OF ty_tab.

DATA: gt_tab  TYPE TABLE OF ty_tab,
      gwa_tab TYPE ty_tab.

OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
  READ DATASET FNAME INTO gwa_tab-line.
  IF SY-SUBRC <> 0.
    EXIT.
  ELSE.
    SPLIT gwa_tab-line
        AT ','
        INTO  idetail-mandt
              idetail-matnr.
    APPEND IDETAIL.
  ENDIF.
ENDDO.

CLOSE DATASET FNAME.

Read only

Former Member
0 Likes
1,268

Dear Mr Asik Shameen

Thanks for taking pains.

I would be highly thankful if you provide us the solution of reading data from CSV file and updating master records

thru that,as it would be of great help for us.

As suggested I created a TEST-Program as per code given by you,but system gives DUMP Error

when it reaches at line -->

"TRANSFER TEXT1 to FNAME"

showing file is not opened. I tried with full path also ie.

DATA: FNAME(60) VALUE 'c:\myfile'.

but still gives same dump error.

My dear we are on SAP ERP2005 with ECC 6.0 on windows/mssql plateform.

with best regards

Anil bedi

Read only

0 Likes
1,267

Hello Anil,

That part of coding is not needed in your case. You have a file already in the application server and you just read it as you did earlier. Use the logic to split and append to a new internal table, not the coding. It is just a sample program. Just remove the below part.

" OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
" TRANSFER TEXT1 TO FNAME.
" CLOSE DATASET FNAME.

Read only

Former Member
0 Likes
1,267

Dear Mr.Asik Shameen

Thanks for solving my problem.

Full Marks to you

with best regards

Anil Bedi

I am just putting the final ABAP Code for my Developer Friends who are not expert in ABAP like me.

(A) Format of Input (CSV) File is

009,000000000000019214,COMP,1001,TEST-BIN-1

009,000000000000019215,COMP,1001,TEST-BIN-2

(B) ABAP CODE as below:

REPORT ZUPDATE_BIN.

PARAMETERS FILENAME(128) DEFAULT 'c:\testfile.csv' LOWER CASE.

DATA: MSG_TEXT(50).

TYPES: BEGIN of ty_tab,

line TYPE c length 255,

END of ty_tab.

DATA: gt_tab TYPE TABLE OF ty_tab,

gwa_tab type ty_tab.

Data : BEGIN OF idetail occurs 0, "This is a temp-table where File data is to be stored

mandt(3) type c, "Client char(3)

matnr(18) type c, "Material char(18)

werks(4) type c, "plant char(4)

lgort(4) type c, "storage location char(4)

bin(10) type c. "Storage bin char(10)

data : END OF idetail.

OPEN DATASET FILENAME FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE MSG_TEXT.

IF SY-SUBRC NE 0.

WRITE: 'File cannot be opened. Reason:', MSG_TEXT.

EXIT.

ENDIF.

  • Reading Data

DO.

READ DATASET FILENAME INTO gwa_tab-line.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

SPLIT gwa_tab-line AT ',' INTO idetail-mandt

idetail-matnr

idetail-werks

idetail-lgort

idetail-bin.

APPEND IDETAIL.

ENDDO.

CLOSE DATASET FILENAME.

LOOP AT IDETAIL.

write 😕 idetail-mandt,idetail-matnr,idetail-werks,idetail-lgort,idetail-bin.

ENDLOOP.