cancel
Showing results for 
Search instead for 
Did you mean: 

Save PDF File Without Display

Former Member
0 Kudos

Hi Folks,

I have a scenario where i need to save a PDF file on desktop without opening it. I've implemented the following approach and code:

1. Created a UI Element fileDownload and associated it with PDFSource variable of type XSTRING in context

2. Called the following method in init method of view



METHOD manual_save .

* Table in XML Format
  DATA : ixml TYPE string.

* Table Data in Hexadecimal Format
  DATA : lv_xstring TYPE xstring.

* Function Module Calling
  DATA : w_fmname TYPE rs38l_fnam,     "FM Name
         fp_outputparams   TYPE sfpoutputparams. "FM Output Parameters

* Form Parameters
  DATA :   fpdocparams TYPE sfpdocparams ,   "Form Parameters
           fpformoutput TYPE fpformoutput .  "Form Output Data

* Get Context Refrence and Table Data
  DATA lo_nd_skutab TYPE REF TO if_wd_context_node.
  DATA lo_nd_skudata TYPE REF TO if_wd_context_node.
  DATA lo_el_skudata TYPE REF TO if_wd_context_element.
  DATA ls_skudata TYPE wd_this->element_skudata.
* navigate from <CONTEXT> to <SKUTAB> via lead selection
  lo_nd_skutab = wd_context->get_child_node( name = wd_this->wdctx_skutab ).

* navigate from <SKUTAB> to <SKUDATA> via lead selection
  lo_nd_skudata = lo_nd_skutab->get_child_node( name = wd_this->wdctx_skudata ).

* @TODO handle not set lead selection
  IF lo_nd_skudata IS INITIAL.
  ENDIF.

* get element via lead selection
  lo_el_skudata = lo_nd_skudata->get_element(  ).

* @TODO handle not set lead selection
  IF lo_el_skudata IS INITIAL.
  ENDIF.

* get all declared attributes
  lo_el_skudata->get_static_attributes(
    IMPORTING
      static_attributes = ls_skudata ).

* Convert Table Data to XML Format (type String)
  CALL METHOD lo_nd_skudata->to_xml
    RECEIVING
      xml = ixml.

* Convert String to Xstring Format

*CALL FUNCTION 'CRM_IC_XML_STRING2XSTRING'
*  EXPORTING
*    instring         = IXML
* IMPORTING
*   OUTXSTRING       = LV_XSTRING
  .

  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = ixml
*   MIMETYPE       = ' '
*   ENCODING       =
    IMPORTING
      buffer         = lv_xstring
 EXCEPTIONS
   failed         = 1
   OTHERS         = 2
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


*  Set Output Parameters
  fp_outputparams-nodialog = 'X'.
  fp_outputparams-getpdf = 'X'.
  fp_outputparams-connection = 'ADS'.


*  Job Open
  CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
      ie_outputparams = fp_outputparams
    EXCEPTIONS
      cancel          = 1
      usage_error     = 2
      system_error    = 3
      internal_error  = 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.

*&-  Identify FM for PDF Form
  CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
    EXPORTING
      i_name           = 'ZTEST_SKU_PDF_FORM'
    IMPORTING
      e_funcname       = w_fmname
*      e_interface_type =
      .

* set form parametsrs
  fpdocparams-langu = 'E'.
  fpdocparams-country = 'US'.
*fpdocparams-FILLABLE = 'X'.

* Generate form
  CALL FUNCTION w_fmname      "'/1BCDWB/SM00000021'
    EXPORTING
     /1bcdwb/docparams        = fpdocparams
      /1bcdwb/docxml           = lv_xstring
   IMPORTING
     /1bcdwb/formoutput       = fpformoutput
   EXCEPTIONS
     usage_error              = 1
     system_error             = 2
     internal_error           = 3
     OTHERS                   = 4
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Job Close
  CALL FUNCTION 'FP_JOB_CLOSE'
    EXCEPTIONS
      usage_error    = 1
      system_error   = 2
      internal_error = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Bind Data to PDF source
  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context TYPE wd_this->element_context.
  DATA lv_pdf LIKE ls_context-pdf.
* get element via lead selection
  lo_el_context = wd_context->get_element(  ).

  lv_pdf = fpformoutput-pdf.

  CALL METHOD lo_el_context->set_attribute
    EXPORTING
      value = lv_pdf
      name  = 'PDF'.


ENDMETHOD.

To explain in simple terms, i've done the following:

1. Stored the context table data in a XML format in a string variable

2. Converted the string variable to xstring format using fm 'SCMS_STRING_TO_XSTRING'

3. Job Open

4. Identify the Actual FM Name

5. Genarate Form

6. Job Close

7. Bind data (fpformoutput-pdf) to the PDF Source variable in context

Issue is, when i run application and download, i am only able to get a PDf with no data in it.

Interestingly, in debug mode, i am able to see some data.

Points to add: When i display in a PDF UIElement the output comes in two pages, and in debug mode when i see the variable FPFORMOUTPUT-PAGES, it has a value of 1.

May be am following the wrong approach or missing someting in code.

Any inputs, appreciated.

Thanks,

Santosh Verma,

Deloitte.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I find the problem, why your pdf do not get the data. Because when you get the ixml from to_XML method, there will be a redundant pair of tabs, <context>...</context> in the string. It is the why the pdf can not parse the string, because these tabs break the mapping relationship in pdf. Eliminate them and try again.

Former Member
0 Kudos

Hi Yichao,

Tried that option but no results. The PDF is appearing but with no data. However, in debug mode am able to see data.

Thanks,

SV.

Former Member
0 Kudos

Hi Yichao,

News is that i was able to resolve the issue. I'll explain it below:

1. <context></context> has to be removed from the XML string. Great caught and i appreciate you for that. Full points awarded!! This point gave a direction to dig further on issue.

2. When we convert a context node to XML, the line items will appear <item></item> while in PDF they appear as DATA. So i replaced the <item></item> occurance with <DATA></DATA. occurance.

3. Compare your tabs with the Data connection in PDF. They all should match.

It works...

Am closing the thread now.

I hope, this helps for issue you are facing.

cheers,

Verma.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi SV,

Below is code that i am writing for preparing the ZSTRING.

DATA : ixml TYPE string.

  • Table Data in Hexadecimal Format

DATA : lv_xstring TYPE xstring.

CALL METHOD lo_nd_main_node->to_xml

RECEIVING

xml = ixml.

ixml = ixml+33.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = ixml

  • MIMETYPE = ' '

  • ENCODING =

IMPORTING

buffer = lv_xstring

EXCEPTIONS

failed = 1

OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

*Convert XSTRING into internal table

DATA: gt_formdata TYPE STANDARD TABLE OF lxe_xtab,

gwa_formdata TYPE lxe_xtab.

CALL FUNCTION 'LXE_COMMON_XSTRING_TO_TABLE'

EXPORTING

in_xstring = lv_xstring

  • IMPORTING

  • PSTATUS =

TABLES

ex_tab = gt_formdata

.

1. I have around 20 fields on my form which i need to capture in this XSTRING.

2. This method is capturing only 10 fields.

3. I am not getting

Inputs would be highly appreciated!!!

Thanks,

Ashish

Former Member
0 Kudos

Hi Ashish,

Had few questions:

1. ixml = ixml+33

This statement will work this way: ixml after execution if this will have first 33 characters. Any reason for this statement/code?

2. If you have an adobe display requirement, why are you converting it to an internatal table for a xstring variable. the XSTRING variable will contain all data you require and it's a single variable which communicates with PDF.

3. the <DATA>/<DATA> or <item></item> was an observation i had in my form and XML variable value. So just check if the names in Data Connection in form and the names in your xml string variable match. Even their hiererchy order should match. Just workaround, and it will be resolved.

Also, this solution/code works for the file download UI ELement. It cannot open a file directly but will provide a Windows SAVE pop up option. To open up directly, i think there are methods available but i didn't gota a chance to look on that.

I hope this resolves.

Cheers,

SV

Former Member
0 Kudos

Hi Santosh,

I am using the same code for saving the abobe form. My form has XML Based Interface. Pls let me know whether this works for form with XML based interface.

When I am using below code, I am not getting all the fields.

CALL METHOD lo_nd_skudata->to_xml

RECEIVING

xml = ixml.

Do you have any idea why I am not getting all the fields here? Is it becuse of ixml which is of type string?

Appreciate your early response.

Former Member
0 Kudos

Hi Vibha,

My apologies for a late reply.

The code works for XML based interface as i had the requirement in Web Dynpro and Webdynpro based form are XML based. I can assure you as i have used the same code again for a requirement here i had 50 fields and deep structured context to pass to adobe. It worked. I've used the UIElement FileDownload and working as expected.

The method you mentioned should bring up all fields and has to be of type string. Am not sure why..but is it possible for you to paste the full code? also check with the node cardinalities.

Cheers,

SV,

Deloitte, India.

Former Member
0 Kudos

Hi Verma,

I am also facing the same kind of prolem, where I am not getting all the fields converted into XML.

I have 20 fields in context node whereas I am getting only 10 fields converted into XML String.

Additionaly, I am getting the string conaining different text in

One more point, when i am converting this string into XSTRING using FM SCMS_STRING_TO_XSTRING its returing me its Hexadecimal value which is of no use. Please suggest how to handle this situation.

Regds,

Ashish

Former Member
0 Kudos

Hi Ashish,

To replace context fields in XML String Variable, use this code:


data: ixml type string.
  CALL METHOD lo_nd_skutab->to_xml
    RECEIVING
      xml = ixml.


constants: lc_1(9) type c value '<context>',
           lc_2(10) type c value '</context>',
           lc_3(6) type c value '<item>',
           lc_4(7) type c value '</item>'.

 replace first occurence of lc_1 in ixml with space.
 shift ixml left deleting leading space.

 replace first occurence of lc_2 in ixml with space.
 shift ixml right deleting trailing space.

 replace all occurences of '<item>' in ixml with '<DATA>'.
 replace all occurences of '</item>' in ixml with '</DATA>'.

For other issue, am not sure for the reason but for now is it possible for you to provide with your code?

Also, i'll be working on a requirement today which has 25+ context fields. So let's see if am able to work on it or land up in any issue..

Cheers,

SV

Former Member
0 Kudos

Following your code, I encounter the same problem. I think is the process which turns string to Xstring cause the problem? Or may be the xml in xstring doesn't map the xml schema? Waiting for experts...

I hate the way passing data with xml in a xstring.