ABAP 上传图片

摘要:
Sap图像上传程序:1.全局字段定义类型:beginofty_pic,pic_data(1024)typex,endofty_pic。数据:pic_ tabtypetableofty_pic。数据:wa_pictypeztpic。数据:c pictypereftocl gui自定义容器,pictypereftocl gui图片。数据:借出

Sap图片上传程序:

1、  全局字段定义

types: begin of ty_pic,
           pic_data(1024) type x,
         end of ty_pic.
data: pic_tab type table of ty_pic.
data: wa_pic type ztpic.
data: c_pic type ref to cl_gui_custom_container,
        pic type ref to cl_gui_picture.
data: len type i,url(256),
        resu type i value 123,
        path_string type string.

2、  选择屏幕定义

               

ABAP 上传图片第1张

       

selection-screen begin of block blk1 with frame.
parameters : p_matnr like zmbt-matnr.
parameters : p_file like rlgrap-filename obligatory .
selection-screen end of block blk1.

at selection-screen on value-request for p_file.
    perform select_file using p_file.

start-of-selection.
  perform upload_pic.
  perform show_pic.
  call screen 100.

*&---------------------------------------------------------------------*
*&      Form  select_file
*&---------------------------------------------------------------------*
form select_file using    p_file.
   call function 'F4_FILENAME'
      importing
        file_name = p_file.
endform.                    " SELECT_FILE

3、  图片上传及保存到数据库

*&---------------------------------------------------------------------*
*&      Form  UPLOAD_PIC
*&---------------------------------------------------------------------*
form upload_pic .
  path_string = p_file.
  data lv_content type xstring.
  call function 'GUI_UPLOAD'
    exporting
      filename   = path_string
      filetype   = 'BIN'
    importing
      filelength = len
    tables
      data_tab   = pic_tab[].

  call function 'SCMS_BINARY_TO_XSTRING'
    exporting
      input_length = len
    importing
      buffer       = lv_content
    tables
      binary_tab   = pic_tab[]
    exceptions
      failed       = 1
      others       = 2.

  wa_pic-matnr = p_matnr.
  wa_pic-picdata = lv_content.
  modify ztpic from wa_pic.
  if sy-subrc = 0.
    message '图片已保存到数据库' type 'S'.
  else.
    message '图片保存失败!' type 'E'.
  endif.
endform.                    " UPLOAD_PIC

4、  显示数据库中的图片

*&---------------------------------------------------------------------*
*&      Form  SHOW_PIC
*&---------------------------------------------------------------------*
form show_pic .
  clear pic_tab.
  select single * from ztpic into wa_pic where matnr = p_matnr.
  call function 'SCMS_XSTRING_TO_BINARY'
    exporting
      buffer     = wa_pic-picdata
    tables
      binary_tab = pic_tab.

  call function 'DP_CREATE_URL'
    exporting
      type    = 'IMAGE'
      subtype = 'JPG'
    tables
      data    = pic_tab
    changing
      url     = url.
  create object c_pic
    exporting
            container_name = 'C_PIC'.
  create object pic
    exporting
            parent = c_pic.
  call method pic->load_picture_from_url
    exporting
      url    = url
    importing
      result = resu.
endform.                    " SHOW_PIC

5、  用到的数据库表:ZTPIC

ABAP 上传图片第2张

6、  屏幕100:因为图片需要放在容器中显示,所以创建一个屏幕,屏幕中只有一个定制控制,名为C_PIC。以下是屏幕元素清单:

ABAP 上传图片第3张

在程序中加入

data: ok_code like sy-ucomm,
        save_ok like sy-ucomm.

屏幕GUI只需要一个退出功能即可

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status '100'.
endmodule.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.
  save_ok = ok_code.
  clear ok_code.
  case save_ok.
    when 'BACK'.
      leave to screen 0.
  endcase.
endmodule.                 " USER_COMMAND_0100  INPUT

免责声明:文章转载自《ABAP 上传图片》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇android Launcher——启动过程详解Java性能分析神器--VisualVM Launcher[1]下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

input上传图片并预览

首先说一下input 大家都知道上传文件,图片是通过input 的file进行上传的。 1. 首先是样式 大家都知道input在HTML的代码为 <input type="file">;在页面的样式是不可以更改的,如下图 但是最为一个投机取巧的前端,一切样式都是可以修改的。 效果图如下 代码: <input type="file...

kindEditor上传图片错误,不成功的问题总结

自己的网站是用的GB2312的编码,ASP做的网站。 原来用了ewebeditor 的后台HTML编译器,在使用了新空间后,编译器上传图片不成功了。 我在网上找ewebeditor相关的资料,发现资料很少,自己去研究太花时间了,ewebeditor也不支持非IE的浏览器。还是另外使用一个HTML后台编辑器吧。 在网上搜索了几个有名的后台编辑器,如下: CK...

ABAP术语-Connection Type

Connection Type 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/17/1042479.html A connection type is a relationship type whose occurrences are visible connections (lines) be...

express + multer 文件上传入门

写在前面的 在web开发中,我们经常会遇到图片上传的功能,接下来我们就在express4.15.0框架中利用multer1.3.0模块来实现图片上传 开始敲代码 首先利用express-generator express框架生成器生成我们的项目 这里我们采用ejs模板引擎(因为我只会这个) express -e uploads 创建好之后,目录结构如下图...

数据词典与ABAP类型映射

数据词典与ABAP类型映射 这些不能够直接在ABAP程序中使用,但可以使用对它们进行包装后的Data element来间接使用,在程序中使用数据字典类型时,将转化为相应的ABAP内置类型。 Type 允许最大长度m Meaning ABAP Type ACCP 6 Accounting period n(6) CHAR 1-255 Char...

【ABAP系列】SAP ABAP MIR7预制凭证BAPI

公众号:matinal 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:【ABAP系列】SAP ABAP MIR7预制凭证BAPI   前言部分 大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。 正文部分 做预制凭证有两个BAPI: BAPI_INCOMINGINVOI...