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

Reading file from application server.

Former Member
0 Likes
1,184

Hi.

I am reading a file from application server. I am reading the data in to a string field and then splitting it into an internal table using '#' as delimiter.

here is the code written:

data: begin of l_t_data occurs 0,

field(50),

end of l_t_data.

data: l_dataset(50),

l_data1 type string.

data: c_tab_del "type x value'09'.

value '#'.

move '/tmp/INPUTFILE.TXT' to l_dataset.

OPEN DATASET l_dataset

FOR INPUT IN text MODE ENCODING DEFAULT.

read dataset l_dataset into l_data1.

*l_data1 = '67#1#60wizard#25/11/2006###'.

split l_data1 at c_tab_del into table l_t_data.

if not l_t_data[] is initial.

loop at l_t_data.

write:/ l_t_data-field.

endloop.

endif.

close dataset l_dataset.

Here I am trying with one record, then need to do same for all the records in the file.

The problem is that in Unicode complaint systems the split command is not actually splitting the values at '#''. But as shown in the commented line if I copy the data as literal in a string variable, its giving me desired result in l_t_data. But its not working with the data read from file.

The file on application server is tab delimited.

Can anyone please help me to split the data from file on application server into an internal table.

Thanks.

Vaishali

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
947

In a unicode system, you need to use the ABAP CHAR class to split at a tab

CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.

CONSTANTS: c_tab_del TYPE C VALUE L_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

Regards

Michael

7 REPLIES 7
Read only

Former Member
0 Likes
947

Hi Vaishali,

All you need to do is to use the Readdataset between DO and ENDDO as follows:

<opendataset>

DO.

<readdataset>

ENDDO.

SPLIT l_data1 at c_tab_del INTO <workarea of l_t_data.>

APPEND <workarea> TO <internal table l_t_data>

This should solve your problem

PLZ REWARD POINTS

Read only

Former Member
0 Likes
948

In a unicode system, you need to use the ABAP CHAR class to split at a tab

CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.

CONSTANTS: c_tab_del TYPE C VALUE L_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

Regards

Michael

Read only

0 Likes
947

refer this sample coe for download/upload file from/to application server -

&----


*& Report ZGILL_AS *

*& *

&----


*& *

*& *

&----


REPORT ZGILL_AS message-id rp .

tables: pa0001,pa0002.

select-options s_pernr for pa0001-pernr no intervals MODIF ID XYZ.

parameters: p_dwnld AS CHECKBOX ,

p_upld AS CHECKBOX DEFAULT 'X'.

parameters: P_DSNI(75) TYPE C MODIF ID ABG DEFAULT

'/usr/local/sapdata/amit.dat' LOWER CASE.

data: begin of itab occurs 0,

pernr(8),

sp1(1) value ',',

werks(4),

sp2(1) value ',',

persg(1),

sp3(1) value ',',

persk(2),

end of itab.

data: s_eof(3).

start-of-selection.

if p_upld = 'X'.

OPEN DATASET P_DSNI FOR OUTPUT IN LEGACY TEXT MODE.

PERFORM FETCH_DATA.

STOP.

elseif p_dwnld = 'X'.

OPEN DATASET P_DSNI FOR INPUT IN LEGACY TEXT MODE.

IF SY-SUBRC NE 0.

MESSAGE E016 WITH

'Error opening seq. file, RC:' SY-SUBRC.

EXIT.

ENDIF.

CLEAR S_EOF.

DO.

PERFORM FETCH_file.

IF S_EOF EQ 'YES'. stop. ENDIF.

ENDDO.

endif.

END-OF-SELECTION.

if itab[] is not initial.

perform print_file1 tables itab.

else.

write:/ 'No records exists'.

endif.

&----


*& Form FETCH_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_DATA .

SELECT * FROM PA0001 WHERE PERNR IN S_PERNR.

MOVE-CORRESPONDING PA0001 TO ITAB.

TRANSFER ITAB TO P_DSNI.

APPEND ITAB.

ENDSELECT.

CLOSE DATASET P_DSNI.

ENDFORM. " FETCH_DATA

&----


*& Form FETCH_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_file .

READ DATASET P_DSNI INTO itab.

append itab.

clear itab.

IF SY-SUBRC NE 0.

S_EOF = 'YES'. EXIT.

ENDIF.

ENDFORM. " FETCH_file

&----


*& Form print_file1

&----


  • text

----


  • -->P_ITAB text

----


FORM print_file1 tables P_ITAB structure itab .

write:/2 'EmpNo',

14 'Personnel Area',

34 'Emp Group',

47 'Emp SubGroup'.

skip 1.

loop at p_itab.

write:2 p_itab-pernr,

14 p_itab-werks,

34 p_itab-persg,

47 p_itab-persk.

skip 1.

endloop.

ENDFORM. " print_file1

Read only

0 Likes
947

Hi Michael.

Thanks a lot for you immediate help. Your answer has solved my problem.

Your answer has been rewarded. Thanks a lot once again.

Regards.

Vaishali.

Read only

Former Member
0 Likes
947

Hi Vaishali,

While u see the file Through AL11, u won't be able to see the space between the fields , but u'll see the '#' inbetween. But when you actually download the file on desktop in .txt or .xls format, the '#' will be replaced by space between the fields & you can see the separated fields.

(Reward helpful answers)

Regards,

Siddhesh sanghvi.

Read only

Former Member
0 Likes
947

Hi,

U'r record is tabbed delimited right?. its a simple logic. u'r record does not necessarily be delimited by # u can even use tab as delimiter. i'll give an example.

string = 'a b c d'.

itab with structure(w x y z) each with single character length.

now how do u put the data in itab.

simple

move string to itab.

append itab.

since the string contains data of single character delimited by tab and the structure of the internal table of length 1 each field.

u can directly push the data.

Try to understand it.

Regards,

Aravind

Read only

Former Member
0 Likes
947

Hi All.

Thanks a lot for your immediate help.

Regards.

Vaishali.