Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7188805
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2008-12-12 12:45:28

REPORT  z_barry_hr_photo_upload.
 
DATA: sapobjid LIKE sapb-sapobjid,
      sappfad LIKE sapb-sappfad.
DATA: gd_path TYPE string ,
      filetab TYPE TABLE OF file_info WITH HEADER LINE,
      count TYPE i.
DATA: filename(40) TYPE c ,
      fileext(10) TYPE c ,
      len TYPE i .
 
PARAMETERS: filepath LIKE rlgrap-filename.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filepath.
  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title    = 'File Directory'
      initial_folder  = 'C:\'
    CHANGING
      selected_folder = gd_path.
  CALL METHOD cl_gui_cfw=>flush.
  CONCATENATE gd_path '' INTO filepath.
 
START-OF-SELECTION.
  gd_path = filepath .
  CALL METHOD cl_gui_frontend_services=>directory_list_files
    EXPORTING
      directory                   = gd_path
      filter                      = '*.jpg'
    CHANGING
      file_table                  = filetab[]
      count                       = count
    EXCEPTIONS
      cntl_error                  = 1
      directory_list_files_failed = 2
      wrong_parameter             = 3
      error_no_gui                = 4
      not_supported_by_gui        = 5
      OTHERS                      = 6.
 
  LOOP AT filetab.
    SPLIT filetab-filename AT '.' INTO filename fileext.
    len = STRLEN( filename ) .
    IF len <> 8 .
      MESSAGE e000(oo) WITH '文件名长度必须等于8位'.
    ENDIF.
  ENDLOOP.
 
  LOOP AT filetab.
    CONCATENATE gd_path '\' filetab-filename INTO sappfad.
    CONCATENATE filetab-filename+0(8) '0002' INTO sapobjid.
    CALL FUNCTION 'ARCHIV_CREATE_FILE'
      EXPORTING
        ar_object               = 'HRICOLFOTO'
        object_id               = sapobjid
        sap_object              = 'PREL'
        doc_type                = 'JPG'
        path                    = sappfad
      EXCEPTIONS
        error_conectiontable    = 1
        error_parameter         = 2
        error_archiv            = 3
        error_upload            = 4
        error_kernel            = 5
        no_entry_possible       = 6
        error_comunicationtable = 7
        OTHERS                  = 8.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
      WRITE : / 'Upload ',sappfad,'To pernr ',filetab-filename+0(8),'Sccuess!'.
    ENDIF.
  ENDLOOP.
 
 
 
REPORT  z_barry_hr_photo_down.
 
DATA: comps2 TYPE STANDARD TABLE OF scms_doinf WITH HEADER LINE,
      comp_names TYPE STANDARD TABLE OF scms_donam WITH HEADER LINE.
 
PARAMETERS p_pernr LIKE pa0001-pernr.
 
PERFORM photo_down USING p_pernr 'A' '18000101' '99991231' 'D:\abc.jpg'  .
 
*&---------------------------------------------------------------------*
*&      Form  URL_GET
*&---------------------------------------------------------------------*
FORM photo_down USING p_pernr LIKE pernr-pernr
                      p_tclas LIKE pspar-tclas
                      p_begda LIKE prelp-begda
                      p_endda LIKE prelp-endda
                      path TYPE c .
  DATA: l_connect_info LIKE toav0,
        l_exists(1) TYPE c .
  CALL FUNCTION 'HR_IMAGE_EXISTS'
    EXPORTING
      p_pernr        = p_pernr
      p_tclas        = p_tclas
      p_begda        = p_begda
      p_endda        = p_endda
    IMPORTING
      p_exists       = l_exists
      p_connect_info = l_connect_info
    EXCEPTIONS
      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 .
    EXIT.
  ENDIF.
  CALL FUNCTION 'SCMS_DOC_READ_FILES'
    EXPORTING
      stor_cat              = space
      crep_id               = l_connect_info-archiv_id
      doc_id                = l_connect_info-arc_doc_id
      path                  = path
      frontend              = 'X'
    TABLES
      comps                 = comps2
      comp_names            = comp_names
    EXCEPTIONS
      bad_storage_type      = 1
      bad_request           = 2
      unauthorized          = 3
      not_found             = 4
      conflict              = 5
      internal_server_error = 6
      error_http            = 7
      error_signature       = 8
      error_config          = 9
      error_hierarchy       = 10
      error_download        = 11
      error_open            = 12
      error_parameter       = 13
      error                 = 14
      OTHERS                = 15.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
  ENDIF.
ENDFORM.                    "photo_down
阅读(6231) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-07-25 18:05:29

我跟了下标准程序!发现个buge! 你如果吧变量的值设置过长就会出现你说的问题!解决办法是: data:pic(10) type c value ‘D:\abc.jpg’. 变量的长度要和变量长度一致就ok!

chinaunix网友2009-02-16 19:08:49

你的SAP版本是多少?UNIX还是WINNT平台?

chinaunix网友2009-02-16 13:54:31

我自已测试了一下,用'D:\abc.jpg'是无法下载的,要用像'D:\abc\'这样的路径,并且生成出来的图片都是DATA的文件名(没有扩展名。也就是说如果用D:\abc\生成的图片是D:\abc\DATA

chinaunix网友2009-02-16 13:54:21

我自已测试了一下,用'D:\abc.jpg'是无法下载的,要用像'D:\abc\'这样的路径,并且生成出来的图片都是DATA的文件名(没有扩展名。也就是说如果用D:\abc\生成的图片是D:\abc\DATA