简体   繁体   中英

How to display WebDynpro ABAP in ABAP report?

I've just started coding ABAP for a few days and I have a task to call the report from transaction SE38 and have

the report's result shown on the screen of the WebDynPro application SE80 .

The report take the user input ( eg: Material Number, Material Type, Plant, Sale Org. ) as a condition for querying, so the WebDynPro application must allow user to key in this parameters.

In some related article they were talking about using SUBMIT rep EXPORTING LIST TO MEMORY and CALL FUNCTION 'LIST_FROM_MEMORY' but so far I really have no idea to implement it.

Any answers will be appreciated. Thanks!

You can export it to PDF. Therefore, when a user clicks on a link, you run the conversion and display the file in the browser window.

To do so, you start by creating a JOB using the following code below:

  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.

Then, you need to get the printer parameters in order to submit the report:

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'.

Now you submit your report using the filters that apply. Do not forget to add the job parameters to it, as the code below shows:

  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.

After that, you close the job:

  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.

Now the job will proceed and you'll need to wait for it to complete. Do it with a loop. Once the job is completed, you can get it's spool output and convert to 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.

If you're going to send it via HTTP, you may need to convert it to BASE64 as well.

  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.

And you're done!

Hope it helps.

As previous speakers said, you should do extensive training before implementing such stuff in productive environment.
However, calling WebdynPro ABAP within report can be done with the help of WDY_EXECUTE_IN_PLACE function module. You should pass there Webdyn Pro application and necessary parameters.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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