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

Writing data into a file on Application Server

Former Member
0 Likes
5,200

Hi,

I need to write data into a file on application server.

The data is a combination of various fields from a table. If the last few fields of the table are empty ( that is there is no data in them ) , blank spaces should appear in them.

Moreoer in my case the last field is a FILLER ( Which is always EMPTY ).

But in such cases no blank spaces are appearing and the line stops where the last filled field stops ( This can be verified by downloading the file as .txt into presentation server ).

Can someone please explain how can the blank spaces be retained when writing into file on application server?

Thanks a Lot

Hi,

I need to write data into a file on application server.

The data is a combination of various fields from a table. If the last few fields of the table are empty ( that is there is no data in them ) , blank spaces should appear in them.

Moreoer in my case the last field is a FILLER ( Which is always EMPTY ).

But in such cases no blank spaces are appearing and the line stops where the last filled field stops ( This can be verified by downloading the file as .txt into presentation server ).

Can someone please explain how can the blank spaces be retained when writing into file on application server?

Thanks a Lot

12 REPLIES 12
Read only

Former Member
0 Likes
2,434

Hi,

Try saving as a .csv file with comma or semicolon as the separator.

Regards,

Ankur Parab

Read only

former_member242255
Active Contributor
0 Likes
2,434

try by writing to fill the FILLER for the fields that are having no values so that the FILLLER is making the line filled but with no data.

Read only

Former Member
0 Likes
2,434

Hi,

Specify the length when transfering the data.


REPORT  z_file_filler                           .


DATA path(30) TYPE c VALUE '/zsap/vsp//tmp/file_temp.txt'.

DATA : BEGIN OF file_struc,
        f1(2) TYPE c,
        f2(10) TYPE c,
        f3(10) TYPE c,
        filler(10),
END OF file_struc.

DATA file_data(32) TYPE c.

file_struc-f1 = 'AB'.
file_struc-f2 = '1234567890'.
file_struc-f3 = ''.

MOVE file_struc TO file_data.

OPEN DATASET path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
  TRANSFER file_struc TO path LENGTH 32.  "Speicy the total length to transfer.
  CLOSE DATASET path.
ENDIF.

WRITE file_struc.

After running this program, the file lenght is 33.

But, still when you download the file to local PC it truncates the data. So the original file is what you write using transfer, it is only when you download using System list >Save> local file it truncates the filler.

KR,

Advait

Edited by: Advait Gode on Jun 10, 2009 3:32 PM

Read only

0 Likes
2,434

I also changed the program to use GUI_DOWNLOAD after writing the file to the application server, to download the file to the presentation server. And it retains the spaces then.


DATA path(30) TYPE c VALUE '/zsap/vsp//tmp/file_temp.txt'.

DATA : BEGIN OF file_struc OCCURS 0,
        f1(2) TYPE c,
        f2(10) TYPE c,
        f3(10) TYPE c,
        filler(10),
END OF file_struc.

file_struc-f1 = 'AB'.
file_struc-f2 = '1234567890'.
file_struc-f3 = ''.


OPEN DATASET path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
  TRANSFER file_struc TO path  LENGTH 32.
  CLOSE DATASET path.
ENDIF.

CLEAR file_struc.
REFRESH file_struc.

OPEN DATASET path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
  READ DATASET path INTO file_struc.
  CLOSE DATASET path.
ENDIF.

APPEND file_struc.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename                        =  'C:\temp\file.txt'
    filetype                        = 'ASC'
  TABLES
    data_tab                        =  file_struc
 EXCEPTIONS
   FILE_WRITE_ERROR                = 1
   NO_BATCH                        = 2
   GUI_REFUSE_FILETRANSFER         = 3
   INVALID_TYPE                    = 4
   NO_AUTHORITY                    = 5
   UNKNOWN_ERROR                   = 6
   HEADER_NOT_ALLOWED              = 7
   SEPARATOR_NOT_ALLOWED           = 8
   FILESIZE_NOT_ALLOWED            = 9
   HEADER_TOO_LONG                 = 10
   DP_ERROR_CREATE                 = 11
   DP_ERROR_SEND                   = 12
   DP_ERROR_WRITE                  = 13
   UNKNOWN_DP_ERROR                = 14
   ACCESS_DENIED                   = 15
   DP_OUT_OF_MEMORY                = 16
   DISK_FULL                       = 17
   DP_TIMEOUT                      = 18
   FILE_NOT_FOUND                  = 19
   DATAPROVIDER_EXCEPTION          = 20
   CONTROL_FLUSH_ERROR             = 21
   OTHERS                          = 22
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Therefore it is working as it should -:) and it does retain the last fields if they are blank.

KR,

Advait

Read only

0 Likes
2,434

Thanks Advait, Now I see that the blanks do get retained in while writing in application server. But when I download the file directly through GUI download ( that is not first to application server , then to presentation server ), the blanks do not appear. Can you please tell what can be done for blanks to appear.

Thank you.

Read only

0 Likes
2,434

This message was moderated.

Read only

0 Likes
2,434

Hi Dagny,

You are right, it doesn't. I tweaked the data declaration a little bit and introduced a dummy field at the end of the file_struc. This dummy field will help retain the data fields including the filler.

 
DATA : BEGIN OF file_struc OCCURS 0,
        f1(2) TYPE c,
        f2(10) TYPE c,
        f3(10) TYPE c,  
        filler(10) TYPE c,       " Filler
        dummy TYPE c,       " To retain the filler , do not populate this field.
END OF file_struc.

After the above change, I ran the program ,even without writing to AS, it transferes 32 characters to the file, truncating the last dummy field.

Sometimes you need to fool the system in order to get things working -:)

Kind regards,

Advait

Read only

0 Likes
2,434

Yes Advait, now the blanks come, thanks a lot :).

Just one question. If I download the file in application server through 'CG3Y' transaction instead of through System --> List --> Save --> Local file, I do get the blanks, but after the blanks a special character ( like a rectangle ) appears .

I need these blanks to appear . Even if I apply your logic of 'Length' specification and a dummy character at the end, the blanks are getting truncated when downloaded through System --> List --> Save --> Local file.

Any work-around for this? Please do tell if any, would be grateful.

Read only

0 Likes
2,434

Hi Dagny,

Glad to know that it worked.

Apparently there is no work around for it when you save it from the list as it is standard code. The only way I could think is to put a value in the dummy field. But process only first 32 charaters when processing the file.


DATA : BEGIN OF file_struc OCCURS 0,
        f1(2) TYPE c,
        f2(10) TYPE c,
        f3(10) TYPE c,
        filler(10) TYPE c,  " Filler
        dummy(1) TYPE c VALUE '#',       " To retain the filler.
END OF file_struc.

"The file content then saves like this :

Directory: /zsap/vsp//tmp

Name: file_temp.txt

-


AB ABCDEFGHIJ #

Hope this helps.

Kind regards,

Advait

Read only

0 Likes
2,434

Ok Thank you Advait.

Read only

Former Member
0 Likes
2,434

APP_FILE = '/tmp/salesorder.log'.

DATA: MESSAGE TYPE STRING.

data: I_RETURN TYPE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE.

*i_return has 3 fields(type, number, MESSAGE)

OPEN DATASET APP_FILE FOR OUTPUT IN BINARY MODE.

IF SY-SUBRC NE 0.

WRITE / 'file can not be open'.

ELSE.

LOOP AT I_RETURN.

TRANSFER I_RETURN-TYPE TO APP_FILE.

TRANSFER I_RETURN-NUMBER TO APP_FILE.

MOVE I_RETURN-MESSAGE TO MESSAGE.

TRANSFER MESSAGE TO APP_FILE.

ENDLOOP.

CLOSE DATASET APP_FILE.

IF SY-SUBRC NE 0.

WRITE / 'file not updated'.

ELSE.

WRITE / 'file /tmp/salesorder.log is updated'.

ENDIF.

ENDIF.

Edited by: mayank jain on Jun 11, 2009 8:26 AM

Edited by: mayank jain on Jun 11, 2009 8:29 AM

Read only

Former Member
0 Likes
2,434

Hi,

Call the FM 'GUI_DOWNLOAD' and pass the parameter filetype is 'ASC'

Otherwise use OPEN DATSET, TRANSFER DATA and CLOSE DATASET statements

Regards,

Jyothi CH.

Edited by: Jyothi Chinnabathuni on Jun 11, 2009 12:23 PM