Posted: Fri Feb 13, 2009 1:21 pm Post subject: Create material Substitution
Code:
FUNCTION z_create_mat_substitution.
*"----------------------------------------------------------------------
""Local Interface:
*" IMPORTING
*" REFERENCE(IT_MAT_SUB) TYPE ZMATERIAL_SUBSTITUTION_T
*" EXPORTING
*" REFERENCE(ET_BAPIRET2) TYPE BAPIRET2_T
*" EXCEPTIONS
*" FAILED
*"----------------------------------------------------------------------
*" This function uses the following standard function modules to
*" create material substitutions:
*" RV_KONDITION_SICHERN
*" RV_MAT_SUB_SAVE
*"----------------------------------------------------------------------
DATA: ls_mat_sub LIKE zmaterial_substitution,
ls_vakedb LIKE vakedb,
ls_xkonddvb LIKE konddvb,
ls_bapiret2 LIKE bapiret2,
lt_vakedb LIKE STANDARD TABLE OF vakedb,
lt_xkonddvb LIKE STANDARD TABLE OF konddvb,
lt_ykonddvb LIKE STANDARD TABLE OF konddvb,
lt_xkonddpvb LIKE STANDARD TABLE OF konddpvb,
lt_ykonddpvb LIKE STANDARD TABLE OF konddpvb,
lv_knumh TYPE knumh.
LOOP AT it_mat_sub INTO ls_mat_sub.
CLEAR: ls_vakedb,
ls_xkonddvb,
lt_vakedb[],
lt_xkonddvb[].
* Populate structure for RV_KONDITION_SICHERN.
MOVE: 'D' TO ls_vakedb-kvewe,
'001' TO ls_vakedb-kotabnr,
'V' TO ls_vakedb-kappl,
'A001' TO ls_vakedb-kschl,
ls_mat_sub-matwa TO ls_vakedb-vakey,
ls_mat_sub-datbi TO ls_vakedb-datbi,
ls_mat_sub-datab TO ls_vakedb-datab,
'I' TO ls_vakedb-xxdbaction.
* Populate structure for RV_MAT_SUB_SAVE.
MOVE: sy-mandt TO ls_xkonddvb-mandt,
ls_mat_sub-smatn TO ls_xkonddvb-smatn,
ls_mat_sub-meins TO ls_xkonddvb-meins,
ls_mat_sub-sugrd TO ls_xkonddvb-sugrd,
'I' TO ls_xkonddvb-updkz.
* Determine next available condition record number.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'KOND'
IMPORTING
number = lv_knumh.
ls_vakedb-knumh = ls_xkonddvb-knumh = lv_knumh.
* Append to internal tables.
APPEND: ls_vakedb TO lt_vakedb,
ls_xkonddvb TO lt_xkonddvb.
ENDLOOP.
* Call RV_KONDITION_SICHERN.
CALL FUNCTION 'RV_KONDITION_SICHERN' IN UPDATE TASK
TABLES
vakedb_tab = lt_vakedb.
* Call RV_MAT_SUB_SAVE to complete creation of Material Substitution.
CALL FUNCTION 'RV_MAT_SUB_SAVE' IN UPDATE TASK
TABLES
x_konddvb = lt_xkonddvb
y_konddvb = lt_ykonddvb
x_konddpvb = lt_xkonddpvb
y_konddpvb = lt_ykonddpvb.
* Commit to DB and wait as we need to check if the updates have been
successful or not.
COMMIT WORK AND WAIT.
* Check that substitutions have been created successfully.
LOOP AT it_mat_sub INTO ls_mat_sub.
SELECT SINGLE matwa INTO ls_mat_sub-matwa
FROM kotd001
WHERE kappl EQ 'V'
AND kschl EQ 'A001'
AND matwa EQ ls_mat_sub-matwa
AND datbi GE sy-datum
AND datab LE sy-datum.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.