MV45AFZZ

<< Click to Display Table of Contents >>

Navigation:  All About ABAP Technique > Indonesia > ABAP Tutorial > ABAP Workbench Tools  > User Exits > Contoh User Exits >

MV45AFZZ

***INCLUDE MV45AFZZ .
 
************************************************************************
*                                                                      *
* This include is reserved for user modifications                      *
*                                                                      *
* Forms for sales document processing                                  *
*                                                                      *
* The name of modification modules should begin with 'ZZ'.             *
*                                                                      *
************************************************************************
 
*---------------------------------------------------------------------*
*       FORM ZZEXAMPLE                                                *
*---------------------------------------------------------------------*
*       text......................................                    *
*---------------------------------------------------------------------*
*FORM ZZEXAMPLE.
 
*  ...
 
*ENDFORM.
 
*eject
*---------------------------------------------------------------------*
*       FORM USEREXIT_DELETE_DOCUMENT                                 *
*---------------------------------------------------------------------*
*       This userexit can be used to delete data in additional tables *
*       when a sales document is deleted.                             *
*                                                                     *
*      This form is called in dialog at the end of form BELEG_LOESCHEN*
*      just before form BELEG_SICHERN is performed to delete the      *
*      datas on the database.                                         *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_DELETE_DOCUMENT.
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_FIELD_MODIFICATION                              *
*---------------------------------------------------------------------*
*       This userexit can be used to modify the attributes of         *
*       screen fields.                                                *
*       This form is processed for each field in the screen.          *
*                                                                     *
*       The use of the fields screen-group1 to screen-group4 is:      *
*                                                                     *
*       Screen-group1: Automatic modification contolles by transaction*
*                      MFAW.                                          *
*       Screen-group2: Contents 'LOO' for steploop-fields.            *
*       Screen-group3: Used for modififaction, which are dependent on *
*                      control tables or other fix information.       *
*       Screen-group4: Unused                                         *
*                                                                     *
*       For field mofifications, which are dependent on the document  *
*       status, you can use the status field in the workareas         *
*       XVBAP for item status and XVBUK for header status.            *
*                                                                     *
*       This form is called from module FELDAUSWAHL.                  *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_FIELD_MODIFICATION.
 
* CASE SCREEN-GROUP3.
*   WHEN '900'.
*     IF VBAK-VBTYP NE 'A'.
*       SCREEN-ACTIVE = 0.
*     ENDIF.
* ENDCASE.
 
* CASE SCREEN-NAME.
*   WHEN 'VBAK-VBELN'.
*     SCREEN-ACTIVE = 0.
* ENDCASE.
*{   INSERT         WDVK900610                                        1
IF VBAK-AUART ne 'ZS02'.     "only for non-export sales
IF VBAP-UEPOS is not initial
    and SCREEN-GROUP2 = 'LOO'.
    SCREEN-INPUT = 0.
ENDIF.
if sy-tcode ne 'VA03'.
IF VBAP-UEPOS is not initial
    and SCREEN-NAME = 'VBAP-WERKS'.
    SCREEN-INPUT = 1.
ENDIF.
IF VBAP-UEPOS is not initial
    and SCREEN-NAME = 'VBAP-VSTEL'.
    SCREEN-INPUT = 1.
ENDIF.
IF VBAP-UEPOS is not initial
    and SCREEN-NAME = 'VBAP-ROUTE'.
    SCREEN-INPUT = 1.
ENDIF.
ENDIF.
 
IF VBAK-VBTYP ne space and sy-tcode = 'VA01'.
  IF SCREEN-NAME = 'VBAK-FAKSK'.
    SCREEN-INPUT = 0.
  ENDIF.
ENDIF.
 
ENDIF.
 
*}   INSERT
*{   INSERT         WDVK902895                                        2
*** Field TOP cannot be changed
IF VBAK-VTWEG ne '07' .
IF SCREEN-NAME = 'VBKD-ZTERM'.
    SCREEN-INPUT = 0.
  ENDIF.
ELSE.
IF SCREEN-NAME = 'VBAP-ROUTE' and SY-TCODE ne 'VA03'..
    SCREEN-INPUT = 1.
ENDIF.
ENDIF.
 
***
IF SY-TCODE = 'VA01'.
  IF SCREEN-NAME = 'VBAK-LIFSK'.
    SCREEN-INPUT = 0.
  ENDIF.
ENDIF.
*}   INSERT
*{   INSERT         WDVK902915                                        3
*** Field Pricing Date is not allowed to change
IF SCREEN-NAME = 'VBKD-PRSDT'.
    AUTHORITY-CHECK OBJECT 'Z_PRSDT'
          ID 'ACTVT' FIELD '02'.
    IF SY-SUBRC ne 0 and SCREEN-INPUT = 1.
      SCREEN-INPUT = 0.
    ENDIF.
ENDIF.
 
*}   INSERT
*{   INSERT         WDVK907470                                        4
****
IF SY-TCODE = 'VA02' and SCREEN-NAME = 'VBAP-VRKME'.
  SCREEN-INPUT = 1.
ENDIF.
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_VBAK                              *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the sales  *
*       dokument header workaerea VBAK.                               *
*                                                                     *
*       SVBAK-TABIX = 0:  Create header                               *
*       SVBAK-TABIX > 0:  Change header                               *
*                                                                     *
*       This form is called at the end of form VBAK_FUELLEN.          *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBAK.
 
*  vbak-zzfield = xxxx-zzfield2.
*{   INSERT         WDVK900216                                        1
data: gw_xvbpa like line of xvbpa.
clear gw_xvbpa.
 
data: gw_pernr like line of xvbpa.
clear gw_pernr.
 
read table xvbpa into gw_xvbpa with key parvw = '1A'.
read table xvbpa into gw_pernr with key parvw = 'VE'.
 
perform fm_userexit_vbak(SAPLZFG_FREEGOODS)
tables xvbap
using  vbak
        vbkd-prsdt
        gw_xvbpa-kunnr
        gw_pernr-pernr.
 
**** For Order Type ZS04 always gets from Plant 2013
if vbak-auart = 'ZS04' or vbak-auart = 'ZS05'.
  RV45A-DWERK = '2013'.
endif.
*}   INSERT
*{   INSERT         WDVK900860                                        2
*** For transaction local in foreign currency, exchange rate is
*** always Tax Rate (T).
*
IF VBAK-WAERK ne 'IDR' and VBAK-AUART ne 'ZS02'.
 VBAK-KURST = 'T'.
ENDIF.
*
*}   INSERT
*{   INSERT         WDVK902915                                        3
*** Get Sales Group and Sales Office from Employee master
tables: pa0900.   "HR infotype 900
IF VBAK-VKORG = 'A201'.
loop at xvbpa where parvw = 'VE'.
  select single * from pa0900 where pernr = xvbpa-pernr.
  if sy-subrc = 0.
    if pa0900-vkbur is not initial.
        vbak-vkbur = pa0900-vkbur.
    endif.
    if pa0900-vkgrp is not initial.
        vbak-vkgrp = pa0900-vkgrp.
    endif.
  endif.
endloop.
ENDIF.
*}   INSERT
*{   INSERT         WDVK905979                                        4
*** For Building Material order creation, always set delivery blok
*changed by christine 18 NOV 2006
*tambahan ZEX1, ZEX2, ZEX3, ZEX4
IF VBAK-VKORG = 'A202' and SVBAK-TABIX = 0 and VBAK-VBTYP = 'C'
  and VBAK-auart np 'ZEX*'.
 VBAK-LIFSK = '10'.
ENDIF.
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_VBAP                              *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the sales  *
*       dokument item workaerea VBAP                                  *
*                                                                     *
*       SVBAP-TABIX = 0:  Create item                                 *
*       SVBAP-TABIX > 0:  Change item                                 *
*                                                                     *
*       This form is called at the end of form VBAP_FUELLEN.          *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBAP.
 
*  VBAP-zzfield = xxxx-zzfield2.
*{   INSERT         WDVK900010                                        1
*** .
LOOP AT XVBPA where PARVW = 'WE'.
  select single * from knvv where kunnr = xvbpa-kunnr
                            and   vkorg = vbak-vkorg
                            and   vtweg = vbak-vtweg
                            and   spart = vbak-spart.
  if sy-subrc = 0.
     VBAP-ANTLF = knvv-antlf.
  endif.
ENDLOOP.
 
****
 
*}   INSERT
*{   INSERT         WDVK900216                                        2
 
*** For building material, sloc in 2012 is from A003.
if vbap-werks = '2012'
  and vbak-vkorg = 'A202'
  and vbap-pstyv ne 'ZKEN'
  and vbap-lgort is initial.
     vbap-lgort = 'A003'.
endif.
 
****
 
perform fm_fill_zta_s_fgsdeals(SAPLZFG_FREEGOODS) tables xvbap changing vbap.
 
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_VBEP                              *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the sales  *
*       dokument schedule line workaerea VBEP                         *
*                                                                     *
*       SVBEP-TABIX = 0:  Create schedule line                        *
*       SVBEP-TABIX > 0:  Change schedule line                        *
*                                                                     *
*       This form is called at the end of form VBEP_FUELLEN.          *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBEP.
 
*  VBEP-zzfield = xxxx-zzfield2.
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_VBKD                              *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the sales  *
*       dokument business data workaerea VBKD                         *
*                                                                     *
*       SVBKD-TABIX = 0:  Create data                                 *
*       SVBKD-TABIX > 0:  Change data                                 *
*                                                                     *
*       This form is called at the end of form VBKD_FUELLEN.          *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBKD.
 
*  VBKD-zzfield = xxxx-zzfield2.
*{   INSERT         WDVK900010                                        1
**** Translate PO number into capital letters
translate vbkd-bstkd to upper case.
 
*}   INSERT
*{   INSERT         WDVK903029                                        2
**** Get sales district from Ship-to Party
loop at xvbpa where parvw = 'WE'.
select single * from knvv where kunnr = xvbpa-kunnr
                            and vkorg = vbak-vkorg
                            and vtweg = vbak-vtweg.
if sy-subrc = 0 and knvv-bzirk is not initial.
    VBKD-BZIRK = KNVV-BZIRK.
endif.
if sy-subrc = 0 and knvv-inco1 is not initial.
    VBKD-INCO1 = KNVV-INCO1.
    VBKD-INCO2 = KNVV-INCO2.
endif.
endloop.
*}   INSERT
*{   INSERT         WDVK907197                                        3
**** Get sales pricing group from Bill-to Party
loop at xvbpa where parvw = 'RE'.
select single * from knvv where kunnr = xvbpa-kunnr
                            and vkorg = vbak-vkorg
                            and vtweg = vbak-vtweg.
if sy-subrc = 0 and knvv-konda is not initial.
   VBKD-konda = KNVV-konda.
endif.
endloop.
*
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_NUMBER_RANGE                                    *
*---------------------------------------------------------------------*
*       This userexit can be used to determine the numberranges for   *
*       the internal document number.                                 *
*                                                                     *
*       US_RANGE_INTERN - internal number range                       *
*                                                                     *
*       This form is called from form BELEG_SICHERN                   *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_NUMBER_RANGE USING US_RANGE_INTERN.
 
* Example: Numer range from TVAK like in standard
* US_RANGE_INTERN = TVAK-NUMKI.
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_PRICING_PREPARE_TKOMK                           *
*---------------------------------------------------------------------*
*       This userexit can be used to move additional fields into the  *
*       communication table which is used for pricing:                *
*                                                                     *
*       TKOMK for header fields                                       *
*                                                                     *
*       This form is called from form PREISFINDUNG_VORBEREITEN.       *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_PRICING_PREPARE_TKOMK.
 
*  TKOMK-zzfield = xxxx-zzfield2.
*{   INSERT         WDVK900010                                        1
*** add PO Number
  MOVE  vbkd-bstkd TO tkomk-zzbstkd.
 
*** add Industry Code 1
  TABLES kna1.
  SELECT SINGLE *
  FROM kna1
  WHERE kunnr EQ vbak-kunnr.
  MOVE: kna1-bran1 TO tkomk-zzbran1.
 
*** get customer hierarchy field
  read table xvbpa with key parvw = '1A'.
  if sy-subrc = 0.
    move xvbpa-kunnr to tkomk-hienr01.
  endif.
 
***
 
*}   INSERT
*{   INSERT         WDVK902978                                        2
*** Move field KDGRP1 to KOMK-ZZKDGRP1.
move vbak-kvgr1 to tkomk-ZZKVGR1.
 
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_PRICING_PREPARE_TKOMP                           *
*---------------------------------------------------------------------*
*       This userexit can be used to move additional fields into the  *
*       communication table which is used for pricing:                *
*                                                                     *
*       TKOMP for item fields                                         *
*                                                                     *
*       This form is called from form PREISFINDUNG_VORBEREITEN.       *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_PRICING_PREPARE_TKOMP.
 
*  TKOMP-zzfield = xxxx-zzfield2.
*{   INSERT         WDVK900010                                        1
*** add Material Group 1 - 5
  MOVE: vbap-mvgr1 TO tkomp-zzmvgr1,
        vbap-mvgr2 TO tkomp-zzmvgr2,
        vbap-mvgr3 TO tkomp-zzmvgr3,
        vbap-mvgr4 TO tkomp-zzmvgr4,
        vbap-mvgr5 TO tkomp-zzmvgr5.
 
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_READ_DOCUMENT                                   *
*---------------------------------------------------------------------*
*       This userexit can be used to read data in additional tables   *
*       when the program reads a sales document.                      *
*                                                                     *
*       This form is called at the end of form BELEG_LESEN.           *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_READ_DOCUMENT.
*{   INSERT         WDVK900566                                        1
*
perform fm_userexit_read_document(SAPLZFG_FREEGOODS) using vbak.
*}   INSERT
 
ENDFORM.
*eject
 
*---------------------------------------------------------------------*
*       FORM USEREXIT_SAVE_DOCUMENT                                   *
*---------------------------------------------------------------------*
*       This userexit can be used to save data in additional tables   *
*       when a document is saved.                                     *
*                                                                     *
*       If field T180-TRTYP contents 'H', the document will be        *
*       created, else it will be changed.                             *
*                                                                     *
*       This form is called at from form BELEG_SICHERN, before COMMIT *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_SAVE_DOCUMENT.
*{   INSERT         WDVK906918                                        3
IF VBAK-AUART = 'ZS02'.
EXIT.
ENDIF.
*
*}   INSERT
 
* Example:
* CALL FUNCTION 'ZZ_EXAMPLE'
*      IN UPDATE TASK
*      EXPORTING
*           ZZTAB = ZZTAB.
*{   INSERT         WDVK900860                                        2
*** Periksa Tukar Guling Prosedur  ***
*** Bandingkan field MVGR2 antara current document dengan referensinya
*** Periksa field KLMENG harus sama di level MVGR2
*** Enhanced by Sy Syarien
 
*** Current Item Document ***********
DATA:   BEGIN OF LI_VBAP1 OCCURS 0.
      INCLUDE STRUCTURE XVBAP.
DATA:   END   OF LI_VBAP1.
 
DATA: BEGIN OF LI_MVGR21 OCCURS 0,
        mvgr2 like vbap-mvgr2,
        klmeng LIKE vbap-klmeng,
    END OF LI_MVGR21.
tables : lips.
*************************************
DATA: xklmeng1 LIKE vbap-klmeng,
     xklmeng2 LIKE vbap-klmeng,
     lv_lines1 LIKE sy-tabix,
     lv_lines2 LIKE sy-tabix.
*** Reference Item Document *********
DATA:   BEGIN OF LI_VBAP2 OCCURS 0.
      INCLUDE STRUCTURE VBAP.
DATA:   END   OF LI_VBAP2.
 
DATA: BEGIN OF LI_MVGR22 OCCURS 0,
        mvgr2 like vbap-mvgr2,
        klmeng LIKE vbap-klmeng,
    END OF LI_MVGR22.
*************************************
data : lv_redetermine(1).
 
IF xvbak-auart = 'ZS13'.
 
 
IF xvbak-vgbel is not initial.
 
loop at xvbap where updkz ne 'D'.
  move-corresponding xvbap to li_vbap1.
  append li_vbap1.
endloop.
 
loop at li_vbap1.
    li_mvgr21-mvgr2 = li_vbap1-mvgr2.
    li_mvgr21-klmeng = 0.
    append li_mvgr21.
endloop.
 
  IF xvbak-auart = 'ZS13'.
    select single * from vbfa where VBTYP_N = 'J'
                                and VBELV   = xvbak-vgbel.
*                                 and posnv   = xvbap-vgpos.
    if sy-subrc = 0.
 
      select * from lips where vbeln = vbfa-vbeln and lfimg ne 0.
        move-corresponding lips to li_vbap2.
        li_vbap2-klmeng = lips-lgmng.
        append li_vbap2.
        li_mvgr22-mvgr2 = li_vbap2-mvgr2.
        li_mvgr22-klmeng = 0.
        append li_mvgr22.
 
      endselect.
 
    endif.
ENDIF.
 
sort li_mvgr21 by mvgr2.
sort li_mvgr22 by mvgr2.
 
DELETE ADJACENT DUPLICATES FROM li_mvgr21 comparing mvgr2.
DELETE ADJACENT DUPLICATES FROM li_mvgr22 comparing mvgr2.
 
DESCRIBE TABLE li_mvgr21 LINES lv_lines1.
DESCRIBE TABLE li_mvgr22 LINES lv_lines2.
 
if vbap-KWMENG ne xvbap-KWMENG and sy-ucomm ne 'YES'.
  MESSAGE ID 'VH' TYPE 'E' NUMBER '611' .
 
endif.
 
IF lv_lines1 ne lv_lines2 and vbak-vbeln is initial.
*** Error: ada ketakcocokan jumlah tukar guling group.
  MESSAGE ID 'VH' TYPE 'E' NUMBER '611' .
ELSE.
  loop at li_mvgr21.
      xklmeng1 = 0.
      loop at li_vbap1 where mvgr2 = li_mvgr21-mvgr2.
         xklmeng1 = xklmeng1 + li_vbap1-klmeng.
      endloop.
      li_mvgr21-klmeng = xklmeng1.
      modify li_mvgr21.
 
      xklmeng2 = 0.
      loop at li_vbap2 where mvgr2 = li_mvgr21-mvgr2.
        xklmeng2 = xklmeng2 + li_vbap2-klmeng.
      endloop.
 
      if sy-subrc ne 0.
***      Error: ada ketakcocokan jumlah tukar guling group.
        MESSAGE ID 'VH' TYPE 'E' NUMBER '611' .
      else.
      if xklmeng1 ne xklmeng2.
***      Error: ada ketakcocokan jumlah tukar guling group.
        MESSAGE ID 'VH' TYPE 'E' NUMBER '611' .
      endif.
      endif.
 
  endloop.
 
ENDIF.
 
ENDIF.
ENDIF.
*}   INSERT
*{   INSERT         WDVK900566                                        1
*
perform fm_save_ZTA_S_FGSDEALS(SAPLZFG_FREEGOODS) tables xvbap using vbak-vbeln.
perform fm_save_zta_s_fguepos(SAPLZFG_FREEGOODS) tables xvbap using vbak-vbeln.
 
*}   INSERT
 
ENDFORM.
*eject
*---------------------------------------------------------------------*
*       FORM USEREXIT_SAVE_DOCUMENT_PREPARE                           *
*---------------------------------------------------------------------*
*       This userexit can be used for changes or checks, before a     *
*       document is saved.                                            *
*                                                                     *
*       If field T180-TRTYP contents 'H', the document will be        *
*       created, else it will be changed.                             *
*                                                                     *
*       This form is called at the beginning of form BELEG_SICHERN    *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_SAVE_DOCUMENT_PREPARE.
*{   INSERT         WDVK906918                                        3
*
IF VBAK-AUART = 'ZS02'.
EXIT.
ENDIF.
*}   INSERT
 
*{   INSERT         WDVK900955                                        1
*
DATA: lv_redetermine type c.
IMPORT lv_redetermine FROM MEMORY ID 'ZFG_RECALCULATE_FREEGOODS'.
IF ( lv_redetermine = 'X' ).
  perform fm_recalc_fg using 'X'.
ENDIF.
CLEAR lv_redetermine.
EXPORT lv_redetermine TO MEMORY ID 'ZFG_RECALCULATE_FREEGOODS'.
 
*}   INSERT
 
ENDFORM.
*{   INSERT         WDVK900894                                        1
* Recalculate Free Goods in SO
INCLUDE ZIN_S_RECALC_FG_SALESORDER.
*}   INSERT
*eject