Application Development 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 dataset issue

Former Member
0 Kudos

Hi,

File declaration state ment:

PARAMETERS: PS_FNAME(128) TYPE C LOWER CASE.

Internal table declaration:

DATA: BEGIN OF MT_INREC OCCURS 0,

EBELN LIKE EKET-EBELN, (char(10))

EBELP LIKE EKET-EBELP, (numc(5))

EMATN LIKE EKPO-EMATN, (char(18))

EINDT LIKE EKET-EINDT, (dats(8))

SLFDT LIKE EKET-SLFDT, (dats(8))

DIFF LIKE EKET-MENGE, (quan(13)

END OF MT_INREC.

Open dataset statement:

OPEN DATASET PS_FNAME FOR INPUT MESSAGE MS_MESSAGE IN TEXT MODE

ENCODING NON-UNICODE.

Read dataset statement:

READ DATASET PS_FNAME INTO MT_INREC.

Is this correct? if so

Please let me know how tha data read into the internal table fields?(how this read dataset statement works? )

if not what should i add in the read data statement in this case?

Thanks,

Radhika

5 REPLIES 5

Former Member
0 Kudos

Hi ,

Use the following code

field-symbols : <line> TYPE ANY.

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

DO.

READ DATASET file INTO <wa_data> MAXIMUM LENGTH 200.

IF sy-subrc = 0.

ASSIGN COMPONENT 'LINE' OF STRUCTURE <wa_data> TO <line>.

IF sy-subrc = 0.

v_char1 = <line>.

*--Replaces . With space

REPLACE FIRST OCCURRENCE OF '.' IN v_char1 WITH ' '.

<line> = v_char1.

*--Spliting the string at the | Delimiter and moving into corresponding

*--fields of the header internal table

SPLIT <line> AT '|'

INTO wa_header-item

wa_header-ebeln

wa_header-bldat

wa_header-budat

v_dummy "Added on 08/08/08

wa_header-bktxt.

enddo.

Edited by: A kumar on Aug 11, 2008 2:14 PM

Former Member
0 Kudos

Hi,

First read data into a string variable and then split into the work area fields as below and append to ur internal table.

do.

READ DATASET file INTO string.

if sy-subrc = 0.

SPLIT string

AT cl_abap_char_utilities=>horizontal_tab "Horizontal tab

INTO MT_INREC-EBELN

MT_INREC-EBELP

MT_INREC-EMATN

MT_INREC-EINDT

MT_INREC-SLFDT

MT_INREC-DIFF.

append MT_INREC.

else.

exit.

endif.

naveen_inuganti2
Active Contributor
0 Kudos

Hi Radhika....

See this sample code....

>OPEN DATASET P_FILE FOR INPUT IN TEXT MODE.

> CHECK SY-SUBRC EQ C_SUCCESS1.

> DO

> READ DATASET P_FILE INTO STR1.

> IF SY-SUBRC <> 0. " NE SUCCESS.

> EXIT.

> ELSEIF SY-SUBRC EQ C_SUCCESS1.

> APPEND STR1.

> CLEAR STR1.

> ENDIF.

> ENDDO.

>

> DELETE STR1 WHERE SLINE EQ ' '.

> DESCRIBE TABLE STR1 LINES V_LINE.

> IF V_LINE EQ 0.

> MESSAGE E001 WITH TEXT-064.

> STOP.

> ENDIF.

> LOOP AT STR1.

> CLEAR: WA_UPTAB.

> SPLIT STR1-SLINE AT C_STR

> INTO WA_UPTAB-MATNR

> WA_UPTAB-WERKS

> WA_UPTAB-VDATU

> WA_UPTAB-BDATU

> WA_UPTAB-EKORG

> WA_UPTAB-LIFNR

> WA_UPTAB-MEINS

> WA_UPTAB-EBELP

> WA_UPTAB-FESKZ

> WA_UPTAB-AUTET

> WA_UPTAB-MESSAGE.

> CLEAR WA_UPTAB-MESSAGE.

> APPEND WA_UPTAB TO I_UPTAB.

> CLEAR WA_UPTAB.

> ENDLOOP.

>

> REFRESH STR1.

> CLEAR STR1.

> CLOSE DATASET P_FILE.

Thanks,

Naveen.I

former_member585060
Active Contributor
0 Kudos

Try this

File declaration state ment:

PARAMETERS : p_asfile TYPE rlgrap-filename DEFAULT 'EMP'.

Internal table declaration:

Types : BEGIN OF TY_INREC ,

EBELN(10) type c,

EBELP(5) type c,

EMATN(18) type c,

EINDT(8) type c,

SLFDT(8) type c,

DIFF(13) type c,

END OF TY_INREC.

DATA : MT_INREC type table of TY_INREC ,

WA_INREC type TY_INREC.

Fill the Data in that internal table.

ur Select Query

Read from Application server.

OPEN DATASET p_asfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET p_asfile INTO WA_INREC.

IF sy-subrc <> 0.

EXIT.

ENDIF.

APPEND WA_INREC TO MT_INREC .

ENDDO.

CLOSE DATASET p_asfile.

Edited by: Bala Krishna on Aug 11, 2008 5:59 PM

Former Member
0 Kudos

Hi,

Check the following syntax and write your code:

For reading:

Open dataset for input in a particular mode.

Start DO loop.

Read dataset into a field. " field can also be a field string / work area / DDIC structure.

If READ is not successful.

Exit the loop.

Endif.

Do relevant processing for that record.

End the do loop.

Close the dataset.

For writing:

Open dataset for output / Appending in a particular mode.

Populate the field that is to be transferred.

TRANSFER the filed to a dataset.

Close the dataset.

Regards,

Bhaskar