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

CSV Line Item

Former Member
0 Likes
1,081

Hi Experts,

Good day!

I am creating a program that will mass scrap materials.

Data will be in CSV file format, for example:

20090713, 20090713,SCRAP1,551,PD01,1,D010, XYN4+F8FJ,1,AW02

20090713, 20090713,SCRAP2,551,PD01,1,D010, XZB10X10A05,2,AW02

20090713, 20090713,SCRAP3,551,PD01,1,D010, XZB10X40A05,3,AW02

20090713, 20090713,SCRAP4,551,PD01,1,D010, XZB32X48A045S,4,AW02

20090713, 20090713,SCRAP5,551,PD01,1,D010,XZB7.5X10A03,5,AW02

20090713, 20090713,SCRAP6,551,PD01,1,D010, XZB7.5X10A03,6,AW02

Execution results in reading the first line item only.

Can anyone help me how to read all the line item in CSV format.

My program is like LSMW Batch Input

Hi Experts,

Good day!

I am creating a program that will mass scrap materials.

Data will be in CSV file format, for example:

20090713, 20090713,SCRAP1,551,PD01,1,D010, XYN4+F8FJ,1,AW02

20090713, 20090713,SCRAP2,551,PD01,1,D010, XZB10X10A05,2,AW02

20090713, 20090713,SCRAP3,551,PD01,1,D010, XZB10X40A05,3,AW02

20090713, 20090713,SCRAP4,551,PD01,1,D010, XZB32X48A045S,4,AW02

20090713, 20090713,SCRAP5,551,PD01,1,D010,XZB7.5X10A03,5,AW02

20090713, 20090713,SCRAP6,551,PD01,1,D010, XZB7.5X10A03,6,AW02

Execution results in reading the first line item only.

Can anyone help me how to read all the line item in CSV format.

My program is like LSMW Batch Input

7 REPLIES 7
Read only

Former Member
0 Likes
1,045

Hi,

if the data is in application server - use open Dataset, read dataset and transfer them to internal table and then loop the itab and do your process.

if it is in presentation server - use gui_download and save it into itab and do your process.

Regards,

Sakthi.

Read only

Former Member
0 Likes
1,045

i guess, some issue is lying with LINE FEDD/LF.....so, pl. search forum for CADRIDGE RETURN/CR....am not sure!

thanq

Read only

vimalv
Active Participant
0 Likes
1,045

Read the file into an internal table before processing.. so that you 'll have all the lines from the file.

If its on the app server code like below:


  OPEN DATASET g_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc EQ 0.
    DO.
      READ DATASET g_file  INTO l_record.
      IF sy-subrc NE 0.
        EXIT.
      ELSE.
        w_sdata-sdata = l_record.
        APPEND w_sdata TO t_sdata.
      ENDIF.
ENDDO
....
..........

If its on pres server use the FM GUI_UPLOAD.


 CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = l_file
      filetype                = 'ASC'
*      has_field_separator     = ','
    TABLES
      data_tab                = t_sdata "lt_file
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
.......
..........

Then loop at the t_sdata table and process the lines one by one.

Read only

Former Member
0 Likes
1,045

can you identify whats wrong with my coding?


  DO.
     CLEAR: WKL-DATA.

 *    INPUT_TAB.
    READ DATASET WKG-NTFLE INTO WKL-DATA.
    IF SY-SUBRC NE 0. EXIT. ENDIF.
    WKG-IPCNT = WKG-IPCNT + 1.                    " Input count
    WKG-ERCNT = WKG-IPCNT.                        " added to!

    IF PA-RDOB2 = 'X'.                            " Tab file
       WKL-SEPRT = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    ENDIF.
*     Separate Input File
      SPLIT WKL-DATA AT WKL-SEPRT
            INTO INPUT_TAB-BLDAT INPUT_TAB-BUDAT INPUT_TAB-BKTXT
                 INPUT_TAB-BWART INPUT_TAB-WERKS INPUT_TAB-GRUND
                 INPUT_TAB-LGORT INPUT_TAB-MATNR INPUT_TAB-ERFMG
                 INPUT_TAB-PRCTR WKL-DUMMY.


*     Input data check
*      PERFORM DATA_CHECK_RTN CHANGING WKL-SUBRC.
*     Input Data = OK -->Append INPUT_TAB
      IF WKL-SUBRC = 0.
        APPEND INPUT_TAB.

*     Input Data includes Error data -->Delete from INPUT_TAB
      ELSEIF NOT ERROR_TAB[] IS INITIAL.
        LOOP AT INPUT_TAB.
          DELETE INPUT_TAB
                 WHERE BUDAT = ERROR_TAB-BUDAT.
        ENDLOOP.
      ENDIF.
  ENDDO.

Edited by: jay on Jul 17, 2009 1:27 PM

Read only

Former Member
0 Likes
1,045

Hi,

Remove this part of the code and see if its working

  • Input Data includes Error data -->Delete from INPUT_TAB

ELSEIF NOT ERROR_TAB[] IS INITIAL.

LOOP AT INPUT_TAB.

DELETE INPUT_TAB

WHERE BUDAT = ERROR_TAB-BUDAT.

ENDLOOP.

Regards

Milan

Read only

Former Member
0 Likes
1,045

HI MILAN,

Still not working, I have 6 different line items and the program is working but line item 1 is processed 6 times also..

Edited by: jay on Jul 17, 2009 3:27 PM

Read only

Former Member
0 Likes
1,045

Hi Jay,

Clear WKL-DATA for each Do - Enddo loop.

Regards

Milan Shah