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

open dataset in binary mode-data missing in pdf file

Former Member
0 Likes
7,480

Hi,

I am downloading a pdf file to the appl server using the below code.

open dataset filename for output in binary mode.

OPEN DATASET file_name FOR OUTPUT IN BINARY MODE.
     LOOP AT lines INTO ls_lines.
       TRANSFER ls_lines TO file_name.
     ENDLOOP.
     CLOSE DATASET file_name.
     MESSAGE 'File has been Transfered' TYPE 'S'.

pdf file is downloading to the appl server.

I am reading the file using CG3Y transaction, an found that some tax values are missing.

please advice on how to fix this issue ASAP.

1 ACCEPTED SOLUTION
Read only

rosenberg_eitan
Active Contributor
0 Likes
3,556

Hi,

Try this code: note the use of bin_file parameter.


*&---------------------------------------------------------------------*

*& Report  Y_R_EITAN_TEST_30_07

REPORT  y_r_eitan_test_30_07 .



TYPE-POOLS: abap .



SELECTION-SCREEN BEGIN OF BLOCK block06 WITH FRAME .

PARAMETERS: p_tdname TYPE thead-tdname OBLIGATORY DEFAULT 'S_DEMO_1'  .



SELECTION-SCREEN SKIP .



PARAMETERS: p_file_i TYPE pathextern OBLIGATORY  .



SELECTION-SCREEN END OF BLOCK block06 .



*----------------------------------------------------------------------*

*----------------------------------------------------------------------*



START-OF-SELECTION .

  PERFORM at_start_of_selection .



*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

FORM at_start_of_selection .



  DATA: st_thead TYPE thead .



  DATA: it_lines TYPE tline_tab .



  st_thead-tdobject = 'TEXT' .

  st_thead-tdname   = p_tdname .

  st_thead-tdid     = 'ST' .

  st_thead-tdspras  = 'E'  .



  CALL FUNCTION 'READ_TEXT'

    EXPORTING

      id                      = st_thead-tdid

      language                = st_thead-tdspras

      name                    = st_thead-tdname

      object                  = st_thead-tdobject

    IMPORTING

      header                  = st_thead

    TABLES

      lines                   = it_lines

    EXCEPTIONS

      id                      = 1

      language                = 2

      name                    = 3

      not_found               = 4

      object                  = 5

      reference_check         = 6

      wrong_access_to_archive = 7

      OTHERS                  = 8.



  IF sy-subrc NE 0 .

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

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

  ENDIF.



  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 .



  APPEND LINES OF it_otfdata TO it_otfdata_m .



  DATA: bin_file TYPE xstring .



  CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

      format                = 'PDF'

    IMPORTING

      bin_file              = bin_file

    TABLES

      otf                   = it_otfdata_m

      lines                 = it_lines

    EXCEPTIONS

      err_max_linewidth     = 1

      err_format            = 2

      err_conv_not_possible = 3

      err_bad_otf           = 4

      OTHERS                = 5.



  DATA: mess TYPE string .



  OPEN DATASET p_file_i FOR OUTPUT IN BINARY MODE MESSAGE mess .

  TRANSFER bin_file TO p_file_i NO END OF LINE .

  CLOSE DATASET p_file_i .



ENDFORM.                    "at_start_of_selection

*----------------------------------------------------------------------*

Hi,

I am downloading a pdf file to the appl server using the below code.

open dataset filename for output in binary mode.

OPEN DATASET file_name FOR OUTPUT IN BINARY MODE.
     LOOP AT lines INTO ls_lines.
       TRANSFER ls_lines TO file_name.
     ENDLOOP.
     CLOSE DATASET file_name.
     MESSAGE 'File has been Transfered' TYPE 'S'.

pdf file is downloading to the appl server.

I am reading the file using CG3Y transaction, an found that some tax values are missing.

please advice on how to fix this issue ASAP.

11 REPLIES 11
Read only

raphael_almeida
Active Contributor
0 Likes
3,556

Hi Praveen

You know FM ARCHIVFILE_SERVER_TO_CLIENT and ARCHIVFILE_CLIENT_TO_SERVER ?!

You can download and upload any file with them, but you must know the directory where this files are.

For discovery this, call Tcode AL11.

Regards,

Read only

0 Likes
3,556

Hi,

thanks for the information.

I am using AL11 read the file using the T-Code CG3Y.

but when i read the file, it is having some values missing..

Read only

raphael_almeida
Active Contributor
0 Likes
3,556

Praveen,

Can you post the error here?!

Read only

0 Likes
3,556

hi,

find the below screen shot. the tax value is missing when download the pdf.

but the same program, instead of downloading to application server, it showing the tax values correctly.

Read only

0 Likes
3,556

hi Raphael,

I have 2 scenarios here.

scenario1: I am downloading the file as pdf to application server and then reading it using CG3Y transaction. In this case, the tax values are missing in the pdf file.(I am using opendataset command in binary mode)

scenario2: the pdf file that got converted is displayed in sap system . in this case the tax values are displayed correctly..

I can send you the code if needed.

Thanks,

Praveen

Read only

0 Likes
3,556

Can you post your code here?!

Read only

0 Likes
3,556

Pls find the code..

In this case, the pdf file tax values are missing out as shown above screenshot..

i also tried with legacy binary mode and binary mode code page 1100.

* Convert OTF Data to pdf data
   CALL FUNCTION 'CONVERT_OTF'
     EXPORTING
       format                = 'PDF'
     IMPORTING
       bin_filesize          = pdf_size
     TABLES
       otf                   = ls_job_info-otfdata
       lines                 = lines
     EXCEPTIONS
       err_max_linewidth     = 1
       err_format            = 2
       err_conv_not_possible = 3
       err_bad_otf           = 4
       OTHERS                = 5.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   LOOP AT lines INTO ls_lines.
     ASSIGN ls_lines TO <fs_x> CASTING.
     CONCATENATE lv_content <fs_x> INTO lv_content IN BYTE MODE.
   ENDLOOP.

*  call SCREEN 9001.

   SHIFT wa_final1-vbeln LEFT DELETING LEADING '0'.
   SHIFT wa_final1-bstkd LEFT DELETING LEADING '0'.
   SHIFT wa_final1-kunnr LEFT DELETING LEADING '0'.

   IF sy-sysid = 'DEV' AND  sy-mandt = '046'.   " Development Server or Client.

     CONCATENATE 'E:\OrdAckNotfctn\Acknowledgements\' wa_final1-erdat
        '_' wa_final1-bstkd '_' wa_final1-vbeln '_' wa_final1-kunnr '.Pdf'
        INTO file_name.

     OPEN DATASET file_name FOR OUTPUT IN BINARY MODE. "TEXT MODE ENCODING DEFAULT.
     LOOP AT lines INTO ls_lines.
       TRANSFER ls_lines TO file_name.
     ENDLOOP.
     CLOSE DATASET file_name.
     MESSAGE 'File has been Transfered' TYPE 'S'.

   ELSEIF sy-sysid = 'SBX' AND  sy-mandt = '046'. " Testing Server or Client.

     CONCATENATE 'E:\OrdAckNotfctn\Acknowledgements\' wa_final1-erdat
          '_' wa_final1-bstkd '_' wa_final1-vbeln '_' wa_final1-kunnr '.Pdf'
          INTO file_name.

     OPEN DATASET file_name FOR OUTPUT IN LEGACY BINARY MODE. "TEXT MODE ENCODING DEFAULT.
     LOOP AT lines INTO ls_lines.
       TRANSFER ls_lines TO file_name.
     ENDLOOP.
     CLOSE DATASET file_name.
     MESSAGE 'File has been Transfered' TYPE 'S'.

   ELSEIF sy-sysid = 'PRD' AND  sy-mandt = '046'. " Production Server or Client.

     CONCATENATE 'E:\OrdAckNotfctn\Acknowledgements\' wa_final1-erdat
       '_' wa_final1-bstkd '_' wa_final1-vbeln '_' wa_final1-kunnr '.Pdf'
       INTO file_name.

     OPEN DATASET file_name FOR OUTPUT IN BINARY MODE. "TEXT MODE ENCODING DEFAULT.
     LOOP AT lines INTO ls_lines.
       TRANSFER ls_lines TO file_name.
     ENDLOOP.
     CLOSE DATASET file_name.
     MESSAGE 'File has been Transfered' TYPE 'S'.
   ENDIF.

Read only

0 Likes
3,556

Praveen,

Sorry for my delay, i've been busy these days.

Analyzing your code i have one question, debugging the FM CONVERT_OTF, wich values the parameter lines get ?!


Regards.


Read only

rosenberg_eitan
Active Contributor
0 Likes
3,557

Hi,

Try this code: note the use of bin_file parameter.


*&---------------------------------------------------------------------*

*& Report  Y_R_EITAN_TEST_30_07

REPORT  y_r_eitan_test_30_07 .



TYPE-POOLS: abap .



SELECTION-SCREEN BEGIN OF BLOCK block06 WITH FRAME .

PARAMETERS: p_tdname TYPE thead-tdname OBLIGATORY DEFAULT 'S_DEMO_1'  .



SELECTION-SCREEN SKIP .



PARAMETERS: p_file_i TYPE pathextern OBLIGATORY  .



SELECTION-SCREEN END OF BLOCK block06 .



*----------------------------------------------------------------------*

*----------------------------------------------------------------------*



START-OF-SELECTION .

  PERFORM at_start_of_selection .



*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

FORM at_start_of_selection .



  DATA: st_thead TYPE thead .



  DATA: it_lines TYPE tline_tab .



  st_thead-tdobject = 'TEXT' .

  st_thead-tdname   = p_tdname .

  st_thead-tdid     = 'ST' .

  st_thead-tdspras  = 'E'  .



  CALL FUNCTION 'READ_TEXT'

    EXPORTING

      id                      = st_thead-tdid

      language                = st_thead-tdspras

      name                    = st_thead-tdname

      object                  = st_thead-tdobject

    IMPORTING

      header                  = st_thead

    TABLES

      lines                   = it_lines

    EXCEPTIONS

      id                      = 1

      language                = 2

      name                    = 3

      not_found               = 4

      object                  = 5

      reference_check         = 6

      wrong_access_to_archive = 7

      OTHERS                  = 8.



  IF sy-subrc NE 0 .

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

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

  ENDIF.



  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 .



  APPEND LINES OF it_otfdata TO it_otfdata_m .



  DATA: bin_file TYPE xstring .



  CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

      format                = 'PDF'

    IMPORTING

      bin_file              = bin_file

    TABLES

      otf                   = it_otfdata_m

      lines                 = it_lines

    EXCEPTIONS

      err_max_linewidth     = 1

      err_format            = 2

      err_conv_not_possible = 3

      err_bad_otf           = 4

      OTHERS                = 5.



  DATA: mess TYPE string .



  OPEN DATASET p_file_i FOR OUTPUT IN BINARY MODE MESSAGE mess .

  TRANSFER bin_file TO p_file_i NO END OF LINE .

  CLOSE DATASET p_file_i .



ENDFORM.                    "at_start_of_selection

*----------------------------------------------------------------------*

Read only

0 Likes
3,556

Hi Eitan,

Thanks for the reply.

I got the problem resolved.

Read only

0 Likes
3,556

Hi Praveen!


How you managed to solve your problem, please close this post as "Assumed Answered" (if you solve the problem alone) or "Answered" by selecting the correct answer among all posted here.


Please read this blog: How to close a discussion and why it shows good practices as foreclosure postings.


Thanks.