Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Not Updating Customized Table when System having Performance Issue

Former Member
0 Kudos

Dear Gurus,

I've built an user exit in MM using EXIT_SAPLMBMB_001

. This userexit is triggered whenever a material document is created. This userexit in turns call a function module that write information to a customized table ZMCHA.

During normal operations, this function has been working fine. Both MCHA and ZMCHB is updated. However during performance issue times, only MCHA table is updated and not ZMCHB.

I've tried a commit statement inside the function module but i've got an abap dump. Function Module used for Commit is DB_COMMIT.

Please let me know if anybody has encounter such issues. Thanks in advance

Regards

Leonard

12 REPLIES 12

former_member188685
Active Contributor
0 Kudos

what is ther Dump you are getting.

and After Dump are you able to check the Debugger.

so that you can see why and where it gave dump..

regards

vijay

Former Member
0 Kudos

Leonard,

The reason I can think of is that whenever there are performance issues, some where the code might not be able to handle the data and is going for a short dump and I guess this is happening even before it reaches the user exit.

Could you please put a break point in the user exit (In case of performance issues) and see of the execution is happening in the first place?

Regards,

Ravi

Note : Please reward the posts that are helpful.

0 Kudos

Dear Gurus,

I really appreciate your reply. Actually, I decided to take away the Commit statement because SAP recommends not to put commit statement inside user exit. Without Commit Statement, there will be no dump.

However still when there is performance issue, table ZMCHB is not updated. I am not sure what is going on. Please advise. Is there other way of ensure that this table is updated whenever standard sap table MCHB is updated. U see, i'm not getting any hint from SM13 and ST22. I cannot see any update failure nor ABAP Dump. The data simply did not update the customized table.

Please advise.

Cheers

Leonard

0 Kudos

How are you Updating the Tables. and what kind of Performance issue.

please let us know...

regards

vijay

0 Kudos

Can you just show the code ...

regards

vijay

0 Kudos

FUNCTION EXIT_SAPLMBMB_001.

*"----


""Lokale Schnittstelle:

*" TABLES

*" XMKPF STRUCTURE MKPF

*" XMSEG STRUCTURE MSEG

*" XVM07M STRUCTURE VM07M

*"----


INCLUDE ZXMBCU01.

ENDFUNCTION.

----


  • INCLUDE ZXMBCU01 *

----


*- Code to save to database ZMM_HIDE

  • for goods movement, transfer posting, post goods issue and

  • reversal

*

*- Owner of process

  • goods movement and transfer, refer to MM, Hason Ho from DC

  • post goods issue and reversal, refer to SD, Chai Kim Feng or

  • Chew Tzin Pang from DC

*

  • Purpose of exit

  • Hide quantity are stored into the Goods Recipient(WEMPF) field

  • in exit MBCF0002. It will be abstracted for ZMM_HIDE

*- check transaction codes

CHECK sy-tcode EQ gc_movement OR "MIGO

sy-tcode EQ gc_transfer OR "MB1B

sy-tcode EQ gc_goodsissue OR "MB1A

sy-tcode EQ gc_goodsrecei OR "MB31

sy-tcode EQ gc_return OR "MB01

sy-tcode EQ 'VL01N' OR

sy-tcode EQ 'MB1C' OR

sy-tcode EQ 'MB11' OR

sy-tcode EQ 'MI07' OR

sy-tcode EQ gc_pgi OR "VL02N

sy-tcode EQ gc_reversal OR "VL09

sy-tcode EQ gc_rev_matl. "MBST

CLEAR lt_value.

*- check that the material document is new

SELECT SINGLE mblnr INTO gw_ymseg-mblnr

FROM mseg

WHERE mblnr EQ xmseg-mblnr.

CHECK sy-subrc NE 0.

*- stock type from database index

CLEAR gt_lbbsa.

IMPORT lbbsa = gt_lbbsa FROM DATABASE indx(sm) ID sy-uname.

DELETE FROM DATABASE indx(sm) ID sy-uname.

*- get hide quantities from the WEMPF field

LOOP AT xmseg INTO gw_ymseg.

*- check special stock indicator

CHECK gw_ymseg-sobkz EQ 'E' OR

gw_ymseg-sobkz EQ space.

CLEAR lw_value.

MOVE-CORRESPONDING gw_ymseg TO lw_value.

*- stock type

READ TABLE gt_lbbsa INTO gw_lbbsa

WITH KEY zeile = gw_ymseg-zeile.

lw_value-lbbsa = gw_lbbsa-lbbsa.

*- sales order stock, take from different field for sales order number

MOVE: gw_ymseg-mat_kdauf TO lw_value-kdauf,

gw_ymseg-mat_kdpos TO lw_value-kdpos.

*- convert only if not blank

IF NOT gw_ymseg IS INITIAL.

MOVE gw_ymseg-wempf TO lw_value-hideq.

*- save

INSERT lw_value INTO TABLE lt_value.

ENDIF.

DATA: lw_xmkpf1 LIKE mkpf.

READ TABLE xmkpf INTO lw_xmkpf1 INDEX 1.

if gw_ymseg-werks = '2011' and

gw_ymseg-lifnr NE space and

lw_xmkpf1-blart = 'WE' and

( gw_ymseg-bwart = '101' or gw_ymseg-bwart = '102' ).

IF sy-tcode EQ 'MIGO' or sy-tcode EQ 'MB01' or sy-tcode EQ 'MBST'.

Tables: ZMM_MSEG.

DATA: l_charg1 like mseg-charg,

l_charg2 like mseg-charg,

l_matkl like mara-matkl,

l_LWRBTR like ZFI_COST_VALID-LWRBTR,

l_UWRBTR like ZFI_COST_VALID-UWRBTR,

l_ZUDCSQF like ZMM_MSEG-ZUDCSQF,

l_ZLDCSQF like ZMM_MSEG-ZULCSQF,

lv_update(1).

select single matkl into l_matkl

from mara

where matnr = gw_ymseg-matnr

and ( matkl = 'WB' or matkl = 'WB SPLIT' ).

if sy-subrc = 0.

split gw_ymseg-charg at '/' into l_charg1 l_charg2.

  • if gw_ymseg-bwart = '101'.

*--Populate data to table ZMM_MSEG.

ZMM_MSEG-WERKS = gw_ymseg-werks.

ZMM_MSEG-MBLNR = gw_ymseg-mblnr.

ZMM_MSEG-ZEILE = gw_ymseg-zeile.

ZMM_MSEG-BUDAT = lw_xmkpf1-budat.

ZMM_MSEG-ZCHRG = l_charg2.

ZMM_MSEG-EBELN = gw_ymseg-ebeln.

ZMM_MSEG-EBELP = gw_ymseg-ebelp.

ZMM_MSEG-MATNR = gw_ymseg-matnr.

ZMM_MSEG-CHARG = gw_ymseg-charg.

ZMM_MSEG-BWART = gw_ymseg-bwart.

ZMM_MSEG-SHKZG = gw_ymseg-shkzg.

ZMM_MSEG-WAERS = space.

ZMM_MSEG-BUALT = space.

ZMM_MSEG-DMBTR = space.

ZMM_MSEG-MENGE = gw_ymseg-menge.

ZMM_MSEG-MEINS = gw_ymseg-meins.

ZMM_MSEG-WEMPF = gw_ymseg-wempf.

ZMM_MSEG-WEMPF = gw_ymseg-wempf.

ZMM_MSEG-ZUDCSQF = space.

ZMM_MSEG-ZULCSQF = space.

INSERT INTO ZMM_MSEG VALUES ZMM_MSEG.

  • endif.

endif.

endif.

endif.

ENDLOOP.

CHECK sy-subrc EQ 0.

  • insert start - tehbm 29/11/03

DATA: lw_xmkpf LIKE mkpf. "tehbm 29/11/03

READ TABLE xmkpf INTO lw_xmkpf INDEX 1.

  • end insert

*- save hide quantity into

CALL FUNCTION 'Z_MM_SAVE_HIDE_QTY'

EXPORTING

  • i_budat = xmkpf-budat "tehbm 29/11

i_budat = lw_xmkpf-budat "tehbm 29/11

TABLES

t_value = lt_value

EXCEPTIONS

save_failed = 1

no_data_found = 2

data_already_exist = 3

no_movement = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

0 Kudos

FUNCTION z_mm_save_hide_qty.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(I_TCODE) LIKE SY-TCODE DEFAULT SY-TCODE

*" REFERENCE(I_BUDAT) LIKE MKPF-BUDAT

*" TABLES

*" T_VALUE STRUCTURE ZSMM_HIDE

*" EXCEPTIONS

*" SAVE_FAILED

*" NO_DATA_FOUND

*" DATA_ALREADY_EXIST

*" NO_MOVEMENT

*" STOCK_TYPE_IS_BLANK

*"----


*- purpose :

  • to save information of hide quantities into the database table

  • based on the debit/credit indicator

  • S = debit, H = credit

*

*- warning :

  • function module does not check whether the GI quantity is more than

  • the stored quantity

*- transfer input values into global data

CLEAR gt_value.

gt_value[] = t_value[].

*- transfer transaction code

gv_tcode = i_tcode.

*- filter valid materials only

PERFORM filter_materials TABLES gt_value.

*- check lines

DESCRIBE TABLE gt_value LINES gv_lines.

IF gv_lines EQ 0.

RAISE no_data_found.

ENDIF.

*- get data from table ZMM_MCHB and ZMM_MCHBH

  • ZMM_MSKA and ZMM_MSKAH

PERFORM get_custom_data.

*- compile amount for same batch

PERFORM process_mseg.

*- check if previous posting is in ZMM_MSKA or ZMM_MCHB

  • then move to the history table

PERFORM past_period_posting USING i_budat.

*- create new data if not found

  • add or subtract depending on credit/debit indicator

  • and update database

PERFORM process_movement USING i_budat.

*- initialize

CLEAR: gt_new,

gt_change.

ENDFUNCTION.

----


***INCLUDE LZMM0001F01 .

----


&----


*& Form transfer_data_out

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


  • Change History

----


  • David Wirawan 10/05/2005 DR019MM DEVK909232

----


FORM transfer_data_out.

*- transfer data to screen

zsmm_hide = gw_data.

*- transfer item number based on line item number

  • WRITE sy-stepl TO gv_posnr RIGHT-JUSTIFIED.

*- get hide unit of measure to hide quantity field

IF zsmm_hide-hideu EQ space.

CLEAR gw_twew.

READ TABLE gt_twew INTO gw_twew

WITH TABLE KEY matnr = zsmm_hide-matnr.

zsmm_hide-hideu = gw_twew-ewbez.

ENDIF.

ENDFORM. " transfer_data_out

&----


*& Form filter_materials

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM filter_materials TABLES pt_data STRUCTURE zsmm_hide.

*- filter valid materials with hide

*- get purchasing document that is 3rd party assignments

CLEAR gt_ekpo.

SELECT ebeln ebelp knttp INTO TABLE gt_ekpo

FROM ekpo

FOR ALL ENTRIES IN pt_data

WHERE ebeln EQ pt_data-ebeln

AND ebelp EQ pt_data-ebelp

AND ( knttp EQ 'X' OR

knttp EQ 'Z' ).

*- check that it is not third party document

LOOP AT pt_data INTO gw_value.

READ TABLE gt_ekpo INTO gw_ekpo

WITH TABLE KEY ebeln = gw_value-ebeln

ebelp = gw_value-ebelp.

IF sy-subrc EQ 0.

DELETE pt_data.

ENDIF.

ENDLOOP.

*- get external material group for checking

CLEAR gt_twew.

SELECT amatnr amatkl bextwg bewbez INTO TABLE gt_twew

FROM mara AS a JOIN twewt AS b

ON amatkl EQ bextwg

FOR ALL ENTRIES IN pt_data

WHERE a~matnr EQ pt_data-matnr

AND b~spras EQ 'E'.

*- check that material is dual unit

LOOP AT pt_data INTO gw_value.

READ TABLE gt_twew INTO gw_twew

WITH TABLE KEY matnr = gw_value-matnr.

IF sy-subrc NE 0.

DELETE pt_data.

CONTINUE.

ENDIF.

*- conversion alpha for sales order number

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = gw_value-kdauf

IMPORTING

output = gw_value-kdauf.

MODIFY pt_data FROM gw_value TRANSPORTING kdauf.

ENDLOOP.

ENDFORM. " filter_materials

&----


*& Form process_movement

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_movement USING pv_datum LIKE sy-datum.

*- save information with positive values, receive values

*- check to MCHB

PERFORM check_save_mchb USING gt_quan

pv_datum.

*- check to MKSA

PERFORM check_save_mska USING gt_quan

pv_datum.

ENDFORM. " process_movement

&----


*& Form add_subtract_cuhide

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM add_subtract_cuhide.

*- add or subtract value based on credit/debit indicator

IF gw_value-shkzg EQ gc_debit.

ADD gw_value-hideq TO gw_hide-cuhide.

ELSE.

SUBTRACT gw_value-hideq FROM gw_hide-cuhide.

ENDIF.

ENDFORM. " add_subtract_cuhide

&----


*& Form process_mseg

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_mseg.

FIELD-SYMBOLS: <hide> LIKE gw_zmm_mchb-clabs,

<quan> LIKE gw_zmm_mchb-clabs.

DATA: lv_save TYPE sy-subrc.

*- sum for same batch

SORT gt_value BY matnr werks lgort charg sobkz kdauf kdpos.

CLEAR gt_quan[].

LOOP AT gt_value INTO gw_value.

*- get the stock type for the automated document entries

CLEAR gw_zmm_stock.

*- read value according to the stock movement + or -

IF gw_value-shkzg EQ gc_debit.

READ TABLE gt_zmm_stock INTO gw_zmm_stock

WITH KEY bwart = gw_value-bwart

tsobk = gw_value-sobkz.

ELSE.

READ TABLE gt_zmm_stock INTO gw_zmm_stock

WITH KEY bwart = gw_value-bwart

fsobk = gw_value-sobkz.

ENDIF.

IF sy-subrc EQ 0.

*- stock type to diff stock type

IF gw_value-shkzg EQ gc_debit.

gw_value-lbbsa = gw_zmm_stock-tlbbs.

gw_value-sobkz = gw_zmm_stock-tsobk.

ELSE.

gw_value-lbbsa = gw_zmm_stock-flbbs.

gw_value-sobkz = gw_zmm_stock-fsobk.

ENDIF.

ENDIF.

*- get stock movement indicator

PERFORM get_movement_ind USING gw_value-lbbsa

gw_value-sobkz

CHANGING gw_t156c

sy-subrc.

CHECK sy-subrc EQ 0.

*- get the stock type

CASE 'X'.

WHEN gw_t156c-xlabst.

ASSIGN: gw_quan-clabh TO <hide>,

gw_quan-clabs TO <quan>.

WHEN gw_t156c-xinsme.

ASSIGN: gw_quan-cinsh TO <hide>,

gw_quan-cinsm TO <quan>.

WHEN gw_t156c-xeinme.

ASSIGN: gw_quan-ceinh TO <hide>,

gw_quan-ceinm TO <quan>.

WHEN gw_t156c-xspeme.

ASSIGN: gw_quan-cspeh TO <hide>,

gw_quan-cspem TO <quan>.

WHEN gw_t156c-xretme.

ASSIGN: gw_quan-creth TO <hide>,

gw_quan-cretm TO <quan>.

WHEN gw_t156c-xumlme.

ASSIGN: gw_quan-cumlh TO <hide>,

gw_quan-cumlm TO <quan>.

WHEN gw_t156c-xmeikl.

ASSIGN: gw_quan-kalah TO <hide>,

gw_quan-kalab TO <quan>.

WHEN gw_t156c-xmeikq.

ASSIGN: gw_quan-kainh TO <hide>,

gw_quan-kains TO <quan>.

WHEN gw_t156c-xmeiks.

ASSIGN: gw_quan-kasph TO <hide>,

gw_quan-kaspe TO <quan>.

WHEN gw_t156c-xmeike.

ASSIGN: gw_quan-kaeih TO <hide>,

gw_quan-kaein TO <quan>.

ENDCASE.

*- different key based on special stock indicator

*- normal stock

IF gw_value-sobkz EQ space.

AT END OF sobkz.

lv_save = 1.

ENDAT.

*- sales order stock

ELSE.

AT END OF kdpos.

lv_save = 1.

ENDAT.

ENDIF.

*- credit/debit movements

IF gw_value-shkzg EQ gc_debit.

ADD: gw_value-hideq TO <hide>,

gw_value-menge TO <quan>.

ELSE.

SUBTRACT: gw_value-hideq FROM <hide>,

gw_value-menge FROM <quan>.

ENDIF.

*- save into temp table

IF lv_save EQ 1.

MOVE-CORRESPONDING gw_value TO gw_quan.

*- sales order stock

IF gw_value-sobkz EQ 'E'.

MOVE: gw_value-kdauf TO gw_quan-vbeln,

gw_value-kdpos TO gw_quan-posnr.

ENDIF.

APPEND gw_quan TO gt_quan.

CLEAR: gw_quan,

lv_save.

ENDIF.

ENDLOOP.

*- delete where no movements

IF sy-subrc EQ 0.

DELETE gt_quan WHERE clabs EQ 0

AND cinsm EQ 0

AND ceinm EQ 0

AND cspem EQ 0

AND cretm EQ 0

AND cumlm EQ 0

AND kalab EQ 0

AND kains EQ 0

AND kaspe EQ 0

AND kaein EQ 0

and clabh EQ 0

AND cinsh EQ 0

AND ceinh EQ 0

AND cspeh EQ 0

AND creth EQ 0

AND cumlh EQ 0

AND kalah EQ 0

AND kainh EQ 0

AND kasph EQ 0

AND kaeih EQ 0.

ENDIF.

ENDFORM. " process_mseg

&----


*& Form past_period_posting

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM past_period_posting USING pv_datum LIKE sy-datum.

*- check if past period posting, then update the history table

  • accordingly

*- check lines

DESCRIBE TABLE gt_quan LINES gv_lines.

IF gv_lines EQ 0.

RAISE no_movement.

ENDIF.

*- for MCHBH

  • perform update_mchbh using gt_quan. "tehbm 29/11

PERFORM update_mchbh USING gt_quan pv_datum. "tehbm 29/11

*- for MSKAH

  • perform update_mskah using gt_quan. "tehbm 29/11

PERFORM update_mskah USING gt_quan pv_datum. "tehbm 29/11

ENDFORM. " past_period_posting

&----


*& Form get_custom_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_custom_data.

*- store the custom data from ZMM_MCHB and ZMM_MCHBH

CLEAR gt_zmm_mchb.

SELECT * INTO TABLE gt_zmm_mchb

FROM zmm_mchb

FOR ALL ENTRIES IN gt_value

WHERE matnr EQ gt_value-matnr

AND werks EQ gt_value-werks

AND lgort EQ gt_value-lgort

AND charg EQ gt_value-charg.

CLEAR gt_zmm_mchbh.

SELECT * INTO TABLE gt_zmm_mchbh

FROM zmm_mchbh

FOR ALL ENTRIES IN gt_value

WHERE matnr EQ gt_value-matnr

AND werks EQ gt_value-werks

AND lgort EQ gt_value-lgort

AND charg EQ gt_value-charg.

CLEAR gt_zmm_mska.

SELECT * INTO TABLE gt_zmm_mska

FROM zmm_mska

FOR ALL ENTRIES IN gt_value

WHERE matnr EQ gt_value-matnr

AND werks EQ gt_value-werks

AND lgort EQ gt_value-lgort

AND charg EQ gt_value-charg

AND sobkz EQ gt_value-sobkz.

  • AND vbeln EQ gt_value-kdauf

  • AND posnr EQ gt_value-kdpos.

CLEAR gt_zmm_mskah.

SELECT * INTO TABLE gt_zmm_mskah

FROM zmm_mskah

FOR ALL ENTRIES IN gt_value

WHERE matnr EQ gt_value-matnr

AND werks EQ gt_value-werks

AND lgort EQ gt_value-lgort

AND charg EQ gt_value-charg

AND sobkz EQ gt_value-sobkz

AND vbeln EQ gt_value-kdauf

AND posnr EQ gt_value-kdpos.

CLEAR gt_zmm_stock.

SELECT * INTO TABLE gt_zmm_stock

FROM zmm_stockmvt.

ENDFORM. " get_custom_data

&----


*& Form check_save_mchb

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_save_mchb USING pt_quan LIKE gt_quan

pv_datum LIKE sy-datum.

FIELD-SYMBOLS: <hide> LIKE gw_zmm_mchb-clabs,

<quan> LIKE gw_zmm_mchb-clabs.

DATA: lv_cur_lfmon LIKE marv-lfmon, "tehbm

lv_cur_lfgja LIKE marv-lfgja, "tehbm

lv_bukrs LIKE marv-bukrs. "tehbm

DATA: lv_bwkey like t001w-bwkey. "David Wirawan

*- initialize

CLEAR: gt_new_mchb,

gt_change_mchb,

gt_change_mchbh.

LOOP AT pt_quan INTO gw_quan WHERE sobkz EQ space.

*-- insert start by tehbm 29/11/03

  • get the current MM posting period

IF lv_cur_lfmon IS INITIAL OR

lv_cur_lfgja IS INITIAL.

*-- Start David Wirawan DR019MM

*--Start Remark this code

  • CLEAR lv_bukrs.

  • SELECT SINGLE bwkey INTO lv_bukrs

  • FROM t001w

  • WHERE werks EQ gw_quan-werks.

*--End Remark this code

CLEAR lv_bukrs.

SELECT SINGLE bwkey INTO lv_bwkey

FROM t001w

WHERE werks EQ gw_quan-werks.

SELECT SINGLE bukrs INTO lv_bukrs

FROM t001k

WHERE bwkey EQ lv_bwkey.

*-- End David Wirawan

SELECT SINGLE lfgja lfmon

INTO (lv_cur_lfgja, lv_cur_lfmon)

FROM marv

WHERE bukrs EQ lv_bukrs.

ENDIF.

*-- insert end by tehbm 29/11/03

*- get value from database

CLEAR gw_zmm_mchb.

READ TABLE gt_zmm_mchb INTO gw_zmm_mchb

WITH KEY matnr = gw_quan-matnr

werks = gw_quan-werks

lgort = gw_quan-lgort

charg = gw_quan-charg.

IF sy-subrc EQ 0.

*- if found, add difference (add or minus is done at consolidation)

ADD: gw_quan-clabs TO gw_zmm_mchb-clabs,

gw_quan-cumlm TO gw_zmm_mchb-cumlm,

gw_quan-cinsm TO gw_zmm_mchb-cinsm,

gw_quan-ceinm TO gw_zmm_mchb-ceinm,

gw_quan-cspem TO gw_zmm_mchb-cspem,

gw_quan-cretm TO gw_zmm_mchb-cretm,

gw_quan-clabh TO gw_zmm_mchb-clabh,

gw_quan-cumlh TO gw_zmm_mchb-cumlh,

gw_quan-cinsh TO gw_zmm_mchb-cinsh,

gw_quan-ceinh TO gw_zmm_mchb-ceinh,

gw_quan-cspeh TO gw_zmm_mchb-cspeh,

gw_quan-creth TO gw_zmm_mchb-creth.

*- changed date & periods

  • move: sy-datum(04) to gw_zmm_mchb-lfgja, "tehbm

  • sy-datum+04(02) to gw_zmm_mchb-lfmon, "tehbm

MOVE: lv_cur_lfgja TO gw_zmm_mchb-lfgja, "tehbm

lv_cur_lfmon TO gw_zmm_mchb-lfmon, "tehbm

sy-datum TO gw_zmm_mchb-laeda,

sy-uname TO gw_zmm_mchb-aenam.

  • IF gv_bwart NE 'Z13'.

*

  • MOVE: lv_cur_lfgja TO gw_zmm_mchb-lfgja, "tehbm

  • lv_cur_lfmon TO gw_zmm_mchb-lfmon. "tehbm

*

  • ENDIF.

*

  • MOVE: sy-datum TO gw_zmm_mchb-laeda,

  • sy-uname TO gw_zmm_mchb-aenam.

*- change

INSERT gw_zmm_mchb INTO TABLE gt_change_mchb.

ELSE.

*- not found, create new entry

*- get unit of measure

CLEAR gw_twew.

READ TABLE gt_twew INTO gw_twew

WITH TABLE KEY matnr = gw_quan-matnr.

CHECK sy-subrc EQ 0.

*- if not found, then create new entry with entered hide quantity

MOVE-CORRESPONDING gw_quan TO gw_zmm_mchb.

*- move values

MOVE: gw_twew-ewbez TO gw_zmm_mchb-hideu,

  • sy-datum(04) to gw_zmm_mchb-lfgja, "tehbm

  • sy-datum+04(02) to gw_zmm_mchb-lfmon, "tehbm

lv_cur_lfgja TO gw_zmm_mchb-lfgja, "tehbm

lv_cur_lfmon TO gw_zmm_mchb-lfmon, "tehbm

sy-datum TO gw_zmm_mchb-ersda,

sy-uname TO gw_zmm_mchb-ernam,

sy-datum TO gw_zmm_mchb-laeda,

sy-uname TO gw_zmm_mchb-aenam.

*- new entry

INSERT gw_zmm_mchb INTO TABLE gt_new_mchb.

ENDIF.

*- back posting ?

PERFORM check_back_posting USING pv_datum

gw_quan-werks

CHANGING sy-subrc.

CHECK sy-subrc EQ 0.

**- start addition by tehbm 29/11/03

    • check if the record was just updated in routine

*'past_period_posting'

    • if true, then should no update again

  • READ TABLE gt_new_mchbh INTO gw_zmm_mchbh

  • WITH KEY matnr = gw_quan-matnr

  • werks = gw_quan-werks

  • lgort = gw_quan-lgort

  • charg = gw_quan-charg

  • lfgja = pv_datum+00(04)

  • lfmon = pv_datum+04(02).

*

  • CHECK sy-subrc NE 0.

**- end addition by tehbm 29/11/03

*

**- get value from database

  • CLEAR gw_zmm_mchbh.

  • READ TABLE gt_zmm_mchbh INTO gw_zmm_mchbh

  • WITH KEY matnr = gw_quan-matnr

  • werks = gw_quan-werks

  • lgort = gw_quan-lgort

  • charg = gw_quan-charg

  • lfgja = pv_datum+00(04)

  • lfmon = pv_datum+04(02).

*

  • CHECK sy-subrc EQ 0.

*

**- add changes

  • ADD: gw_quan-clabs TO gw_zmm_mchbh-clabs,

  • gw_quan-cumlm TO gw_zmm_mchbh-cumlm,

  • gw_quan-cinsm TO gw_zmm_mchbh-cinsm,

  • gw_quan-ceinm TO gw_zmm_mchbh-ceinm,

  • gw_quan-cspem TO gw_zmm_mchbh-cspem,

  • gw_quan-cretm TO gw_zmm_mchbh-cretm,

  • gw_quan-clabh TO gw_zmm_mchbh-clabh,

  • gw_quan-cumlh TO gw_zmm_mchbh-cumlh,

  • gw_quan-cinsh TO gw_zmm_mchbh-cinsh,

  • gw_quan-ceinh TO gw_zmm_mchbh-ceinh,

  • gw_quan-cspeh TO gw_zmm_mchbh-cspeh,

  • gw_quan-creth TO gw_zmm_mchbh-creth.

*

**- not found, transfer (default, should not be found)

  • INSERT gw_zmm_mchbh INTO TABLE gt_change_mchbh.

ENDLOOP.

IF sy-subrc EQ 0.

*- create into customized table MCHB

DESCRIBE TABLE gt_new_mchb LINES gv_lines.

IF gv_lines GT 0.

INSERT zmm_mchb FROM TABLE gt_new_mchb.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

*- save into customized table MCHB

DESCRIBE TABLE gt_change_mchb LINES gv_lines.

IF gv_lines GT 0.

UPDATE zmm_mchb FROM TABLE gt_change_mchb.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

**- save into customized table MCHBH

  • DESCRIBE TABLE gt_change_mchbh LINES gv_lines.

*

  • IF gv_lines GT 0.

  • UPDATE zmm_mchbh FROM TABLE gt_change_mchbh.

*

  • IF sy-subrc NE 0.

  • RAISE save_failed.

  • ENDIF.

  • ENDIF.

ENDIF.

ENDFORM. " check_save_mchb

&----


*& Form get_movement_ind

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_movement_ind USING pv_lbbsa LIKE vm07m-lbbsa

pv_sobkz LIKE mseg-sobkz

CHANGING pw_t156c LIKE gw_t156c

pv_subrc LIKE sy-subrc.

*- get the movement indicator

CLEAR pw_t156c.

SELECT SINGLE * INTO pw_t156c

FROM t156c

WHERE lbbsa EQ pv_lbbsa

AND sobkz EQ pv_sobkz.

pv_subrc = sy-subrc.

ENDFORM. " get_movement_ind

&----


*& Form check_save_mska

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_save_mska USING pt_quan LIKE gt_quan

pv_datum LIKE sy-datum.

FIELD-SYMBOLS: <hide> LIKE gw_zmm_mchb-clabs,

<quan> LIKE gw_zmm_mchb-clabs.

DATA: lv_cur_lfmon LIKE marv-lfmon, "tehbm

lv_cur_lfgja LIKE marv-lfgja, "tehbm

lv_bukrs LIKE marv-bukrs. "tehbm

*- initialize

CLEAR: gt_new_mska,

gt_change_mska,

gt_change_mskah.

LOOP AT pt_quan INTO gw_quan WHERE sobkz EQ 'E'.

*-- insert start by tehbm 29/11/03

  • get the current MM posting period

IF lv_cur_lfmon IS INITIAL OR

lv_cur_lfgja IS INITIAL.

CLEAR lv_bukrs.

SELECT SINGLE bwkey INTO lv_bukrs

FROM t001w

WHERE werks EQ gw_quan-werks.

SELECT SINGLE lfgja lfmon

INTO (lv_cur_lfgja, lv_cur_lfmon)

FROM marv

WHERE bukrs EQ lv_bukrs.

ENDIF.

*-- insert end by tehbm 29/11/03

*- get value from database

CLEAR gw_zmm_mska.

READ TABLE gt_zmm_mska INTO gw_zmm_mska

WITH KEY matnr = gw_quan-matnr

werks = gw_quan-werks

lgort = gw_quan-lgort

charg = gw_quan-charg

sobkz = gw_quan-sobkz

vbeln = gw_quan-vbeln

posnr = gw_quan-posnr.

IF sy-subrc EQ 0.

*- if found, add difference (add or minus is done at consolidation)

ADD: gw_quan-kalab TO gw_zmm_mska-kalab,

gw_quan-kains TO gw_zmm_mska-kains,

gw_quan-kaspe TO gw_zmm_mska-kaspe,

gw_quan-kaein TO gw_zmm_mska-kaein,

gw_quan-kalah TO gw_zmm_mska-kalah,

gw_quan-kainh TO gw_zmm_mska-kainh,

gw_quan-kasph TO gw_zmm_mska-kasph,

gw_quan-kaeih TO gw_zmm_mska-kaeih.

  • move: sy-datum(04) to gw_zmm_mska-lfgja,

  • sy-datum+04(02) to gw_zmm_mska-lfmon.

  • IF gv_bwart NE 'Z13'.

MOVE: lv_cur_lfgja TO gw_zmm_mska-lfgja,

lv_cur_lfmon TO gw_zmm_mska-lfmon.

  • ENDIF.

*- change

INSERT gw_zmm_mska INTO TABLE gt_change_mska.

ELSE.

*- not found, create new entry

*- get unit of measure

CLEAR gw_twew.

READ TABLE gt_twew INTO gw_twew

WITH TABLE KEY matnr = gw_quan-matnr.

CHECK sy-subrc EQ 0.

*- if not found, then create new entry with entered hide quantity

MOVE-CORRESPONDING gw_quan TO gw_zmm_mska.

*- move values

MOVE: gw_twew-ewbez TO gw_zmm_mska-hideu,

  • sy-datum(04) to gw_zmm_mska-lfgja, "tehbm

  • sy-datum+04(02) to gw_zmm_mska-lfmon. "tehbm

lv_cur_lfgja TO gw_zmm_mska-lfgja, "tehbm

lv_cur_lfmon TO gw_zmm_mska-lfmon. "tehbm

*- new entry

INSERT gw_zmm_mska INTO TABLE gt_new_mska.

ENDIF.

**- back posting ?

  • PERFORM check_back_posting USING pv_datum

  • gw_quan-werks

  • CHANGING sy-subrc.

*

  • CHECK sy-subrc EQ 0.

*

**- start addition by tehbm 29/11/03

    • check if the record was just updated in routine

*'past_period_posting'

    • if true, then should no update again

  • READ TABLE gt_new_mskah INTO gw_zmm_mskah

  • WITH KEY matnr = gw_quan-matnr

  • werks = gw_quan-werks

  • lgort = gw_quan-lgort

  • charg = gw_quan-charg

  • sobkz = gw_quan-sobkz

  • vbeln = gw_quan-vbeln

  • posnr = gw_quan-posnr

  • lfgja = pv_datum+00(04)

  • lfmon = pv_datum+04(02).

*

  • CHECK sy-subrc NE 0.

**- end addition by tehbm 29/11/03

*

**- get value from database

  • CLEAR gw_zmm_mskah.

  • READ TABLE gt_zmm_mskah INTO gw_zmm_mskah

  • WITH KEY matnr = gw_quan-matnr

  • werks = gw_quan-werks

  • lgort = gw_quan-lgort

  • charg = gw_quan-charg

  • sobkz = gw_quan-sobkz

  • vbeln = gw_quan-vbeln

  • posnr = gw_quan-posnr

  • lfgja = pv_datum+00(04)

  • lfmon = pv_datum+04(02).

*

    • check sy-subrc ne 0. "tehbm 1/12/03

  • CHECK sy-subrc EQ 0. "tehbm 1/12/03

*

**- add changes

  • ADD: gw_quan-kalab TO gw_zmm_mskah-kalab,

  • gw_quan-kains TO gw_zmm_mskah-kains,

  • gw_quan-kaspe TO gw_zmm_mskah-kaspe,

  • gw_quan-kaein TO gw_zmm_mskah-kaein,

  • gw_quan-kalah TO gw_zmm_mskah-kalah,

  • gw_quan-kainh TO gw_zmm_mskah-kainh,

  • gw_quan-kasph TO gw_zmm_mskah-kasph,

  • gw_quan-kaeih TO gw_zmm_mskah-kaeih.

*

**- not found, transfer (default, should not be found)

  • INSERT gw_zmm_mskah INTO TABLE gt_change_mskah.

ENDLOOP.

IF sy-subrc EQ 0.

*- create into customized table MSKA

DESCRIBE TABLE gt_new_mska LINES gv_lines.

IF gv_lines GT 0.

INSERT zmm_mska FROM TABLE gt_new_mska.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

*- save into customized table MSKA

DESCRIBE TABLE gt_change_mska LINES gv_lines.

IF gv_lines GT 0.

UPDATE zmm_mska FROM TABLE gt_change_mska.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

**- save into customized table MSKAH

  • DESCRIBE TABLE gt_change_mskah LINES gv_lines.

*

  • IF gv_lines GT 0.

  • UPDATE zmm_mskah FROM TABLE gt_change_mskah.

*

  • IF sy-subrc NE 0.

  • RAISE save_failed.

  • ENDIF.

  • ENDIF.

ENDIF.

ENDFORM. " check_save_mska

&----


*& Form update_mchbh

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM update_mchbh USING pt_quan LIKE gt_quan

pv_budat LIKE sy-datum.

FIELD-SYMBOLS: <hide> LIKE gw_zmm_mchb-clabs,

<quan> LIKE gw_zmm_mchb-clabs.

DATA: lv_cur_lfmon LIKE marv-lfmon, "tehbm

lv_cur_lfgja LIKE marv-lfgja, "tehbm

lv_bukrs LIKE marv-bukrs. "tehbm

DATA: lv_tab_lfmon LIKE marv-lfmon,

lv_tab_lfgja LIKE marv-lfgja.

DATA: lv_matnr TYPE matnr,

lw_zmm_mchbh LIKE gw_zmm_mchbh.

*- initialize

CLEAR gt_new_mchbh.

LOOP AT pt_quan INTO gw_quan WHERE sobkz EQ space.

*-- insert start by tehbm 29/11/03

  • get the current MM posting period

IF lv_cur_lfmon IS INITIAL OR

lv_cur_lfgja IS INITIAL.

CLEAR lv_bukrs.

SELECT SINGLE bwkey INTO lv_bukrs

FROM t001w

WHERE werks EQ gw_quan-werks.

SELECT SINGLE lfgja lfmon

INTO (lv_cur_lfgja, lv_cur_lfmon)

FROM marv

WHERE bukrs EQ lv_bukrs.

ENDIF.

*-- insert end by tehbm 29/11/03

*- get value from database

CLEAR: gw_zmm_mchb, gw_zmm_mchbh.

READ TABLE gt_zmm_mchb INTO gw_zmm_mchb

WITH KEY matnr = gw_quan-matnr

werks = gw_quan-werks

lgort = gw_quan-lgort

charg = gw_quan-charg.

IF sy-subrc EQ 0.

*- if current period, no change to history table

  • replace start by tehbm 29/11/2003

  • if gw_zmm_mchb-lfgja eq sy-datum(04) and

  • gw_zmm_mchb-lfmon eq sy-datum+04(02).

IF gw_zmm_mchb-lfmon EQ lv_cur_lfmon AND "month

gw_zmm_mchb-lfgja EQ lv_cur_lfgja. "year

  • replace end by tehbm 29/11/03

*- replce start by tehbm 29/11/2003

  • continue.

IF gw_zmm_mchb-lfmon NE pv_budat+4(2) OR

gw_zmm_mchb-lfgja NE pv_budat(4).

*- add value into history table

MOVE-CORRESPONDING gw_zmm_mchb TO gw_zmm_mchbh.

gw_zmm_mchbh-lfgja = pv_budat(4).

gw_zmm_mchbh-lfmon = pv_budat+4(2).

CLEAR: gw_zmm_mchbh-clabs,

gw_zmm_mchbh-cumlm,

gw_zmm_mchbh-cinsm,

gw_zmm_mchbh-ceinm,

gw_zmm_mchbh-cspem,

gw_zmm_mchbh-cretm,

gw_zmm_mchbh-clabh,

gw_zmm_mchbh-cumlh,

gw_zmm_mchbh-cinsh,

gw_zmm_mchbh-ceinh,

gw_zmm_mchbh-cspeh,

gw_zmm_mchbh-creth.

READ TABLE gt_zmm_mchbh INTO gw_zmm_mchbh

WITH KEY matnr = gw_zmm_mchbh-matnr

werks = gw_zmm_mchbh-werks

lgort = gw_zmm_mchbh-lgort

charg = gw_zmm_mchbh-charg

lfgja = gw_zmm_mchbh-lfgja

lfmon = gw_zmm_mchbh-lfmon.

IF sy-subrc EQ 0.

DELETE gt_zmm_mchbh INDEX sy-tabix.

ENDIF.

ADD: gw_quan-clabs TO gw_zmm_mchbh-clabs,

gw_quan-cumlm TO gw_zmm_mchbh-cumlm,

gw_quan-cinsm TO gw_zmm_mchbh-cinsm,

gw_quan-ceinm TO gw_zmm_mchbh-ceinm,

gw_quan-cspem TO gw_zmm_mchbh-cspem,

gw_quan-cretm TO gw_zmm_mchbh-cretm,

gw_quan-clabh TO gw_zmm_mchbh-clabh,

gw_quan-cumlh TO gw_zmm_mchbh-cumlh,

gw_quan-cinsh TO gw_zmm_mchbh-cinsh,

gw_quan-ceinh TO gw_zmm_mchbh-ceinh,

gw_quan-cspeh TO gw_zmm_mchbh-cspeh,

gw_quan-creth TO gw_zmm_mchbh-creth.

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

SUBTRACT 1 FROM gw_zmm_mchbh-lfmon.

IF gw_zmm_mchbh-lfmon EQ 0.

gw_zmm_mchbh-lfmon = '12'.

SUBTRACT 1 FROM gw_zmm_mchbh-lfgja.

ENDIF.

lw_zmm_mchbh = gw_zmm_mchbh.

CLEAR: gw_zmm_mchbh-clabs,

gw_zmm_mchbh-cumlm,

gw_zmm_mchbh-cinsm,

gw_zmm_mchbh-ceinm,

gw_zmm_mchbh-cspem,

gw_zmm_mchbh-cretm,

gw_zmm_mchbh-clabh,

gw_zmm_mchbh-cumlh,

gw_zmm_mchbh-cinsh,

gw_zmm_mchbh-ceinh,

gw_zmm_mchbh-cspeh,

gw_zmm_mchbh-creth.

*- create only if it does not exist

READ TABLE gt_zmm_mchbh FROM gw_zmm_mchbh

TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

ENDIF.

ELSE.

CONTINUE.

ENDIF.

*- replace end by tehbm 29/11/2003

ELSE.

*- different period, move to history table

CLEAR gw_zmm_mchbh.

MOVE-CORRESPONDING gw_zmm_mchb TO gw_zmm_mchbh.

*- table period

lv_tab_lfmon = gw_zmm_mchbh-lfmon.

lv_tab_lfgja = gw_zmm_mchbh-lfgja.

  • IF gw_zmm_mchbh-lfmon EQ pv_budat+4(2) AND

  • gw_zmm_mchbh-lfgja EQ pv_budat(4).

*- create entry of the previous entry

gw_zmm_mchbh-lfmon = lv_cur_lfmon.

gw_zmm_mchbh-lfgja = lv_cur_lfgja.

SUBTRACT 1 FROM gw_zmm_mchbh-lfmon.

IF gw_zmm_mchbh-lfmon EQ 0.

gw_zmm_mchbh-lfmon = '12'.

SUBTRACT 1 FROM gw_zmm_mchbh-lfgja.

ENDIF.

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

*---- add changes

*- add by dc_adriant

*- get value from database

lw_zmm_mchbh = gw_zmm_mchbh.

  • gw_zmm_mchbh = lw_zmm_mchbh.

  • gw_zmm_mchbh-lfmon = pv_budat+4(2).

  • gw_zmm_mchbh-lfgja = pv_budat(4).

DO 2 TIMES.

SUBTRACT 1 FROM gw_zmm_mchbh-lfmon.

IF gw_zmm_mchbh-lfmon EQ 0.

gw_zmm_mchbh-lfmon = '12'.

SUBTRACT 1 FROM gw_zmm_mchbh-lfgja.

ENDIF.

  • READ TABLE gt_zmm_mchbh INTO gw_zmm_mchbh

  • WITH KEY matnr = gw_zmm_mchbh-matnr

  • werks = gw_zmm_mchbh-werks

  • lgort = gw_zmm_mchbh-lgort

  • charg = gw_zmm_mchbh-charg

  • lfgja = gw_zmm_mchbh-lfgja

  • lfmon = gw_zmm_mchbh-lfmon.

*- add by dc_adriant

IF ( gw_zmm_mchbh-lfmon LT lv_tab_lfmon AND

gw_zmm_mchbh-lfgja EQ lv_tab_lfgja ) OR

( gw_zmm_mchbh-lfgja LT lv_tab_lfgja ).

CLEAR: gw_zmm_mchbh-clabs,

gw_zmm_mchbh-cumlm,

gw_zmm_mchbh-cinsm,

gw_zmm_mchbh-ceinm,

gw_zmm_mchbh-cspem,

gw_zmm_mchbh-cretm,

gw_zmm_mchbh-clabh,

gw_zmm_mchbh-cumlh,

gw_zmm_mchbh-cinsh,

gw_zmm_mchbh-ceinh,

gw_zmm_mchbh-cspeh,

gw_zmm_mchbh-creth.

ENDIF.

READ TABLE gt_zmm_mchbh FROM gw_zmm_mchbh

TRANSPORTING NO FIELDS.

*- create if not exist

IF sy-subrc NE 0.

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

ENDIF.

ENDDO.

gw_zmm_mchbh = lw_zmm_mchbh.

*- add quantity of posting date is in period

IF pv_budat+04(02) NE lv_cur_lfmon OR

pv_budat+00(04) NE lv_cur_lfgja.

gw_zmm_mchbh-lfmon = pv_budat+04(02).

gw_zmm_mchbh-lfgja = pv_budat+00(04).

READ TABLE gt_zmm_mchbh INTO gw_zmm_mchbh

WITH KEY matnr = gw_zmm_mchbh-matnr

werks = gw_zmm_mchbh-werks

lgort = gw_zmm_mchbh-lgort

charg = gw_zmm_mchbh-charg

lfgja = gw_zmm_mchbh-lfgja

lfmon = gw_zmm_mchbh-lfmon.

*- delete

IF sy-subrc EQ 0.

DELETE gt_zmm_mchbh INDEX sy-tabix.

READ TABLE gt_new_mchbh FROM gw_zmm_mchbh

TRANSPORTING NO FIELDS.

IF sy-subrc EQ 0.

DELETE gt_new_mchbh INDEX sy-tabix.

ENDIF.

ENDIF.

ADD: gw_quan-clabs TO gw_zmm_mchbh-clabs,

gw_quan-cumlm TO gw_zmm_mchbh-cumlm,

gw_quan-cinsm TO gw_zmm_mchbh-cinsm,

gw_quan-ceinm TO gw_zmm_mchbh-ceinm,

gw_quan-cspem TO gw_zmm_mchbh-cspem,

gw_quan-cretm TO gw_zmm_mchbh-cretm,

gw_quan-clabh TO gw_zmm_mchbh-clabh,

gw_quan-cumlh TO gw_zmm_mchbh-cumlh,

gw_quan-cinsh TO gw_zmm_mchbh-cinsh,

gw_quan-ceinh TO gw_zmm_mchbh-ceinh,

gw_quan-cspeh TO gw_zmm_mchbh-cspeh,

gw_quan-creth TO gw_zmm_mchbh-creth.

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

ENDIF.

  • ENDIF.

*------ end insertion by tehbm 29/11

ENDIF.

ELSE.

*- start deletion by tehbm 29/11/03

**- if no value; do not continue

  • exit.

*- end deletion by tehbm 29/11/03

*- start insertion by tehbm 29/11/03

*- if it's a new record in zmm_mchb, create a history in zmm_mchbh as

  • well if it is a back posting

*- if it is not a back posting, only upadate zmm_mchb

*- check posting date

IF pv_budat(4) EQ lv_cur_lfgja AND

pv_budat+4(2) EQ lv_cur_lfmon.

  • EXIT.

CONTINUE.

ENDIF.

*- get unit of measure

CLEAR gw_twew.

READ TABLE gt_twew INTO gw_twew

WITH TABLE KEY matnr = gw_quan-matnr.

CHECK sy-subrc EQ 0.

*- if not found, then create new entry with entered hide quantity

MOVE-CORRESPONDING gw_quan TO gw_zmm_mchbh.

*- move values

MOVE: gw_twew-ewbez TO gw_zmm_mchbh-hideu,

pv_budat(4) TO gw_zmm_mchbh-lfgja,

pv_budat+4(2) TO gw_zmm_mchbh-lfmon.

*- end insertion by tehbm 29/11/03

  • ENDIF.

**- check if back posting more than 2 periods

  • PERFORM check_back_posting USING pv_datum

  • gw_quan-werks

  • CHANGING sy-subrc.

*

  • CHECK sy-subrc EQ 0.

*- get value from database

READ TABLE gt_zmm_mchbh FROM gw_zmm_mchbh TRANSPORTING NO FIELDS.

CHECK sy-subrc NE 0.

*- not found, transfer (default, should not be found)

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

*- check if previous period is available

SUBTRACT 1 FROM gw_zmm_mchbh-lfmon.

IF gw_zmm_mchbh-lfmon EQ 0.

gw_zmm_mchbh-lfmon = 12.

SUBTRACT 1 FROM gw_zmm_mchbh-lfgja.

ENDIF.

*- not found, create entry of previous period with null values

READ TABLE gt_zmm_mchbh FROM gw_zmm_mchbh TRANSPORTING NO FIELDS.

CHECK sy-subrc NE 0.

CLEAR: gw_zmm_mchbh-clabs,

gw_zmm_mchbh-cumlm,

gw_zmm_mchbh-cinsm,

gw_zmm_mchbh-ceinm,

gw_zmm_mchbh-cspem,

gw_zmm_mchbh-cretm,

gw_zmm_mchbh-clabh,

gw_zmm_mchbh-cumlh,

gw_zmm_mchbh-cinsh,

gw_zmm_mchbh-ceinh,

gw_zmm_mchbh-cspeh,

gw_zmm_mchbh-creth.

INSERT gw_zmm_mchbh INTO TABLE: gt_new_mchbh,

gt_zmm_mchbh.

ENDIF.

ENDLOOP.

IF sy-subrc EQ 0.

*- check if already exist

CLEAR gt_change_mchbh.

LOOP AT gt_new_mchbh INTO gw_zmm_mchbh.

*- get value from database

SELECT SINGLE matnr INTO lv_matnr

FROM zmm_mchbh

WHERE matnr EQ gw_zmm_mchbh-matnr

AND werks EQ gw_zmm_mchbh-werks

AND lgort EQ gw_zmm_mchbh-lgort

AND charg EQ gw_zmm_mchbh-charg

AND lfgja EQ gw_zmm_mchbh-lfgja

AND lfmon EQ gw_zmm_mchbh-lfmon.

*- not found?

IF sy-subrc EQ 0.

DELETE gt_new_mchbh.

APPEND gw_zmm_mchbh TO gt_change_mchbh.

ENDIF.

ENDLOOP.

*- create into customized table

  • IF gv_tcode NE 'Z13'.

DESCRIBE TABLE gt_new_mchbh LINES gv_lines.

IF gv_lines GT 0.

INSERT zmm_mchbh FROM TABLE gt_new_mchbh.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

  • ENDIF.

*- update into customized table

DESCRIBE TABLE gt_change_mchbh LINES gv_lines.

IF gv_lines GT 0.

UPDATE zmm_mchbh FROM TABLE gt_change_mchbh.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " update_mchbh

&----


*& Form update_mskah

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM update_mskah USING pt_quan LIKE gt_quan

pv_budat LIKE sy-datum.

FIELD-SYMBOLS: <hide> LIKE gw_zmm_mchb-clabs,

<quan> LIKE gw_zmm_mchb-clabs.

DATA: lv_cur_lfmon LIKE marv-lfmon, "tehbm

lv_cur_lfgja LIKE marv-lfgja, "tehbm

lv_bukrs LIKE marv-bukrs. "tehbm

DATA: lv_tab_lfmon LIKE marv-lfmon,

lv_tab_lfgja LIKE marv-lfgja.

DATA: lv_matnr TYPE matnr,

lw_zmm_mskah LIKE gw_zmm_mskah.

*- initialize

CLEAR gt_new_mskah.

LOOP AT pt_quan INTO gw_quan WHERE sobkz EQ 'E'.

*-- insert start by tehbm 29/11/03

  • get the current MM posting period

IF lv_cur_lfmon IS INITIAL OR

lv_cur_lfgja IS INITIAL.

CLEAR lv_bukrs.

SELECT SINGLE bwkey INTO lv_bukrs

FROM t001w

WHERE werks EQ gw_quan-werks.

SELECT SINGLE lfgja lfmon

INTO (lv_cur_lfgja, lv_cur_lfmon)

FROM marv

WHERE bukrs EQ lv_bukrs.

ENDIF.

*-- insert end by tehbm 29/11/03

*- get value from database

CLEAR: gw_zmm_mska, gw_zmm_mskah.

READ TABLE gt_zmm_mska INTO gw_zmm_mska

WITH KEY matnr = gw_quan-matnr

werks = gw_quan-werks

lgort = gw_quan-lgort

charg = gw_quan-charg

sobkz = gw_quan-sobkz

vbeln = gw_quan-vbeln

posnr = gw_quan-posnr.

IF sy-subrc EQ 0.

*- if current period, no change to history table

  • replace start by tehbm 29/11/2003

  • if gw_zmm_mska-lfgja eq sy-datum(04) and

  • gw_zmm_mska-lfmon eq sy-datum+04(02).

IF gw_zmm_mska-lfmon EQ lv_cur_lfmon AND "month

gw_zmm_mska-lfgja EQ lv_cur_lfgja. "year

  • replace end by tehbm 29/11/03

*- replce start by tehbm 29/11/2003

  • continue.

IF gw_zmm_mska-lfmon NE pv_budat+4(2) OR

gw_zmm_mska-lfgja NE pv_budat(4).

MOVE-CORRESPONDING gw_zmm_mska TO gw_zmm_mskah.

gw_zmm_mskah-lfgja = pv_budat(4).

gw_zmm_mskah-lfmon = pv_budat+4(2).

CLEAR: gw_zmm_mskah-kalab,

gw_zmm_mskah-kains,

gw_zmm_mskah-kaspe,

gw_zmm_mskah-kaein,

gw_zmm_mskah-kalah,

gw_zmm_mskah-kainh,

gw_zmm_mskah-kasph,

gw_zmm_mskah-kaeih.

READ TABLE gt_zmm_mskah INTO gw_zmm_mskah

WITH KEY matnr = gw_zmm_mskah-matnr

werks = gw_zmm_mskah-werks

lgort = gw_zmm_mskah-lgort

charg = gw_zmm_mskah-charg

sobkz = gw_zmm_mskah-sobkz

vbeln = gw_zmm_mskah-vbeln

posnr = gw_zmm_mskah-posnr

lfgja = gw_zmm_mskah-lfgja

lfmon = gw_zmm_mskah-lfmon.

IF sy-subrc EQ 0.

DELETE gt_zmm_mskah INDEX sy-tabix.

ENDIF.

*---- add changes

ADD: gw_quan-kalab TO gw_zmm_mskah-kalab,

gw_quan-kains TO gw_zmm_mskah-kains,

gw_quan-kaspe TO gw_zmm_mskah-kaspe,

gw_quan-kaein TO gw_zmm_mskah-kaein,

gw_quan-kalah TO gw_zmm_mskah-kalah,

gw_quan-kainh TO gw_zmm_mskah-kainh,

gw_quan-kasph TO gw_zmm_mskah-kasph,

gw_quan-kaeih TO gw_zmm_mskah-kaeih.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

*- check if previous period is available

SUBTRACT 1 FROM gw_zmm_mskah-lfmon.

IF gw_zmm_mskah-lfmon EQ 0.

gw_zmm_mskah-lfmon = 12.

SUBTRACT 1 FROM gw_zmm_mskah-lfgja.

ENDIF.

lw_zmm_mskah = gw_zmm_mskah.

CLEAR: gw_zmm_mskah-kalab,

gw_zmm_mskah-kains,

gw_zmm_mskah-kaspe,

gw_zmm_mskah-kaein,

gw_zmm_mskah-kalah,

gw_zmm_mskah-kainh,

gw_zmm_mskah-kasph,

gw_zmm_mskah-kaeih.

*- create only if it does not exist

READ TABLE gt_zmm_mskah FROM gw_zmm_mskah

TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

ENDIF.

ELSE.

CONTINUE.

ENDIF.

*- replace end by tehbm 29/11/2003

ELSE.

*- different period, move to history table

CLEAR gw_zmm_mskah.

MOVE-CORRESPONDING gw_zmm_mska TO gw_zmm_mskah.

*- table period - tbm @ 7/2/2004

lv_tab_lfmon = gw_zmm_mskah-lfmon.

lv_tab_lfgja = gw_zmm_mskah-lfgja.

  • IF gw_zmm_mskah-lfmon EQ pv_budat+4(2) AND

  • gw_zmm_mskah-lfgja EQ pv_budat(4).

*------ start insertion by tehbm 29/11/2003

gw_zmm_mskah-lfmon = lv_cur_lfmon - 1.

gw_zmm_mskah-lfgja = lv_cur_lfgja.

IF gw_zmm_mskah-lfmon EQ 0.

gw_zmm_mskah-lfmon = '12'.

SUBTRACT 1 FROM gw_zmm_mskah-lfgja.

ENDIF.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

  • SUBTRACT 1 FROM gw_zmm_mskah-lfmon.

*

  • IF gw_zmm_mskah-lfmon EQ 0.

  • gw_zmm_mskah-lfmon = '12'.

  • SUBTRACT 1 FROM gw_zmm_mskah-lfgja.

  • ENDIF.

lw_zmm_mskah = gw_zmm_mskah.

DO 2 TIMES.

SUBTRACT 1 FROM gw_zmm_mskah-lfmon.

IF gw_zmm_mskah-lfmon EQ 0.

gw_zmm_mskah-lfmon = '12'.

SUBTRACT 1 FROM gw_zmm_mskah-lfgja.

ENDIF.

IF ( gw_zmm_mskah-lfmon LT lv_tab_lfmon AND

gw_zmm_mskah-lfgja EQ lv_tab_lfgja ) OR

( gw_zmm_mskah-lfgja LT lv_tab_lfgja ).

CLEAR: gw_zmm_mskah-kalab,

gw_zmm_mskah-kains,

gw_zmm_mskah-kaspe,

gw_zmm_mskah-kaein,

gw_zmm_mskah-kalah,

gw_zmm_mskah-kainh,

gw_zmm_mskah-kasph,

gw_zmm_mskah-kaeih.

ENDIF.

*- create only if not exists

READ TABLE gt_zmm_mskah FROM gw_zmm_mskah

TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

ENDIF.

ENDDO.

*- add by dc_adriant

*- get value from database

gw_zmm_mskah = lw_zmm_mskah.

gw_zmm_mskah-lfmon = pv_budat+4(2).

gw_zmm_mskah-lfgja = pv_budat(4).

  • READ TABLE gt_zmm_mskah INTO gw_zmm_mskah

  • WITH KEY matnr = gw_zmm_mskah-matnr

  • werks = gw_zmm_mskah-werks

  • lgort = gw_zmm_mskah-lgort

  • charg = gw_zmm_mskah-charg

  • sobkz = gw_zmm_mskah-sobkz

  • vbeln = gw_zmm_mskah-vbeln

  • posnr = gw_zmm_mskah-posnr

  • lfgja = gw_zmm_mskah-lfgja

  • lfmon = gw_zmm_mskah-lfmon.

*- add by dc_adriant

*- add quantity of posting date is in period

IF pv_budat+04(02) NE lv_cur_lfmon OR

pv_budat+00(04) NE lv_cur_lfgja.

gw_zmm_mskah-lfmon = pv_budat+04(02).

gw_zmm_mskah-lfgja = pv_budat+00(04).

READ TABLE gt_zmm_mskah INTO gw_zmm_mskah

WITH KEY matnr = gw_zmm_mskah-matnr

werks = gw_zmm_mskah-werks

lgort = gw_zmm_mskah-lgort

charg = gw_zmm_mskah-charg

sobkz = gw_zmm_mskah-sobkz

vbeln = gw_zmm_mskah-vbeln

posnr = gw_zmm_mskah-posnr

lfgja = gw_zmm_mskah-lfgja

lfmon = gw_zmm_mskah-lfmon.

*- delete

IF sy-subrc EQ 0.

DELETE gt_zmm_mskah INDEX sy-tabix.

READ TABLE gt_new_mskah FROM gw_zmm_mskah

TRANSPORTING NO FIELDS.

IF sy-subrc EQ 0.

DELETE gt_new_mskah INDEX sy-tabix.

ENDIF.

ENDIF.

*---- add changes

ADD: gw_quan-kalab TO gw_zmm_mskah-kalab,

gw_quan-kains TO gw_zmm_mskah-kains,

gw_quan-kaspe TO gw_zmm_mskah-kaspe,

gw_quan-kaein TO gw_zmm_mskah-kaein,

gw_quan-kalah TO gw_zmm_mskah-kalah,

gw_quan-kainh TO gw_zmm_mskah-kainh,

gw_quan-kasph TO gw_zmm_mskah-kasph,

gw_quan-kaeih TO gw_zmm_mskah-kaeih.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

ENDIF.

ENDIF.

*------ end insertion by tehbm 29/11

  • ENDIF.

ELSE.

*- start deletion by tehbm 29/11/03

**- if no value; do not continue

  • exit.

*- end deletion by tehbm 29/11/03

*- start insertion by tehbm 29/11/03

*- if it's a new record in zmm_mska, create a history in zmm_mskah as

  • well if it is a back posting

*- if it is not a back posting, only upadate zmm_mska

*- check posting date

IF pv_budat(4) EQ lv_cur_lfgja AND

pv_budat+4(2) EQ lv_cur_lfmon.

  • EXIT.

CONTINUE.

ENDIF.

*- get unit of measure

CLEAR gw_twew.

READ TABLE gt_twew INTO gw_twew

WITH TABLE KEY matnr = gw_quan-matnr.

CHECK sy-subrc EQ 0.

*- if not found, then create new entry with entered hide quantity

MOVE-CORRESPONDING gw_quan TO gw_zmm_mskah.

*- move values

MOVE: gw_twew-ewbez TO gw_zmm_mskah-hideu,

pv_budat(4) TO gw_zmm_mskah-lfgja,

pv_budat+4(2) TO gw_zmm_mskah-lfmon.

*- end insertion by tehbm 29/11/03

  • ENDIF.

**- check if back posting more than 2 periods

  • PERFORM check_back_posting USING pv_datum

  • gw_quan-werks

  • CHANGING sy-subrc.

*

  • CHECK sy-subrc EQ 0.

*- get value from database

  • clear gw_zmm_mskah. "commented out by tehbm

READ TABLE gt_zmm_mskah FROM gw_zmm_mskah TRANSPORTING NO FIELDS.

*- not found, transfer (default, should not be found)

CHECK sy-subrc NE 0.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

*- check if previous period is available

SUBTRACT 1 FROM gw_zmm_mskah-lfmon.

IF gw_zmm_mskah-lfmon EQ 0.

gw_zmm_mskah-lfmon = 12.

SUBTRACT 1 FROM gw_zmm_mskah-lfgja.

ENDIF.

*- not found, create entry of previous period with null values

READ TABLE gt_zmm_mskah FROM gw_zmm_mskah TRANSPORTING NO FIELDS.

CHECK sy-subrc NE 0.

CLEAR: gw_zmm_mskah-kalab,

gw_zmm_mskah-kains,

gw_zmm_mskah-kaspe,

gw_zmm_mskah-kaein,

gw_zmm_mskah-kalah,

gw_zmm_mskah-kainh,

gw_zmm_mskah-kasph,

gw_zmm_mskah-kaeih.

INSERT gw_zmm_mskah INTO TABLE: gt_new_mskah,

gt_zmm_mskah.

ENDIF.

ENDLOOP.

IF sy-subrc EQ 0.

*- check if already exist

CLEAR gt_change_mskah.

LOOP AT gt_new_mskah INTO gw_zmm_mskah.

*- get value from database

SELECT SINGLE matnr INTO lv_matnr

FROM zmm_mskah

WHERE matnr EQ gw_zmm_mskah-matnr

AND werks EQ gw_zmm_mskah-werks

AND lgort EQ gw_zmm_mskah-lgort

AND charg EQ gw_zmm_mskah-charg

AND sobkz EQ gw_zmm_mskah-sobkz

AND vbeln EQ gw_zmm_mskah-vbeln

AND posnr EQ gw_zmm_mskah-posnr

AND lfgja EQ gw_zmm_mskah-lfgja

AND lfmon EQ gw_zmm_mskah-lfmon.

*- not found?

IF sy-subrc EQ 0.

DELETE gt_new_mskah.

APPEND gw_zmm_mskah TO gt_change_mskah.

ENDIF.

ENDLOOP.

*- create into customized table

  • IF gv_tcode NE 'Z13'.

  • describe table gt_new_mska lines gv_lines. "tehbm

DESCRIBE TABLE gt_new_mskah LINES gv_lines. "tehbm

IF gv_lines GT 0.

  • insert zmm_mska from table gt_new_mska. "tehbm

INSERT zmm_mskah FROM TABLE gt_new_mskah. "tehbm

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

  • ENDIF.

*- update into customized table

DESCRIBE TABLE gt_change_mskah LINES gv_lines.

IF gv_lines GT 0.

UPDATE zmm_mskah FROM TABLE gt_change_mskah.

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " update_mskah

&----


*& Form check_back_posting

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_back_posting USING pv_datum LIKE sy-datum

pv_werks TYPE werks_d

CHANGING pv_subrc LIKE sy-subrc.

DATA: diff_perio TYPE i,

curr_year LIKE marv-lfgja,

curr_month LIKE marv-lfmon.

*- default error unless otherwise

pv_subrc = 4.

*- get the previous posting period from material control

SELECT SINGLE avmgja avmmon INTO (curr_year,curr_month)

FROM marv AS a JOIN t001k AS b

ON abukrs EQ bbukrs

JOIN t001w AS c

ON bbwkey EQ cbwkey

WHERE c~werks EQ pv_werks

AND a~xruem EQ 'X'.

CHECK sy-subrc EQ 0.

*- start addition by tehbm 29/11/03

  • do not update history table if posting period is the same as

  • current period

IF curr_year EQ pv_datum(4) AND

curr_month EQ pv_datum+4(2).

EXIT.

ENDIF.

*- calculate the difference

COMPUTE diff_perio = ( ( ( curr_year - pv_datum+00(04) ) * 12 )

+ curr_month ) - pv_datum+04(02).

IF diff_perio EQ 0 OR

diff_perio EQ 1.

pv_subrc = 0.

ENDIF.

ENDFORM. " check_back_posting

0 Kudos

Hi Can you Check <b>Sy-subrc</b> after insert and then say <b>commit work</b>.

and what are the key fields in ztable.

regards

vijay

0 Kudos

Hi Vijay,

We use the same key fields as standard SAP.

E.g ZMM_MCHB will be using same Key Field as MCHB.

In this case, they are as follows.

MANDT

MATNR

WERKS

LGORT

CHARG

0 Kudos

Check all keys are holding values,and try to check sy-subrc after insert.

regards

vijay

0 Kudos

Hi Vijay,

We've actually coded the error checking as below. Please give us your comment. Thanks

INSERT zmm_mskah FROM TABLE gt_new_mskah. "tehbm

IF sy-subrc NE 0.

RAISE save_failed.

ENDIF.

Cheers

Leonard

0 Kudos

yeah it is fine..

are you able to capture sy-subrc.

regards

vijay