Working with batch Classification Change Function Module
Here I want to change the batch classification details through FUNCTION MODULE.
Function Module Name : VB_CHANGE_BATCH.
Example Code:
DATA:YMCHA TYPE MCHA,
CHAR_OF_BATCH TYPE TABLE OF CLBATCH,
WA_OF_BATCH TYPE CLBATCH,
CHANGED_BATCH TYPE TABLE OF MCHA,
ZIMSEG TYPE TABLE OF IMSEG,
RETURN TYPE TABLE OF BAPIRET2.
SELECT SINGLE MATNR,
WERKS,
CHARG FROM MSEG
INTO @DATA(WA_MSEG)
WHERE MBLNR = '2020024858'."give any other material document
"number in MSEG table which contain Batch
IF WA_MSEG IS NOT INITIAL.
YMCHA-MATNR = WA_MSEG-MATNR. "here i am passing material
YMCHA-WERKS = WA_MSEG-WERKS. "plant
YMCHA-CHARG = WA_MSEG-CHARG. "batch
CLEAR WA_MSEG.
WA_OF_BATCH-ATNAM = 'FB'. "characteristic name
WA_OF_BATCH-ATWTB = '45'. "characteristic Value
APPEND WA_OF_BATCH TO CHAR_OF_BATCH.
WA_OF_BATCH-ATNAM = 'TB'. ""characteristic name
WA_OF_BATCH-ATWTB = '57'. ""characteristic Value
APPEND WA_OF_BATCH TO CHAR_OF_BATCH.
CALL FUNCTION 'VB_CHANGE_BATCH'
EXPORTING
YMCHA = YMCHA
KZCLA = '1'
XKCFC = 'X'
SET_OLD_BATCH = 'X'
IMPORTING
YMCHA = YMCHA
TABLES
CHAR_OF_BATCH = CHAR_OF_BATCH
CHANGED_BATCH = CHANGED_BATCH
ZIMSEG = ZIMSEG
RETURN = RETURN
EXCEPTIONS
NO_MATERIAL = 1
NO_BATCH = 2
NO_PLANT = 3
MATERIAL_NOT_FOUND = 4
PLANT_NOT_FOUND = 5
LOCK_ON_MATERIAL = 6
LOCK_ON_PLANT = 7
LOCK_ON_BATCH = 8
LOCK_SYSTEM_ERROR = 9
NO_AUTHORITY = 10
BATCH_NOT_EXIST = 11
NO_CLASS = 12
ERROR_IN_CLASSIFICATION = 13
ERROR_IN_VALUATION_CHANGE = 14
ERROR_IN_STATUS_CHANGE = 15
REGION_OF_ORIGIN_NOT_FOUND = 16
COUNTRY_OF_ORIGIN_NOT_FOUND = 17
OTHERS = 18.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
WRITE:'SUCCESS'.
ENDIF.
ENDIF.
test it MSC3N Tansaction.
Function Module Name : VB_CHANGE_BATCH.
Example Code:
DATA:YMCHA TYPE MCHA,
CHAR_OF_BATCH TYPE TABLE OF CLBATCH,
WA_OF_BATCH TYPE CLBATCH,
CHANGED_BATCH TYPE TABLE OF MCHA,
ZIMSEG TYPE TABLE OF IMSEG,
RETURN TYPE TABLE OF BAPIRET2.
SELECT SINGLE MATNR,
WERKS,
CHARG FROM MSEG
INTO @DATA(WA_MSEG)
WHERE MBLNR = '2020024858'."give any other material document
"number in MSEG table which contain Batch
IF WA_MSEG IS NOT INITIAL.
YMCHA-MATNR = WA_MSEG-MATNR. "here i am passing material
YMCHA-WERKS = WA_MSEG-WERKS. "plant
YMCHA-CHARG = WA_MSEG-CHARG. "batch
CLEAR WA_MSEG.
WA_OF_BATCH-ATNAM = 'FB'. "characteristic name
WA_OF_BATCH-ATWTB = '45'. "characteristic Value
APPEND WA_OF_BATCH TO CHAR_OF_BATCH.
WA_OF_BATCH-ATNAM = 'TB'. ""characteristic name
WA_OF_BATCH-ATWTB = '57'. ""characteristic Value
APPEND WA_OF_BATCH TO CHAR_OF_BATCH.
CALL FUNCTION 'VB_CHANGE_BATCH'
EXPORTING
YMCHA = YMCHA
KZCLA = '1'
XKCFC = 'X'
SET_OLD_BATCH = 'X'
IMPORTING
YMCHA = YMCHA
TABLES
CHAR_OF_BATCH = CHAR_OF_BATCH
CHANGED_BATCH = CHANGED_BATCH
ZIMSEG = ZIMSEG
RETURN = RETURN
EXCEPTIONS
NO_MATERIAL = 1
NO_BATCH = 2
NO_PLANT = 3
MATERIAL_NOT_FOUND = 4
PLANT_NOT_FOUND = 5
LOCK_ON_MATERIAL = 6
LOCK_ON_PLANT = 7
LOCK_ON_BATCH = 8
LOCK_SYSTEM_ERROR = 9
NO_AUTHORITY = 10
BATCH_NOT_EXIST = 11
NO_CLASS = 12
ERROR_IN_CLASSIFICATION = 13
ERROR_IN_VALUATION_CHANGE = 14
ERROR_IN_STATUS_CHANGE = 15
REGION_OF_ORIGIN_NOT_FOUND = 16
COUNTRY_OF_ORIGIN_NOT_FOUND = 17
OTHERS = 18.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
WRITE:'SUCCESS'.
ENDIF.
ENDIF.
test it MSC3N Tansaction.