cancel
Showing results for 
Search instead for 
Did you mean: 

read the input file

Former Member
0 Kudos
173

Hi All,

i have got a input file that has to be read in to SAP and the technical SAP Field are to be mapped with legacy file fields for the purpose of inbound interfacing.

help by providing the open data set and read data set method to get the feilds of lecay file to be populated in the internal table.

give some needful sample code or example as per my requirment.

thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Naveen Sharma,

Basically when u transfer lagacy data into R/3 system u have do it with BDC or LSMW.

place the flat in Apllication server, then

1. Normally u go for Open data set and read data set for opening or read the flat file.(suppose u r flat file is in presentation server u have to use gui_upload and gui_down load function module to process flat file)

that is placed in the application server,

2. read it in the internal table in the presentation server,

3. process the data in the internal table i fu need to capture the errors in the flat file.

4, then upload the data into R/3 database using the code.

This is the sample code for BDC(batch data communication)

processed through using call transaction method. in se80.

&----


*& Report ZBDCCUS *

*& *

&----


*& *

*& *

&----


REPORT ZBDCCUS.

DATA: BEGIN OF WA_CUSTGEN,

ZZCUSID TYPE ZCUSTGEN-ZZCUSID,

ZZCUSNAME TYPE ZCUSTGEN-ZZCUSNAME,

ZZCONTNO TYPE ZCUSTGEN-ZZCONTNO,

ZZADD TYPE ZCUSTGEN-ZZADD,

ZZCITY TYPE ZCUSTGEN-ZZCITY,

END OF WA_CUSTGEN.

DATA: BEGIN OF WA_CUSTGEN_FLATFILE,

ZZCUSID(6) TYPE C,

ZZCUSNAME(25) TYPE C,

ZZCONTNO(12) TYPE C,

ZZADD(30) TYPE C,

ZZCITY(10) TYPE C,

END OF WA_CUSTGEN_FLATFILE.

DATA IT_BDC LIKE TABLE OF BDCDATA WITH HEADER LINE.

DATA IT_CUSTGEN LIKE TABLE OF WA_CUSTGEN WITH HEADER LINE.

DATA IT_CUSTGEN_FLATFILE LIKE TABLE OF WA_CUSTGEN_FLATFILE WITH

HEADER LINE.

DATA IT_MSG LIKE TABLE OF BDCMSGCOLL WITH HEADER LINE.

DATA :

V_DSN TYPE STRING VALUE 'C:\CUSTFLAT.TXT',

G_TOTAL(3) TYPE N VALUE 0,

G_ERROR(3) TYPE N VALUE 0,

G_SAVED(3) TYPE N VALUE 0,

G_STRING1 TYPE STRING,

G_STRING2 TYPE STRING,

G_STRING3 TYPE STRING.

OPEN DATASET V_DSN FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC = 0.

DO.

READ DATASET V_DSN INTO WA_CUSTGEN_FLATFILE.

IF SY-SUBRC = 0.

PERFORM BDC_HEADER USING 'ZBDC_SCREEN1' '9000'.

PERFORM BDC_DETAILS USING 'BDC_OKCODE' 'SAVE'.

PERFORM BDC_DETAILS USING 'ZCUSTGEN-ZZCUSID'

WA_CUSTGEN_FLATFILE-ZZCUSID.

PERFORM BDC_DETAILS USING 'ZCUSTGEN-ZZCUSNAME'

WA_CUSTGEN_FLATFILE-ZZCUSNAME.

PERFORM BDC_DETAILS USING 'ZCUSTGEN-ZZCONTNO'

WA_CUSTGEN_FLATFILE-ZZCONTNO.

PERFORM BDC_DETAILS USING 'ZCUSTGEN-ZZADD'

WA_CUSTGEN_FLATFILE-ZZADD.

PERFORM BDC_DETAILS USING 'ZCUSTGEN-ZZCITY'

WA_CUSTGEN_FLATFILE-ZZCITY.

ADD 1 TO G_TOTAL.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET V_DSN.

PERFORM BDC_PROCESS USING 'ZBDCSCR'.

MESSAGE 'TOTAL RECORDS UPDATED ' TYPE 'S'.

  • MESSAGE L_UPDATE_COUNTER TYPE 'S'.

ENDIF.

FORM BDC_HEADER USING PROGRAMNAME DYNPRO.

IT_BDC-PROGRAM = PROGRAMNAME.

IT_BDC-DYNPRO = DYNPRO.

IT_BDC-DYNBEGIN = 'X'.

APPEND IT_BDC.

ENDFORM.

FORM BDC_DETAILS USING FIELDNAME FIELDVAL.

CLEAR IT_BDC.

IT_BDC-FNAM = FIELDNAME.

IT_BDC-FVAL = FIELDVAL.

APPEND IT_BDC.

ENDFORM.

FORM BDC_PROCESS USING TCODE.

CALL TRANSACTION TCODE

USING

IT_BDC

MODE 'A'

UPDATE 'A'

MESSAGES INTO IT_MSG.

ENDFORM.

look at this code how it used for open data set and close data set and read data set.

i think it is helpful for you please reward points,

with regards,

venkatesh mani

Former Member
0 Kudos

Hello naveen

check the legacy file in al11 & path inside which the file is there you cna open & check the file see if any seperators are there where the fields have fix length,

if it is a fix length file then declare a internal table with same structure & type as that of legacy file

then code as :

OPEN DATASET w_getdata FOR INPUT IN TEXT MODE ENCODING DEFAULT .

IF sy-subrc = 0.

********" discarding first record as it is header

    • READ DATASET w_filename INTO w_string1 . "wa_data.

CLEAR wa_data .

      • Get records into internal table ( without header data )

READ DATASET w_getdata INTO w_string1. "wa_gid.

WHILE sy-subrc = 0.

APPEND wa_data TO it_gid.

READ DATASET w_getdata INTO wa_gid.

ENDWHILE.

close dataset

endif.

if seperator is there then instead of ur work area

read it in a string & split string into work area.

reward points if helpful