Examples:
- If the quotation contains 1 line items with quantity = 3, then the contract should be 3 line items with quantity = 1 (of the same material.)
- If the quotation contains 2 line items with quantity = 3 and 2, then the contract should be 5 line items with quantity = 1 (first material for the first 3 line items, and the second material for the last 2.)
For once, I can get the items spread as the requirement ask but when I see the billing plan and pricing condition of the items, I recognise that they are not spread at all. I stuck at this condition for some days, trying to figure out how to properly recalculate the billing plan and the pricing condition.
Finally I ask a friend for a help. He help me trace the code and then he tries something that I would never think of. That is when spreading the line items he did not resequence the item numbers. He let it duplicated so the links to other data in memory are still intact. That's the solution.
From there I am doing more tests and figure out that I can strip out much of my previous codes because most of other data will be regenerated from the copied vbap only.
After much trial, I finally choose the user exit USEREXIT_MOVE_FIELD_TO_VBAK in program SAPMV45A to put my code, because it is where I can get a complete copy of VBAP in CVBAP internal table and not much processing has been done.
So here is the code:
FORM userexit_move_field_to_vbak.
DATA: lt_cvbap LIKE TABLE OF cvbap WITH HEADER LINE,
ld_quantity TYPE i.
CASE fcode.
WHEN 'RKON'.
IF ( sy-tcode = 'VA41' ). "contract creation
LOOP AT cvbap INTO lt_cvbap.
ld_quantity = lt_cvbap-zmeng / 1000.
DIVIDE:
lt_cvbap-zmeng BY ld_quantity,
lt_cvbap-orfmng BY ld_quantity,
lt_cvbap-netwr BY ld_quantity,
lt_cvbap-netpr BY ld_quantity.
DO ld_quantity TIMES.
APPEND lt_cvbap.
ENDDO.
ENDLOOP.
cvbap[] = lt_cvbap[].
ENDIF.
ENDCASE.
ENDFORM.
No comments:
Post a Comment