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: 

Regarding reading data from a file in the application server.

Former Member
0 Kudos

Hello Everyone,

My question is:

The file in the application server consists of data with header, detail and trail out of which the detail contains the main information. The detail again contains the data in the form of a continuous string and again some spaces corresponding to a single record. I need to split the data in the internal table in such a way so that the first few characters get into field-1 of the target internal table. Again I need to consider the spaces for accessing the data for filling up in field-2. How do I decide on the 'Split' statement and specially when the whole string has to be taken care of as contatining data in a single string format without space and again some data after some spaces corresponding to a single record.

Your help is very much needed. Thanks to all the experts in advance.

4 REPLIES 4

former_member181962
Active Contributor
0 Kudos

hi amrita,

you got to have some indication to indicate the end of line and this indicator should be different from the character that separates the fields.

then only you can use the split statement.

regards,

ravi

sreeramkumar_madisetty
Active Contributor
0 Kudos

Hi

This is the sample code I was used for the similar requirement.

DATA: single_line TYPE string .

v_file_listings = pa_filn1.

IF v_file_listings IS INITIAL .

MESSAGE e039 WITH v_file_listings.

ENDIF.

*-- read file, split lines into fields and put data into table

OPEN DATASET v_file_listings FOR INPUT IN TEXT MODE ENCODING NON-UNICODE. "Opening the files

IF sy-subrc EQ 0.

DO.

READ DATASET v_file_listings INTO single_line. "Reading the content of file into line

IF sy-subrc = 0.

IF sy-index > 1. "skip header-line

SPLIT "Split the content of line into work area

single_line

AT k_split

INTO

wa_listings-kschl " Condition type

wa_listings-tabname16 " Condition table name

wa_listings-vkorg " Sales organisation

wa_listings-kunnr " sold-to party numberor ship-to party number

wa_listings-matnr " Material Number

wa_listings-kodatab " Valid-from date

wa_listings-kodatb1. " Valid-to date

APPEND wa_listings TO itab_listings. "Appending Work Area to internal table

ENDIF.

ELSE.

EXIT.

ENDIF.

v_count1 = sy-tabix.

ENDDO.

Regards,

Sreeram

Former Member
0 Kudos

Hi,

Have to do like this

OPEN DATASET P_FNAME FOR INPUT IN TEXT MODE.

if sy-subrc ne 0.

write : / 'File could not be uploaded.. Check file name.'.

stop.

endif.

CLEAR : itab[], itab.

DO.

READ DATASET P_FNAME INTO V_STR.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

SPLIT V_STR AT ',' INTO itab-key

itab-F1 itab-F2 itab-F3

itab-F4 itab-F5 .

APPEND itab.

CLEAR itab.

ENDDO.

IF itab[] IS INITIAL.

WRITE : / 'No data found to upload'.

STOP.

ENDIF.

reward points if sueful

regards,

Anji

0 Kudos

Hello Anji,

First of all, thanks for taking your time out to answer my question. But I think that you didn`t get my question till now.Actually, the data in a single string goes like this.

9N87734ALL3POAOCUF80:SPICEPSL TWO NEW DS1242110 C.

Now,in this case,the first 3 characters correspond to (suppose) company code,the next three (773) to plant code and so on. The last alphabet is c corresponding to change indicator. In this case, the number of spaces between each one has been mentioned.My question is how to seperate the data in this case when a single string has all the characters pertaining to differen fields like I mentioned above. If you have any questions about this, do feel free to ask me. I would be glad to answer you as soon as possible.