sapdev logo background
sapdev logo sapdev logo
Comments

Validate WBS (code used in ME21)




The below ABAP code shows one use for COBL_CODINGBLOCK_CHECK which is a function module used by ME21(purchase order creation) during validation of WBS, Cost center or Internal order. The example below validates a WBS to see if it is technically closed (TECO).

Please note I am not entirly sure of the full use of this function module but this provides documentation of uses so far and a basis for further development.

  data: ld_cobl like cobl,
        it_mess type standard table of bapireturn1 initial size 0,
        wa_mess type bapireturn.

  ld_cobl-vorgn   = 'RMBE'.              "Value from ME21
  ld_cobl-awtyp      = 'PORD'.           "Value from ME21
  ld_cobl-budat      = sy-datum.
  ld_cobl-bukrs      = zimt_bukrs.       "Company code
  ld_cobl-werks      = zimt-werks.       "
  ld_cobl-process    = 'BEST'.           "Value from ME21
  ld_cobl-event      = 'CHECKALL'.       "Value from ME21
  ld_cobl-gjahr      = sy-datum(4).
  ld_cobl-PS_PSP_PNR = zimk-pspnr       "WBS internal number

* converts WBS internal number to external format
*                              e.g. 3426 to CP.222111.001 
  call function 'PSPNUM_INTERN_TO_EXTERN_CONV'
       exporting
*         EDIT_IMP  =  
            int_num   = ld_cobl-PS_PSP_PNR
      importing
           ext_num   = ld_cobl-ps_posid
      exceptions
           not_found = 1
           others    = 2.
  if sy-subrc eq 0.
    call function 'COBL_CODINGBLOCK_CHECK'
         exporting
              check_cobl              = ld_cobl
*            PBO_COBL                =  
              cust_fields_dynp_checks = 'X'
              collect_messages        = 'X'
              external_fields_used    = ' '
*      IMPORTING
*           CHECKED_COBL            =  
         tables
             t_messages               = it_mess  .

*   check if message has been returned
    loop at it_mess into wa_mess.
*     check if message is technically closed message (TECO)
      if sy-msgid = 'BS'  and
         sy-msgty = 'E'   and
         sy-msgno = '013' and
         sy-msgv1 = 'TECO'.
        message id sy-msgid type sy-msgty number sy-msgno
           with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    endloop.
  endif.




comments powered by Disqus