cancel
Showing results for 
Search instead for 
Did you mean: 

Call smartform in web dynpro abap

Former Member
0 Kudos

hi guys,

I am tring to create PDF from smartform but am getting sy-subrc = 1 error after call function LV_FNAM.

I am attaching the code below. Am not using InteractiveForm UI Elemnt .

data: lv_fnam type rs38l_fnam,
      ls_ssfctrlop type ssfctrlop,
      ls_ssfcompop type ssfcompop,
      ls_book type ppftbook,
      ls_job_output_info type ssfcrescl,
      ls_job_output_options type ssfcresop,
      lv_bytecount type i,
      lt_lines type table of tline,
      ls_line type tline,
      lv_string type string,
      lv_buffer type xstring,
      l_xline type xstring,
      l_pdfstring type xstring,
      it_add_rel type table of zprint_add_rel.
*      p_pdf type xstring.
data : wa_board type mara-matnr,
       plant type marc-werks.

wa_board =  'SYPJ764'.
plant = '2001'.

call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'ZSSF_ADD_REL'
importing
fm_name = lv_fnam.

ls_ssfctrlop-no_dialog = 'X'.
ls_ssfctrlop-getotf  = 'X'.
ls_ssfctrlop-preview = 'X'.

ls_ssfcompop-tdnoprev = 'X'.
ls_ssfcompop-tdtitle = 'X'.
ls_ssfcompop-tdnewid = 'X'.


call function lv_fnam
exporting
control_parameters = ls_ssfctrlop
output_options = ls_ssfcompop
*is_book = ls_book
board = wa_board " 'SYPJ764'
plant = plant " '2001'
importing
job_output_info = ls_job_output_info
job_output_options = ls_job_output_options
tables
it_add_rel_i = it_add_rel
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
other = 5.
if sy-subrc <> 0.
endif.
*convert to pdf
call function 'CONVERT_OTF'
exporting
format = 'PDF'
importing
bin_filesize = lv_bytecount
tables
otf = ls_job_output_info-otfdata
lines = lt_lines
exceptions
err_conv_not_possible = 1
err_bad_otf = 2.

loop at lt_lines into ls_line.
lv_string = ls_line.
export mydata = lv_string to data buffer lv_buffer.
import mydata to l_xline from data buffer lv_buffer in char-to-hex mode.

concatenate l_pdfstring l_xline into l_pdfstring in byte mode.
endloop.

p_pdf = l_pdfstring.

Please help me out with this error.

Regards,

Santosh

Accepted Solutions (0)

Answers (2)

Answers (2)

KiranJ
Active Participant
0 Kudos

Hai ,

Try with this code ,,


****
  DATA : table1 TYPE wdr_context_element_set,
         row TYPE REF TO if_wd_context_element.
data : wa_nast type nast.

***** get data.
  DATA lo_nd_invoice_item TYPE REF TO if_wd_context_node.
  DATA lo_el_invoice_item TYPE REF TO if_wd_context_element.
  DATA ls_invoice_item TYPE wd_this->element_invoice_item.
  DATA lt_invoice_item TYPE wd_this->elements_invoice_item.

* navigate from <CONTEXT> to <INVOICE_ITEM> via lead selection
  lo_nd_invoice_item = wd_context->get_child_node( name = wd_this->wdctx_invoice_item ).

* get element via lead selection
  lo_el_invoice_item = lo_nd_invoice_item->get_element( ).

CALL METHOD lo_nd_invoice_item->get_selected_elements
      RECEIVING
        set = table1.
    LOOP AT table1 INTO row.
      CALL METHOD row->get_static_attributes
        IMPORTING
          static_attributes = ls_invoice_item.
      wa_nast-OBJKY = ls_invoice_item-invoice.
    endloop.
**** window
DATA lo_window_manager TYPE REF TO if_wd_window_manager.
DATA lo_api_component  TYPE REF TO if_wd_component.
DATA lo_window         TYPE REF TO if_wd_window.

lo_api_component  = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
lo_window         = lo_window_manager->create_window(
                   window_name            = 'TEST_REPORT_FORMS'
                   title                  = 'Invoice'
*                  close_in_any_case      = abap_true
                   message_display_mode   = if_wd_window=>co_msg_display_mode_selected
*                  close_button           = abap_true
                   button_kind            = if_wd_window=>co_buttons_ok
                   message_type           = if_wd_window=>co_msg_type_none
                   default_button         = if_wd_window=>co_button_ok
                   ).

Edited by: Neil Gardiner on Nov 3, 2010 4:55 PM

former_member186750
Contributor
0 Kudos


*.................GET SMARTFORM FUNCTION MODULE NAME.................*
  DATA: fun_mod TYPE rs38l_fnam.
  DATA : l_x(1) VALUE 'X'.
  DATA: lv_text TYPE char3,
  lv_syucomm TYPE char1,
  ls_pdf TYPE xstring,
  lv_fm_name TYPE rs38l_fnam,
  lv_control_parameters TYPE ssfctrlop,
  lv_output_options TYPE ssfcompop,
  lv_ssf_output TYPE ssfcrescl,
  lt_otfdata TYPE TABLE OF itcoo.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'Zkk_INV'
      variant            = ' '
      direct_call        = ' '
    IMPORTING
      fm_name            = fun_mod
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

* Set relevant control parameters
  lv_control_parameters-getotf = l_x. "OTF output
  lv_control_parameters-no_dialog = l_x. "No print dialog
  lv_control_parameters-preview = space. "No preview
* Set relevant output options
  lv_output_options-tdnewid = l_x. "Print parameters,
  lv_output_options-tddelete = space. "Print parameters,

**...........................CALL SMARTFORM............................*
  CALL FUNCTION fun_mod
   EXPORTING
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
     control_parameters         = lv_control_parameters
*   MAIL_APPL_OBJ              =
*   MAIL_RECIPIENT             =
*   MAIL_SENDER                =
     output_options             = lv_output_options
*   USER_SETTINGS              = 'X'
    WA_NAST                    = wa_nast
   IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
     job_output_info            = lv_ssf_output
*   JOB_OUTPUT_OPTIONS         =

   EXCEPTIONS
     formatting_error           = 1
     internal_error             = 2
     send_error                 = 3
     user_canceled              = 4
     OTHERS                     = 5 .

  REFRESH lt_otfdata.
  lt_otfdata[] = lv_ssf_output-otfdata[].
  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
    EXPORTING
      i_otf                    = lt_otfdata
    EXCEPTIONS
      convert_otf_to_pdf_error = 1
      cntl_error               = 2
      OTHERS                   = 3.

  DATA: l_dummy TYPE STANDARD TABLE OF tline,
  pdf_data TYPE xstring,
  pdf_size TYPE i.
  CLEAR: pdf_data, pdf_size.

* convert otf to pdf
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = pdf_size
      bin_file              = pdf_data
    TABLES
      otf                   = lt_otfdata[]
      lines                 = l_dummy
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      OTHERS                = 4.

  DATA lo_nd_pdf TYPE REF TO if_wd_context_node.

  DATA lo_el_pdf TYPE REF TO if_wd_context_element.
  DATA lv_source TYPE wd_this->element_pdf-source.

* navigate from <CONTEXT> to <PDF> via lead selection
  lo_nd_pdf = wd_context->get_child_node( name = wd_this->wdctx_pdf ).

* get element via lead selection
  lo_el_pdf = lo_nd_pdf->get_element( ).

CALL METHOD lo_el_pdf->set_attribute
  EXPORTING
    value  = pdf_data
    name   = `SOURCE`
    .
lo_window->open( ).
Former Member
0 Kudos

hi,

This code is still not working... Its giving me the same eroor .

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

This doesn't actually seem to be a web dynpro abap related question. If your problem is just with the calling of the smart forms function modules for processing, then how does this have anything to do with Web Dynpro?

Former Member
0 Kudos

My question is just not calling a function module... I have problem in web dynpro.Because when the same code I run in a Abap Editor or in Report Transaction then its working very fine. It is only showing error or SY-SUBRC = 1 in Web Dynpro application.

Regards,

Santosh

Edited by: Neil Gardiner on Nov 3, 2010 3:19 PM

Edited by: Santosh Alle on Nov 3, 2010 6:23 AM

Former Member
0 Kudos

Hi Santosh,

The similar requirement I've performed in another way.

As usual, I've written the similar code to generate a smartform but inside a Function Module. But instead of displaying it immediately, I converted it to XSTRING data with the format being 'PDF'. I called this Function Module from my Webdynpro ABAP application.

In the layout, I've used the INTERACTIVEFORM UI Element which accepts the XSTRING Data in the form of PDF.

Regards,

-Syed.

Edited by: wahid hussain syed on Nov 3, 2010 6:48 AM

Former Member
0 Kudos

Hi Syed,

Can you please elaborate how u have done this..

regards,

Santosh

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You are getting a formatting error, which tells me that you might not have a default printer selected in your user profile. When you run smartforms generation from the SAPGUI, it can produce a printer dialog to ask you what printer type to use for formatting (still needed even when just converting to PDF). From Web Dynpro (or any background processing for that matter), there can be no dialog to query you for the printer id. Therefore you must have a default printer selected in your user profile and can't be a frontend printer type. Otherwise you need to fill in a printer value and pass it into the printer parameters importing parameters of the Smart Forms function modules.

Former Member
0 Kudos

Hi Santhosh,

Please find the below code:

FUNCTION ZP3088_NEW_JOINEE_ACT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(PERNR) TYPE  PERSNO
*"  EXPORTING
*"     REFERENCE(L_DISPLAY_PDF) TYPE  NUM1
*"     REFERENCE(L_DATA) TYPE  XSTRING
*"  EXCEPTIONS
*"      TRAINEE_PERNR
*"----------------------------------------------------------------------

* Tables declaration
  TABLES: NAST,PA0041.

*   Type pools declaration
  TYPE-POOLS: SZADR.

*   Internal table declaration
  DATA: L_PDF_LEN TYPE I,
        IT_PDF_LINES TYPE TABLE OF TLINE,
        JOB_OUTPUT_INFO TYPE  SSFCRESCL.

*   Variables declaration

  DATA: G_RETCODE LIKE SY-SUBRC,
        G_FMNAME TYPE RS38L_FNAM.

  DATA: L_HIRE_DATE TYPE DATS,
        L_INCLUDE_DATE TYPE DATS,
        L_WEEK_DAYS TYPE P,
        IT_P0041 LIKE PA0041.
  DATA: DAR TYPE PA0041-DAR01,
        DAT TYPE PA0041-DAT01.

  DATA: L_DEVICE(30) TYPE C,
        LA_CTRL_FORM TYPE SSFCTRLOP,
        LA_OUTPUT_OPT TYPE SSFCOMPOP.

  data: l_persg type PA0001-persg.  

***************************************************************************************
* Start of Actual Code
***************************************************************************************
  SELECT SINGLE persg
    from PA0001
    INTO l_persg
   where pernr eq pernr
     and endda eq '99991231'.

    if l_persg eq 'T' or
       l_persg eq 'W' or
       l_persg eq 'X'.
      raise trainee_pernr.
    endif.

  L_DISPLAY_PDF = 0.
  SELECT SINGLE * FROM PA0041 INTO IT_P0041
         WHERE PERNR EQ PERNR.
  IF SY-SUBRC = 0.
    DO 12 TIMES VARYING DAR FROM IT_P0041-DAR01
                              NEXT IT_P0041-DAR02
                  VARYING DAT FROM IT_P0041-DAT01
                              NEXT IT_P0041-DAT02.
      CASE DAR .
*        WHEN '09'.          "Hiring Date
        WHEN '51'.          "Hiring Date
          L_HIRE_DATE = DAT.
          EXIT.
        WHEN ''.
          EXIT.
      ENDCASE.
    ENDDO.
  ENDIF.

*To get the no. of weekdays between the hire date and current date excluding sat and sun
  IF NOT L_HIRE_DATE IS INITIAL.
    WHILE L_HIRE_DATE LE SY-DATUM.
      CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
        EXPORTING
          DATE_IN  = L_HIRE_DATE
        IMPORTING
          DATE_OUT = L_INCLUDE_DATE.

      DO 5 TIMES.
        " Making sure that it starts from the from date till to_date calculate before
        IF L_INCLUDE_DATE GE L_HIRE_DATE AND L_INCLUDE_DATE LE SY-DATUM.
          L_WEEK_DAYS = L_WEEK_DAYS + 1.
        ENDIF.
        L_INCLUDE_DATE = L_INCLUDE_DATE + 1.
      ENDDO.
      L_HIRE_DATE = L_INCLUDE_DATE + 2.
    ENDWHILE.

IF L_WEEK_DAYS LE 30.
      L_DISPLAY_PDF = 1.         "Display the PDF document
    ELSE.
      L_DISPLAY_PDF = 0.         "Do Not Display the PDF document
    ENDIF.
  ENDIF.
  IF L_DISPLAY_PDF = 1.
* Clear local variables

    CLEAR:   L_DEVICE,
             LA_CTRL_FORM,
             LA_OUTPUT_OPT.

** Spool Parameters
    LA_OUTPUT_OPT-TDIMMED = 'X'.
    LA_OUTPUT_OPT-TDDELETE = 'X'.
    LA_OUTPUT_OPT-TDLIFETIME = 'X'.
    LA_OUTPUT_OPT-TDDEST = 'LOCL'.
****************************************************************************
* Get Smartform function module name
****************************************************************************

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        FORMNAME           = 'ZP3088_NEW_JOINEE_ACT_PDF'
      IMPORTING
        FM_NAME            = G_FMNAME
      EXCEPTIONS
        NO_FORM            = 1
        NO_FUNCTION_MODULE = 2
        OTHERS             = 3.
    IF SY-SUBRC <> 0.
      G_RETCODE = SY-SUBRC.
      SYST-MSGTY = 'E'.

    ELSE.
****************************************************************************
* Parameters passes to get the output in PDF format
****************************************************************************
      LA_CTRL_FORM-NO_DIALOG = 'X'.
      LA_CTRL_FORM-PREVIEW = SPACE.
      LA_CTRL_FORM-GETOTF = 'X'.
      LA_CTRL_FORM-LANGU = NAST-SPRAS.
      LA_CTRL_FORM-DEVICE = 'PRINTER'.

Edited by: wahid hussain syed on Nov 4, 2010 3:41 AM

Edited by: wahid hussain syed on Nov 4, 2010 3:41 AM

Edited by: Neil Gardiner on Nov 4, 2010 2:04 PM

Former Member
0 Kudos

Hi Santhosh,

I've tried all the possible ways of displaying the code in the most cleanest ways. But it is displaying the code in the normal way. Please copy the code and split it at every . That will make the way easier to get the actual code.

Please let me know if you don't understand the code.

Regards,

-Syed.

former_member186750
Contributor
0 Kudos

* Call Smartform function module to display the PDF
      CALL FUNCTION G_FMNAME
        EXPORTING
          CONTROL_PARAMETERS = LA_CTRL_FORM
          OUTPUT_OPTIONS     = LA_OUTPUT_OPT
        IMPORTING
          JOB_OUTPUT_INFO    = JOB_OUTPUT_INFO
        EXCEPTIONS
          FORMATTING_ERROR   = 1
          INTERNAL_ERROR     = 2
          SEND_ERROR         = 3
          USER_CANCELED      = 4
          OTHERS             = 5.
      IF SY-SUBRC <> 0.
        G_RETCODE = SY-SUBRC.
        SYST-MSGTY = 'E'.
      ENDIF.

****************************************************************************
* For getting the PDF preview
****************************************************************************
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          FORMAT                = 'PDF'
        IMPORTING
          BIN_FILESIZE          = L_PDF_LEN
          BIN_FILE              = L_DATA       " binary file
        TABLES
          OTF                   = JOB_OUTPUT_INFO-OTFDATA
          LINES                 = IT_PDF_LINES
        EXCEPTIONS
          ERR_MAX_LINEWIDTH     = 1
          ERR_FORMAT            = 2
          ERR_CONV_NOT_POSSIBLE = 3
          ERR_BAD_OTF           = 4
          OTHERS                = 5.

      IF SY-SUBRC = 0.
* Export the PDF data to shared memory ID .
        FREE MEMORY ID SY-UNAME.
        EXPORT P_XSTRING = L_DATA TO SHARED MEMORY INDX(XY) ID SY-UNAME.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFUNCTION.

Edited by: Neil Gardiner on Nov 4, 2010 2:07 PM

former_member186750
Contributor
0 Kudos

This is my Function module where the smartform is built and L_DATA which is XSTRING data type is exported.

Under the WDDOINIT of WDA, I've just called this FM using the below procedure:


METHOD wddoinit .
  DATA: lv_pernr TYPE persno,
        lv_disp  TYPE num1.

  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA lv_uname   TYPE bapiusr01-uname.
  DATA l_pernr    TYPE bapiusr01-employeeno.
  DATA l_return   TYPE bapiret2.
  DATA v_pernr    TYPE persno.
  DATA lv_data    TYPE xstring.
  DATA lo_nd_data TYPE REF TO if_wd_context_node.
  DATA lo_el_data TYPE REF TO if_wd_context_element.

  lv_uname = sy-uname.
  TRANSLATE lv_uname to UPPER CASE.
  CALL FUNCTION 'BAPI_USR01DOHR_GETEMPLOYEE'
    EXPORTING
      id             = lv_uname
      begindate      = sy-datum
      enddate        = sy-datum
    IMPORTING
      return         = l_return
      employeenumber = l_pernr.

  IF l_pernr NE 0.
    v_pernr = l_pernr.

CALL FUNCTION 'ZP3088_NEW_JOINEE_ACT'
  EXPORTING
    pernr               = v_pernr
 IMPORTING
   L_DISPLAY_PDF       = lv_disp
   L_DATA              = lv_data --> this is the data which is passed to the INTERACTIVE UI Element
 EXCEPTIONS
   TRAINEE_PERNR       = 1
   OTHERS              = 2.

IF sy-subrc <> 0.
* get message manager
DATA lo_api_controller     TYPE REF TO if_wd_controller.
DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
data w_msg type string.

lo_api_controller ?= wd_this->wd_get_api( ).

CALL METHOD lo_api_controller->get_message_manager
  RECEIVING
    message_manager = lo_message_manager.

* report message
CALL METHOD lo_message_manager->report_error_message
  EXPORTING
    message_text              = 'You are not Authorized to Access the Form'.

exit.
ENDIF.

*       get element via lead selection
      lo_el_context = wd_context->get_element( ).

*       set single attribute
      lo_el_context->set_attribute(
        name =  `DISPLAY`
        value = lv_disp ).

    IF lv_disp = '1'.

*       navigate from <CONTEXT> to <DATA> via lead selection
      lo_nd_data = wd_context->get_child_node( name = wd_this->wdctx_data ).

*       get element via lead selection
      lo_el_data = lo_nd_data->get_element( ).

*       set single attribute
      lo_el_data->set_attribute(
        name =  `DATA`
        value = lv_data ).  --> Data Binded.

* get element via lead selection
      lo_el_context = wd_context->get_element( ).

* set single attribute
      lo_el_context->set_attribute(
        name =  `VISIBLE`
        value = abap_true ).
    ELSEIF lv_disp = '0'.
*       navigate from <CONTEXT> to <DATA> via lead selection
      lo_nd_data = wd_context->get_child_node( name = wd_this->wdctx_data ).

*       get element via lead selection
      lo_el_data = lo_nd_data->get_element( ).

*       set single attribute
      lo_el_data->set_attribute(
        name =  `DATA`
        value = lv_data ).

IF lv_data EQ space.
* get element via lead selection
        lo_el_context = wd_context->get_element( ).

* set single attribute
        lo_el_context->set_attribute(
          name =  `VISIBLE`
          value = abap_false ).

        call_popup( ).
      ENDIF.
    ENDIF.
  ENDIF.
ENDMETHOD.

Under the layout I created an INTERACTIVEFORM UI Element and the PDFSOURCE will be the data of type XSTRING, to which the exported L_DATA is passed.

Regards,

-Syed.

Former Member
0 Kudos

how can i put a default printer using abap code? becouse i need to set a default printer for 1000 users