Ansicht
Dokumentation

CFX_S_API_WRITE - Single API to create or change objects in cFolders

CFX_S_API_WRITE - Single API to create or change objects in cFolders

Vendor Master (General Section)   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.
SAP E-Book

Functionality

This function module allows you to create or Change Materials, BOM, Generic Object, and Document using a single API call.

Fill in the corresponding table CT_BOM,CT_MATERIAL,CT_GENERIC,CT_DOCUMENT with data to create or change the objects in cFolders.

The table structure uses the structure that used in the APIs of CFX_API_DOC function group.

All of the tables contain a general structure which is explained below.

M_ID is the GUID of the object in cFolders [ Go to the object in cFolders application from URL get the p_doc_id ]

The field BACKEND_NAME is used for identifying an object, uniquely, by the API (to ensure the uniqueness please use GUIDs)

HEADER gives the header information of the object (name, type, folder id etc.,)

VERSION_INFO and VERSION_ATTR are version information about the objects.

In VERSION_ATTR you can also refer to other objects in cFolders these are the objects of type reference(IDREF). To achieve this the BACKEND_NAME as a reference to the object.

For example:

To link MPNs to the Material we can give

,,attribute id as "MPNS" [CL_CFX_S_API_HLP=>SC_LINK_MPN_CL_TYP ]

,,attribute value as "mpn1_backendname" , this is the BACKEND_NAME of the object present in the CT_GENERIC table.

,,If you want to link an existing MPN in cFolders to an material that is being created using the API, define it in CT_IDS table with a BACKEND_NAME and the GUID of the object along with the type.

Similarly in case of BOMs,

,,The BACKEND_NAME of the material in CT_MATERIAL or CT_IDS can be passed as the "PARENT_ID"

,,To link documents to materials use the same as described in the above example.

,,In the ITEMS structure also

,,,, The ITEM_ID can be any unique identifier [This will be used as a reference in ITEM_ATTR_VALUES]

,,,,The COMPONENT_NAME is nothing but the BACKEND_NAME reference to material in CT_MATERIAL ,,,,or CT_IDS tables. [component name will be empty in case of text items]

The other attributes are similar to the ones that are use in the older APIs in (CFX_API_DOC)

Example

Create a 'Z_S_API_WRITE' program to call the CFX_S_API_WRITE API

Please go through the example and note down how the BACKEND_NAME are used as reference in multiple places while intializing the objects.

REPORT z_s_api_write.

*Types

TYPE-POOLS: cfxf1,

cfxa0.

*General Declaration

DATA : lt_fault TYPE cfx_s_api_tt_fault,

ls_fault TYPE cfx_s_api_ts_fault,

l_error TYPE cfx_api_t_bool,

ls_id TYPE cfx_s_api_ts_ids,

lt_ids,, TYPE cfx_s_api_tt_ids,

lt_document TYPE cfx_s_api_tt_document.

*Material Declaration

DATA : lt_material TYPE cfx_s_api_tt_mat,

ls_material TYPE cfx_s_api_ts_mat,

ls_attr_value TYPE cfx_api_ts_attribute_value.

*BOM declaration

DATA : ls_bom,, TYPE cfx_s_api_ts_bom,

lt_bom,, TYPE cfx_s_api_tt_bom,

ls_item TYPE cfx_s_api_ts_item,

ls_item_attr TYPE cfx_api_ts_item_attrib_value.

*Generic Object declaration (MPN)

DATA : ls_generic TYPE cfx_s_api_ts_generic,

lt_generic TYPE cfx_s_api_tt_generic,

ls_field_value TYPE cfx_api_ts_go_field_value.

DATA: lt_folder_id LIKE TABLE OF cfx_fol-folder_id.

DATA: l_folder_id LIKE cfx_fol-folder_id.

DATA: l_topic_id TYPE string.

Data: l_type_id TYPE string.

*Go to the folder where you want to create objects, get the p_topic_id

*from the URL (use the folder tree on the left, click on the folder)

l_topic_id = ''."give the p_topic_id.

IF l_topic_id IS INITIAL.

WRITE 'Please enter a value for l_topic_id'.

ELSE.

SELECT folder_id FROM cfx_fol INTO TABLE lt_folder_id WHERE topic_id = l_topic_id.

READ TABLE lt_folder_id INDEX 1 INTO l_folder_id.

ENDIF.

INCLUDE intialize_material.

INCLUDE intialize_mpn.

INCLUDE intialize_ecn.

INCLUDE intialize_bom.

*Create a document and material in the folder, manually

*Go the object in cFolders, get p_doc_id from the URL and give it as

*ls_id-m_id

*we can now link these objects, which are already existing in cFolders,

*to the objects that are being created (using INTIALIZE_MATERIAL,

*INTIALIZE_BOM etc.)

*To link doc or objects to objects, which already existing in cFolders,

*more source code is required to perform this operation.

CLEAR: lt_ids, ls_id.

ls_id-backend_name = 'doc1'.

ls_id-type_id = cfxf1_sc_doc_type_document.

ls_id-m_id = ''

APPEND ls_id TO lt_ids.

ls_id-backend_name = 'mat2'.

ls_id-type_id = cfxf1_sc_doc_type_material.

ls_id-m_id = ''

APPEND ls_id TO lt_ids.

*call to single API

CALL FUNCTION 'CFX_S_API_WRITE'

IMPORTING

et_fault = lt_fault

e_error = l_error

CHANGING

ct_bom = lt_bom

ct_material = lt_material

ct_generic = lt_generic

ct_document = lt_document

ct_ids = lt_ids.

IF l_error = cfxa0_sc_true.

WRITE : 'An error occurred.'.

SKIP.

LOOP AT lt_fault INTO ls_fault.

WRITE:/'Error Occured during processing object wth Backend Name::',ls_fault-backend_name.

l_type_id = ls_fault-type_id.

WRITE:/'With Type::', l_type_id.

WRITE:/'Cause of error ::',ls_fault-faultstring.

ENDLOOP.

ELSE.

WRITE : 'Successfully executed'.

ENDIF.

INCLUDES:

*&---------------------------------------------------------------------*

*& Include INTIALIZE_MATERIAL

*&---------------------------------------------------------------------*

CLEAR: ls_material, ls_attr_value.

*Material

ls_material-m_id = ''."GUID of the material if you want to change else blank

ls_material-backend_name = 'mat1'."you can refer this material using this name in other objects

*example: when you want to attach this material to ECN, go to INTIALIZE_ECN to see.

*Header

ls_material-header-name = '1 Desc'.

ls_material-header-description = 'Description1'.

ls_material-header-type_id = cfxf1_sc_doc_type_material.

ls_material-header-type_namespace = ''.

ls_material-header-master = cfxa0_sc_true.

ls_material-header-parent_folder_id = l_folder_id. "GUID of the folder

*Version info

ls_material-version_info-change_current_version = cfxa0_sc_false.

*Version attributes

*PACKAGE: CFX_FOLDERS :: BSP APPLICATION:CFX_ATTRIBUTES :: MIMES:mat_attributes.xml to get the attribute ids

ls_attr_value-namespace = ''.

ls_attr_value-id = 'MaterialDescription'.

ls_attr_value-value = 'Desc1'.

APPEND ls_attr_value TO ls_material-version_attr.

ls_attr_value-namespace = ''.

ls_attr_value-id = 'MaterialNumber'.

ls_attr_value-value = '1'.

APPEND ls_attr_value TO ls_material-version_attr.

ls_attr_value-namespace = ''.

ls_attr_value-id = cl_cfx_s_api_hlp=>sc_link_mpn_cl_typ.

ls_attr_value-value = 'mpn1'.

APPEND ls_attr_value TO ls_material-version_attr.

ls_attr_value-namespace = ''.

ls_attr_value-id = cl_cfx_s_api_hlp=>sc_link_doc_cl_typ.

ls_attr_value-value = 'doc1'.

APPEND ls_attr_value TO ls_material-version_attr.

APPEND ls_material TO lt_material.

*&---------------------------------------------------------------------*

*& Include INTIALIZE_MPN

*&---------------------------------------------------------------------*

CLEAR: ls_generic, ls_field_value .

*Generic Object (MPN)

ls_generic-m_id = ''."GUID of the mpn if you want to change else blank

ls_generic-backend_name = 'mpn1'."you can refer this mpn using this name in other objects

*example: when you want to attach this mpn to ECN, go to INTIALIZE_ECN to see.

*HEADER

ls_generic-header-name = 'MPN1'.

ls_generic-header-description = 'Description1'.

ls_generic-header-type_id = cfxf1_sc_type_mpn_id.

ls_generic-header-type_namespace = cfxf1_sc_type_sap_namespace.

ls_generic-header-master = cfxa0_sc_true.

ls_generic-header-parent_folder_id = l_folder_id.

*Version info

ls_generic-version_info-change_current_version = cfxa0_sc_false.

*Genric object data ..(attributes and linked list values)

*PACKAGE: CFX_FOLDERS :: BSP APPLICATION:CFX_GEN_OBJ_TYP :: MIMES:MPN.xml to get the attribute ids

ls_field_value-field_id = 'Manufacturer'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'Manufact'.

APPEND ls_field_value TO ls_generic-generic_object_data.

ls_field_value-field_id = 'Material'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'mat1'. "Backend name reference

APPEND ls_field_value TO ls_generic-generic_object_data.

ls_field_value-field_id = 'MaterialGroup'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = '01'.

APPEND ls_field_value TO ls_generic-generic_object_data.

ls_field_value-field_id = 'Documents'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'doc1'.

APPEND ls_field_value TO ls_generic-generic_object_data.

APPEND ls_generic TO lt_generic.

*&---------------------------------------------------------------------*

*& Include INTIALIZE_BOM

*&---------------------------------------------------------------------*

CLEAR : ls_bom,ls_attr_value.

*BOM

ls_bom-m_id = ''. "GUID of the material if you want to change else blank

ls_bom-backend_name = 'bom1'."you can refer this bom using this name in other objects

*example: when you want to attach this bom to ECN, go to INTIALIZE_ECN to see.

*HEADER

ls_bom-header-name = 'BOM1'.

ls_bom-header-description = 'Description1'.

ls_bom-header-type_id = cfxf1_sc_doc_type_structure.

ls_bom-header-type_namespace = ''.

ls_bom-header-master = cfxa0_sc_true.

ls_bom-header-parent_folder_id = l_folder_id.

*Version info

ls_bom-version_info-change_current_version = cfxa0_sc_false.

*parent id.

ls_bom-parent_id = 'mat1'.

*Version attributes

*PACKAGE: CFX_FOLDERS :: BSP APPLICATION:CFX_ATTRIBUTES :: MIMES:structure_attributes.xml to get the attribute ids

ls_attr_value-namespace = ''.

ls_attr_value-id = 'BOM_Usage'.

ls_attr_value-value = '1'.

APPEND ls_attr_value TO ls_bom-version_attr.

ls_attr_value-namespace = ''.

ls_attr_value-id = 'BaseQuantity'.

ls_attr_value-value = '1'.

APPEND ls_attr_value TO ls_bom-version_attr.

ls_attr_value-namespace = ''.

ls_attr_value-id = 'BOM_Status'.

ls_attr_value-value = '01'.

APPEND ls_attr_value TO ls_bom-version_attr.

*Item 1

ls_item-item_id = 'item1'. "this item ID is used internally

ls_item-component_name = 'mat2'. "backend name reference of a material

APPEND ls_item TO ls_bom-items.

*Item 2 attr

*PACKAGE: CFX_FOLDERS :: BSP APPLICATION:CFX_ATTRIBUTES :: MIMES:s_item_attributes.xml to get the attribute ids

ls_item_attr-item_id = 'item1'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'Type'.

ls_item_attr-value = 'L'. " STOCK ITEM

APPEND ls_item_attr TO ls_bom-item_attr_values.

ls_item_attr-item_id = 'item1'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'Number'.

ls_item_attr-value = '01'.

APPEND ls_item_attr TO ls_bom-item_attr_values.

ls_item_attr-item_id = 'item1'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'Quantity'.

ls_item_attr-value = '10'.

APPEND ls_item_attr TO ls_bom-item_attr_values.

ls_item_attr-item_id = 'item1'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'UnitOfMeasure'.

ls_item_attr-value = 'ST'.

APPEND ls_item_attr TO ls_bom-item_attr_values.

*Item 2

ls_item-item_id = 'item2'.

ls_item-component_name = ''.

APPEND ls_item TO ls_bom-items.

*Item 2 attr

ls_item_attr-item_id = 'item2'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'Type'.

ls_item_attr-value = 'T'. "TEXT ITEM

APPEND ls_item_attr TO ls_bom-item_attr_values.

ls_item_attr-item_id = 'item2'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'Number'.

ls_item_attr-value = '02'.

APPEND ls_item_attr TO ls_bom-item_attr_values.

ls_item_attr-item_id = 'item2'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'Quantity'.

ls_item_attr-value = '10'.

APPEND ls_item_attr TO ls_bom-item_attr_values.

ls_item_attr-item_id = 'item2'.

ls_item_attr-namespace = ''.

ls_item_attr-id = 'UnitOfMeasure'.

ls_item_attr-value = 'ST'.

APPEND ls_item_attr TO ls_bom-item_attr_values.

APPEND ls_bom TO lt_bom.

*&---------------------------------------------------------------------*

*& Include INTIALIZE_ECN

*&---------------------------------------------------------------------*

CLEAR : ls_generic, ls_field_value.

*Generic Object (ECN)

ls_generic-m_id = ''."GUID of the mpn if you want to change else blank

ls_generic-backend_name = 'ecn1'."you can refer this ecn using this name in other objects

*HEADER

ls_generic-header-name = 'ECN1'.

ls_generic-header-description = 'Description1'.

ls_generic-header-type_id = cfxf1_sc_type_ecn_id.

ls_generic-header-type_namespace = cfxf1_sc_type_sap_namespace.

ls_generic-header-master = cfxa0_sc_true.

ls_generic-header-parent_folder_id = l_folder_id.

*Version info

ls_generic-version_info-change_current_version = cfxa0_sc_false.

*Genric object data ..(attributes and linked list values)

*PACKAGE: CFX_FOLDERS :: BSP APPLICATION:CFX_GEN_OBJ_TYP :: MIMES:MPN.xml to get the attribute ids

ls_field_value-field_id = 'ChangeOwner'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = sy-uname.

APPEND ls_field_value TO ls_generic-generic_object_data.

ls_field_value-field_id = 'Change Type'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = '001'.

APPEND ls_field_value TO ls_generic-generic_object_data.

ls_field_value-field_id = 'Change Category'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = '001'.

APPEND ls_field_value TO ls_generic-generic_object_data.

ls_field_value-field_id = 'Priority'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = '001'.

APPEND ls_field_value TO ls_generic-generic_object_data.

** Linked docs

ls_field_value-field_id = 'Documents'. "Id given in the ECN.xml

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'doc1'. "backendname reference

APPEND ls_field_value TO ls_generic-generic_object_data.

** Linked material

ls_field_value-field_id = 'Materials'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'mat1'. "backendname reference

APPEND ls_field_value TO ls_generic-generic_object_data.

** Linked BOM

ls_field_value-field_id = 'Bills of Material'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'bom1'. "backendname reference

APPEND ls_field_value TO ls_generic-generic_object_data.

** Linked MPNs

ls_field_value-field_id = 'MPNs'.

ls_field_value-field_namespace = cfxf1_sc_type_sap_namespace.

ls_field_value-item_id = ''.

ls_field_value-item_namespace = ''.

ls_field_value-template_number = ''.

ls_field_value-value = 'mpn1'. "backendname reference

APPEND ls_field_value TO ls_generic-generic_object_data.

APPEND ls_generic TO lt_generic.

Notes

Further information





Parameters

CT_BOM
CT_DOCUMENT
CT_GENERIC
CT_IDS
CT_MATERIAL
ET_FAULT
E_ERROR

Exceptions

Function Group

CFX_S_API_DOC

Vendor Master (General Section)   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 22630 Date: 20240523 Time: 092040     sap01-206 ( 176 ms )