How to save an XML Doc to a RAW Field with out the trailing Wierd values

dondeebarrera

New Member
Hi ,
Happy New year... i have written a programs that writes to a raw field, but the problem is its alway have this weird characters after the proper file. Any suggestions so i can only store the proper file.... any idea? is it the writing or the storing is the problem because in both places im setting the file size to 30KB...

17.gif



/*Reads a File to Stores it to a Field*/


input from value("./tmp/pda-" + lc-postfix-name + ".req") BINARY NO-MAP NO-CONVERT.
repeat:
empty temp-table ttb-file-content.
set-size(memptr-data) = 30 * 1024.
import unformatted memptr-data.
create ttb-file-content.
assign i-pos = i-pos + 1
ttb-file-content.ttf-pos = i-pos
ttb-file-content.ttf-content = memptr-data
ttb-file-content.ttf-filename = "pda-" + lc-postfix-name.
create xmldoc_content.
assign xmldoc_content.xmldoc_filename = ttb-file-content.ttf-filename.
raw-transfer ttb-file-content to xmldoc_content.
end.
input close.
set-size(memptr-data) = 0.
----------------------------------------------------------------------------------------------------

/*Writes the Field to File*/
for each xmldoc_content where xmldoc_content.xmldoc_filename = ip-filename no-lock :
create ttb-file-content.
buffer-copy xmldoc_content using xmldoc_filename to ttb-file-content.
buffer-copy xmldoc_content using xmldoc_document to ttb-file-content.
end.
for each ttb-file-content break by ttb-file-content.xmldoc_filename:
if last-of(ttb-file-content.xmldoc_filename ) then do:
run create-file.
empty temp-table ttb-file-content.
end.
end.
procedure create-file :
assign ip-filename = ip-file-output + ip-filename + ".req".
output to value(ip-filename) NO-MAP NO-CONVERT BINARY.
for each ttb-file-content by ttb-file-content.xmldoc_pos:
set-size(lmemptr-data) = (30) * 1024.
put-bytes(lmemptr-data, 1) = ttb-file-content.xmldoc_document.
export lmemptr-data.
end.
output close.
end procedure.

Tried this but does not work....

/*************************************************************************************
def var lc-clear-mem as char no-undo.
def var lf-ini-memsize as integer no-undo.
def var li-ascii as integer no-undo.
def var li-ctr as integer no-undo.
assign lf-ini-memsize = 30 * 1024.
set-size(memptr-data) = lf-ini-memsize.
input from value("./tmp/pda-" + lc-postfix-name + ".req") BINARY NO-MAP NO-CONVERT.
repeat:
empty temp-table ttb-file-content.
import unformatted memptr-data.
end.
input close.
do li-ctr = 1 to lf-ini-memsize:
li-ascii = get-byte(memptr-data, li-ctr).
if li-ascii = 0 then leave.
lc-clear-mem = lc-clear-mem + chr(li-ascii).
end.
set-size(memptr-data) = 0.
set-size(memptr-data) = length(lc-clear-mem) + 1.
put-string ( memptr-data , 1) = lc-clear-mem.
create ttb-file-content.
assign i-pos = i-pos + 1
ttb-file-content.ttf-pos = i-pos
ttb-file-content.ttf-content = memptr-data
ttb-file-content.ttf-filename = "pda-" + lc-postfix-name.
create xmldoc_content.
assign xmldoc_content.xmldoc_filename = ttb-file-content.ttf-filename.
raw-transfer ttb-file-content to xmldoc_content.
set-size(memptr-data) = 0.
**************************************************************************************/
 
Well just tried something not using memptr but raw field of temp-table. But this seems to create exact file sizes (check is in commented part ).

Is this what you try to acomplish?
Code:
DEFINE INPUT  PARAMETER cp_file AS CHARACTER  NO-UNDO.
DEFINE VARIABLE i_len      AS INTEGER    NO-UNDO.
DEFINE VARIABLE ra_rawdata AS RAW        NO-UNDO.
 
DEFINE STREAM sOUt.
 
DEFINE TEMP-TABLE ttData
    FIELD rawdata AS RAW.
 
INPUT FROM VALUE(cp_file) BINARY NO-MAP NO-CONVERT.
 
/* check for file size */
/* SEEK INPUT TO END.                     */
/* i_len = SEEK(INPUT).                   */
/* MESSAGE i_len                          */
/*     VIEW-AS ALERT-BOX INFO BUTTONS OK. */
/* SEEK INPUT TO 0.                       */
 
ASSIGN LENGTH (ra_rawdata) = 30 * 1024.
REPEAT:
    IMPORT UNFORMATTED ra_rawdata.
    CREATE ttData.
    ASSIGN ttData.rawdata = ra_rawdata.
    RELEASE ttData.
END.
ASSIGN LENGTH (ra_rawdata) = 0.  /* Deallocate memory */
INPUT CLOSE.
 
/* CREATE FILE FROM TEMP-TABLE */
OUTPUT STREAM Sout TO c:\temp\test.xml.
FOR EACH ttData:
    PUT STREAM sOut CONTROL ttData.rawdata.
END.
OUTPUT STREAM sOut CLOSE.
 
/* check for filesize just created file           */
/* INPUT FROM c:\temp\test.xml BINARY NO-CONVERT. */
/* SEEK INPUT TO END.                             */
/* i_len = SEEK(INPUT).                           */
/* SEEK INPUT TO 0.                               */
/*                                                */
/* INPUT CLOSE.                                   */
/*                                                */
/* MESSAGE i_len                                  */
/*     VIEW-AS ALERT-BOX INFO BUTTONS OK.         */

Sorry for the hard coded paths.....

Casper.
 
Hi Casper,
This is exactly what i'm looking for, tested it and works perfect... Thanks very much for spending some time and actually coding it for me. i did'nt expect it to be direct as this and just hoping to get some descriptive idea on how to do it... Thanks heaps!!!!
:blush:
 
Back
Top