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

PDF save to application server/customer master

Former Member
0 Likes
6,489

Hi,

I need help saving an SAP generated PDF to the customer master. The form is a billing letter.

I have generated a PDF using FP_JOB_OPEN, call Form FM, FP_JOB_CLOSE; passing the value getPDF.

I now have the returned PDF value of type fpformoutput-pdf, but do not know how to process this value so I can save the PDF document.

My first thought was to save the PDF to the application server and then use FM BDS_BUSINESSDOCUMENT_CREATEF to save the file to the customer master.

Most the discussions I have read deal with sending the output to the spool and then saving the file using CONVERT_ABAPSPOOLJOB_2_PDF; which to me is a bit clunky.

Am I able to use the returned PDF value to generate a PDF document on the application server? And if so how?

Or is there a better way to save the form to the customer master?

thanks

Julian

Hi,

I need help saving an SAP generated PDF to the customer master. The form is a billing letter.

I have generated a PDF using FP_JOB_OPEN, call Form FM, FP_JOB_CLOSE; passing the value getPDF.

I now have the returned PDF value of type fpformoutput-pdf, but do not know how to process this value so I can save the PDF document.

My first thought was to save the PDF to the application server and then use FM BDS_BUSINESSDOCUMENT_CREATEF to save the file to the customer master.

Most the discussions I have read deal with sending the output to the spool and then saving the file using CONVERT_ABAPSPOOLJOB_2_PDF; which to me is a bit clunky.

Am I able to use the returned PDF value to generate a PDF document on the application server? And if so how?

Or is there a better way to save the form to the customer master?

thanks

Julian

4 REPLIES 4
Read only

FredericGirod
Active Contributor
0 Likes
3,545

Hi Julian,

could you clarify your question, you would like to save a smartform / form / something into a PDF file format ? 

What did you have now ?  what's format ?  PDF ?

regards

Fred

Read only

GirieshM
Active Contributor
0 Likes
3,545

Hi Julian,

Hope the billing letter might be SAP Script / Smartform.

Please check the below coding for converting Smartform into PDF and saving it in to the Application Server.

   * This function module call is used to retrieve the name of the Function
* module generated when the SMARTFORM is activated
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = gv_fname " Form name
      IMPORTING
        fm_name            = lv_fmodule
      EXCEPTIONS
        no_form            = 1
        no_function_module = 2
        OTHERS             = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

   * Calling the SMARTFORM using the function module retrieved above
* GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
* format of the output

    lt_cparam-no_dialog = 'X'.
    lt_cparam-preview = space. " Suppressing the dialog box
    " for print preview
    lt_cparam-getotf = 'X'.

* Printer name to be used is provided in the export parameter
* OUTPUT_OPTIONS
    lt_outoptions-tddest = 'LP01'.

Note: call the function module generated for your smartform.

CALL FUNCTION smartform fm.

      CALL FUNCTION 'CONVERT_OTF_2_PDF'
      EXPORTING
        use_otf_mc_cmd         = 'X'
      IMPORTING
        bin_filesize           = bin_filesize
      TABLES
        otf                    = lt_otf_from_fm-otfdata
        doctab_archive         = doctab_archive
        lines                  = lines
      EXCEPTIONS
        err_conv_not_possible  = 1
        err_otf_mc_noendmarker = 2
        OTHERS                 = 3.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

      " Write PDF Binary Data to App Server
    OPEN DATASET lv_filename FOR OUTPUT IN BINARY MODE.
    IF sy-subrc = 0.
      LOOP AT lines INTO ls_data. "INTO wa_binary_data.
        TRANSFER ls_data TO lv_filename.
      ENDLOOP.
    ENDIF.

    CLOSE DATASET lv_filename.

It will save the PDF into the Application server and you can download it. Can you please explain what is that customer master ?

Hope it might help you. Revert back in case of any issues.

With Regards,

Giriesh M

Read only

Former Member
0 Likes
3,545

Hi,

Since posting this response I found t-code CG3Y which allowed me to download the PDF I uploaded to the application server; thus proving my file creation worked. Haven't got time just at the moment to investigate further why my progrm to download the file isn't working, but if anyone can resolve the issue I'm sure it would benefit others ( I will update it if i get time to ).


Firstly thanks to Fred and Giriesh for replying to my request for help.

To clarify the form in question is an Adobe form.

I thought I found the answer to my questions in this article Creating Attachments to Work Items or to User Decisions in Workflows by Ramakanth Reddy.

Interestingly I found this article using search engine DuckDuckGo; Google did not present this article in it's search results (at least not in the first few pages).

Based on this article  I was using the wrong data type for the table lt_tab.

lt_tab TYPE TABLE OF solix-line


CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
         EXPORTING
           buffer        = ls_pdf
     IMPORTING
       output_length = lv_len
         TABLES
           binary_tab    = lt_tab.

I can now save the data to the application server, that is good. But I wanted to verify that the data is correct so I wrote a test application to download the file from th eapplication server to my laptop. A PDF is created but it will not open and I get the message "There was an error opening this document.  The file is damaged  and could not be repaired".


Below is my code for uploading and downloading the file. If someone can point out what I am doing wrong I would be very grateful.

Once I have this resolved I can start look at how to attach the file to the customer master (XD02) attachment list.

UPLOAD

TYPES : BEGIN OF ty_tab,
            line TYPE x LENGTH 255,
          END OF ty_tab.

     DATA: lv_filedir TYPE string,
           lt_tab TYPE TABLE OF ty_tab,
           ls_tab LIKE LINE OF lt_tab,
           lv_len TYPE i,
           lv_xstring TYPE xstring,

           is_pdf TYPE fpformoutput-pdf.  "value returned from pdf creation


     CONCATENATE '/Billing Letter_' iv_kunnr '_' iv_bukrs'_' sy-uzeit '.pdf' INTO ev_filename.

     CONCATENATE lv_directory ev_filename INTO lv_filedir.

     CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
       EXPORTING
         buffer        = is_pdf
       IMPORTING
         output_length = lv_len
       TABLES
         binary_tab    = lt_tab.

     OPEN DATASET lv_filedir FOR OUTPUT IN BINARY MODE.
     LOOP AT lt_tab INTO ls_tab.
       TRANSFER ls_tab TO lv_filedir.
     ENDLOOP.

     CLOSE DATASET lv_filedir.

DOWNLOAD

TYPES : BEGIN OF ty_lines,
                 line(1024) TYPE x,
             END OF ty_lines.

DATA: gt_lines TYPE TABLE OF ty_lines,
       wa_lines LIKE LINE OF gt_lines.



PARAMETERS: p_fname TYPE string.

OPEN DATASET p_fname  FOR INPUT IN BINARY MODE.
READ DATASET p_fname INTO wa_lines-line.
APPEND wa_lines TO gt_lines.
CLOSE DATASET p_fname.

CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filename = 'C:\temp\pdf\xxx.pdf'
     filetype = 'BIN'
   TABLES
     data_tab = gt_lines.


Message was edited by: julian christian

Read only

0 Likes
3,545

Hi Julian,

Can you please try this FM by passing application and presentation path details:

   CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'

and also try "ENCODING DEFAULT" keyword with your OPEN DATASET.

With Regards,

Giriesh M