对于销售订单的项目的交货工厂(VBAP-WERKS)决定是由单元FV45PF0V_VBAP-WERKS_ERMITTELN的FORM VBAP-WERKS_ERMITTELN子过程来填写的,具体怎么决定的大家一看下列的代码照抄自然就知道。
Unit name: FV45PF0V_VBAP-WERKS_ERMITTELN
*---------------------------------------------------------------------*
* FORM VBAP-WERKS_ERMITTELN *
*---------------------------------------------------------------------*
* Ermitteln des Werkes einer Position *
* Determine the work of a position
*---------------------------------------------------------------------*
FORM VBAP-WERKS_ERMITTELN.
DATA: DA_MSG TYPE C.
DATA: DA_EDATU LIKE VBEP-EDATU.
CLEAR DA_MSG.
* Während der Variantenfindung kein neues Werk ermitteln
CHECK TYPE_MATCHING IS INITIAL OR VBAP-WERKS IS INITIAL.
* Im Positionsvorschlag für eine Position kein Werk ermitteln
* Determine no work in the position proposal for a position
CHECK VBAK-VBTYP NE 'D'.
* Neue Werksermittlung bei geändertem Material
* New work determination with changed material
IF ( VBAP-MATNR NE *VBAP-MATNR OR
NOT MATNR_CHANGED IS INITIAL ) AND
TVSU-SUBAR IS INITIAL AND
WERKS_CHANGED IS INITIAL AND SVBAP-TABIX > 0 AND
( VBAP-WERKS = *VBAP-WERKS OR VBAP-WERKS = VBAPIN-WERKS ).
CLEAR: VBAP-WERKS, VBAP-BERID, VBAP-LGORT.
ENDIF.
CHECK: VBAP-WERKS = SPACE.
* 1. Werk aus der Hauptposition vorschlagen
* Work from the main position suggest
* VBAP-UEPOS=物料单结构中的上层项目
IF VBAP-UEPOS > 0 AND
VBAP-WERKS = SPACE AND
HVBAP-WERKS NE SPACE.
* Vorschlagswerk prüfen
* Proposal work examine
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
HVBAP-WERKS
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC EQ 0.
* Vorschlagswerk setzen
VBAP-WERKS = HVBAP-WERKS.
ENDIF.
ENDIF.
* 2. Werk aus dem eingegebenen Kopfwerk vorschlagen
* Work from the entered head work suggest
IF VBAP-WERKS = SPACE AND
RV45A-DWERK NE SPACE.
* Vorschlagswerk prüfen
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
RV45A-DWERK
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC EQ 0.
* Vorschlagswerk setzen
VBAP-WERKS = RV45A-DWERK.
ELSE.
DA_MSG = CHARX.
ENDIF.
ENDIF.
* 3. Werk aus dem Infosatz vorschlagen
* Work from the information record suggest
* KNMT=客户-物料信息记录数据表
* TCODE VD51
IF VBAP-WERKS = SPACE.
PERFORM RV_CUSTOMER_MATERIAL_READ USING SY-SUBRC.
IF SY-SUBRC = 0 AND NOT KNMT-WERKS IS INITIAL.
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
KNMT-WERKS
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC EQ 0.
* Vorschlagswerk setzen
VBAP-WERKS = KNMT-WERKS.
ENDIF.
ENDIF.
ENDIF.
* 3.a Werk aus Kunde/Warengruppe/Datum/Artikel vorschlagen (Retail)
* Work from customer/category of commodities/date/articles suggest (Retail)
IF VBAP-WERKS = SPACE.
IF VBEP-EDATU IS INITIAL.
DA_EDATU = VBAK-VDATU.
ELSE.
DA_EDATU = VBEP-EDATU.
ENDIF.
CALL FUNCTION 'LOCATION_ISS_PLANT_DETERMINE'
EXPORTING
I_KUNNR = VBAK-KUNNR
I_MATKL = MAAPV-MATKL
I_VALID_DATE = DA_EDATU
I_MATNR = VBAP-MATNR
IMPORTING
O_ISSUING_PLANT = VBAP-WERKS
EXCEPTIONS
INVALID_PLANT = 1
PLANT_NOT_FOUND = 2
LIEFERWERK_NO_ENTRIES = 3
NO_VALID_ISSUING_PLANT = 4
ARTICEL_NOT_CONTINUED = 5
NO_ISSUING_PLANT_FOUND = 6
OTHERS = 7.
IF VBAP-WERKS NE SPACE.
* Vorschlagswerk prüfen
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
VBAP-WERKS
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC NE 0.
* Vorschlagswerk zurücksetzen
CLEAR VBAP-WERKS.
ENDIF.
ENDIF.
ENDIF.
* 4. Werk aus dem Warenempfänger vorschlagen
* Work from the consignee suggest
* KUWEV=客户主文件记录送达方总览
* 注意 KUWEV-DWERK数据有'KNVV_SINGLE_READ'函数读取销售视图来填写,参见代码二
PERFORM KUWEV_SELECT_POSITION(SAPMV45A) USING VBAP-POSNR
SPACE
VBAP-SPART
CHARX
CHANGING SY-SUBRC.
IF KUWEV-DWERK NE SPACE AND VBAP-WERKS = SPACE.
* Vorschlagswerk prüfen
*关于VBAP-WERKS_PRUEFEN子例程的运行操作参见代码三,只有该例程监测正确才会填写VBAP-WERKS字段
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
KUWEV-DWERK
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC EQ 0.
* Vorschlagswerk setzen
VBAP-WERKS = KUWEV-DWERK.
ENDIF.
ENDIF.
* 5. Werk aus dem Material vorschlagen
* Work from the material suggest
* MAAPV=物料主记录视图: 销售屏幕1,参见后面的代码四
* 注意 MAAPV-DWERK数据有'MVKE_SINGLE_READ'函数读取销售视图来填写
IF MAAPV-DWERK NE SPACE AND VBAP-WERKS = SPACE.
* Vorschlagswerk prüfen
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
MAAPV-DWERK
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC EQ 0.
* Vorschlagswerk setzen
VBAP-WERKS = MAAPV-DWERK.
ENDIF.
ENDIF.
* 6. Werk aus *VBAP-Werks füllen.
IF NOT *VBAP-WERKS IS INITIAL AND VBAP-WERKS IS INITIAL.
* Vorschlagswerk prüfen
PERFORM VBAP-WERKS_PRUEFEN USING VBAP-POSNR
*VBAP-WERKS
SPACE
SPACE
SPACE
SY-SUBRC
SPACE.
IF SY-SUBRC EQ 0.
* Vorschlagswerk setzen
VBAP-WERKS = *VBAP-WERKS.
ENDIF.
ENDIF.
IF NOT DA_MSG IS INITIAL.
IF V4231_SHOWN IS INITIAL.
* Das Material &1 ist im Werk &2 nicht vorhanden
* 工厂 &2 中不存在物料 &1。新工厂:&3
PERFORM MESSAGE_VARIABEL(SAPFV45L)
USING 'V4' '231'
SPACE CHARX
VBAP-MATNR RV45A-DWERK VBAP-WERKS SPACE.
V4231_SHOWN = CHARX.
ENDIF.
ENDIF.
ENDFORM.
*代码二 单元:LV05EF1Q
*---------------------------------------------------------------------*
* FORM LESEN_KUWEV_KNVV_01 *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM LESEN_KUWEV_KNVV_01.
DATA: CUST_FUNC_ACTIVE TYPE XFLAG.
PERFORM READ_KNVV_KNVV_D1_00.
IF RCODE EQ 4.
* USER-EXIT if no KNVV was found
CALL FUNCTION 'MODX_FUNCTION_ACTIVE_CHECK'
EXPORTING
CPROGNAME = 'SAPLV09A'
FUNCNUMBER = '002'
IMPORTING
ACTIVE = CUST_FUNC_ACTIVE
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
* Customer Function 002 is active, execute it
IF SY-SUBRC = 0 AND CUST_FUNC_ACTIVE = 'X'.
CALL FUNCTION 'EXIT_SAPLV09A_002'
EXPORTING
FIF_PARVW = VTCOM-PARVW
FIF_NRART = 'KU'
FIF_PARTNER = VTCOM-KUNNR
FIF_VBTYP = VTCOM-VBTYP
FIF_VBOBJ = VTCOM-VBOBJ
FIF_VKORG = VTCOM-VKORG
FIF_VTWEG = VTCOM-VTWEG
FIF_SPART = VTCOM-SPART
FIF_PROCESSMODE = GV_PROCESSMODE.
ENDIF.
IF VTCOM-MSGKZ = ' '.
MESSAGE E210 WITH VTCOM-KUNNR
VTCOM-VKORG
VTCOM-VTWEG
VTCOM-SPART
RAISING NO_KNVV.
CHECK 1 = 2.
ENDIF.
ENDIF.
*销售视图填写工厂
PERFORM MOVE_LKNVV_TO_KUWEV.
IF NOT VTCOM-DEAR6 IS INITIAL.
KUWEV-KUNNR = VTCOM-KUNNR.
ENDIF.
INCLUDE V05EZZWE.
ENDFORM. "LESEN_KUWEV_KNVV_01
代码三
:检查TVKWZ是否存在(机构单位: 每个销售机构允许的工厂数)
:检查MARC
代码位置:LMG22FSQ的子过程FORM SELECT_SINGLE
MARC PREPARE 0 SELECT WHERE "MANDT" = :A0 AND "MATNR" = :A1 AND "WERKS" = :A2
MARC OPEN 0 SELECT WHERE "MANDT" = '800' AND "MATNR" = '00057047' AND "WERKS" = '3101'
:检查MLAN 物料的税分类
代码位置:LMATLF28的子过程 LESEN_MLAN
MLAN PREPARE 0 SELECT WHERE "MANDT" = :A0 AND "MATNR" = :A1 AND "ALAND" = :A2
MLAN OPEN 0 SELECT WHERE "MANDT" = '800' AND "MATNR" = '00057047' AND "ALAND" = 'CN'
:检查KNVI 客户基本税指示符
代码位置:在KNVI_GENERIC_READ_LAND函数里
KNVI PREPARE 0 SELECT WHERE "MANDT" = :A0 AND "KUNNR" = :A1
KNVI OPEN 0 SELECT WHERE "MANDT" = '800' AND "KUNNR" = '0010506537'
代码四:参见单元:LMATLF31
*--------------------------------------------
* LESEN_MAPOV
*--------------------------------------------
FORM LESEN_MAPOV .
MTCOR-RMAPOV = X.
PERFORM LESEN_MARA."该代码会调用MARA_SINGLE_READ函数来读取物料数据
IF SY-SUBRC = 0.
PERFORM LESEN_MVKE. "该代码会调用MVKE_SINGLE_READ函数来读取物料销售视图数据
ENDIF.
IF SY-SUBRC = 0.
PERFORM LESEN_MAKT.
ENDIF.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING MARA TO MAPOV.
MOVE-CORRESPONDING MVKE TO MAPOV.
MAPOV-ZIEME = MVKE-VRKME.
MAPOV-ARKTX = MAKT-MAKTX.
MOVE-CORRESPONDING MAKT TO MAPOV.
ENDIF.
IF SY-SUBRC NE 0.
CLEAR MAPOV .
ENDIF.
IF SY-SUBRC = 0.
CLEAR MTCOR-RMAPOV .
ENDIF.
IF MAPOV-LVORM NE SPACE.
MTCOR-LVORM = MAPOV-LVORM .
ENDIF.
ENDFORM.