Hello everyone,
Is it possible to generate TXT files using a specific delimiter (|) with a built-in function in Visual LANSA and then retrieve them into my web application? I would appreciate any guidance or examples on how to implement this.
Thank you!
Generating TXT Files with Specific Delimiters in Visual LANSA
-
OmarMonroy
- Posts: 6
- Joined: Fri Jan 31, 2025 2:09 am
Re: Generating TXT Files with Specific Delimiters in Visual LANSA
Hi.
this is what I use when I want to create a log file.
Define_Com Class(#prim_dc.UnicodeString) Name(#CarriageReturn)
Define_Com Class(#prim_dc.UnicodeString) Name(#LineFeed)
#LineFeed := (10).AsUnicodeString
#CarriageReturn := (13).AsUnicodeString
#Logtxt01 += 'id_token: ' + #id_token + #CarriageReturn.AsNativeString + #LineFeed.asnativestring
Change Field(#OPTIONS) To('''WRITE notrim Text lineTerminator= CRLF CodePage=1208''')
#FILEname := '/LANSA_DCXPGMLIB/tmp/erc/' + *guid + '.txt'
Use Builtin(STM_FILE_OPEN) With_Args(#FILEname #OPTIONS) To_Get(#FILENO #RETNCODE)
*
#string01 := #Logtxt01.AsNativeString
#string02 := #Logtxt02.AsNativeString
#string03 := #Logtxt03.AsNativeString
#string04 := #Logtxt04.AsNativeString
#string05 := #Logtxt05.AsNativeString
Use Builtin(STM_FILE_WRITE) With_Args(#FILENO #string01 #string02 #string03 #string04 #string05) To_Get(#RETNCODE)
*
Use Builtin(STM_FILE_CLOSE) With_Args(#FILENO)
this is what I use when I want to create a log file.
Define_Com Class(#prim_dc.UnicodeString) Name(#CarriageReturn)
Define_Com Class(#prim_dc.UnicodeString) Name(#LineFeed)
#LineFeed := (10).AsUnicodeString
#CarriageReturn := (13).AsUnicodeString
#Logtxt01 += 'id_token: ' + #id_token + #CarriageReturn.AsNativeString + #LineFeed.asnativestring
Change Field(#OPTIONS) To('''WRITE notrim Text lineTerminator= CRLF CodePage=1208''')
#FILEname := '/LANSA_DCXPGMLIB/tmp/erc/' + *guid + '.txt'
Use Builtin(STM_FILE_OPEN) With_Args(#FILEname #OPTIONS) To_Get(#FILENO #RETNCODE)
*
#string01 := #Logtxt01.AsNativeString
#string02 := #Logtxt02.AsNativeString
#string03 := #Logtxt03.AsNativeString
#string04 := #Logtxt04.AsNativeString
#string05 := #Logtxt05.AsNativeString
Use Builtin(STM_FILE_WRITE) With_Args(#FILENO #string01 #string02 #string03 #string04 #string05) To_Get(#RETNCODE)
*
Use Builtin(STM_FILE_CLOSE) With_Args(#FILENO)
-
OmarMonroy
- Posts: 6
- Joined: Fri Jan 31, 2025 2:09 am
Re: Generating TXT Files with Specific Delimiters in Visual LANSA
Thank you very much for the support, it worked perfectly.
-
stevelee67
- Posts: 22
- Joined: Tue Mar 13, 2018 8:25 am
- Location: Madison WI
Re: Generating TXT Files with Specific Delimiters in Visual LANSA
in an RDMLX world, there is an additional option of using the #PRIM_IOC.xxx primitives. they're a little more complicated to use but they get the job done.
you can also use #XPRIM_FILE objects to do a lot of stuff.
honestly, the BIFs work just fine and are probably more familiar. but if you need something complex you can look in to them.
if you are looking for a delimited file, you can also use the TRANSFORM_LIST BIF (as long as your cool with either comma or tab delimiters). if you need things in unicode, use the "U" formats (e.g., AU instead of A for comma delimited or TU for tab delimited). there are ways to keep the file open while you're writing to allow for a significant amount of flexibility. it is kinda slow, so if you're dumping big batches of data, the STM_FILE BIFs or #PRIM_IOC objects are your better option.
you can also use #XPRIM_FILE objects to do a lot of stuff.
honestly, the BIFs work just fine and are probably more familiar. but if you need something complex you can look in to them.
if you are looking for a delimited file, you can also use the TRANSFORM_LIST BIF (as long as your cool with either comma or tab delimiters). if you need things in unicode, use the "U" formats (e.g., AU instead of A for comma delimited or TU for tab delimited). there are ways to keep the file open while you're writing to allow for a significant amount of flexibility. it is kinda slow, so if you're dumping big batches of data, the STM_FILE BIFs or #PRIM_IOC objects are your better option.
The path to wisdom does, in fact, begin with a single step. Where people go wrong is in ignoring all the thousands of other steps that come after it.
Hogfather (Terry Pratchett)
Hogfather (Terry Pratchett)