壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9976|回复: 31

[ABAP资料区] IDOC 编程实践 - ABAP DEMO 系列

  [复制链接]
发表于 2007/8/3 14:23:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
Main program
*&---------------------------------------------------------------------*
*& Report  Z_IDOC_STATUS_CHANGE                                        *
*&---------------------------------------------------------------------*
*& AUTHOR: Samson_Zhu(朱信澄xincheng24@gmail.com)                      *
*& DESCRIPTION: Reset Idoc statuses by uploading spreadsheet of IDocs  *
*&---------------------------------------------------------------------*

report  z_idoc_status_change message-id zedi.
*--- INCLUDES ---------------------------------------------------------*
include z_idoc_status_change_data.
include z_idoc_status_change_forms.

*--- SELECTION OPTIONS ------------------------------------------------*
selection-screen begin of block b1 with frame title text-001.
parameters: filename like sapb-sappfad.
selection-screen skip.

selection-screen begin of block b2 with frame title text-002.
parameters: status   like edidc-status default '52',
            msgty    like edids-statyp default 'I',
            msgid    like edids-stamid default 'ZEDI',
            msgno    like edids-stamno default '029',
            msgv1    like edids-stapa1 default sy-uname,
            msgv2    like edids-stapa2 default sy-datum,
            msgv3    like edids-stapa3,
            msgv4    like edids-stapa4.
selection-screen end of block b2.
selection-screen end of block b1.

*--- Initialization ---------------------------------------------------*
initialization.
  filename = 'C:\IDocs.xls'.

*--- START OF SELECTION TO DATABASE -----------------------------------*
start-of-selection.

* Check for XLS extension
  if not filename cs '.XLS'.

* You wish to upload an Excel file &. It must have extension .XLS
    message i078 with filename.
    exit.

  else.

    clear: return.
    perform upload_excel tables itab_idocs
                         using  filename
                         changing return.
    if return is initial.

* Confirm action
      clear t_answer.
      call function 'POPUP_TO_CONFIRM'
           exporting
                titlebar              = text-t01
                text_question         = text-t02
                text_button_1         = 'Yes'(t03)
                text_button_2         = 'No'(t04)
                default_button        = '2'
                display_cancel_button = 'X'
           importing
                answer                = t_answer
           exceptions
                text_not_found        = 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.

      else.

        if t_answer = '1'.   "Yes

          format color col_positive.
          write: /5 'Choose to continue.'.
          format color off.
          perform process_idocs tables itab_idocs
                                using  status msgty msgid msgno
                                       msgv1  msgv2 msgv3 msgv4.

        elseif t_answer = '2'.   "No

          format color col_negative.
          write: /5 'Choose not to continue. No records changed'.
          format color off.

        else.   "Cancel

          format color col_negative.
          write: /5 'Choose to cancel. No records changed'.
          format color off.

        endif.

      endif.

    endif.
  endif.

*--- AT SELECTION SCREEN ACTION ---------------------------------------*
at selection-screen on value-request for filename.

  call function 'AL_POPUP_FOR_LOCAL_PATH'
       importing
            filereturn = filename
       exceptions
            others     = 1.
Include Z_IDOC_STATUS_CHANGE_DATA
*----------------------------------------------------------------------*
***INCLUDE Z_IDOC_STATUS_CHANGE_DATA .
*----------------------------------------------------------------------*
*--- TABLES  DEFINITIONS ----------------------------------------------*
tables: edidc.

*--- STRUCTURE  DEFINITIONS -------------------------------------------*
types: begin of itab_idoc_structure,
        docnum like edidc-docnum.
types: end of itab_idoc_structure.

*--- INTERNAL TABLE AND WORK AREA DEFINITIONS -------------------------*
data: itab_idocs type standard table of itab_idoc_structure,
      wa_idocs   type itab_idoc_structure.

*--- VARIABLES --------------------------------------------------------*
data: return like sy-subrc,
      t_answer.
Include Z_IDOC_STATUS_CHANGE_FORMS
*----------------------------------------------------------------------*
***INCLUDE Z_IDOC_STATUS_CHANGE_FORMS .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  upload_excel
*&---------------------------------------------------------------------*
* Only handles Excel file upload - Column A has a list of IDoc numbers
* Maximum 2000 IDocs passed
*&---------------------------------------------------------------------*
form upload_excel tables   p_itab_idoc like itab_idocs
                  using    p_filename
                  changing p_return.

  data: file_name like  rlgrap-filename,
        file_type like  rlgrap-filetype,
        itab_excel like alsmex_tabline occurs 0 with header line.

  move p_filename to file_name.
  move 'XLS'      to file_type.

  refresh itab_excel.

  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       exporting
            filename                = file_name
            i_begin_col             = 1
            i_begin_row             = 1
            i_end_col               = 1
            i_end_row               = 2000
       tables
            intern                  = itab_excel
       exceptions
            inconsistent_parameters = 1
            upload_ole              = 2
            others                  = 3.
  if sy-subrc <> 0.
    p_return = sy-subrc.
    message i060 with sy-subrc file_name.
  else.
    loop at itab_excel.
      wa_idocs-docnum = itab_excel-value.
      select single docnum into edidc-docnum
        from edidc
        where docnum = wa_idocs-docnum.
      if sy-subrc = 0.
        collect wa_idocs into p_itab_idoc.
        write: /5 'IDoc', wa_idocs-docnum, 'added for processing.'.
      else.
        write: /5 wa_idocs-docnum, 'IGNORED for processing.'.
      endif.
    endloop.
    if sy-subrc <> 0.
      p_return = sy-subrc.
      message i061 with file_name.
    endif.
  endif.

endform.                    " upload_excel
*&---------------------------------------------------------------------*
*&      Form  process_idocs
*&---------------------------------------------------------------------*
form process_idocs tables   p_itab_idocs like itab_idocs
                   using    p_status
                            p_msgty
                            p_msgid
                            p_msgno
                            p_msgv1
                            p_msgv2
                            p_msgv3
                            p_msgv4.

  data: bdidocstat like bdidocstat occurs 0 with header line.

  loop at p_itab_idocs into wa_idocs.

    refresh bdidocstat.

    bdidocstat-docnum = wa_idocs-docnum.       "IDoc number
    bdidocstat-status = p_status.              "IDoc status
    bdidocstat-msgty  = p_msgty.               "Message type
    bdidocstat-msgid  = p_msgid.               "Message ID
    bdidocstat-msgno  = p_msgno.               "Message number
    bdidocstat-msgv1  = p_msgv1.               "Message variable 1
    bdidocstat-msgv2  = p_msgv2.               "Message variable 2
    bdidocstat-msgv3  = p_msgv3.               "Message variable 3
    bdidocstat-msgv4  = p_msgv4.               "Message variable 4
    append bdidocstat.

    call function 'IDOC_STATUS_WRITE_TO_DATABASE'
         exporting
              idoc_number               = wa_idocs-docnum
              no_dequeue_flag           = 'X'
         tables
              idoc_status               = bdidocstat
         exceptions
              idoc_foreign_lock         = 1
              idoc_not_found            = 2
              idoc_status_records_empty = 3
              idoc_status_invalid       = 4
              db_error                  = 5
              others                    = 6.

    if sy-subrc <> 0.
      format color col_negative.
      write: /10 'IDoc', wa_idocs-docnum, 'had NO status update!'.
      format color off.
    else.
      write: /10 'IDoc', wa_idocs-docnum,
                 'has had it''s status updated'.
    endif.

  endloop.

endform.                    " process_idocs

IDocExcelUpload.doc

50.5 KB, 下载次数: 110, 下载积分: 努力值 -5 点

发表于 2007/8/3 14:47:38 | 显示全部楼层
楼主幸苦咯。
发表于 2007/8/6 10:18:40 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2007/8/31 09:02:07 | 显示全部楼层
谢谢楼主提供宝贵资料~~~~~~~~~~~~~~~~~~
发表于 2007/9/12 20:52:11 | 显示全部楼层

sssssssssssss

ssssssss
发表于 2007/9/27 16:55:42 | 显示全部楼层
太感谢搂主了,正在找呢
发表于 2007/10/4 15:34:05 | 显示全部楼层
DING................................
发表于 2007/10/10 08:46:22 | 显示全部楼层
学习一下,多谢了!
发表于 2007/10/16 09:04:19 | 显示全部楼层
已经下载,谢谢!!
发表于 2007/11/3 16:16:11 | 显示全部楼层
太感谢搂主了
发表于 2007/12/3 13:07:55 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:10:47 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:11:26 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:12:26 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:13:18 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:13:54 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:14:44 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:15:07 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:17:01 | 显示全部楼层
★感谢这里,给我这么难得的机会★
发表于 2007/12/3 13:19:40 | 显示全部楼层
★感谢这里,给我这么难得的机会★
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 04:28 , Processed in 0.025694 second(s), 17 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表