I am trying to go from an ORACLE value of (18,2) to an overpunched values of S9(9)V99. The amount field defined below is what I am trying to convert
CREATE OR REPLACE PROCEDURE req_plant_unload
-- 11/2003-for now hard code directory path
-- (p_filedir in varchar2)
-- output file names will be hard coded since these are DIFMS files
-- and names will not change
IS
v_filehandle_log UTL_FILE.file_type;
v_filehandle UTL_FILE.file_type;
BEGIN
v_filehandle_log := UTL_FILE.fopen ('e:\tasi\data','apr_req_plant4235_unload.log', 'w');
UTL_FILE.put_line (v_filehandle_log, 'Begin REQ UNLOAD Process');
DECLARE
v_errortext varchar2(200);
v_errornumber number;
v_count_4235 INTEGER := 0;
expense_element_pos1 VARCHAR2(1);
expense_element_pos2_4 VARCHAR2(3);
requisition_number VARCHAR2(13);
nomenclature VARCHAR2(28);
originator VARCHAR2(12);
pcc VARCHAR2(6);
deliver_to_bldg VARCHAR2(10);
total_amount NUMBER(9,2);
TYPE plant_4235_rec IS RECORD (
plant_4235_requisition_number VARCHAR2 (13),
plant_4235_expense_element FINANCE.EXPENSE_ELEMENT_TABLE.EET_EXPENSE_ELEMENT%TYPE,
plant_4235_nomenclature VARCHAR2 (28),
plant_4235_originator VARCHAR2 (12),
plant_4235_pcc VARCHAR2 (6),
plant_4235_deliver_to_bldg VARCHAR2 (10),
plant_4235_jon VARCHAR2 (6),
plant_4235_fiscal_year ASIDBA.APR_JON_TABLE.AJT_FY%TYPE,
plant_4235_total_amount NUMBER (9,2)
);
plant_4235_out_rec plant_4235_rec;
--CURSOR
CURSOR unload_plant_4235
IS
SELECT
NVL(SUBSTR (art_requisition_number, 2, 13),13,' '),
art_expense_element,
NVL(SUBSTR(art_nomenclature,1,28),' '),
NVL(SUBSTR(art_originator,1,12),' '),
NVL(SUBSTR(art_pcc,1,6),6' '),
NVL(SUBSTR(art_deliver_to_bldg,1,10),10,' '),
NVL(SUBSTR(ajt_jon,1,6),6' '),
art_fy,
art_total_document
FROM joyceba.v_apr_unload_req
WHERE art_plant_flag = 'Y'
AND art_fy_type = 'C'
AND art_requisition_type = '2';
BEGIN
v_filehandle :=
UTL_FILE.fopen ('e:\tasi\data','apr_unload_plant.dat',
'w'
);
OPEN unload_plant_4235;
UTL_FILE.put_line (v_filehandle_log, 'Begin PLANT unload Process');
LOOP
FETCH unload_plant_4235 INTO plant_4235_out_rec;
EXIT WHEN unload_plant_4235%NOTFOUND;
expense_element_pos1 :=
SUBSTR (plant_4235_out_rec.plant_4235_jon, 1, 1);
IF SUBSTR (plant_4235_out_rec.plant_4235_jon, 1, 1) >= 'A'
THEN
expense_element_pos1 := '5';
END IF;
IF SUBSTR (plant_4235_out_rec.plant_4235_jon, 1, 1) = 'I'
THEN
expense_element_pos1 := '8';
END IF;
expense_element_pos2_4 := substr(plant_4235_out_rec.plant_4235_expense_element,1,3);
plant_4235_out_rec.plant_4235_expense_element := expense_element_pos1||expense_element_pos2_4;
-- realize now this can be done in the PUT_LINE logic!!!
requisition_number :=RPAD(plant_4235_out_rec.plant_4235_requisition_number,13,' ');
nomenclature:=RPAD(plant_4235_out_rec.plant_4235_nomenclature,28,' ');
originator :=RPAD(plant_4235_out_rec.plant_4235_originator,12,' ');
pcc := RPAD(plant_4235_out_rec.plant_4235_pcc,6,' ');
deliver_to_bldg := RPAD(plant_4235_out_rec.plant_4235_deliver_to_bldg,10,' ');
--****** total amount should contain leading zeros
--****** stored as signed ASCII number RIGHT OVERPUNCHED
---******
----*******
total_amount :=(plant_4235_out_rec.plant_4235_total_amount);
-- WRITE RECORD
UTL_FILE.put_line
(v_filehandle,
requisition_number
|| total_amount
|| plant_4235_out_rec.plant_4235_expense_element
|| nomenclature
|| originator
|| pcc
|| deliver_to_bldg
|| plant_4235_out_rec.plant_4235_jon
|| plant_4235_out_rec.plant_4235_fiscal_year);
v_count_4235 := v_count_4235 + 1;
END LOOP;
UTL_FILE.put_line (v_filehandle_log,
'Plant 4235 records written to output file: '
|| TO_CHAR (v_count_4235));
CLOSE unload_plant_4235;
UTL_FILE.put_line (v_filehandle_log, 'PLANT 4235 process has completed');
EXCEPTION
WHEN OTHERS
THEN
IF SQL%NOTFOUND
THEN
UTL_FILE.put_line (v_filehandle_log,
'No PLANT data found, file created' );
END IF;
v_errornumber:= sqlcode;
v_errortext := substr(sqlerrm,1,200);
UTL_FILE.PUT_LINE(v_filehandle_log, 'Unhandled exception occurred');
UTL_FILE.PUT_LINE(v_filehandle_log,v_errornumber||v_errortext);
UTL_FILE.fclose (v_filehandle_log);
END;
UTL_FILE.fclose (v_filehandle);
UTL_FILE.fclose (v_filehandle_log);
END;
/