BAPI使用HR_INFOTYPE_OPERATION函数批量导入HR信息纪录代码样例(0759信息类型)

report  zp_pa_ecm_conv_0759
        no standard page heading.
 
* tables
tables:
       pernr.  "Standard Selections for HR Master Data
 
* infotypes
infotypes:
    0001,    "Org Assignment
    0008,    "Basic Pay  "SD1K911053
    0758,    "Compensation Program
    0759.    "Compensation Process
 
* data declarations
* Types
type-pools : slis.   "Global data for ALV
 
* alv field catalog
data: t_fieldcat type slis_t_fieldcat_alv with header line.
 
*constants
constants:
      c_usd   type waers             value 'USD',     "Currency  "SD1K913769
      c_pernr(5)                     value 'PERNR',   "Pers no
      c_sname(5)                     value 'SNAME',   "Emp Name
      c_werks(5)                     value 'WERKS',   "Pers Area
      c_btrtl(5)                     value 'BTRTL',   "Pers Subarea
      c_persg(5)                     value 'PERSG',   "Emp Grp
      c_persk(5)                     value 'PERSK',   "Emp Subgrp
      c_orgeh(5)                     value 'ORGEH',   "Org Unit
      c_citem(5)                     value 'CITEM',   "Comp Review Item
      c_effdt(5)                     value 'EFFDT',   "Effective date
      c_0759  type infty             value '0759',    "Comp Process
      c_tclas type pspar-tclas       value 'A',       "Transaction class for data storage
      c_actio type pspar-actio       value 'INS',     "Infotype operation
      c_10    type ecm_carea         value '10',      "Comp Area
      c_background_id type bds_typeid value 'PMMN_BACKGROUND'.  "ALV background
 
 
* work fields
data:
       w_title type lvc_title,                      "#EC NEEDED  "Title
       w_count type i.      "no of recs
 
* field strings
* return structure
data: rec_return type bapiret1.   "return code
 
* internal tables
data:
     begin of t_out occurs 0,
      pernr   type pernr_d,         "Pers. No
      sname   type smnam,           "Employee name
      werks   type persa,           "Pers Area
      btrtl   type btrtl,           "Pers Subarea
      persg   type persg,           "Emp Group
      persk   type persk,           "Emp Subgrp
      orgeh   type orgeh,           "Org. Unit
      citem   type ecm_citem,       "Compensation Review Item
      effdt   type ecm_effdt,       "Effective date
      bssal   type ecm_bssal,       "Caluclation Base  "SD1K913769
      curre   type waers,           "Currency          "SD1K913769
end of t_out.
 
* error table
data:
      begin of t_error occurs 0,
       pernr type pernr_d,   "Pers no
       sname type sname,     "Emp Name
       citem type ecm_citem, "Review item
       effdt type ecm_effdt, "effective date
      end of t_error.
 
data t_events  type slis_t_event.   "ALV top of page
 
 
* temp table to store comp data
data:
     begin of t_citem occurs 0,
      cplan type ecm_cplan,   "Comp Plan
      citem type ecm_citem,   "Review Item
      effdt type ecm_effdt,   "Effective date
      cpgr1 type ecm_cpgr1,   "1st Program grouping
      cpgr2 type ecm_cpgr2,   "2nd Program grouping
     end of t_citem.
 
 
* selection screen
selection-screen begin of block abc with frame title text-001.
parameters:
             p_crevi like t71adm08-crevi.  "Comp Review "SD1K913769
* begin of change  "SD1K911053
select-options:
             s_trfst for p0008-trfst.  "Pay Scale Level
parameters:
* end of change  "SD1K911053
             p_test as checkbox.                 "Test option
selection-screen end of block abc.
 
************************************************************************
* PROCESSING
************************************************************************
* initialization.
initialization.
  perform eventtab_build using t_events[].
 
* start of selection
start-of-selection.
 
* get all the relevant Comp Review items for the comp review entered on
* the selection screen
  perform fill_citem.
 
 
get pernr.
  clear: p0001,p0758,p0008.                                 "SD1K911053
* Validate Pay Scale level with selection screen values     "SD1K911053
  rp-provide-from-last p0008 space pn-begda pn-endda.       "SD1K911053
  check p0008-trfst in s_trfst.                             "SD1K911053
 
* Obtain Org Info from infotype 0001
  rp-provide-from-last p0001 space pn-begda pn-endda.
  check pnp-sw-found eq 1.
 
* Obtain Compensation Program details from infotype 0758
  rp-provide-from-last p0758 space pn-begda pn-endda.
  check pnp-sw-found eq 1.
 
* fill the output table with info from 0001 , 0758 & the
* temp table t_citem
  loop at t_citem where cpgr1 = p0758-cpgr1
                    and cpgr2 = p0758-cpgr2.
    t_out-pernr   =   pernr-pernr.
    t_out-sname   =   p0001-sname.
    t_out-werks   =   p0001-werks.
    t_out-btrtl   =   p0001-btrtl.
    t_out-persg   =   p0001-persg.
    t_out-persk   =   p0001-persk.
    t_out-orgeh   =   p0001-orgeh.
    t_out-citem   =   t_citem-citem.
    t_out-effdt   =   t_citem-effdt.
    rp-provide-from-last p0008 space t_citem-effdt t_citem-effdt."SD1K913769
    t_out-bssal   =   p0008-ansal.                          "SD1K913769
    t_out-curre   =   c_usd.                                "SD1K913769
    append t_out.
    clear t_out.
  endloop.
 
end-of-selection.
* check if any data selected for processing
  if t_out[] is initial.
* no data found.
    write:/ 'No data found'(004).
  else.
    if p_test eq space.
* If test option is not selected, create infotype 0759 records
* using standard function module.
      perform create_0759.
      if not t_error[] is initial.
* display errors
        perform write_error.
      endif.
      if w_count eq 1.
        message s016(rp) with  w_count 'record was updated'(002).
* ALV display of records that will be updated
        perform list_display.
      else.
        message s016(rp) with w_count 'records were updated'(003).
* ALV display of records that will be updated
        perform list_display.
      endif.
    else.
* ALV display of records that will be updated
      perform list_display.
    endif.
  endif.
 
*&---------------------------------------------------------------------*
*&      Form EVENTTAB_BUILD
*&---------------------------------------------------------------------*
form eventtab_build using t_lt_events type slis_t_event.
  data: rec_event type slis_alv_event.
  constants: c_top_of_page(11) value 'TOP_OF_PAGE'.
  call function 'REUSE_ALV_EVENTS_GET'
    exporting
      i_list_type = 0
    importing
      et_events   = t_lt_events.
  read table t_lt_events with key name =  slis_ev_top_of_page
                           into rec_event.
  if sy-subrc = 0.
    move c_top_of_page to rec_event-form.
    append rec_event to t_lt_events.
  endif.
endform.                    "EVENTTAB_BUILD
 
*&---------------------------------------------------------------------*
*&      Form  fill_citem
*&---------------------------------------------------------------------*
form fill_citem .
  select a~cplan a~citem b~effdt c~cpgr1 c~cpgr2 into table t_citem
                  from t71adm09 as a
                       inner join t71adm10 as b on a~citem = b~citem
                       inner join t71adm07 as c on a~cplan = c~cplan
                                               and b~carea = c~carea
                                             where a~crevi = p_crevi
                                               and b~carea = c_10.
 
  if sy-subrc ne 0.
    clear t_citem[].
  else.
    sort t_citem.
  endif.
endform.                    " fill_citem
*&---------------------------------------------------------------------*
*&      Form  list_display
*&---------------------------------------------------------------------*
form list_display .
* fill ALV filed catalog ( column names )
  perform fill_fieldcat using c_pernr  9  'Pers. No'(005).
  perform fill_fieldcat using c_sname  40 'Employee Name'(006).
  perform fill_fieldcat using c_werks  10 'Pers. Area'(007).
  perform fill_fieldcat using c_btrtl  13 'Pers. Subarea'(008).
  perform fill_fieldcat using c_persg  14 'Employee Group'(009).
  perform fill_fieldcat using c_persk  17 'Employee Subgroup'(010).
  perform fill_fieldcat using c_orgeh  9  'Org. Unit'(011).
  perform fill_fieldcat using c_citem  9  'Comp Review Item'(012).
  perform fill_fieldcat using c_effdt  10 'Effectiev Date'(013).
  w_title = sy-title.
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_background_id    = c_background_id
      i_callback_program = sy-repid
      i_grid_title       = w_title
      it_fieldcat        = t_fieldcat[]
      it_events          = t_events[]
    tables
      t_outtab           = t_out
    exceptions
      program_error      = 1
      others             = 2.
  if sy-subrc ne 0.
    message e208(00) with 'Error in FM REUSE_ALV_GRID_DISPLAY'(014).
  endif.
 
endform.                    " list_display
*&---------------------------------------------------------------------*
*&      Form  fill_fieldcat
*&---------------------------------------------------------------------*
form fill_fieldcat  using    p_fieldname type c
                             p_length type i
                             p_header type c.
  t_fieldcat-fieldname     = p_fieldname.
  t_fieldcat-outputlen     = p_length.
  t_fieldcat-seltext_m     = p_header.
  t_fieldcat-seltext_l     = p_header.
  t_fieldcat-reptext_ddic  = p_header.
  append t_fieldcat.
  clear t_fieldcat.
endform.                    " fill_fieldcat
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
form top_of_page .                                          "#EC CALLED
  data: t_list_top_of_page type slis_t_listheader.
  data: ls_line type slis_listheader.
*
  constants: c_h value 'H'.
 
* List Type
  clear ls_line.
  ls_line-typ  = c_h.
* LS_LINE-KEY:  not used for this type
  ls_line-info = sy-title.
  append ls_line to t_list_top_of_page.
 
  call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
      it_list_commentary = t_list_top_of_page.
 
* end of change SD1K910827
endform.                    " top_of_page
 
*&---------------------------------------------------------------------*
*&      Form  create_0759
*&---------------------------------------------------------------------*
form create_0759 .
  refresh p0759.
  clear p0759.
  loop at t_out.
* Enqueue personnel number
    call function 'BAPI_EMPLOYEE_ENQUEUE'
      exporting
        number = t_out-pernr
      importing
        return = rec_return.
    if not rec_return is initial.
* fill the error tab & continue with the next loop pass
      t_error-pernr = t_out-pernr.
      t_error-sname = t_out-sname.
      t_error-citem = t_out-citem.
      t_error-effdt = t_out-effdt.
      append t_error.
      clear t_error.
    else.
* fill the p0759 record structure
      p0759-pernr         = t_out-pernr.
      p0759-infty         = c_0759.
      p0759-citem         = t_out-citem.
      p0759-begda         = t_out-effdt.
      p0759-endda         = t_out-effdt.
      p0759-cstat         = 1.
      p0759-carea         = c_10.
      p0759-cpamt         = 0.
      p0759-bssal         = t_out-bssal.                    "SD1K913769
      p0759-curre         = t_out-curre.                    "SD1K913769
* update infotype 0759 using std function module
      call function 'HR_INFOTYPE_OPERATION'
        exporting
          infty         = c_0759
          number        = t_out-pernr
          record        = p0759
          validityend   = p0759-endda
          validitybegin = p0759-begda
          operation     = c_actio
          tclas         = c_tclas
        importing
          return        = rec_return.
* if the update is successful increment the count, else
* pass the record to error table for display in the end
      if rec_return is initial.
        w_count = w_count + 1.
      else.
        t_error-pernr = t_out-pernr.
        t_error-sname = t_out-sname.
        t_error-citem = t_out-citem.
        t_error-effdt = t_out-effdt.
        append t_error.
        clear t_error.
      endif.
    endif.
  endloop.
 
endform.                    " create_0759
*&---------------------------------------------------------------------*
*&      Form  write_error
*&---------------------------------------------------------------------*
form write_error .
  skip.
  write:/3 'List of records that were not updated'(015).
  loop at t_error.
    if sy-tabix eq 1.
      uline /(80).
      write:/ sy-vline,       'Pers. No'(016),
           12 sy-vline,    13 'Emp. Name'(017),
           47 sy-vline,    48 'Comp Review Item'(018),
           58 sy-vline,    59 'Effective Date'(019),
           80 sy-vline.
      uline /(80).
    endif.
    write:/ sy-vline,          t_error-pernr under text-016,
         12 sy-vline,          t_error-sname under text-017,
         47 sy-vline,          t_error-citem under text-018,
         58 sy-vline,          t_error-effdt under text-019 mm/dd/yyyy,
         80 sy-vline.
    uline /(80).
  endloop.
 
endform.                    " write_error

原文地址:https://www.cnblogs.com/xiaomaohai/p/6157195.html