Sunday 29 March 2020

Customer Contact Details Update -- API

SET SERVEROUTPUT ON;
DECLARE
Cursor c1 is
select location_id, POSTAL_CODE from xx_zipcode_tbl
where POSTAL_CODE is not null;
p_location_rec          HZ_LOCATION_V2PUB.LOCATION_REC_TYPE;
p_object_version_number NUMBER;
x_return_status         VARCHAR2(2000);
x_msg_count             NUMBER;
x_msg_data              VARCHAR2(2000);
l_obj_ver               CHAR(2);
BEGIN
-- Setting the Context --
mo_global.init('AR');
fnd_global.apps_initialize ( user_id      => 111111
                            ,resp_id      => 11111
                            ,resp_appl_id => 222);
mo_global.set_policy_context('S',204);
fnd_global.set_nls_context('AMERICAN');
for i in c1 loop
l_obj_ver := NULL;
SELECT hl.object_version_number INTO l_obj_ver
FROM HZ_LOCATIONS hl
WHERE hl.location_id = i.location_id;

-- Initializing the Mandatory API parameters
p_location_rec.location_id := i.location_id;
p_location_rec.postal_code    := i.POSTAL_CODE;

hz_location_v2pub.update_location
            (
             p_init_msg_list           => FND_API.G_TRUE,
             p_location_rec            => p_location_rec,
             p_object_version_number   => l_obj_ver,
             x_return_status           => x_return_status,
             x_msg_count               => x_msg_count,
             x_msg_data                => x_msg_data
                  );
             
IF x_return_status = fnd_api.g_ret_sts_success THEN
UPDATE xx_zipcode_tbl SET STATUS = 'Y' WHERE LOCATION_ID = I.LOCATION_ID;
    COMMIT;
    DBMS_OUTPUT.PUT_LINE('New POSTAL CODE : '||p_location_rec.postal_code||'-'||p_location_rec.location_id);
ELSE
    DBMS_OUTPUT.put_line ('Creation of Location failed:'||x_msg_data);
    ROLLBACK;
    FOR i IN 1 .. x_msg_count
    LOOP
      x_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');
      dbms_output.put_line( i|| ') '|| x_msg_data);
    END LOOP;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Completion of API');
END;
/

2 comments: