Code 1: Update Purchase Order Partner Details By Kathirvel Balakrishnan
This is a very simple code sample to update the purchase order partner details. The following function modules are used:
BBP_PD_SC_GETDETAIL : Read the details of a Purchase Order
BBP_PD_SC_UPDATE : Updates the details of a Purchase Order
BBP_PD_SC_SAVE : Finally called to save the details of a Purchase Order
This is just an illustrative example and can be enhanced to update any existing detail of a purchase order.
REPORT zkb_partner_chg.
* Declaration – Internal Tables
DATA: lt_e_item TYPE TABLE OF bbp_pds_po_item_d.
DATA: lt_e_partner TYPE TABLE OF bbp_pds_partner.
DATA: lt_e_messages TYPE TABLE OF bbp_pds_messages.
DATA: lt_i_item TYPE TABLE OF bbp_pds_po_item_icu.
DATA: lt_i_partner TYPE TABLE OF bbp_pds_partner.
* Declaration – Work Areas
DATA: ls_e_header TYPE bbp_pds_po_header_d.
DATA: ls_e_item TYPE bbp_pds_po_item_d.
DATA: ls_e_partner TYPE bbp_pds_partner.
DATA: ls_i_item TYPE bbp_pds_po_item_icu.
DATA: ls_i_header TYPE bbp_pds_po_header_u .
DATA: ls_but000 TYPE but000.
* Declaration – Variables
DATA: lv_e_changed TYPE xfeld.
* Declaration – Field Symbols
FIELD-SYMBOLS: <fs_partner> TYPE bbp_pds_partner.
* Read an existing PO
CALL FUNCTION ‘BBP_PD_PO_GETDETAIL’
EXPORTING
i_object_id = ’3200000576′
i_with_itemdata = ‘X’
IMPORTING
e_header = ls_e_header
TABLES
e_item = lt_e_item
e_partner = lt_e_partner
e_messages = lt_e_messages.
* Populate Header Data
MOVE-CORRESPONDING ls_e_header TO ls_i_header.
* Populate Item data
LOOP AT lt_e_item INTO ls_e_item .
MOVE-CORRESPONDING ls_e_item TO ls_i_item.
APPEND ls_i_item TO lt_i_item.
ENDLOOP.
* Populate all the existing partner data first
LOOP AT lt_e_partner INTO ls_e_partner.
APPEND ls_e_partner TO lt_i_partner.
ENDLOOP.
** Delete Partner (vendor)
READ TABLE lt_i_partner ASSIGNING <fs_partner>
WITH KEY partner_fct = ’00000019′
p_guid = ls_i_header-guid.
IF sy-subrc EQ 0.
<fs_partner>-del_ind = ‘X’.
ENDIF.
UNASSIGN <fs_partner>.
** Add Partner (vendor)
SELECT SINGLE * FROM but000 INTO ls_but000 WHERE partner = ’0087000004′.
CLEAR ls_e_partner.
ls_e_partner-partner_guid = 1.
ls_e_partner-partner_no = ls_but000-partner_guid.
ls_e_partner-partner_fct = ’00000019′.
ls_e_partner-p_guid = ls_i_header-guid.
APPEND ls_e_partner TO lt_i_partner.
* Update Doc
CALL FUNCTION ‘BBP_PD_PO_UPDATE’
EXPORTING
i_header = ls_i_header
i_save = ‘X’
iv_with_change_approval = ‘ ‘
IMPORTING
e_changed = lv_e_changed
TABLES
i_item = lt_i_item
i_partner = lt_i_partner
e_messages = lt_e_messages.
* Save Doc
IF NOT lv_e_changed IS INITIAL.
CALL FUNCTION ‘BBP_PD_PO_SAVE’
EXPORTING
iv_header_guid = ls_i_header-guid.
COMMIT WORK AND WAIT.
ENDIF.
Report to display user attributes by Kathirvel Balakrishnan
The below program takes the User Id and the list of attributes as input and displays the value of the attributes maintained in the Organization structure.
The program uses the standard function module BBP_READ_ATTRIBUTES to read and display the attributes.
*&———————————————————————*
*& Report ZKB_READ_ATTRIBUTES
*&———————————————————————*
REPORT zkb_read_attributes.
*&———————————————————————*
* Data Declaration
*&———————————————————————*
TYPES: BEGIN OF lty_user_attr,
attr_id TYPE om_attrib,
value_logsys TYPE log_system,
value TYPE char30,
END OF lty_user_attr.
DATA: lo_salv_table TYPE REF TO cl_salv_table.
DATA: lt_user_attr TYPE TABLE OF lty_user_attr.
DATA: lt_attr_list TYPE bbpt_attr_list.
DATA: lt_attr_data TYPE bbpt_attr.
DATA: lt_vlist TYPE bbpt_attr_values.
DATA: ls_attr_list TYPE bbp_attr_list.
DATA: ls_attr_data TYPE bbps_attr.
DATA: ls_user_attr TYPE lty_user_attr.
DATA: ls_vlist TYPE bbps_attr_values.
DATA: ls_t77omattr TYPE t77omattr.
*&———————————————————————*
* Selection Screen
*&———————————————————————*
PARAMETERS : p_user TYPE sy-uname DEFAULT sy-uname OBLIGATORY.
SELECT-OPTIONS: s_attr FOR ls_t77omattr-attrib OBLIGATORY NO INTERVALS.
*&———————————————————————*
* START-OF-SELECTION.
*&———————————————————————*
START-OF-SELECTION.
LOOP AT s_attr.
CLEAR ls_attr_list.
ls_attr_list-attr_id = s_attr-low.
APPEND ls_attr_list TO lt_attr_list.
ENDLOOP.
* Read Attributes
CALL FUNCTION ‘BBP_READ_ATTRIBUTES’
EXPORTING
iv_user = p_user
it_attr_list = lt_attr_list
IMPORTING
et_attr = lt_attr_data
EXCEPTIONS
object_id_not_found = 1
no_attributes_requested = 2
attributes_read_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Populate the Output List
LOOP AT lt_attr_data INTO ls_attr_data.
ls_user_attr-attr_id = ls_attr_data-attr_id.
CLEAR : lt_vlist.
lt_vlist = ls_attr_data-vlist.
LOOP AT lt_vlist INTO ls_vlist.
ls_user_attr-value_logsys = ls_vlist-value_logsys.
ls_user_attr-value = ls_vlist-value.
APPEND ls_user_attr TO lt_user_attr.
ENDLOOP.
ENDLOOP.
* Display Data in Alv Grid
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_salv_table
CHANGING
t_table = lt_user_attr.
CALL METHOD lo_salv_table->display.
Updating Extended Attributes (Storage Location) By Kathirvel Balakrishnan
The below program takes the User Id and the list of storage location attribute values and updates them.
The program uses the standard function module BBP_UPDATE_ATTRIBUTES to update the storage location values for the user.
Note: To update multiple values, all the values needs to be passed.
*&———————————————————————*
*& Report ZKB_UPDATE_STORAGE_LOC
*&———————————————————————*
* This program is used to update the values in Extended Attributes,
* in this example the attribute Storage Location is updated (LAG)
*&———————————————————————*
REPORT zkb_update_storage_loc.
* Declaration for Internal Tables
DATA: lt_bbp_attributes TYPE TABLE OF bbp_attributes.
* Declaration for Structures
DATA: ls_bbp_attributes TYPE bbp_attributes.
* Populate the Storage Location Value
CLEAR ls_bbp_attributes.
ls_bbp_attributes-attr_id = ‘LAG’. “Storage Location
ls_bbp_attributes-value_logsys = ‘<BACKEND SYS>’.
ls_bbp_attributes-value(20) = ‘<Storage Loc>’.
ls_bbp_attributes-value+20(10) = ‘<BACKEND SYS>’.
ls_bbp_attributes-value+30(4) = ‘<Company Code>’.
APPEND ls_bbp_attributes TO lt_bbp_attributes.
* Function Call to Update Values
CALL FUNCTION ‘BBP_UPDATE_ATTRIBUTES’
EXPORTING
user_id_p = ‘USER ID’
scenario_p = ‘BBP’
start_date_p = sy-datum
end_date_p = ’99991231′
TABLES
it_attr_p = lt_bbp_attributes
EXCEPTIONS
object_id_missed = 1
no_active_plvar = 2
object_not_found = 3
no_attributes = 4
times_invalid = 5
inconsistent_values = 6
update_error = 7
ambiguous_position = 8
OTHERS = 9.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* Save to DB
COMMIT WORK AND WAIT.
ENDIF.
