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

Re Open dataset file command

Former Member
0 Likes
1,079

Hi Expert,

I am uploading the file for which i a have written code below.In 'it_fname-file' it contain the file but it is not appending in it_fname sy-subrc eq '8' it is showing

in the debuggin.

   OPEN DATASET it_fname-file FOR INPUT IN TEXT MODE ENCODING
DEFAULT.

   IF sy-subrc EQ '0'.
          APPEND it_fname."""""""if present then add to internal table
          CLOSE DATASET it_fname-file.
        ENDIF.
        CLEAR it_fname.

please can any one throw some light on this

Regards,

Am

8 REPLIES 8
Read only

Former Member
0 Likes
959

Hi Am,

As far as i know APPEND wont work..

You have to use

TRANSFER dobj TO dset [LENGTH len]
                      [NO END OF LINE].

to transfer the content to the file.

Thanks ,

Santanu Mohapatra

Read only

Former Member
0 Likes
959

Hi Antha,

we get sy-subrc eq 8 only when the file is not present on application server. Try to give file names in CAPITALS.

Below pseudo codes might help you.

-> To read the file from app server to internal table :

OPEN DATASET p_asfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

   REFRESH t_file.

   DO.

     READ DATASET p_asfile INTO w_string.

     IF sy-subrc <> 0.

       EXIT.

     ELSEIF sy-subrc EQ 0.

       wa_file-c1 = w_string+0(20).

       wa_file-c2 = w_string+20(20).

       wa_file-c3 = w_string+40(20).

       wa_file-c4 = w_string+60(20).

       wa_file-c5 = w_string+80(100).

       APPEND wa_file TO t_file.

       CLEAR wa_file.

     ENDIF.                               " IF sy-subrc <> 0

   ENDDO.                                 " DO

-> To upload data from internal table to App server file

OPEN DATASET w_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

   LOOP AT t_split INTO wa_split.

     TRANSFER wa_split-c1 TO w_file LENGTH 20 NO END OF LINE.

     TRANSFER wa_split-c2 TO w_file LENGTH 20 NO END OF LINE.

     TRANSFER wa_split-c3 TO w_file LENGTH 20 NO END OF LINE.

     TRANSFER wa_split-c4 TO w_file LENGTH 20 NO END OF LINE.

     TRANSFER wa_split-c5 TO w_file.

   ENDLOOP.                             " LOOP AT t_split ...

   CLOSE DATASET w_file.

Thanks

Vivek


Read only

Former Member
0 Likes
959

Hello,

use it:

open dataset (file name) for input in text mode encoding default.

do.

if sy-subrc ne 0.

exit.

endif.

read dataset (file name) into wa.

append wa to it. [ it = internal table.....]

enddo.

close dataset (file name).

copy the above code and paste it.......

hope your problem will be solved.....

Thanks

Sabyasachi

Read only

Former Member
0 Likes
959

Hi antha,

for you, i post a small code follow it..

this program is used for application server to internal table.......

TYPES : BEGIN OF ST_DEMO,
REG_NO(
10) TYPE C,
NAME(
20) TYPE C,
ADDR(
20) TYPE C,
END OF ST_DEMO.

DATA : WA_DEMO TYPE ST_DEMO,
IT_DEMO
TYPE TABLE OF ST_DEMO,
L_FNAME
TYPE STRING .


PARAMETERS: P_FNAME(128) TYPE C DEFAULT  'D:\usr\sap\DEV\SYS\SRC\SABYA1.txt' OBLIGATORY.
L_FNAME = P_FNAME.
                                                                             

OPEN DATASET L_FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.                   
DO.
IF SY-SUBRC <> 0.                                                             
EXIT.
ENDIF.
READ DATASET L_FNAME INTO  WA_DEMO.
APPEND WA_DEMO TO IT_DEMO.
ENDDO.
CLOSE DATASET L_FNAME.

LOOP AT IT_DEMO INTO WA_DEMO.
WRITE😕 WA_DEMO-REG_NO,
WA_DEMO-NAME,
WA_DEMO-ADDR.
ENDLOOP.

Thanks

Sabyasachi

Read only

Former Member
0 Likes
959

Hi,

Instead of APPEND, you should use TRANSFER command as following:

OPEN DATASET file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

   IF sy-subrc = 0.

     LOOP AT itab INTO work_area.

       TRANSFER work_area-field1 TO file_name.

       TRANSFER work_area-field2 TO file_name.

       and so on.....

     ENDLOOP.                          

     CLOSE DATASET file_name.

endif.

Read only

0 Likes
959

Hello bhartilal,

bharatilal says:

OPEN DATASET file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

   IF sy-subrc = 0.

     LOOP AT itab INTO work_area.

       TRANSFER work_area-field1 TO file_name.

       TRANSFER work_area-field2 TO file_name.

       and so on.....

     ENDLOOP.                          

CLOSE DATASET file_name.

you just see antha' s code.....do you use transfer wa to internal table??????? we use append statement...... your coding is use for storing data from internal table to application server...... but antha's code is used for storing data from application server to internal table........hope you understand....

Thanks

Sabyasachi...

Thanks

Read only

Former Member
0 Likes
959

Hi Antha,

While using open dataset the append statement wont work.

You have to use use Transfer statement to upload the file.

Data is read or written in a form which is compatible to BINARY MODE in Releases <= 4.6. This addition is primarily used to convert a file into the code page format specified already when it is opened. At runtime, the system uses the format of the system code page of the application server. The system saves the file then again in the code page specified. This procedure is important if data is exchanged between systems using different code pages. For more information, see READ DATASET and TRANSFER.

Hope this will help .....

Regards,

AKS

Read only

Former Member
0 Likes
959

Hello antha,

this program is used for internal table to application server.

TYPES : BEGINOF ST_DEMO,
REG_NO(
10) TYPEC,
NAME(
20) TYPEC,
ADDR(
20) TYPEC,                     
ENDOF ST_DEMO.

DATA : WA_DEMO TYPE st_demo,

                                       
IT_DEMO
TYPE TABLE OF ST_DEMO,
L_FNAME
TYPE STRING .

PARAMETERS: P_FNAME(128) TYPECDEFAULT'D:\usr\sap\DEV\SYS\SRC\SABYA1.txt'   OBLIGATORY.

L_FNAME = P_FNAME.

WA_DEMO-REG_NO = '10'.
WA_DEMO-NAME =
'ANAND'.
WA_DEMO-ADDR =
'NAGARKOVIL'.
APPEND WA_DEMO TO IT_DEMO.

WA_DEMO-REG_NO =
'11'.
WA_DEMO-NAME =
'VIKRAM'.
WA_DEMO-ADDR =
'CHENNAI'.
APPEND WA_DEMO TO IT_DEMO.

OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
WRITE :5 'REG NUM',16 'NAME',37 'ADDRESS' .
LOOP AT IT_DEMO INTO WA_DEMO.
IF SY-SUBRC = 0.
TRANSFER WA_DEMO TO L_FNAME.
WRITE :/5 WA_DEMO-REG_NO,16 WA_DEMO-NAME,37 WA_DEMO-ADDR.
ENDIF.
ENDLOOP.
CLOSE DATASET L_FNAME.