0
点赞
收藏
分享

微信扫一扫

ME54N 采购申请审批


保存增强

EXIT_SAPLMEREQ_010

点审批和点保存都会进来,点审批的时候进来的数据是审批状态改变前的,所以不要做检查,在保存时检查

发送邮件

可以增强自己写发送邮件代码

也可以使用标准的工作流邮件功能

工作流相关tcode

SWELS打开trace,me54n审批保存,SWEL查看trace结果

SWO1 看BOR Object type,SWE3 看 BOR object type 和回调函数的关联

配置

ME54N 采购申请审批_增强

SWETYPV 根据object type 看 workflow number,SWDD查看workflow

debug

起点:触发工作流是在保存时的 update task 里 call trfc 的

PROCESS (CL_SWF_EVT_STRATEGY_SIBF_FB)

ME54N 采购申请审批_增强_02

ME54N 采购申请审批_发送邮件_03

调试BOR:开系统调试,用户WF-BATCH外部断点SWO_INVOKE_INTERNAL 92行

ME54N 采购申请审批_hive_04

发送邮件:函数SWW_SRV_MAIL_SEND

demo

*****           Implementation of object type ZBUS2009             *****

include <object>.

begin_data object. " Do not change.. DATA is generated

* only private members may be inserted into structure private

data:

" begin of private,

"   to declare private attributes remove comments and

"   insert private attributes here ...

" end of private,

  begin of key,

      number like eban-banfn,

      item like eban-bnfpo,

  end of key,

      prrelease type swc_object,

      costcenterinternalorder type coas-cycle,

      rejectiontext type tline-tdline occurs 0,

      createdbyuseremail type adr6-smtp_addr,

      createdbyuser type wfsyst-agent,

      createdbyfullname type swldy_list-wi_aagt_n,

      agentname type addr3_val-name_text,

      _anla like anla,

      _anlz like anlz,

      _coas like coas,

      _ebkn like ebkn,

      _t001k like t001k.

end_data object. " Do not change.. DATA is generated

tables t001k.

*

get_table_property t001k.

data : subrc like sy-subrc,

     lv_werks type werks.

select  single werks from  eban into  lv_werks

       where  banfn  =  object-key-number

       and    bnfpo  = object-key-item.

* Fill TABLES T001K to enable Object Manager Access to Table Properties

perform select_table_t001k using subrc  lv_werks.

if subrc ne 0.

  exit_object_not_found.

endif.

end_property.

*

* Use Form also for other(virtual) Properties to fill TABLES T001K

form select_table_t001k using subrc like sy-subrc

      lv_werks type werks.

* Select single * from T001K, if OBJECT-_T001K is initial

  if object-_t001k-mandt is initial

  and object-_t001k-bwkey is initial.

    select single * from t001k client specified

        where mandt = sy-mandt

        and bwkey = lv_werks.

    subrc = sy-subrc.

    if subrc ne 0. exit. endif.

    object-_t001k = t001k.

  else.

    subrc = 0.

    t001k = object-_t001k.

  endif.

endform.                    "SELECT_TABLE_T001K

tables ebkn.

*

get_table_property ebkn.

data subrc like sy-subrc.

* Fill TABLES EBKN to enable Object Manager Access to Table Properties

perform select_table_ebkn using subrc.

if subrc ne 0.

  exit_object_not_found.

endif.

end_property.

*

* Use Form also for other(virtual) Properties to fill TABLES EBKN

form select_table_ebkn using subrc like sy-subrc.

* Select single * from EBKN, if OBJECT-_EBKN is initial

  if object-_ebkn-mandt is initial

  and object-_ebkn-banfn is initial

  and object-_ebkn-bnfpo is initial

  and object-_ebkn-zebkn is initial.

    select single * from ebkn client specified

        where mandt = sy-mandt

        and banfn = object-key-number

        and bnfpo = object-key-item.

*        AND ZEBKN = ??????????.

    subrc = sy-subrc.

    if subrc ne 0. exit. endif.

    object-_ebkn = ebkn.

  else.

    subrc = 0.

    ebkn = object-_ebkn.

  endif.

endform.                    "SELECT_TABLE_EBKN

tables anlz.

*

get_table_property anlz.

data subrc like sy-subrc.

data: lv_anln1 type ebkn-anln1,

      lv_bukrs type bukrs.

swc_get_property self 'CompanyCode' lv_bukrs.

swc_get_property self 'asset' lv_anln1.

* Fill TABLES ANLZ to enable Object Manager Access to Table Properties

perform select_table_anlz using subrc lv_bukrs lv_anln1.

if subrc ne 0.

  exit_object_not_found.

endif.

end_property.

*

* Use Form also for other(virtual) Properties to fill TABLES ANLZ

form select_table_anlz using subrc like sy-subrc

lv_bukrs type bukrs

lv_anln1 type anln1.

* Select single * from ANLZ, if OBJECT-_ANLZ is initial

  if object-_anlz-mandt is initial

  and object-_anlz-bukrs is initial

  and object-_anlz-anln1 is initial.

    select single * from anlz client specified

        where mandt = sy-mandt

        and bukrs = lv_bukrs

        and anln1 = lv_anln1.

    subrc = sy-subrc.

    if subrc ne 0. exit. endif.

    object-_anlz = anlz.

  else.

    subrc = 0.

    anlz = object-_anlz.

  endif.

endform.                    "SELECT_TABLE_ANLZ

tables coas.

*

get_table_property coas.

data subrc like sy-subrc.

data : lv_aufnr type aufnr.

select single aufnr from  ebkn client specified into lv_aufnr

       where  mandt  = sy-mandt

       and    banfn  = object-key-number

       and    bnfpo  = object-key-item.

if lv_aufnr is not initial .

* Fill TABLES COAS to enable Object Manager Access to Table Properties

  perform select_table_coas using subrc  lv_aufnr.

  if subrc ne 0.

    exit_object_not_found.

  endif.

endif.

end_property.

*

* Use Form also for other(virtual) Properties to fill TABLES COAS

form select_table_coas using subrc like sy-subrc

      lv_aufnr type aufnr.

* Select single * from COAS, if OBJECT-_COAS is initial

  if object-_coas-mandt is initial

  and object-_coas-aufnr is initial.

    select single * from coas client specified

        where mandt = sy-mandt

        and aufnr =  lv_aufnr.

    subrc = sy-subrc.

    if subrc ne 0. exit. endif.

    object-_coas = coas.

  else.

    subrc = 0.

    coas = object-_coas.

  endif.

endform.                    "SELECT_TABLE_COAS

tables anla.

*

get_table_property anla.

data subrc like sy-subrc.

data: lv_anln1 type ebkn-anln1,

      lv_bukrs type bukrs.

swc_get_property self 'CompanyCode' lv_bukrs.

swc_get_property self 'asset' lv_anln1.

* Fill TABLES ANLA to enable Object Manager Access to Table Properties

perform select_table_anla using subrc lv_bukrs lv_anln1.

if subrc ne 0.

  exit_object_not_found.

endif.

end_property.

*

* Use Form also for other(virtual) Properties to fill TABLES ANLA

form select_table_anla using subrc like sy-subrc

      lv_bukrs type bukrs

      lv_anln1 type anln1.

* Select single * from ANLA, if OBJECT-_ANLA is initial

  if object-_anla-mandt is initial

  and object-_anla-bukrs is initial

  and object-_anla-anln1 is initial

  and object-_anla-anln2 is initial.

    select single * from anla client specified

        where mandt = sy-mandt

        and bukrs = lv_bukrs

        and anln1 = lv_anln1.

    subrc = sy-subrc.

    if subrc ne 0. exit. endif.

    object-_anla = anla.

  else.

    subrc = 0.

    anla = object-_anla.

  endif.

endform.                    "SELECT_TABLE_ANLA

get_property costcenterinternalorder changing container.

data : lv_intorder type anla-eaufn.

swc_get_property self 'InternalOrder' lv_intorder.

if lv_intorder is not initial.

  select single cycle  from coas client specified into object-costcenterinternalorder

          where mandt = sy-mandt

          and aufnr =  lv_intorder.

endif.

swc_set_element container 'CostCenterInternalOrder'

     object-costcenterinternalorder.

end_property.

get_property rejectiontext changing container.

data: lt_lines type table of tline .

data: lv_line type tdline .

data: lv_name type tdobname .

data: lv_spras type spras.

lv_name = object-key .

clear object-rejectiontext .

field-symbols: <ls_lines> like line of lt_lines.

select single tdspras from stxh

into lv_spras

where tdobject = 'EBAN'

and tdname = lv_name

and tdid = 'B07'.

call function 'READ_TEXT'

  exporting

    client                  = sy-mandt

    id                      = 'B07'

    language                = lv_spras

    name                    = lv_name

    object                  = 'EBAN'

  tables

    lines                   = lt_lines

  exceptions

*   ID                      = 1

*   LANGUAGE                = 2

*   NAME                    = 3

*   NOT_FOUND               = 4

*   OBJECT                  = 5

*   REFERENCE_CHECK         = 6

*   WRONG_ACCESS_TO_ARCHIVE = 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.

endif.

loop at lt_lines assigning <ls_lines> .

  append <ls_lines>-tdline to object-rejectiontext .

endloop .

swc_set_table container 'RejectionText' object-rejectiontext.

end_property.

get_property createdbyuseremail changing container.

data: lv_ernam type ernam.

data: lv_email type ad_smtpadr.

data: lt_error type standard table of rpbenerr.

swc_get_property self 'CreatedBy' lv_ernam.

*-------------------------------------------------------

*11.02.2022 09:00:54 chenyl for alex

*取HR地址变更为取SU01地址

select single adr6~smtp_addr

  into lv_email

  from usr21

  inner join adr6 on usr21~persnumber = adr6~persnumber and usr21~addrnumber = adr6~addrnumber

  where usr21~bname = lv_ernam.

*-------------------------------------------------------

*CALL FUNCTION 'HR_FBN_GET_USER_EMAIL_ADDRESS'

*  EXPORTING

*    user_id       = lv_ernam

*    reaction      = ''

*  IMPORTING

*    email_address = lv_email

**   SUBRC         =

*  TABLES

*    error_table   = lt_error.

object-createdbyuseremail = lv_email.

swc_set_element container 'CreatedByUserEmail'

     object-createdbyuseremail.

end_property.

get_property createdbyfullname changing container.

data: lv_agent type swlwi_list-wi_aagent.

swc_get_property self 'CreatedBy' lv_agent.

call function 'SWL_AGENTS_NAME_DETERMIN'

  exporting

    agent            = lv_agent

*   CHECK_HIDE_AGENT = 'X'

  importing

    agent_name       = object-createdbyfullname.

swc_set_element container 'CreatedByFullName'

     object-createdbyfullname.

end_property.

get_property createdbyuser changing container.

data: lv_user type wfsyst-agent.

swc_get_property self 'CreatedBy' lv_user.

concatenate 'US' lv_user into object-createdbyuser.

swc_set_element container 'CreatedByUser' object-createdbyuser.

end_property.

get_property agentname changing container.

swc_set_element container 'AgentName' object-agentname.

end_property.

begin_method setagentname changing container.

data: agentname like addr3_val-name_text .

swc_get_element container 'AgentName' agentname.

object-agentname = agentname.

swc_set_element container 'AgentName'

     object-agentname.

end_method.

get_property prrelease changing container.

data: lo_zbs2009r type swc_object.

data: lv_key type sww_wi2obj-instid.

concatenate object-key-number object-key-item into lv_key.

swc_create_object lo_zbs2009r 'ZBS2009R' lv_key.

swc_set_element container 'PRRelease' lo_zbs2009r.

end_property.

begin_method releaseinformationget changing container.

data: releaseinfirmation type tline-tdline occurs 0.

data: lv_frgzu type eban-frgzu.

data: lv_frgst type eban-frgst.

data: lv_frggr type eban-frggr.

data: ls_t16fs type t16fs.

data: lv_objectid type cdhdr-objectid.

data: lv_tablekey type cdpos-tabkey.

data: lt_editpos type standard table of cdred.

data: ls_editpos like line of lt_editpos.

data: lv_approver type cdred-username.

data: lv_approver_full_name type swr_wihdr-wi_aa_name.

data: lv_length type i.

data: lv_length_c type c.

data: lv_fieldname type fieldname.

data: lv_key type swotobjid-objkey.

data: lt_wi_container type standard table of swcont.

data: ls_wi_container like line of lt_wi_container.

data: lt_worklist type standard table of swr_wihdr.

data: ls_worklist like line of lt_worklist.

data: lv_agent type  swlwi_list-wi_aagent.

data: lv_name type swldy_list-wi_aagt_n.

data: lv_line type tline-tdline.

data: lt_actor type standard table of swhactor.

data: ls_actor like line of lt_actor.

data: lo_req_item type ref to zcl_wf_req_item_offline_data.

data: lt_t16fd type standard table of t16fd.

data: ls_t16fd like line of lt_t16fd.

field-symbols: <field_value> type any.

refresh releaseinfirmation[].

swc_get_property self 'ReleaseStatus' lv_frgzu.

swc_get_property self 'ReleaseStrategy' lv_frgst.

swc_get_property self 'ReleaseGroup' lv_frggr.

concatenate object-key-number object-key-item into lv_key.

**release strategy

select single *

  from t16fs into ls_t16fs

 where frggr = lv_frggr

   and frgsx = lv_frgst.

**release code description

select *

  from t16fd

  into table lt_t16fd

 where spras = 'E'

   and frggr = lv_frggr.

** approved by

lv_length = strlen( lv_frgzu ).

lv_length_c = lv_length.

concatenate 'FRGC' lv_length_c into lv_fieldname.

assign component lv_fieldname of structure ls_t16fs to <field_value>.

lv_objectid = object-key-number.

concatenate sy-mandt object-key-number object-key-item into lv_tablekey.

call function 'CHANGEDOCUMENT_READ'

  exporting

*   ARCHIVE_HANDLE                   = 0

*   CHANGENUMBER                     = ' '

*   DATE_OF_CHANGE                   = '00000000'

    objectclass                      = 'BANF'

    objectid                         = lv_objectid

    tablekey                         = lv_tablekey

    tablename                        = 'EBAN'

*   TIME_OF_CHANGE                   = '000000'

*   USERNAME                         = ' '

*   LOCAL_TIME                       = ' '

*   TIME_ZONE                        = 'UTC'

*   TABLEKEY254                      = ' '

*   KEYGUID                          = ' '

*   DATE_UNTIL                       = '99991231'

*   TIME_UNTIL                       = '235959'

*   KEYGUID_STR                      = ' '

*   READ_CHANGEDOCU                  = ' '

* IMPORTING

*   ET_CDRED_STR                     =

  tables

    editpos                          = lt_editpos

 exceptions

   no_position_found                = 1

   wrong_access_to_archive          = 2

   time_zone_conversion_error       = 3

   others                           = 4

          .

if sy-subrc <> 0.

* Implement suitable error handling here

endif.

sort lt_editpos by changenr descending.

read table lt_editpos into ls_editpos

  with key fname = 'FRGZU'

           f_new = lv_frgzu.

if sy-subrc = 0.

  lv_approver = ls_editpos-username.

endif.

if lv_approver = 'WF-BATCH'. "get actual approver from WF

  call function 'SAP_WAPI_WORKITEMS_TO_OBJECT'

    exporting

*         OBJECT_POR               =

      objtype                  = 'BUS2009'

      objkey                   = lv_key

      top_level_items          = ' '

      selection_status_variant = 0000

*         TIME                     =

*         TEXT                     = 'X'

*         OUTPUT_ONLY_TOP_LEVEL    = ' '

*         LANGUAGE                 = SY-LANGU

*         DETERMINE_TASK_FILTER    = 'X'

*         REMOVED_OBJECTS          = ' '

*        IMPORTING

*         RETURN_CODE              =

    tables

*         TASK_FILTER              =

      worklist                 = lt_worklist

*         MESSAGE_LINES            =

*         MESSAGE_STRUCT           =

    .

*  lv_length = strlen( lv_frgzu ).

*  lv_length_c = lv_length.

*  CONCATENATE 'FRGC' lv_length_c INTO lv_fieldname.

*  ASSIGN COMPONENT lv_fieldname OF STRUCTURE ls_t16fs TO <field_value>.

  if not <field_value> is initial.

    sort lt_worklist by wi_id descending.

    loop at lt_worklist into ls_worklist

      where wi_rh_task = 'TS92700357'

      and wi_stat = 'COMPLETED'.

      call function 'SWW_WI_CONTAINER_READ'

        exporting

          wi_id                          = ls_worklist-wi_id

*         IMPORTING

*           WI_CONTAINER_HANDLE            =

       tables

         wi_container                   = lt_wi_container

*         CHANGING

*           WI_HEADER                      =

       exceptions

         container_does_not_exist       = 1

         read_failed                    = 2

         others                         = 3

                .

      if sy-subrc <> 0.

* Implement suitable error handling here

      endif.

      read table lt_wi_container into ls_wi_container

      with key element = 'RELEASECODE'

               value = <field_value>.

      if sy-subrc = 0.

        lv_approver = ls_worklist-wi_aagent.

        lv_approver_full_name = ls_worklist-wi_aa_name.

        exit.

      endif.

    endloop.

  endif.

else.

  lv_agent = lv_approver.

  call function 'SWL_AGENTS_NAME_DETERMIN'

    exporting

      agent            = lv_agent

*     CHECK_HIDE_AGENT = 'X'

    importing

      agent_name       = lv_name.

  lv_approver_full_name = lv_name.

endif.

read table lt_t16fd into ls_t16fd

with key frgco = <field_value>.

concatenate 'was last approved by' ls_t16fd-frgct '-' lv_approver_full_name into lv_line separated by space.

concatenate lv_line '.' into lv_line.

append lv_line to releaseinfirmation.

** next approver

lv_length_c = lv_length_c + 1.

concatenate 'FRGC' lv_length_c into lv_fieldname.

assign component lv_fieldname of structure ls_t16fs to <field_value>.

if not <field_value> is initial.

  create object lo_req_item.

  call method lo_req_item->/dps/if_ex_wf_req_item_offline~agent_get

    exporting

      iv_banfn = object-key-number

      iv_bnfpo = object-key-item

      iv_frgco = <field_value>

    importing

      et_actor = lt_actor.

  if not lt_actor[] is initial.

    read table lt_actor into ls_actor index 1.

    lv_agent = ls_actor-objid.

    call function 'SWL_AGENTS_NAME_DETERMIN'

      exporting

        agent            = lv_agent

*       CHECK_HIDE_AGENT = 'X'

      importing

        agent_name       = lv_name.

    lv_approver_full_name = lv_name.

    read table lt_t16fd into ls_t16fd

    with key frgco = <field_value>.

    concatenate 'Next Approver:' ls_t16fd-frgct '-' lv_approver_full_name into lv_line separated by space.

    concatenate lv_line '.' into lv_line.

    append lv_line to releaseinfirmation.

  endif.

else.

  lv_line = 'The item was fully approved'.

  append lv_line to releaseinfirmation.

endif.

swc_set_table container 'ReleaseInfirmation' releaseinfirmation.

end_method.

begin_method approveragentget changing container.

data: lv_releasecode type t16fc-frgco.

data: lv_agent type  usr01-bname.

data: lv_agentname type addr3_val-name_text.

data: lt_actor type standard table of swhactor.

data: lo_req_item type ref to zcl_wf_req_item_offline_data.

data: tmp_user_adr type addr3_val.

swc_get_element container 'ReleaseCode' lv_releasecode.

create object lo_req_item.

call method lo_req_item->/dps/if_ex_wf_req_item_offline~agent_get

  exporting

    iv_banfn = object-key-number

    iv_bnfpo = object-key-item

    iv_frgco = lv_releasecode

  importing

    et_actor = lt_actor.

read table lt_actor into lv_agent index 1.

lv_agent = lv_agent+2.

call function 'SUSR_USER_ADDRESS_READ'

  exporting

    user_name              = lv_agent

*   READ_DB_DIRECTLY       = ' '

  importing

    user_address           = tmp_user_adr

*   user_usr03             =

  exceptions

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

endif.

lv_agentname = tmp_user_adr-name_text.

swc_set_element container 'Agent' lv_agentname.

end_method.

begin_method releasecodedescription changing container.

data: lv_frgco type t16fc-frgco.

data: lv_codedescription type t16fd-frgct.

data:lv_frggr type frggr.

swc_get_element container 'ReleaseCode' lv_frgco.

swc_get_property self  'ReleaseGroup' lv_frggr.

select single frgct

from t16fd

into lv_codedescription

where frgco = lv_frgco

and frggr = lv_frggr

and spras = 'E'.

swc_set_element container 'RelCodeDescription' lv_codedescription.

end_method.


举报

相关推荐

0 条评论