sap wda 调用smartforms生成PDF

method ONACTIONPRINT .
  CONSTANTS: c_f_x(1) TYPE c VALUE 'X'.
  DATA: l_f_fm_name  TYPErs38l_fnam.
  DATA:  l_current_controllerTYPE REF TO if_wd_controller,
        l_message_manager   TYPE REF TO if_wd_message_manager.
  DATA : Z_BID_INFO TYPE STANDARD TABLE OFZSRMII_BID_VEN .
    DATA:
     node_zbid_info                     TYPE REF TO if_wd_context_node,
     elem_zbid_info                     TYPE REF TO if_wd_context_element,
     stru_zbid_info                     TYPE if_result_view=>element_zbid_info .
  navigate from<CONTEXT> to<ZBID_INFO> via lead selection
   node_zbid_info = wd_context->get_child_node( name =if_result_view=>wdctx_zbid_info ).

  get element via leadselection
   elem_zbid_info =node_zbid_info->get_element( ).

  get all declaredattributes
   elem_zbid_info->get_static_attributes(
     IMPORTING
       static_attributes = stru_zbid_info ).
    APPENDstru_zbid_info TO Z_BID_INFO .


    IFstru_zbid_info-OBJECT_ID IS NOT INITIAL .
     TRY.
       CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
         EXPORTING
           formname                = 'ZSRMII_WDA_0013'
         IMPORTING
           fm_name                 = l_f_fm_name
         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.

       CATCH cx_fp_api_repository.
         RETURN.
       CATCH cx_fp_api_usage.
         RETURN.
       CATCH cx_fp_api_internal.
         RETURN.
     ENDTRY.
     CHECK l_f_fm_name IS NOT INITIAL.

  Set relevant controlparameters
     DATA: l_f_rspoptype TYPE rspoptype.
     CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
       EXPORTING
         i_language                  = '1'
       IMPORTING
         e_devtype                   = l_f_rspoptype
       EXCEPTIONS
         no_language                 = 1
         language_not_installed      = 2
         no_devtype_found            = 3
         system_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.

     DATA: l_s_control_parameters TYPE ssfctrlop.
     l_s_control_parameters-getotf   = c_f_x. "OTF output
     l_s_control_parameters-no_dialog = c_f_x. "No print dialog
     l_s_control_parameters-preview  = space. "No preview
  l_s_control_parameters-langu    = sy-langu.
  Set relevant outputoptions
     DATA: l_s_output_options TYPE ssfcompop.
     l_s_output_options-tdnewid   =c_f_x.  "Print parameters: Spool control
     l_s_output_options-tddelete  =space.  "Print parameters: Spool control
     l_s_output_options-tdprinter = l_f_rspoptype.
     l_s_output_options-tddest = 'DEFAULT'.


     DATA: l_s_job_output_info TYPE ssfcrescl.
     CALL FUNCTION l_f_fm_name
       EXPORTING
         control_parameters        = l_s_control_parameters
         output_options            = l_s_output_options
       IMPORTING
         job_output_info           = l_s_job_output_info
       TABLES
         Z_BID_INFO                = Z_BID_INFO
       EXCEPTIONS
         formatting_error          = 1
         internal_error            = 2
         send_error                = 3
         user_canceled             = 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.
       RETURN.
     ENDIF.

  产生PDF源数据
     WD_COMP_CONTROLLER->generate_pdf_xstring(
       s_job_output_info = l_s_job_output_info
     ).

  invoke PDF view
     WD_COMP_CONTROLLER->create_popup(
       i_f_title    = '供应商认证'
       i_f_view_name = 'POPUP_PDF'
     ).
    ELSE .
     "查询成功
       l_current_controller ?= wd_this->wd_get_api( ).

       CALL METHODl_current_controller->get_message_manager
         RECEIVING
           message_manager = l_message_manager .

       report message
       CALL METHODl_message_manager->report_t100_message
         EXPORTING
           MSGID        = 'Z_SRM_MESSAGE'
           MSGNO        = '047'
           MSGTY        = 'E' .
    ENDIF .

endmethod.

上面调用WD_COMP_CONTROLLER->create_popup 和WD_COMP_CONTROLLER->generate_pdf_xstring方法

下面为这两个方法:

method CREATE_POPUP .
  DATA: l_ref_component TYPE REF TOif_wd_component.

  CHECK i_f_view_name IS NOT INITIAL.

  l_ref_component =wd_this->wd_get_api( ).
  TRY.
     CALL METHODcl_wdr_runtime_services=>display_view_in_popup
       EXPORTING
         component            = l_ref_component
        target_component_name =
        target_cmp_usage_name =
        target_window_name   =
         target_view_name     = i_f_view_name
         modal                = abap_true
         window_title         = i_f_title
         close_button         = abap_true
        button_kind          =
        create_only          = abap_false
        message_type         = if_wd_window=>co_msg_type_none
        is_value_help        = abap_false
        close_in_any_case    = abap_true
        message_display_mode  =
        default_button       =
      IMPORTING
        popup_window         =
        component_usage      =
         .
    CATCHcx_wd_runtime_repository .
  ENDTRY.
endmethod.

method GENERATE_PDF_XSTRING .
  DATA:l_itab_otfdata     TYPE tsfotf.
* Smart Forms: Smart Composer
  l_itab_otfdata = s_job_output_info-otfdata.

  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
   EXPORTING
     i_otf                   = l_itab_otfdata
   EXCEPTIONS
     convert_otf_to_pdf_error = 1
     cntl_error              = 2
     OTHERS                  = 3.
  IF sy-subrc <>0.
    MESSAGE IDsy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  DATA: l_dummy  TYPE STANDARDTABLE OF tline,
       pdf_data TYPE xstring,
       pdf_size TYPE i.
  CALL FUNCTION 'CONVERT_OTF'
   EXPORTING
     format                     = 'PDF'
   MAX_LINEWIDTH              = 132
   ARCHIVE_INDEX              = ' '
   COPYNUMBER                 = 0
   ASCII_BIDI_VIS2LOG         = ' '
   PDF_DELETE_OTFTAB          = ' '
   IMPORTING
     bin_filesize               = pdf_size
     bin_file                   = pdf_data
    TABLES
     otf                        = l_itab_otfdata[]
     lines                      = l_dummy
   EXCEPTIONS
     err_max_linewidth          = 1
     err_format                 = 2
     err_conv_not_possible      = 3
     err_bad_otf                = 4
     OTHERS                     = 5.
  IF sy-subrc <>0.
    MESSAGE IDsy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   RETURN.
  ENDIF.

  DATA:
   node_pdf                           TYPE REF TO if_wd_context_node,
   elem_pdf                           TYPE REF TO if_wd_context_element,
   stru_pdf                           TYPE if_componentcontroller=>element_pdf .
* navigate from <CONTEXT> to<PDF> via lead selection
  node_pdf =wd_context->get_child_node( name =if_componentcontroller=>wdctx_pdf ).

* get element via lead selection
  elem_pdf =node_pdf->get_element(  ).

** get all declared attributes
elem_pdf->get_static_attributes(
  IMPORTING
    static_attributes = stru_pdf ).

* set single attribute
  CALL METHODelem_pdf->set_attribute
   EXPORTING
     value = pdf_data
     name  = 'SOURCE' .
endmethod.

需要建一个node 里面有个一个xstring类型的attribute ,对interactiveforms进行绑定!

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
WDA是一个用于iOS端自动化测试的Python库,而allure是一个用于生成漂亮报告的工具。要将WDA测试结果集成到allure报告中,可以使用pytest和allure-pytest插件来实现。 首先需要安装pytest和allure-pytest插件,可以使用以下命令进行安装: ``` pip install pytest pip install allure-pytest ``` 安装完成后,在pytest的测试用例中,可以使用pytest的fixture和allure的装饰器来将WDA测试结果保存到allure报告中。下面是一个示例: ```python import wda import allure import pytest @pytest.fixture(scope='module') def client(): c = wda.Client() return c @allure.feature('WDA测试') class TestWDA(object): @allure.story('测试页面标题') def test_title(self, client): title = client.title() assert title == 'Example Page' allure.attach(client.screenshot(format='png'), name='screenshot', attachment_type=allure.attachment_type.PNG) @allure.story('测试按钮点击') def test_button(self, client): btn = client(name='example_button') btn.tap() assert btn.exists allure.attach(client.screenshot(format='png'), name='screenshot', attachment_type=allure.attachment_type.PNG) ``` 在上面的示例中,使用了一个名为`client`的fixture来获取WDA的客户端连接,然后使用`allure.feature`和`allure.story`装饰器来定义测试用例的特性和故事。在每个测试用例中,使用了`allure.attach`方法将截图保存到allure报告中。 最后,可以使用以下命令来运行测试,并生成allure报告: ``` pytest --alluredir ./allure-results allure serve ./allure-results ``` 这样就可以将WDA测试结果集成到allure报告中,并且在报告中查看测试结果和截图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SAP剑客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值