繁体   English   中英

如何在 ABAP 报告中显示 WebDynpro ABAP?

[英]How to display WebDynpro ABAP in ABAP report?

我刚刚开始编写 ABAP 几天,我有一项任务从事务SE38调用报告并有

报告的结果显示在 WebDynPro 应用程序SE80的屏幕上。

该报表以用户输入(例如:物料编号、物料类型、工厂、销售组织)作为查询条件,因此 WebDynPro 应用程序必须允许用户键入此参数。

在一些相关文章中,他们谈论使用SUBMIT rep EXPORTING LIST TO MEMORYCALL FUNCTION 'LIST_FROM_MEMORY'但到目前为止我真的不知道实现它。

任何答案将不胜感激。 谢谢!

您可以将其导出为 PDF。 因此,当用户单击链接时,您会运行转换并在浏览器窗口中显示文件。

为此,您首先使用以下代码创建一个 JOB:

  constants c_name type tbtcjob-jobname value 'YOUR_JOB_NAME'.

  data v_number type tbtcjob-jobcount.
  data v_print_parameters type pri_params.

  call function 'JOB_OPEN'
    exporting
      jobname          = c_name
    importing
      jobcount         = v_number
    exceptions
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      others           = 4.

  if sy-subrc = 0.
    commit work and wait.
  else.
    EXIT. "// todo: err handling here
  endif.

然后,您需要获取打印机参数才能提交报告:

call function 'GET_PRINT_PARAMETERS'
  exporting
    destination            = 'LP01'
    immediately            = space
    new_list_id            = 'X'
    no_dialog              = 'X'
    user                   = sy-uname
  importing
    out_parameters         = v_print_parameters
  exceptions
    archive_info_not_found = 1
    invalid_print_params   = 2
    invalid_archive_params = 3
    others                 = 4.

v_print_parameters-linct = 55.
v_print_parameters-linsz = 1.
v_print_parameters-paart = 'LETTER'.

现在您使用适用的过滤器提交报告。 不要忘记向其中添加作业参数,如下面的代码所示:

  submit your_report_name
         to sap-spool
         spool parameters v_print_parameters
         without spool dynpro
         with ...(insert all your filters here)
         via job c_name number v_number
         and return.

  if sy-subrc = 0.
    commit work and wait.
  else.
    EXIT. "// todo: err handling here
  endif.

之后,您关闭作业:

  call function 'JOB_CLOSE'
    exporting
      jobcount             = v_number
      jobname              = c_name
      strtimmed            = 'X'
    exceptions
      cant_start_immediate = 1
      invalid_startdate    = 2
      jobname_missing      = 3
      job_close_failed     = 4
      job_nosteps          = 5
      job_notex            = 6
      lock_failed          = 7
      others               = 8.

  if sy-subrc = 0.
    commit work and wait.
  else.
    EXIT. "// todo: err handling here
  endif.

现在作业将继续,您需要等待它完成。 用循环来做。 作业完成后,您可以获得它的假脱机输出并转换为 PDF。

  data v_rqident type tsp01-rqident.

  data v_job_head type tbtcjob.

  data t_job_steplist type tbtcstep occurs 0 with header line.

  data t_pdf like tline occurs 0 with header line.

  do 200 times.

    wait up to 1 seconds.

    call function 'BP_JOB_READ'
      exporting
        job_read_jobcount     = v_number
        job_read_jobname      = c_name
        job_read_opcode       = '20'
      importing
        job_read_jobhead      = v_job_head
      tables
        job_read_steplist     = t_job_steplist
      exceptions
        invalid_opcode        = 1
        job_doesnt_exist      = 2
        job_doesnt_have_steps = 3
        others                = 4.

    read table t_job_steplist index 1.

    if not t_job_steplist-listident is initial.
      v_rqident = t_job_steplist-listident.
      exit.
    else.
      clear v_job_head.
      clear t_job_steplist.
      clear t_job_steplist[].
    endif.

  enddo.

  check not v_rqident is initial.

  call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
    exporting
      src_spoolid              = v_rqident
      dst_device               = 'LP01'
    tables
      pdf                      = t_pdf
    exceptions
      err_no_abap_spooljob     = 1
      err_no_spooljob          = 2
      err_no_permission        = 3
      err_conv_not_possible    = 4
      err_bad_destdevice       = 5
      user_cancelled           = 6
      err_spoolerror           = 7
      err_temseerror           = 8
      err_btcjob_open_failed   = 9
      err_btcjob_submit_failed = 10
      err_btcjob_close_failed  = 11
      others                   = 12.

如果您打算通过 HTTP 发送它,您可能还需要将其转换为 BASE64。

  field-symbols <xchar> type x.
  data v_offset(10) type n.
  data v_char type c.
  data v_xchar(2) type x.
  data v_xstringdata_aux type xstring.
  data v_xstringdata type xstring.
  data v_base64data type string.
  data v_base64data_aux type string.

  loop at t_pdf.
    do 134 times.
      v_offset = sy-index - 1.
      v_char = t_pdf+v_offset(1).
      assign v_char to <xchar> casting type x.
      concatenate v_xstringdata_aux <xchar> into v_xstringdata_aux in byte mode.
    enddo.
    concatenate v_xstringdata v_xstringdata_aux into v_xstringdata in byte mode.
    clear v_xstringdata_aux.
  endloop.

  call function 'SCMS_BASE64_ENCODE_STR'
    exporting
      input  = v_xstringdata
    importing
      output = v_base64data.

  v_base64data_aux = v_base64data.

  while strlen( v_base64data_aux ) gt 255.
    clear t_base64data.
    t_base64data-data = v_base64data_aux.
    v_base64data_aux = v_base64data_aux+255.
    append t_base64data.
  endwhile.

  if not v_base64data_aux is initial.
    t_base64data-data = v_base64data_aux.
    append t_base64data.
  endif.

你完成了!

希望能帮助到你。

正如前面的演讲者所说,在生产环境中实施这些东西之前,您应该进行广泛的培训。
但是,可以借助WDY_EXECUTE_IN_PLACE功能模块在报表中调用 WebdynPro ABAP。 您应该在那里传递 Webdyn Pro 应用程序和必要的参数。

CALL FUNCTION 'WDY_EXECUTE_IN_PLACE'
 EXPORTING
*   PROTOCOL                     =
    INTERNALMODE                 = ' '
*   SMARTCLIENT                  =
    APPLICATION                  = 'Z_MY_WEBDYNPRO'
*   CONTAINER_NAME               =
    PARAMETERS                   = lt_parameters
    SUPPRESS_OUTPUT              =
    TRY_TO_USE_SAPGUI_THEME      = ' '
 IMPORTING
    OUT_URL                       = ex_url
.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM