Complete document for creating Specification(CG02) with Property Tree
creation of Specification in CG02 along with Property Tree using BAPI BAPI_BUS1077_CREATE.
Whenever we create specification from the Program then we have the best option use is BAPI,so that it can execute well in the background as well as in Foreground and multiple specifications should be created.
We created specification by taking data from External Files. Upload them into SAP and then process the steps for Creation of Specifications.
Here are the things Maintained in the Document, which are important while creating Specification
- Specification Number genaration
- filling of Property tree
- Specification will be rolled back in case of fail transaction.
- For Specification Number
wa_ihead-primarykey = lv_sprimkey. ” int key
wa_ihead-flgprimkey = ‘X’.
wa_ihead-subauthgrp = ‘ALL’. ” auth group
* creating specification type
CONCATENATE c_z
lw_designcode-str_type
c_underscore
lw_designcode-st_sub_type INTO wa_ihead-subcategry.
APPEND wa_ihead TO i_head.
Identifier
wa_ident_header-primarykey = lv_phprimkey.
wa_ident_header-flgprimkey = true.
wa_ident_header-foreignkey = lv_sprimkey.
wa_ident_header-flgfrgnkey = ‘X’.
wa_ident_header-id_type = ‘NUM’. “ident.’s type
wa_ident_header-id_categry = ‘ZDES’. “ident.’s category
wa_ident_header-langu = ‘EN’. “ident.’s language
wa_ident_header-identifier = lw_designcode-desig_code.
APPEND wa_ident_header TO i_ident_header_tab.
Sub Identifier
wa_ident_sublist-primarykey = lv_identkey. .
wa_ident_sublist-flgprimkey = true.
wa_ident_sublist-foreignkey = lv_phprimkey.
wa_ident_sublist-flgfrgnkey = ‘ ‘ .
wa_ident_sublist-sublist = ‘EINECS’.
APPEND wa_ident_sublist TO i_ident_sublist.
Inheritance Relationship
This Inheritance data can be taken from ESTRI and ESTRH for the required Identifiers.
READ TABLE i_ispec INTO wa_ispec
WITH KEY ident = lw_designcode-desig_code.
IF sy-subrc = 0.
” I Spec number will fetch the record num from ESTRH table
CLEAR : wa_irec.
READ TABLE i_irec INTO wa_irec
WITH KEY subid = wa_ispec-subid.
IF sy-subrc = 0.
wa_irel-record_no_of_source = wa_irec-recn.
ENDIF.
CLEAR : wa_irec.
ENDIF.
” assigning template value
wa_irel-record_no_of_templ_header = lv_tempnum.
APPEND wa_irel TO i_rel.
- Prepare Property Tree
LOOP AT i_file3 INTO wa_file3 WHERE desig_code = lw_designcode-desig_code.
Property Header
CLEAR : wa_iprophead.
lv_phprimkey = lv_phprimkey + 1.
wa_iprophead-primarykey = lv_phprimkey.
wa_iprophead-flgprimkey = ‘X’.
wa_iprophead-foreignkey = wa_ihead-primarykey.
wa_iprophead-flgfrgnkey = ‘X’.
CLEAR : wa_file1.
wa_iprophead-subchacat = estcat.
APPEND wa_iprophead TO i_prophead.
ENDIF.
* This will create the instance number in the value assign tab
* and assign sequence to each instance number
Property Value
CLEAR : wa_ipropval.
lv_pvprimkey = lv_pvprimkey + 1.
wa_ipropval-primarykey = lv_pvprimkey.
wa_ipropval-flgprimkey = ‘X’.
wa_ipropval-foreignkey = wa_iprophead-primarykey.
wa_ipropval-flgfrgnkey = ‘X’.
wa_ipropval-sequence = lv_seq.
” seq number changes with each loop pass
APPEND wa_ipropval TO i_propval.
* to fill the status according to the below logic
* if status is Draft (D), rating will be draft
* if status is release (R), rating will be public
* if status is official (O), rating will be official
IF wa_file3-status EQ ‘D’.
wa_iuse-rating = text–006.
wa_iuse-val_area = ‘REG_WORLD’.
ELSEIF wa_file3-status EQ ‘O’.
wa_iuse-rating = text–008.
wa_iuse-val_area = ‘REG_WORLD’.
wa_iuse-act_ind = true.
ELSEIF wa_file3-status EQ ‘R’.
wa_iuse-rating = text–007.
wa_iuse-val_area = ‘REG_WORLD’.
ENDIF.
Identifier Usage
lv_puprimkey = lv_puprimkey + 1.
wa_iuse-primarykey = lv_puprimkey.
wa_iuse-flgprimkey = ‘X’.
wa_iuse-foreignkey = wa_ipropval-primarykey.
wa_iuse-flgfrgnkey = true.
wa_iuse-mastertabl = ‘ESTVA’.
APPEND wa_iuse TO i_use.
CLEAR wa_iuse.
Property Data
LOOP AT i_temp_file3 INTO wa_temp_file3
WHERE baseset = wa_file3-baseset.
lv_pd1primkey = lv_pd1primkey + 1.
wa_ipropdata-primarykey = lv_pd1primkey.
wa_ipropdata-foreignkey = wa_ipropval-primarykey.
wa_ipropdata-flgfrgnkey = ‘X’.
wa_ipropdata-flgprimkey = ‘X’.
wa_ipropdata-obj_type = ‘ESTVA’.
wa_ipropdata-char_value = wa_temp_file3-prop_value .
wa_ipropdata-meas_unit1 = lv_uom.
wa_ipropdata-descr_cval = wa_temp_file3-remarks.
wa_ipropdata-name_char = wa_file1-char_id.
wa_ipropdata-descr_char = wa_file1-char_des.
APPEND wa_ipropdata TO i_propdata.
CLEAR wa_ipropdata.
wa_ipropdata-char_value = wa_temp_file3-method.
wa_ipropdata-meas_unit1 = lv_uom.
wa_ipropdata-descr_cval = c_meth.
wa_ipropdata-name_char = wa_file1-char_id.
wa_ipropdata-descr_char = wa_file1-char_des.
lv_pd1primkey = lv_pd1primkey + 1.
wa_ipropdata-primarykey = lv_pd1primkey.
wa_ipropdata-foreignkey = wa_ipropval-primarykey.
wa_ipropdata-flgfrgnkey = ‘X’.
wa_ipropdata-flgprimkey = ‘X’.
wa_ipropdata-obj_type = ‘ESTVA’.
APPEND wa_ipropdata TO i_propdata.
CLEAR wa_ipropdata.
PROP_COMPONENT
CLEAR : wa_icomposition.
” fetching the i spec coresponding to the component design code
CLEAR : wa_ispec.
READ TABLE i_ispec INTO wa_ispec
WITH KEY ident = wa_temp_file3-comp_des_code.
IF sy-subrc = 0.
” I Spec number of componet code
wa_icomposition-comproot = wa_ispec-recnroot.
ENDIF.
” Assigning component type
CONDENSE wa_temp_file3-comp_role.
wa_icomposition-compcat = ‘ACT_AGENT’.
lv_cprimkey = lv_cprimkey + 1.
wa_icomposition-primarykey = lv_cprimkey.
wa_icomposition-flgprimkey = ‘X’.
wa_icomposition-foreignkey = wa_ipropval-primarykey.
wa_icomposition-flgfrgnkey = true.
wa_icomposition-sequence = lv_seq1.
APPEND wa_icomposition TO i_composition.
For Range Type- Data
If the Components are Numbers then we split the property value into : 1. number 2. UOM both of these are
wa_icomposition-exponent = lwa_t006a-msehi. ” assigning Unit of measure
IF lv_val CS ‘,’.
REPLACE ALL OCCURRENCES OF ‘,’ IN lv_val WITH ‘.’.
ENDIF.
IF lv_val CS ‘>=’ .
CLEAR: lv_lowop , lv_lowval.
SPLIT lv_val AT ‘>=’ INTO lv_lowop lv_lowval.
wa_icomposition-oplowlimit = lv_lowop.
wa_icomposition-low_limit = lv_lowval.
wa_icomposition-low_limit = lv_lowval.
wa_icomposition-opupplimit = lv_upop.
wa_icomposition-upp_limit = lv_upval1.
wa_icomposition-oplowlimit = ‘>=’.
wa_icomposition-avg_val = lv_upval1.
wa_icomposition-sequence = lv_seq1.
ELSEIF lv_val CS ‘>’.
CLEAR: lv_lowop , lv_lowval.
SPLIT lv_val AT ‘>’ INTO lv_lowop lv_lowval.
wa_icomposition-oplowlimit = lv_lowop.
wa_icomposition-low_limit = lv_lowval.
wa_icomposition-opupplimit = lv_upop.
wa_icomposition-upp_limit = lv_upval1.
wa_icomposition-oplowlimit = ‘>’.
wa_icomposition-avg_val = lv_upval1.
wa_icomposition-sequence = lv_seq1.
ELSEIF lv_val CS ‘<=’.
CLEAR: lv_upop , lv_upval.
lv_upval1 = lv_upval.
SPLIT lv_val AT ‘<=’ INTO lv_upop lv_upval1.
wa_icomposition-low_limit = lv_upop.
wa_icomposition-upp_limit = lv_upval1.
wa_icomposition-opupplimit = ‘<=’.
wa_icomposition-avg_val = lv_upval1.
wa_icomposition-sequence = lv_seq1.
ELSEIF lv_val CS ‘<‘ .
CLEAR: lv_upop , lv_upval.
lv_upval1 = lv_upval.
SPLIT lv_val AT ‘<‘ INTO lv_upop lv_upval1.
wa_icomposition-low_limit = lv_upop.
wa_icomposition-upp_limit = lv_upval1.
wa_icomposition-opupplimit = lv_upop.
wa_icomposition-upp_limit = lv_upval1.
wa_icomposition-opupplimit = ‘<‘.
wa_icomposition-avg_val = lv_upval1.
wa_icomposition-sequence = lv_seq1.
ELSEIF lv_val CS ‘-‘.
” this means a number range ex- 10-20
CLEAR : lv_lowval , lv_upval.
SPLIT lv_val AT ‘-‘ INTO lv_lowval lv_upval1.
wa_icomposition-low_limit = lv_lowval.
wa_icomposition-upp_limit = lv_upval1.
wa_icomposition-sequence = lv_seq1.
ELSE.
wa_icomposition-avg_val = lv_val. “upval1.
wa_icomposition-sequence = lv_seq1.
ENDIF.
lv_cprimkey = lv_cprimkey + 1.
wa_icomposition-primarykey = lv_cprimkey.
wa_icomposition-flgprimkey = ‘X’.
wa_icomposition-foreignkey = wa_ipropval-primarykey.
wa_icomposition-flgfrgnkey = true.
APPEND wa_icomposition TO i_composition.
CLEAR: wa_icomposition,lv_val,lv_uom.
Endloop
- Endloop.
CALL FUNCTION ‘BAPI_BUS1077_CREATE’
EXPORTING
key_date = sy-datum
* change_number = lv_chngnum
flg_header = ‘X’
flg_ident = ‘X’
flg_ident_sublist = true
* flg_header_usage = ‘X’
flg_ident_usage = ‘X’
flg_tplrel = ‘X’
flg_prop_header = ‘X’
flg_prop = ‘X’
flg_prop_data = ‘X’
flg_prop_comp = ‘X’
flg_prop_rel = ‘X’
flg_val_check_by_status =’X’
flg_prop_usage = ‘X’
TABLES
return = i_return
sub_header = i_head
tplrel = i_rel
prop_header = i_prophead
ident_sublist = i_ident_sublist
prop_val = i_propval
prop_data = i_propdata
prop_component = i_composition
ident_header = i_ident_header_tab
prop_usage = i_use.
handle possible problems
CALL METHOD cl_ehsb_aunit_helper=>error_handler
EXPORTING
i_pre_msg = ‘BAPI_BUS1077_CREATE’
i_return_tab = i_return.
- For Commit Work
CLEAR wa_return.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’
IMPORTING
return = wa_return.
Yes, this document is related .
The document is based on the usage of BAPI (used for creation of Specification), thus directly related to the Interface which is always known as web services for any other system.
Since these are interface thus directly is a part of SAP application Interface Framework.