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

Read file from application server

Former Member
0 Likes
21,395

Hi,

I am reading a tab delimited file from application server. In the application server it is stored as # separated. I want to read the file and place the contents in the internal table with every field separated as # into separate fields in internal table.

PLesae help.

Regards,

Jeetu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
8,079

Hi Jeetu,

If u want to read from Files from Applicatin Server U can go for

Open Data Set File for reading in text mode encoding default

This option enables u to read the file from Application Server & coming to Reading Header details into one internal table & Item detail into One Internal table

U can use

AT First

On change of

conditions to read

Plz reward points if answer is useful...

Regards,

Mandeep...

6 REPLIES 6
Read only

Former Member
0 Likes
8,079

Hi jeetu,

Normally, when you want to read the file from application server, you will have 5 steps:

Open file in application server by statement:

OPEN DATASET file_name FOR INPUT IN TEXT MODE.

Checking the file is opened sucessfully by SY-SUBRC = 0

After checking, you can read data from file by statement:

READ DATASET file_name INTO itab. Note: This statement should be in DO statement

Append data to internal table

Close file by statement:

CLOSE DATASET file_name

Example

DATA: BEGIN OF i_tab OCCURS 0,  
      text(100),  
    END OF i_tab,    
  gv_dataset1(30) VALUE ’/temp/testfile.txt’.
OPEN DATASET gv_dataset1 FOR INPUT IN TEXT MODE.  
 DO.  
   IF SY-SUBRC <> 0.  
     EXIT.
     ENDIF.   
  READ DATASET gv_dataset1 INTO i_tab.    
 APPEND i_tab. 
    CLEAR i_tab. 
  ENDDO. 
CLOSE DATASET gv_dataset1.

reward pts if found usefull

regards

Sathish

Read only

Former Member
0 Likes
8,079

Hi Jeetu,

Use open dataset

read dataset

and get the values into one internal table

Loop through this internal table

split itab at '#' into itab1-field1 itab2-field2

endloop

Read only

Former Member
0 Likes
8,079

Hi

See the sample code

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 : it_pricing[], it_pricing.

DO.

READ DATASET P_FNAME INTO V_STR.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

SPLIT V_STR AT '#' INTO it_pricing-key

it_pricing-F1 it_pricing-F2 it_pricing-F3

it_pricing-F4 it_pricing-F5 .

APPEND it_pricing.

CLEAR it_pricing.

ENDDO.

<b>Reward points for useful Answers</b>

Regards

Anji

Read only

Former Member
0 Likes
8,079

Hi,

Here is the example Program

&----


*& Report ZUPLOADTAB *

*& *

&----


*& Example of Uploading tab delimited file *

*& *

&----


REPORT zuploadtab .

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT '/usr/sap/'..

DATA: ld_file LIKE rlgrap-filename.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 like pa0002-VORNA,

name2 like pa0002-name2,

age type i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Text version of data table

TYPES: begin of t_uploadtxt,

name1(10) type c,

name2(15) type c,

age(5) type c,

end of t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) type c.

constants: con_tab TYPE x VALUE '09'.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

************************************************************************

*START-OF-SELECTION

START-OF-SELECTION.

ld_file = p_infile.

OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

ELSE.

DO.

CLEAR: wa_string, wa_uploadtxt.

READ DATASET ld_file INTO wa_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

wa_uploadtxt-name2

wa_uploadtxt-age.

MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.

APPEND wa_upload TO it_record.

ENDIF.

ENDDO.

CLOSE DATASET ld_file.

ENDIF.

************************************************************************

*END-OF-SELECTION

END-OF-SELECTION.

*!! Text data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

Regards

Sudheer

Read only

Former Member
0 Likes
8,080

Hi Jeetu,

If u want to read from Files from Applicatin Server U can go for

Open Data Set File for reading in text mode encoding default

This option enables u to read the file from Application Server & coming to Reading Header details into one internal table & Item detail into One Internal table

U can use

AT First

On change of

conditions to read

Plz reward points if answer is useful...

Regards,

Mandeep...

Read only

0 Likes
8,079

Hi,

what could i use if i have a text-file on my local PC and i want to take the content and load it into a internal table to use the values to create BP and suchs.

Lets say i have a text file like this:

Peter Pan 11.06.1980

Klaus Kasper 10.06.1980

Now i want to go ahead and read it into a internal table.

First Row - Field 1: Peter

First Row - Field 2: Pan

First Row - Field 3: 11.06.1980

Second Row - Field 1: Klaus

Second Row - Field 1: Kasper

Second Row - Field 1: 10.06.1980

The whole idea of this is that i can then pass the data on and create for example a Business Partner from the following data in the internal table.

Best Regards

Rene