SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Changing Configuration Values of a Configurable Material



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Sep 05, 2007 6:56 pm    Post subject: Changing Configuration Values of a Configurable Material Reply with quote

Author: Sharath Kumar Radhakrishna

Description
Changing Configuration Values of a Configurable Material in a SO, PO or a Service Order through an ABAP Program.

When doing a bulk update of a PO or an SO through ABAP there could be a requirement of updating new values to the configuration of a material, In these situations you can make use of this article to find out how to update the configuration values by ABAP program. (Since BDC recording supports adding new configuration values not modifying the existing ones).

Where is this Useful?
Configuration Data is maintained at the material master data and when this material becomes an item in a sales order or a purchase order, the configuration data is picked from the Material Master. But there can be situations where this configuration has to be modified, if you have to modify the configuration data of a configurable material through ABAP program you can fallow simple steps given in this article.

Overall Processing Logic
Let's take an example of a Sales order item, if the item material is configurable (MARA-KZKFG = 'X') then you can fetch the Configuration number (CUOBJ) which is a unique number within the system. This number is the key field to identify the configuration values stored in the database table; hence this field is available in VBAP, EKPO and AFKO. We have to pass this number to method GET_CURRENT_CBASE_BY_INSTANCE of class CL_CBASE in order to create an instance of this configuration data. Using this instance you can call method GET_CONFIGURATION to get the current configured values for that item and then you can change this values as you want and call method SET_CONFIGURATION to update it with modified values. For detailed processing logic you can refer the program code given below.

Program Code
Program below can be copied and used for updating material configuration. It will work for Sales order, Purchase order and service orders. In the selection screen you have to pass the Characteristic that you want to update and the new value of the characteristic. Class CL_BASE has been used to update the configuration values.

Code:
*&---------------------------------------------------------------------*
*& Report ZZ_TEST_CONFIG_CREATE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT zz_test_config_create MESSAGE-ID v1 .

TYPE-POOLS:
cucbt,
ibxx,
ibco2.

PARAMETERS : p_vbeln TYPE vbak-vbeln,
p_posnr TYPE vbap-posnr,
p_ebeln TYPE ekko-ebeln,
p_ebelp TYPE ekpo-ebelp,
p_aufnr TYPE afko-aufnr.

PARAMETERS : p_charac TYPE cabn-atinn,
p_upd TYPE v_ibin_syval-atwrt.

DATA : w_instance TYPE cuib_cuobj.

DATA: add_chr TYPE ibco2_value_tab,
l1_ind LIKE sy-tabix.
DATA: old_l TYPE i,
new_l TYPE i.

DATA: wa_chr LIKE ibvalue0,
wa_chr1 LIKE ibvalue0,
wa_con TYPE ibco2_instance_rec2.
DATA: l_obj TYPE REF TO cl_cbase.
CLEAR l_obj.
DATA: it_instances TYPE cuib_cuobj_tab.
DATA: l_head TYPE ibco2_ibase_rec,
l_config TYPE ibco2_instance_tab2.
DATA: wa_instances LIKE LINE OF it_instances.
CLEAR wa_instances.
APPEND wa_instances TO it_instances.
DATA: flg_invalid TYPE c.
CLEAR flg_invalid.

* Processing LOGIC.

IF p_vbeln IS NOT INITIAL.
SELECT SINGLE cuobj
INTO w_instance
FROM vbap
WHERE vbeln EQ p_vbeln
AND posnr EQ p_posnr.

ELSEIF p_ebeln IS NOT INITIAL.
SELECT SINGLE cuobj
INTO w_instance
FROM ekpo
WHERE ebeln EQ p_ebeln
AND ebelp EQ p_ebelp.

ELSEIF p_aufnr IS NOT INITIAL.

SELECT SINGLE cuobj
INTO w_instance
FROM afko
WHERE aufnr EQ p_aufnr.

ENDIF.

CALL METHOD cl_cbase=>get_current_cbase_by_instance
EXPORTING
iv_instance = w_instance
iv_check_only_buffer = space
IMPORTING
eo_cbase = l_obj
ev_instance_is_invalid = flg_invalid.

CALL METHOD l_obj->get_configuration
IMPORTING
es_cbase_head = l_head
et_instances = l_config.

DATA: c_ind LIKE sy-tabix.
CLEAR add_chr.CLEAR l1_ind.CLEAR wa_chr.
LOOP AT l_config INTO wa_con.
l1_ind = sy-tabix.
add_chr = wa_con-values.
LOOP AT add_chr INTO wa_chr WHERE atinn EQ p_charac.
wa_chr-atwrt = p_upd.
MODIFY add_chr FROM wa_chr.
ENDLOOP.
wa_con-values = add_chr.
MODIFY l_config FROM wa_con INDEX l1_ind.
ENDLOOP.

DATA: lcfg_head TYPE ibibconf.
CLEAR lcfg_head.
CALL METHOD l_obj->get_head_of_cfg
IMPORTING
es_head_cfg = lcfg_head.

CALL METHOD l_obj->set_configuration
EXPORTING
is_head_cfg = lcfg_head
CHANGING
ct_instances = l_config.
CALL METHOD l_obj->set_mark_for_saving.
CALL METHOD l_obj->save_and_free.
COMMIT WORK AND WAIT.
MESSAGE s899 WITH 'Configuration Updated'.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.