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 coding with the sequential files

Former Member
0 Kudos

hi experts,

in my company i hvnt worked on the sequential files dats y i request u to all experts,to send me the small sample program for uploading from the apllication server,,,,,,plz send me the file format also.........and how to save on the application server.....i know it will take some time but plz help me.....

5 REPLIES 5

Former Member
0 Kudos

Hi

You can use the Transactions

CG3Y and CG3Z for transfering the files from application to Presenetation server and vice versa.

see the sample BDC for uploading the data from Application server.

Refer this:

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/frameset.htm

ABAP code for uploading a TAB delimited file into an internal table. See code below for structures.

&----


*& 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.

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

Regards

Anji

varma_narayana
Active Contributor
0 Kudos

Hi..

You have a file with two fields where first 18 chars matno and next 4 chars Mattype.

Check the below code to upload.

Types : Begin of Mat,

matnr(18),

mtart(4),

End of Mat.

data : it_mat type table of mat,

Wa_mat type mat.

Parameters: P_DSN(30) default 'matfile.txt'.

data : v_msg type string.

Start-of-selection.

OPEN DATASET P_DSN

FOR INPUT "reading from file

IN text Mode " Line be line reading

Encoding Default "Unicode format

Message v_msg. "To store the message incase of error.

If sy-subrc ne 0.

Message v_msg type 'S'.

Leave list-processing.

Else.

Do.

Read dataset p_dsn into wa_mat.

if sy-subrc ne 0. "end of file

EXIT.

else.

APPEND wa_mat to it_mat.

endif.

Enddo.

close dataset p_dsn.

Endif.

<b>Reward if Helpful.</b>

Former Member
0 Kudos

Hi,

Refer this link:

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3c7f358411d1829f0000e829fbfe/frameset.htm

e.g. is:

The following program shows how you can write internal tables into a file:

DATA FNAME(60) VALUE 'myfile'.

TYPES: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

TYPES ITAB TYPE LINE OCCURS 10.

DATA: LIN TYPE LINE,

TAB TYPE ITAB.

DO 5 TIMES.

LIN-COL1 = SY-INDEX.

LIN-COL2 = SY-INDEX ** 2.

APPEND LIN TO TAB.

ENDDO.

OPEN DATASET FNAME FOR OUTPUT.

LOOP AT TAB INTO LIN.

TRANSFER LIN TO FNAME.

ENDLOOP.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO LIN.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE: / LIN-COL1, LIN-COL2.

ENDDO.

CLOSE DATASET FNAME.

The output is:

1 1

2 4

3 9

4 16

5 25

In this example, a structure LIN and an internal table TAB with line type LINE are created. Once the internal table TAB has been filled, it is written line by line into the file "myfile". The file is then read into the structure LIN, whose contents are displayed on the screen.

The following example works in R/3 Systems that are running on UNIX systems using ASCII.

DATA FNAME(60) VALUE 'myfile'.

DATA: TEXT1(4) VALUE '1234',

TEXT2(8) VALUE '12345678',

HEX TYPE X.

OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.

TRANSFER: TEXT1 TO FNAME LENGTH 6,

TEXT2 TO FNAME LENGTH 6.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO HEX.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE HEX.

ENDDO.

CLOSE DATASET FNAME.

The output is:

31 32 33 34 20 20 0A 31 32 33 34 35 36 0A

This example writes the strings TEXT1 and TEXT2 to the file "myfile" in text mode. The output length is set to 6. By reading the file byte by byte into the hexadecimal field, you can see how it is stored. The numbers 31 to 36 are the ASCII codes for the digits 1 to 6. 20 is a space, and 0A marks the end of the line. TEXT1 is filled with two trailing spaces. Two characters are truncated from TEXT2.

Jogdand M B

mohammed_moqeeth
Active Participant
0 Kudos

<b>Sequential File:</b>

<b>In BDC when we are working with the file in the application server, We open the file for different reasons(read/write/append) using this concept.

Ex for opening file from app. server:

open dataset <filename> for <input/output/append> in <text/binary> mode encoding default.</b>

Here,

Input is for reading the file from Application server

output is for writing the file into Application server

append is for adding more info to the existing file.

<b>

<u>Example:</u></b>

tables : zkunal3.

data:

dsn(20) type c value 'test.dat',

rec(80) type c.

data : begin of itab occurs 0.

include structure zkunal1.

data : end of itab.

select * from zkunal3 into table itab.

open dataset dsn for output in text mode encoding default.

" opens a file for writing; if the file is not thr in the working direct

"ory it will create one with the same name.

loop at itab.

concatenate itab-fname itab-lname itab-place into rec separated by space

.

transfer rec to dsn.

rec = ''.

endloop.

close dataset dsn.

rec = ''.

open dataset dsn for input in text mode encoding default.

" opens the file for reading only.

*READ DATASET dsn INTO rec.

if sy-subrc = 0.

message i005(zmsg_kunal).

endif.

*write rec.

*

while sy-subrc = 0.

write / rec. read dataset dsn into rec.

endwhile.

  • EXIT.

<u>Check the below links for your kind reference:</u>

<b>http://www.sapdevelopment.co.uk/file/file_downloadsap.htm

http://www.sapdevelopment.co.uk/file/file_uptabsap.htm

http://help.sap.com/saphelp_40b/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm</b>;

Reward ponits if useful......

Regards,

Moqeeth.

Former Member
0 Kudos

hi Ravi,

Use this sample code as an example for ur problem.

&----


  • table declaration

**&----


tables: mara.

&----


*data declaration

&----


data: begin of it_lfa1 occurs 0,

vendor like lfa1-lifnr,

land1 like lfa1-land1,

name1 like lfa1-name1,

ort01 like lfa1-ort01,

end of it_lfa1.

&----


  • selection screen

**&----


selection-screen: begin of block b1 with frame.

parameters: p_file type rlgrap-filename obligatory.

selection-screen: end of block b1.

&----


  • at selection screen

**&----


at selection-screen on value-request for p_file.

&----


*& start-of-selection

&----


start-of-selection.

perform transfer_file using p_file.

perform write.

&----


*& Form transfer_file

&----


  • text

----


  • -->P_P_FILE text

----


form transfer_file using p_p_file.

data: l_message(30) type c.

***opening dataset for reading

open dataset p_p_file for input in text mode encoding default message

l_message.

if sy-subrc ne 0.

message i001(zerr2) with p_p_file.

endif.

*******transferring data from file to app server.

do.

read dataset p_p_file into it_lfa1.

if sy-subrc = 0.

append it_lfa1.

clear it_lfa1.

else.

exit.

endif.

enddo.

*******closing dataset

close dataset p_p_file.

endform. " transfer_file

&----


*& Form write

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form write .

loop at it_lfa1.

write:/ it_lfa1-vendor,

it_lfa1-land1,

it_lfa1-name1,

it_lfa1-ort01.

endloop.

endform. " write

Please check this link also for sample code.

http://www.sapdevelopment.co.uk/file/file_uptabsap.htm

Plz reward points if useful....

Regards,

Mandeep.