smartfroms 动态打印图片

将图片上传至se78,特定图片格式,smartfrom调用动态调用。

INCLUDE zbarcode_convert.

 PERFORM download_qrcode USING w_name 'http://xxxxxxxx'.    "上传图片
 PERFORM convert_image   USING w_name '200'  '200'.

PERFORM delete_image USING w_name.  “删除图片       

*&---------------------------------------------------------------------*
*&  包括                ZBARCODE_CONVERT
*&---------------------------------------------------------------------*

data : bds_description  like bapisignat-prop_value.
* BDS handling
constants:
  c_bds_classname type sbdst_classname  value 'DEVC_STXD_BITMAP',
  c_bds_classtype type sbdst_classtype  value 'OT',          " others
  c_bds_mimetype  type bds_mimetp       value 'application/octet-stream',
  c_bds_original  type sbdst_doc_var_tg value 'OR'.

* Graphic handling
constants:
      c_stdtext  like thead-tdobject value 'TEXT',
      c_graphics like thead-tdobject value 'GRAPHICS',
      c_bmon     like thead-tdid     value 'BMON',
      c_bcol     like thead-tdid     value 'BCOL'.
data: gi_filename    type rlgrap-filename,
      gi_name        type stxbitmaps-tdname,
      gi_object      type stxbitmaps-tdobject,
      gi_id          type stxbitmaps-tdid,
      gi_btype       type stxbitmaps-tdbtype,
      gi_resident    type stxbitmaps-resident,
      gi_autoheight  type stxbitmaps-autoheight,
      gi_bmcomp      type stxbitmaps-bmcomp,
      gi_resolution  type stxbitmaps-resolution,
      l_extension type rlgrap-filename,
      l_docid     type stxbitmaps-docid.

"Picture Control
data: picture_container type ref to cl_gui_custom_container,
      picture_control   type ref to cl_gui_picture.
data:   l_img_url     type w3url.
data :  l_img_subtype type w3param-cont_type.
data :  l_str_length  type i.
data :  urls type string.
data :  l_content_length type  i.
data :  zmessage type string.
data :  mime type  w3mimetabtype.
data :  blob type  w3mimetabtype,
        blob_size type w3param-cont_len,
        blob_type type w3param-cont_type.

data : i_igs_image_converter type ref to cl_igs_image_converter.
data : content type xstring.
data : http_client type ref to if_http_client.

types : begin of ty_binary,
        binary_field(1000) type c,
       end of ty_binary.

data : hex_tab1 type table of ty_binary with header line.

data :       width type int3 value  '100',
             height type int3 value '100'.

data : number type i,
       message type string.

*&---------------------------------------------------------------------*
*&      Form  download_qrcode
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->QR_TEXT    text
*----------------------------------------------------------------------*
form download_qrcode using qr_text url_text.

  data zhttp TYPE string.

  clear :urls,http_client,content,l_str_length,mime,zhttp.
  zhttp = url_text.  "'http://plm.pressmetal.com.cn:8080/GONGYECAI/G/G2475.png'.
  "zhttp = 'http://plm.pressmetal.com.cn:8080/GONGYECAI/G/G2475.png'.
  "zhttp = 'http://172.16.0.241/GPM16948.png'.

  call method cl_http_client=>create_by_url
    exporting
      url                = zhttp
    importing
      client             = http_client
    exceptions
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      others             = 4.

  if sy-subrc = 0.

    http_client->send( ).

    call method cl_http_client=>GET_LAST_ERROR
    importing
      message = zmessage.

    http_client->receive( ).

    call method cl_http_client=>GET_LAST_ERROR
    importing
       message = zmessage.
   content = http_client->response->get_data( ).

   call method cl_http_client=>GET_LAST_ERROR
    importing
       message = zmessage.

    http_client->close( ).

    l_str_length = xstrlen( content ).

    call function 'RSFO_XSTRING_TO_MIME'
      exporting
        c_xstring = content
        i_length  = l_str_length
      tables
        c_t_mime  = mime.

  endif.

endform.                    " DOWNLOAD_QRCODE

*&---------------------------------------------------------------------*
*&      Form  convert_image
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->BARCODE    text
*----------------------------------------------------------------------*
form convert_image using barcode width height.

  clear i_igs_image_converter.
  create object i_igs_image_converter .

  clear :blob,blob_size,blob_type,l_docid,gi_resolution.

  i_igs_image_converter->input = 'image/png'.
  i_igs_image_converter->output = 'image/bmp'.
  i_igs_image_converter->width  = width.
  i_igs_image_converter->height = height.

  call method i_igs_image_converter->set_image
    exporting
      blob      = mime
      blob_size = l_content_length.

  call method i_igs_image_converter->execute
    exceptions
      communication_error = 1
      internal_error      = 2
      external_error      = 3
      others              = 4.

  call METHOD i_igs_image_converter->get_error
     importing
     number = number
     message = message  .

  if sy-subrc = 0.

    call method i_igs_image_converter->get_image
      importing
        blob      = blob
        blob_size = blob_size
        blob_type = blob_type.

  endif.

  if sy-subrc = 0.

    gi_name     = barcode.         "name of the qrcode will be in se78 after one time running this program
    gi_object   = 'GRAPHICS'.
    gi_id       = 'BMAP'.
    gi_btype    = 'BCOL'. "If u want black and white pass BMON
    gi_resident = ' '.
    gi_autoheight  = 'X'.
    gi_bmcomp      = 'X'.
    l_extension    = 'BMP'.

    "importing the image into se78 before displaying it in the smartform.

    perform import_bitmap_bds    using blob
                                     gi_name
                                     gi_object
                                     gi_id
                                     gi_btype
                                     l_extension
                                     ' '
                                     gi_resident
                                     gi_autoheight
                                     gi_bmcomp
                            changing l_docid
                                     gi_resolution.


  endif.

endform.                    " CONVERT_IMAGE


*&---------------------------------------------------------------------*
*&      Form  IMPORT_BITMAP_BDS (Copied from standard program and modified it as per the requirement)
*&---------------------------------------------------------------------*
form import_bitmap_bds
        using    p_blob           type w3mimetabtype
                 p_name           type stxbitmaps-tdname
                 p_object         type stxbitmaps-tdobject
                 p_id             type stxbitmaps-tdid
                 p_btype          type stxbitmaps-tdbtype
                 p_format         type c
                 p_title          like bds_description
                 p_resident       type stxbitmaps-resident
                 p_autoheight     type stxbitmaps-autoheight
                 p_bmcomp         type stxbitmaps-bmcomp
        changing p_docid          type stxbitmaps-docid
                 p_resolution     type stxbitmaps-resolution.


  data: l_object_key type sbdst_object_key.
  data: l_tab        type ddobjname.

  data: begin of l_bitmap occurs 0,
          l(64) type x,
        end of l_bitmap.

  data: l_filename        type string,
        l_bytecount       type i,
        l_bds_bytecount   type i.
  data: l_color(1)        type c,

        l_width_tw        type stxbitmaps-widthtw,
        l_height_tw       type stxbitmaps-heighttw,
        l_width_pix       type stxbitmaps-widthpix,
        l_height_pix      type stxbitmaps-heightpix.
  data: l_bds_object      type ref to cl_bds_document_set,
        l_bds_content     type sbdst_content,
        l_bds_components  type sbdst_components,
        wa_bds_components type line of sbdst_components,
        l_bds_signature   type sbdst_signature,
        wa_bds_signature  type line of sbdst_signature,
        l_bds_properties  type sbdst_properties,
        wa_bds_properties type line of sbdst_properties.

  data  wa_stxbitmaps type stxbitmaps.

* Enqueue
  perform enqueue_graphic using p_object
                                p_name
                                p_id
                                p_btype.


* Bitmap conversion
  call function 'SAPSCRIPT_CONVERT_BITMAP_BDS'
    exporting
      color                    = 'X'
      format                   = p_format
      resident                 = p_resident
      bitmap_bytecount         = l_bytecount
      compress_bitmap          = p_bmcomp
    importing
      width_tw                 = l_width_tw
      height_tw                = l_height_tw
      width_pix                = l_width_pix
      height_pix               = l_height_pix
      dpi                      = p_resolution
      bds_bytecount            = l_bds_bytecount
    tables
      bitmap_file              = p_blob
      bitmap_file_bds          = l_bds_content
    exceptions
      format_not_supported     = 1
      no_bmp_file              = 2
      bmperr_invalid_format    = 3
      bmperr_no_colortable     = 4
      bmperr_unsup_compression = 5
      bmperr_corrupt_rle_data  = 6
      others                   = 7.

  if sy-subrc <> 0.

    perform dequeue_graphic using p_object
                                  p_name
                                  p_id
                                  p_btype.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
    raising conversion_failed.

  endif.

* Save bitmap in BDS
  create object l_bds_object.

  wa_bds_components-doc_count  = '1'.
  wa_bds_components-comp_count = '1'.
  wa_bds_components-mimetype   = c_bds_mimetype.
  wa_bds_components-comp_size  = l_bds_bytecount.
  append wa_bds_components to l_bds_components.

  if p_docid is initial.          " graphic is new

    wa_bds_signature-doc_count = '1'.
    append wa_bds_signature to l_bds_signature.

    call method l_bds_object->create_with_table
      exporting
        classname  = c_bds_classname
        classtype  = c_bds_classtype
        components = l_bds_components
        content    = l_bds_content
      changing
        signature  = l_bds_signature
        object_key = l_object_key
      exceptions
        others     = 1.

    if sy-subrc <> 0.

      perform dequeue_graphic using p_object
                                    p_name
                                    p_id
                                    p_btype.
*      message e285 with p_name  'BDS'.

    endif.

    read table l_bds_signature index 1 into wa_bds_signature
    transporting doc_id.

    if sy-subrc = 0.

      p_docid = wa_bds_signature-doc_id.

    else.

      perform dequeue_graphic using p_object
                                    p_name
                                    p_id
                                    p_btype.
*      message e285 with p_name 'BDS'.

    endif.

  else.                " graphic already exists

********* read object_key for faster access *****
    clear l_object_key.
    select single * from stxbitmaps into wa_stxbitmaps
        where tdobject = p_object
          and tdid     = p_id
          and tdname   = p_name
          and tdbtype  = p_btype.

    select single tabname from bds_locl into l_tab
       where classname = c_bds_classname
          and classtype = c_bds_classtype.

    if sy-subrc = 0.

      select single object_key from (l_tab) into l_object_key
        where loio_id = wa_stxbitmaps-docid+10(32)
          and classname = c_bds_classname
            and classtype = c_bds_classtype.

    endif.

******** read object_key end ********************

    call method l_bds_object->update_with_table
      exporting
        classname     = c_bds_classname
        classtype     = c_bds_classtype
        object_key    = l_object_key
        doc_id        = p_docid
        doc_ver_no    = '1'
        doc_var_id    = '1'
      changing
        components    = l_bds_components
        content       = l_bds_content
      exceptions
        nothing_found = 1
        others        = 2.

    if sy-subrc = 1.   " inconsistency STXBITMAPS - BDS; repeat check in

      wa_bds_signature-doc_count = '1'.
      append wa_bds_signature to l_bds_signature.

      call method l_bds_object->create_with_table
        exporting
          classname  = c_bds_classname
          classtype  = c_bds_classtype
          components = l_bds_components
          content    = l_bds_content
        changing
          signature  = l_bds_signature
          object_key = l_object_key
        exceptions
          others     = 1.

      if sy-subrc <> 0.
        perform dequeue_graphic using p_object
                                      p_name
                                      p_id
                                      p_btype.
*        message e285 with p_name 'BDS'.

      endif.

      read table l_bds_signature index 1 into wa_bds_signature
      transporting doc_id.
      if sy-subrc = 0.
        p_docid = wa_bds_signature-doc_id.
      else.

        perform dequeue_graphic using p_object
                                      p_name
                                      p_id
                                      p_btype.

*        message e285 with p_name 'BDS'.

      endif.

    elseif sy-subrc = 2.

      perform dequeue_graphic using p_object
                                    p_name
                                    p_id
                                    p_btype.

*      message e285 with p_name 'BDS'.

    endif.

  endif.

* Save bitmap header in STXBITPMAPS
  wa_stxbitmaps-tdname     = p_name.
  wa_stxbitmaps-tdobject   = p_object.
  wa_stxbitmaps-tdid       = p_id.
  wa_stxbitmaps-tdbtype    = p_btype.
  wa_stxbitmaps-docid      = p_docid.
  wa_stxbitmaps-widthpix   = l_width_pix.
  wa_stxbitmaps-heightpix  = l_height_pix.
  wa_stxbitmaps-widthtw    = l_width_tw.
  wa_stxbitmaps-heighttw   = l_height_tw.
  wa_stxbitmaps-resolution = p_resolution.
  wa_stxbitmaps-resident   = p_resident.
  wa_stxbitmaps-autoheight = p_autoheight.
  wa_stxbitmaps-bmcomp     = p_bmcomp.
  insert into stxbitmaps values wa_stxbitmaps.

  if sy-subrc <> 0.

    update stxbitmaps from wa_stxbitmaps.

    if sy-subrc <> 0.

*       message e285 with p_name 'STXBITMAPS'.

    endif.

  endif.

* Set description in BDS attributes

  wa_bds_properties-prop_name  = 'DESCRIPTION'.
  wa_bds_properties-prop_value = p_title.
  append wa_bds_properties to l_bds_properties.


  call method l_bds_object->change_properties
    exporting
      classname  = c_bds_classname
      classtype  = c_bds_classtype
      object_key = l_object_key
      doc_id     = p_docid
      doc_ver_no = '1'
      doc_var_id = '1'
    changing
      properties = l_bds_properties
    exceptions
      others     = 1.

  perform dequeue_graphic using p_object
                                p_name
                                p_id
                                p_btype.

endform.                    "import_bitmap_bds


*&---------------------------------------------------------------------*
*&      Form  enqueue_graphic
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OBJECT   text
*      -->P_NAME     text
*      -->P_ID       text
*      -->P_BTYPE    text
*----------------------------------------------------------------------*
form enqueue_graphic using p_object
                           p_name
                           p_id
                           p_btype.


  call function 'ENQUEUE_ESSGRABDS'
    exporting
*     MODE_STXBITMAPS = 'E'
      tdobject        = p_object
      tdname          = p_name
      tdid            = p_id
      tdbtype         = p_btype
*     X_TDOBJECT      = ' '
*     X_TDNAME        = ' '
*     X_TDID          = ' '
*     X_TDBTYPE       = ' '
*     _SCOPE          = '2'
*     _WAIT           = ' '
*     _COLLECT        = ' '
    exceptions
      foreign_lock    = 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
    raising enqueue_failed.
  endif.

endform.                    " ENQUEUE_GRAPHIC


*&---------------------------------------------------------------------*
*&      Form  dequeue_graphic
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OBJECT   text
*      -->P_NAME     text
*      -->P_ID       text
*      -->P_BTYPE    text
*----------------------------------------------------------------------*
form dequeue_graphic using p_object
                           p_name
                           p_id
                           p_btype.

  call function 'DEQUEUE_ESSGRABDS'
    exporting
*     MODE_STXBITMAPS = 'E'
*     X_TDOBJECT      = ' '
*     X_TDNAME        = ' '
*     X_TDID          = ' '
*     X_TDBTYPE       = ' '
*     _SCOPE          = '3'
*     _SYNCHRON       = ' '
*     _COLLECT        = ' '
      tdobject        = p_object
      tdname          = p_name
      tdid            = p_id
      tdbtype         = p_btype.

endform.                    " DEQUEUE_GRAPHIC


*&---------------------------------------------------------------------*
*&      Form  DELETE_image
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->BARCODE    text
*----------------------------------------------------------------------*
form delete_image using barcode.

  data i_name like  stxbitmaps-tdname.
  i_name = barcode.

  call function 'SAPSCRIPT_DELETE_GRAPHIC_BDS'
    exporting
      i_object       = 'GRAPHICS'
      i_name         = i_name
      i_id           = 'BMAP'
      i_btype        = 'BCOL'"'BMON'
      dialog         = 'N'
    exceptions
      enqueue_failed = 1
      delete_failed  = 2
      not_found      = 3
      canceled       = 4
      others         = 5.
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.

endform.                    "DELETE_image      

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值