ZXCOFU14

<< Click to Display Table of Contents >>

Navigation:  All About ABAP Technique > Indonesia > ABAP Tutorial > ABAP Workbench Tools  > Enhancement > Customer Exits > Contoh Customer Exits > Project ZPPWS002 > Funtions Exits > EXIT_SAPLCORF_104 >

ZXCOFU14

*&---------------------------------------------------------------------*
*&  Include           ZXCOFU14                                         *
*&---------------------------------------------------------------------*
 
DATA : zlv_startdate like LTAK-STDAT,
      zlv_starttime like LTAK-STUZT,
      zlv_enddate like LTAK-ENDAT,
      zlv_endtime like LTAK-ENUZT,
      zlv_timeuom like LTAK-ZEIEI,
      zlv_timediff like LTAK-ISTWM.
 
DATA : begin of zcrhs occurs 0.
      include structure crhs.
DATA :  name like crhh-name.
DATA : end of zcrhs.
DATA : begin of zcrhs2 occurs 0.
      include structure crhs.
DATA : end of zcrhs2.
DATA : zOBJID_ord like afrud-arbid,
      zOBJID_cnf like afrud-arbid.
DATA : ztabix like sy-tabix.
DATA : zkapid like crhd-kapid.
DATA : ZCX_DURATION_SEC type CXZEIT-BEARB,
      zDURATION_DAYS_OUT type F,
      zMIN_NUM_CAPACITIES like KAPA-ANZHL,
      zPOINT_IN_TIME_END_OUT type CXZEIT-FSAV,
      zPOINT_IN_TIME_START_OUT type CXZEIT-FSAV,
      zDATE_START_OUT like sy-datum,
      zTIME_START_OUT like sy-uzeit,
      zDATE_END_OUT like sy-datum,
      zTIME_END_OUT like sy-uzeit,
      zFLG_ONLY_STD_CAPACITY_OUT type C,
      zFLG_PREV_DAY_OUT type C.
**<<< INSERT START 20051115
DATA : zwkcord_in_hierarchy type c,
      zwkccnf_in_hierarchy type c.
**<<< INSERT END   20051115
clear: zobjid_ord, zobjid_cnf, zcrhs, zcrhs2, ztabix,
      zkapid, ZCX_DURATION_SEC.
 
**End Changed
 
*For make sure all local value are cleared.
clear zlv_startdate.
clear zlv_starttime.
clear zlv_enddate.
clear zlv_endtime.
clear zlv_timeuom.
clear zlv_timediff.
clear AFRUD_EXP.
**<<< INSERT START 20051115
clear: zwkcord_in_hierarchy, zwkccnf_in_hierarchy.
**<<< INSERT END   20051115
 
* Validation for workcenter with hierarchy
*
* First get object id for wkc confirmation (i.e. HR workcenter)
* zOBJID_cnf is wkc confirmation
select OBJID from crhd into zOBJID_cnf
            where OBJTY = 'A'
            and   ARBPL = AFRUD_IMP-ARBPL
            and   WERKS = AFRUD_IMP-WERKS.   "sgt20072006
endselect.
* Then get object id for wkc order (i.e. Main workcenter)
* zOBJID_ord is wkc order
select OBJID kapid from crhd into (zOBJID_ord, zkapid)
                  where OBJTY = 'A'
                  and   ARBPL = AFVGD_IMP-ARBPL
                  and   WERKS = AFRUD_IMP-WERKS.   "sgt20072006
endselect.
* Make sure if workcenter field is empty, system pre-enter
* with order workcenter
if AFRUD_IMP-ARBPL = ''.
 AFRUD_IMP-ARBPL = AFVGD_IMP-ARBPL.
endif.
 
* Check wkc order is member in wkc hierarchy if yes it means
* it needs to be compared with the wkc confirmation, otherwise continue
select single * from crhs into corresponding fields of zcrhs
                                  where objty_up = 'A' and
                                   objid_up = zOBJID_ord.
* just check exist no need to retain data in internal table
**<<< INSERT START 20051115
if sy-subrc = 0.
 zwkcord_in_hierarchy = 'X'.
endif.
 
select single * from crhs into corresponding fields of zcrhs
                                  where objty_ho = 'A' and
                                   objid_ho = zOBJID_cnf.
if sy-subrc = 0.
 zwkccnf_in_hierarchy = 'X'.
endif.
 
**<<< INSERT END   20051115
 
**<<< UPDATE START 20051115
*if sy-subrc = 0.                                           "****
if zwkcord_in_hierarchy = 'X' OR                           "****
  zwkccnf_in_hierarchy = 'X'.
**<<< UPDATE END   20051115
 
if AFRUD_IMP-ARBPL = AFVGD_IMP-ARBPL.                   "***
  MESSAGE E481(CO) WITH 'child' 'work center parent'.
 
* Find parent wkc and hierarchy data
else.                                                   "***
  clear zcrhs.
 
  select * from crhs into corresponding fields of zcrhs
                                      where objty_ho = 'A' and
                                       objid_ho = zOBJID_cnf.
    append zcrhs.
  endselect.
 
  loop at zcrhs.
     ztabix = sy-tabix.
    select name into zcrhs-name from crhh
                                    where objty = zcrhs-OBJTY_HY and
                                           objid = zcrhs-OBJID_HY.
      modify zcrhs index ztabix.
    endselect.
  endloop.
 
  Data : lv_name(3).
  loop at zcrhs.
* Validation. For certain hierarchy will get higher level wkc
* and compare with order wkc.
     lv_name = zcrhs-name.
    IF lv_name = 'KIL'.
       zcrhs-name = lv_name.
    ENDIF.
    case zcrhs-name.
      when 'PWD' or 'PWD2' or 'KIL'.
        if zobjid_ord ne zcrhs-objid_up.
          select * from crhs into corresponding fields of zcrhs2
                                              where objty_ho = 'A' and
                                             objid_ho = zcrhs-objid_up.
            append zcrhs2.
          endselect.
          if sy-subrc ne 0.
            MESSAGE E481(CO) WITH 'child' 'work center parent'.
          else.
            if zobjid_ord ne zcrhs2-objid_up.
              MESSAGE E481(CO) WITH 'child' 'work center parent'.
            else.
              if sy-tcode = 'CO11N'.
                MESSAGE E481(CO) WITH 'child' 'work center parent'.
              endif.
            endif.
          endif.
        endif.
 
      when 'PWD3'.
        if zobjid_ord ne zcrhs-objid_up.
          select * from crhs into corresponding fields of zcrhs2
                                              where objty_ho = 'A' and
                                             objid_ho = zcrhs-objid_up.
            append zcrhs2.
          endselect.
          if sy-subrc ne 0.
            MESSAGE E481(CO) WITH 'child' 'work center parent'.
          else.
            if zobjid_ord ne zcrhs2-objid_up.
              MESSAGE E481(CO) WITH 'child' 'work center parent'.
            else.
              if sy-tcode = 'CO11N'.
                MESSAGE E481(CO) WITH 'child' 'work center parent'.
              endif.
            endif.
          endif.
        else.
          if sy-tcode = 'CO12'.
            MESSAGE E481(CO) WITH 'child' 'work center parent'.
          endif.
        endif.
 
      when others.
        if zobjid_ord ne zcrhs-objid_up.
          MESSAGE E481(CO) WITH 'child' 'work center parent'.
        endif.
 
 
    endcase.
  endloop.
 
 
endif.                                                   "***
 
endif.                                                     "****
 
**Validation for downtime
 
if sy-tcode = 'CO12' and AFRUD_IMP-GRUND ne ''.
case CAUFVD_IMP-FEVOR.
  when '242'.                                         "packing soap
    if not ( AFRUD_IMP-GRUND >= '4200' and
              AFRUD_IMP-GRUND <= '4299' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '132' & '232'.                                 "packing cream
    if not ( AFRUD_IMP-GRUND >= '3200' and
              AFRUD_IMP-GRUND <= '3299' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '131' & '231'.                                 "mixing cream
    if not ( AFRUD_IMP-GRUND >= '3100' and
              AFRUD_IMP-GRUND <= '3199' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '162' & '262'.                                 "packing pwd
    if not ( AFRUD_IMP-GRUND >= '6200' and
              AFRUD_IMP-GRUND <= '6299' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '252'.                                         "packing liquid
    if not ( AFRUD_IMP-GRUND >= '5200' and
              AFRUD_IMP-GRUND <= '5299' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '251'.                                         "mixing liquid
    if not ( AFRUD_IMP-GRUND >= '5100' and
              AFRUD_IMP-GRUND <= '5199' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '211' & '212'.                                 "plastik
    if not ( AFRUD_IMP-GRUND >= '1000' and
              AFRUD_IMP-GRUND <= '1099' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '222'.                                         "packing bar
    if not ( AFRUD_IMP-GRUND >= '2200' and
              AFRUD_IMP-GRUND <= '2299' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
  when '221'.                                         "mixing bar
    if not ( AFRUD_IMP-GRUND >= '2100' and
              AFRUD_IMP-GRUND <= '2199' ).
      MESSAGE E062(CO) WITH 'reason for variance'.
    endif.
 
  when others.
endcase.
 
 
endif.
 
**end Validation for downtime
 
**End Changed
 
*To convert
zlv_startdate = AFRUD_IMP-ISDD.
zlv_starttime = AFRUD_IMP-ISDZ.
zlv_enddate   = AFRUD_IMP-IEDD.
zlv_endtime   = AFRUD_IMP-IEDZ.
 
*This is to count difference time between enddate and startdate.
zlv_timeuom = 'H'.
 
*CALL FUNCTION 'L_TO_TIME_DIFF'
*  EXPORTING
*    I_START_DATE     = zlv_startdate
*    I_START_TIME     = zlv_starttime
*    I_END_DATE       = zlv_enddate
*    I_END_TIME       = zlv_endtime
*    I_TIME_UOM       = zlv_timeuom
*  IMPORTING
*    E_TIME_DIFF      = zlv_timediff
*  EXCEPTIONS
*    INPUT_DATA_EMPTY = 1
*    OTHERS           = 2.
 
IF zOBJID_ord <> '' and zkapid <> '' and
  not zlv_startdate is initial and not zlv_enddate is initial and
  sy-tcode = 'CO11N'.
*Changed in function module, count exclude break
CALL FUNCTION 'CR_SCHED_VIA_OPERATING_TIME'
  EXPORTING
     ARBID                            = zOBJID_ord
*   DURATION_IN                      = 0
*   DURATION_UNIT                    = 0
*   FLG_CAPACITY_SCHEDULING          = ' '
     FLG_COMPUTE_BEG_END_PROD         = 'X'
*   FLG_DAYS_VIA_STD_CAPACITY        = ' '
     FLG_EXACT_BREAKS                 = 'X'
*   FLG_UNIT_GE_DAY                  = ' '
*   KAPA_VERSNR                      = 0
*   POINT_IN_TIME_END_IN             = 0
*   POINT_IN_TIME_START_IN           = 0
*   UNIT                             = ' '
     DATE_START_IN                    = zlv_startdate
     TIME_START_IN                    = zlv_starttime
     DATE_END_IN                      = zlv_enddate
     TIME_END_IN                      = zlv_endtime
     KAPID                            = zkapid
     FLG_NO_BREAKS                    = 'X'
  IMPORTING
     DURATION_DAYS_OUT                = zDURATION_DAYS_OUT
     DURATION_OUT                     = ZCX_DURATION_SEC
     MIN_NUM_CAPACITIES               = zMIN_NUM_CAPACITIES
     POINT_IN_TIME_END_OUT            = zPOINT_IN_TIME_END_OUT
     POINT_IN_TIME_START_OUT          = zPOINT_IN_TIME_START_OUT
     DATE_START_OUT                   = zDATE_START_OUT
     TIME_START_OUT                   = zTIME_START_OUT
     DATE_END_OUT                     = zDATE_END_OUT
     TIME_END_OUT                     = zTIME_END_OUT
     FLG_ONLY_STD_CAPACITY_OUT        = zFLG_ONLY_STD_CAPACITY_OUT
     FLG_PREV_DAY_OUT                 = zFLG_PREV_DAY_OUT
  EXCEPTIONS
     CAPACITY_NOT_FOUND               = 1
     DATE_OUT_OF_CALENDAR_RANGE       = 2
     DATE_OUT_OF_PIT_RANGE            = 3
     NO_ACTIVE_CAPACITY               = 4
     NO_FREE_CAPACITY                 = 5
     NO_OPERATING_TIME                = 6
     PARAMETERS_NOT_VALID             = 7
     WORKCENTER_NOT_VALID             = 8
     UNIT_CONVERSION_ERROR            = 9
    OTHERS                           = 10
           .
IF SY-SUBRC <> 0.
*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
IF ZCX_DURATION_SEC > 0.
   zlv_timediff = ZCX_DURATION_SEC / 3600.
else.
  CALL FUNCTION 'L_TO_TIME_DIFF'
    EXPORTING
       I_START_DATE     = zlv_startdate
       I_START_TIME     = zlv_starttime
       I_END_DATE       = zlv_enddate
       I_END_TIME       = zlv_endtime
       I_TIME_UOM       = zlv_timeuom
    IMPORTING
       E_TIME_DIFF      = zlv_timediff
    EXCEPTIONS
       INPUT_DATA_EMPTY = 1
      OTHERS           = 2.
 
 
ENDIF.
 
 
endif.
*Move structure import AFRUD to Export AFRUD.
move-corresponding AFRUD_IMP to AFRUD_EXP.
 
**Changed By Willy At 22 July 2005 18:00:00
**To Number Of person From Production Order
if AFRUD_EXP-ISM02 is initial and AFRUD_EXP-ILE02 is initial.
if AFVGD_IMP-VGW02 is not initial and AFVGD_IMP-VGE02 is not initial.
   AFRUD_EXP-ISM02 = AFVGD_IMP-VGW02.
   AFRUD_EXP-ILE02 = AFVGD_IMP-VGE02.
endif.
endif.
 
**End Changed
 
*To count Machine time when user command enter.
*AFRUD_EXP-ISM01 = zlv_timediff.
if zlv_timediff gt 0.
 AFRUD_EXP-ISM01 = zlv_timediff.
 AFRUD_EXP-ISM03 = AFRUD_EXP-ISM01 * AFRUD_EXP-ISM02.
endif.
 
*To count Labor time when user command enter.1
*AFRUD_EXP-ISM03 = AFRUD_EXP-ISM01 * AFRUD_EXP-ISM02.
 
*To set default machine time to Hour(H)
AFRUD_EXP-ILE01 = zlv_timeuom.
 
if AFRUD_EXP-ISM03 <> 0.
 AFRUD_EXP-ILE03 = zlv_timeuom.
endif.
 
**Copy default execution date time
if ( AFRUD_EXP-ISDD is initial and AFRUD_EXP-ISDZ is initial and
    AFRUD_EXP-IEDD is initial and AFRUD_EXP-IEDZ is initial ) and
    sy-tcode = 'CO11N'.
 
 AFRUD_EXP-ISDD = AFVGD_IMP-FSSBD.
if AFRUD_EXP-ISDD > sy-datum. AFRUD_EXP-ISDD = sy-datum. endif.
 AFRUD_EXP-ISDZ = AFVGD_IMP-FSSBZ.
 AFRUD_EXP-IEDD = AFVGD_IMP-FSSAD.
if AFRUD_EXP-IEDD > sy-datum. AFRUD_EXP-IEDD = sy-datum. endif.
 AFRUD_EXP-IEDZ = AFVGD_IMP-FSSAZ.
endif.
 
**Copy default down time date
if sy-tcode = 'CO12'.
 
*processing start date
if AFRUD_EXP-ISBD is initial.
   AFRUD_EXP-ISBD = AFVGD_IMP-FSSBD.
  if AFRUD_EXP-ISBD > sy-datum. AFRUD_EXP-ISBD = sy-datum. endif.
endif.
*processing finish date
if AFRUD_EXP-IEBD is initial.
   AFRUD_EXP-IEBD = AFVGD_IMP-FSSAD.
  if AFRUD_EXP-IEBD > sy-datum. AFRUD_EXP-IEBD = sy-datum. endif.
endif.
*tear down start date
if AFRUD_EXP-ISAD is initial.
   AFRUD_EXP-ISAD = AFVGD_IMP-FSSAD.
  if AFRUD_EXP-ISAD > sy-datum. AFRUD_EXP-ISAD = sy-datum. endif.
endif.
 
*check yield already input or not
if CAUFVD_IMP-IGMNG = 0.
  MESSAGE W001(00) WITH 'ANDA INPUT DOWNTIME SEBELUM KONFIRMASI'.
endif.
 
endif.
 
*Default unit of measure copy from prod order
if sy-tcode = 'CO11N'.
 AFRUD_EXP-MEINH = CAUFVD_IMP-GMEIN.
endif.
**End Include