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

Convert text file on application server to binary (send mail in background)

Former Member
0 Likes
1,076

Hi,

I have a report that does the foll:

1. Foreground

u2022 ALV

u2022 Download data into a text file on desktop

u2022 Send data as email text file attachment

2. Background

u2022 Generate spool

u2022 Download data into a text file on application server

u2022 Send data as email text file attachment

The report runs correctly in foreground.

But in background, when I try to send the email, the data is not properly formatted. Further, many records are absent in the email attachment. The file on the application server is properly formatted and contains all records.

On further analysis, it was found that the problem occurs when we convert the file data from text to binary.

I cannot use the function module u2018GUI_UPLOADu2019 (which I have used in foreground)as the file is on the application server.

I tried using the function module u2018SCMS_TEXT_TO_BINARYu2019, but the problem persists.

I also tried using u2018OPEN DATASET filename FOR INPUT IN BINARY MODEu2019 and read the file data. Still the records are truncated, and formatting is incorrect.

On comparing the files from foreground and background, while debugging, it was seen that the internal table is a standard table of TLINE, with fields TDFORMAT (CHAR2), and TDLINE (CHAR132).

In foreground, the data is stored in both fields, while in background the data is either stored in TDFORMAT or in TDLINE.

Can you please help me with the file conversion from text to binary, retaining the proper formatting and the no. of records?

Regards,

Smruthi

P.S : I have searched on SDN as well as on Google but have not found any relevant solution.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
809

The data downloaded to application server is in which format ? Could you post the code for reading data from application server?

Hi,

I have a report that does the foll:

1. Foreground

u2022 ALV

u2022 Download data into a text file on desktop

u2022 Send data as email text file attachment

2. Background

u2022 Generate spool

u2022 Download data into a text file on application server

u2022 Send data as email text file attachment

The report runs correctly in foreground.

But in background, when I try to send the email, the data is not properly formatted. Further, many records are absent in the email attachment. The file on the application server is properly formatted and contains all records.

On further analysis, it was found that the problem occurs when we convert the file data from text to binary.

I cannot use the function module u2018GUI_UPLOADu2019 (which I have used in foreground)as the file is on the application server.

I tried using the function module u2018SCMS_TEXT_TO_BINARYu2019, but the problem persists.

I also tried using u2018OPEN DATASET filename FOR INPUT IN BINARY MODEu2019 and read the file data. Still the records are truncated, and formatting is incorrect.

On comparing the files from foreground and background, while debugging, it was seen that the internal table is a standard table of TLINE, with fields TDFORMAT (CHAR2), and TDLINE (CHAR132).

In foreground, the data is stored in both fields, while in background the data is either stored in TDFORMAT or in TDLINE.

Can you please help me with the file conversion from text to binary, retaining the proper formatting and the no. of records?

Regards,

Smruthi

P.S : I have searched on SDN as well as on Google but have not found any relevant solution.

4 REPLIES 4
Read only

Former Member
0 Likes
810

The data downloaded to application server is in which format ? Could you post the code for reading data from application server?

Read only

0 Likes
809

Hi Satyajit,

Thank you for going through the thread.

The data downloaded to application server is in textformat

The code for reading data from application server:

DATA : record(132) TYPE c.

* Open the dataset
    OPEN DATASET text_file FOR INPUT IN BINARY MODE.

    DO.
      READ DATASET text_file INTO record.
      IF sy-subrc <> 0.
        EXIT.
      ELSEIF sy-subrc EQ 0.
        wa_itab-tdline = record.
        APPEND wa_itab TO itab.
        CLEAR wa_itab.
      ENDIF.
    ENDDO

Regards,

Smruthi

Read only

0 Likes
809

further analysis, it was found that the problem occurs when we convert the file data from text to binary.

Still not able to get your issue......If your data is saved in application server in text mode, why you are converting it to binary?

Is there any special reason...

As you said, the file is perfect in application server and the problem is with email. How are you sending the data through email?

You must be sending the same data via email and writing it to application server. Then why reading application server is required when email can be sent using the internal table contents directly?

Read only

Former Member
0 Likes
809

Thank you for taking time out to help me, Satyajit.

The problem is solved now.

Regards,

Smruthi