Skip to Content

New line for text file

Hi,

I am trying to send text file as an email attachment using   cl_document_bcs->add_attachment method.

My requirment is to get the file in below format..

%FDF-1.2%âãÏÓ

1 0 obj

<</FDF

<</Fields[

<</T(COMPANY_ADDRESS)/V(ABC PVT) Ltd PO Box 7058 Greenstone 1616 ZA ZA)>>

/ID[]/UF()>>/Type/Catalog>>

endobj

trailer

<</Root 1 0 R>>

%%EOF


I have hard coded most of the stuff like below..

DATA:

DATA:it_fdf  TYPE bcsy_text,

                 wa_fdf TYPE soli.


CONSTANT:

d14(8) VALUE '%FDF-1.2',

                      d15(6) VALUE '%âãÏÓ',

                      d16(7) VALUE '1 0 obj',

                      d17(20) VALUE '/FDF << /Fields [',

                      d18(6)  VALUE '[ << /T ('.



wa_fdf = d14.

  CONDENSE wa_fdf.

  APPEND wa_fdf TO it_fdf.

  wa_fdf = d15.

  CONDENSE wa_fdf.

  APPEND wa_fdf TO it_fdf.

  wa_fdf = d16.

  CONDENSE wa_fdf.

  APPEND wa_fdf TO it_fdf.

  wa_fdf = d17.

  CONDENSE wa_fdf.

  APPEND wa_fdf TO it_fdf.


  ls_atatchments-objtp = 'txt'.

             ls_atatchments-subject = pv_subject.

             ls_atatchments-cont_text = it_fdf.

             APPEND ls_atatchments TO attachment.

CALL METHOD lo_document->add_attachment

                       EXPORTING

                         i_attachment_type    = ls_atatchments-objtp

                         i_attachment_subject = pv_title

                         i_att_content_text   = ls_atatchments-cont_text.

but output text file is appearing as per the attachment..

but I want to write text file like

%FDF-1.2%âãÏÓ- in first line

1 0 obj- in second line (Currently second line is appearing in first line after 250 char as line for SOLI is 250 char...)


Could you any one tell me how I can achieve this in order to get the line in second line not after the 250 char..?


I really appreciate your help on this.

Thanks,

Sara.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jan 06, 2015 at 10:17 PM

    Hi Sara,

    Have you tried concatenating the carriage returns to your strings for each line you expect? 

    Class CL_ABAP_CHAR_UTILITIES has a public static attribute for a carriage return line feed.  "CR_LF"

    You could try....

    wa_fdf = d14 && CL_ABAP_CHAR_UTILITIES=>CR_LF .

    CONDENSE wa_fdf.

    APPEND wa_fdf TO it_fdf.

    Or.....

    CONCATENATE d14 CL_ABAP_CHAR_UTILITIES=>CR_LF INTO wa_fdf .

    CONDENSE wa_fdf.

    APPEND wa_fdf TO it_fdf.

    Cheers,

    Katan

    Add comment
    10|10000 characters needed characters exceeded

    • Thanks Katan..It resolved my Issue but I am facing the Issue like..when I send file type .TXT in add_attachment the format is coming correctly..But when I changed the file type to FDF in add_attachment it's adding one space before and after the each character.. and not recognizing the new line I guess it's taking that as unicode format..

      Do you have any idea how we can avoid spaces before and after each char..and recognize the new line in FDF file.

      I am using CONDENSE space before populating the output data.

      My data is fine while sending it to add_attachment.But in the output it's adding space before and after each charter.

      I appreciate your help on this.

      Thanks,

      Sara.

  • Jan 10, 2015 at 05:48 PM

    Hi,

    It seems that you try to generate PDF .

    You can use the PRINT_TEXT and get the OTFDATA that can be converted to PDF . 

    regards. 

    FORM mail_1_prep_4

      CHANGING

        ob_document_bcs TYPE REF TO cl_document_bcs .

      DATA: st_thead TYPE thead .

      DATA: it_lines TYPE tline_tab .

      st_thead-tdobject = 'TEXT' .

      st_thead-tdname   = 'AAAA .

      st_thead-tdid     = 'ST' .

      st_thead-tdspras  = 'E'  .

       CALL FUNCTION 'INIT_TEXT'

        EXPORTING

          id       = st_thead-tdid

          language = st_thead-tdspras

          name     = st_thead-tdname

          object   = st_thead-tdobject

        TABLES

          lines    = it_lines

        EXCEPTIONS

          id       = 1

          language = 2

          name     = 3

          object   = 4

          OTHERS   = 5.

    DATA: st_lines LIKE LINE OF it_lines .

      DO 1000 TIMES .

        st_lines-tdformat = '*' .

        st_lines-tdline = 'This is a test +++++++++++++++++++++++++++++++++++++++++++++++' .

        APPEND st_lines TO it_lines .

      ENDDO .

      DATA: it_otfdata TYPE otf_t_itcoo .

      DATA: st_options TYPE itcpo.

      st_options-tdgetotf = abap_true .

      CALL FUNCTION 'PRINT_TEXT'

        EXPORTING

          dialog                   = abap_false

          header                   = st_thead

          OPTIONS                  = st_options

        TABLES

          lines                    = it_lines

          otfdata                  = it_otfdata

        EXCEPTIONS

          canceled                 = 1

          device                   = 2

          form                     = 3

          OPTIONS                  = 4

          unclosed                 = 5

          unknown                  = 6

          format                   = 7

          textformat               = 8

          communication            = 9

          bad_pageformat_for_print = 10

          OTHERS                   = 11.

      IF sy-subrc <> 0.

        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

      ENDIF.

      DATA: it_otfdata_m TYPE otf_t_itcoo .

    * "Merge pdf output demo"

      APPEND LINES OF it_otfdata TO it_otfdata_m .

      DATA: bin_file TYPE xstring .

      DATA: it_lines_dummy TYPE tline_tab .

      DATA: bin_filesize TYPE i .

      CALL FUNCTION 'CONVERT_OTF'

        EXPORTING

          format                = 'PDF'

        IMPORTING

          bin_file              = bin_file

          bin_filesize          = bin_filesize

        TABLES

          otf                   = it_otfdata_m

          lines                 = it_lines_dummy

        EXCEPTIONS

          err_max_linewidth     = 1

          err_format            = 2

          err_conv_not_possible = 3

          err_bad_otf           = 4

          OTHERS                = 5.

      DATA: it_solix TYPE solix_tab .

      CALL METHOD cl_bcs_convert=>xstring_to_solix

        EXPORTING

          iv_xstring = bin_file

        RECEIVING

          et_solix   = it_solix.

      DATA: attachment_subject TYPE so_obj_des .

      MESSAGE s000(oo) WITH 'attachment PDF hex' space INTO attachment_subject .

      TRY.

          CALL METHOD ob_document_bcs->add_attachment

            EXPORTING

              i_attachment_type    = 'pdf'

              i_attachment_subject = attachment_subject

              i_att_content_hex    = it_solix.

        CATCH cx_document_bcs .

      ENDTRY.

    ENDFORM .                    "mail_1_prep_4

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      Are you attempting to generate manually adobe interactive form with input fields ?

      http://wiki.scn.sap.com/wiki/display/ABAP/SAP+Interactive+Forms+by+Adobe

      Also try:

      1 .

      ls_atatchments-objtp = 'pdf'.

      CALL METHOD lo_document->add_attachment

                             EXPORTING

                               i_attachment_type    = ls_atatchments-objtp

                               i_attachment_subject = pv_title

                               i_att_content_text   = ls_atatchments-cont_text .

      2.

      Try to concatenate every thing into a big xString/String

      use CL_ABAP_CHAR_UTILITIES=>CR_LF  as seperator .

      and then:

      cl_bcs_convert=>xstring_to_solix or cl_bcs_convert=>string_to_soli

                           

      I did not have the chance to generate adobe interactive even using "Adobe LiveCycle Designer"  .                 

      Regards.

  • Jan 11, 2015 at 10:07 AM

    Hi,

    I can see binary data in CSF_Univ. Of Bradford_SO#310205490.txt

                            

    Have you consider using external tools to generate your form .

    If I had to do this task without using "Adobe LiveCycle Designer"

    I would probably will use java with ITEXT library .

    - We can generate a text file from SAp

    - call java as external command to generate the PDF interactive form .

    - Read the file created as binary attachment.

    I wrote about generating Excel using Java here :

    Creating Excel the Java way

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Sara,

      the system codepage is unicode with 2 bytes per char. You probably want to convert the text to unicode UTF-8 using

          cl_abap_conv_out_ce=>create( encoding = 'UTF-8' )->convert(

             EXPORTING data = iv_string

             IMPORTING buffer = rv_xstring ).

      That will give you 1 byte for most chars, some characters will need more.

      A better solution would be to

      - use XSTRING instead or C for your binary header and

      - convert the rest (normal text data) to UTF-8.

      Look at Otto Frost's code for examples.

      hope this helps,

      JNN