Baanboard.com

Go Back   Baanboard.com > Forum > Baan Quick Support: Functional & Technical > Tools Development

User login

Frontpage Sponsor

Main

Poll
How big is your Baan-DB (just Data AND Indexes)
0 - 200 GB
19%
200 - 500 GB
27%
500 - 800 GB
4%
800 - 1200 GB
7%
1200 - 1500 GB
7%
1500 - 2000 GB
12%
> 2000 GB
25%
Total votes: 85

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 19th March 2020, 07:39
smusba smusba is offline
Senior Member
 
Join Date: Apr 2008
Posts: 182
smusba is on a distinguished road
Baan: Baan 1V - DB: Oracle 9i - OS: Windows xp
Logic to extract lots
Baan: Infor ERP 10.1 (FP7)
C/S: Both

Dear,

WE want to separate the lots like

For Example :Lot F-43797UQ01-32-32 or F-642977-11-11
We want to remove F- and -32-32 from first lot and F-11-11 from 2nd lot. The second set must only appear in the invoice but after prefix F- the characters varies how can we write a logic to extract only the 2nd part?

Last edited by smusba : 26th March 2020 at 15:46.
Reply With Quote
  #2  
Old 19th March 2020, 08:41
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Bangkok, Thailand
Posts: 274
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
Rough implementation I can think of right now is using str.substring$()

Quote:
Syntax:
function string str.substring$ (const string string$, long beginpos [, long endpos])

Description

Returns a substring from the specified string. The substring starts at the specified begin position. When an end position is specified, the substring extends to the character at position endpos - 1.

Note that when using the var(x;y) construction, the y is the size of the substring, but when calling str.substring$(var, x, y), the y is the end position in var. See the example code below to see the difference.


Arguments
const string string$ a string

long beginpos the begin position, inclusive; note that:

if beginpos <= 0, beginpos is set to 1
if beginpos > len(string$), then an empty string is returned

[long endpos] optional, the end position, exclusive; note that:

if endpos <= beginpos, an empty string is returned
if endpos > len(string$), then endpos is not taken into account
and len().

Quote:
Syntax:
function long len (string str_expr)

Description

This returns the number of characters in string_expr. For strings declared as FIXED, the total length of the string is returned. For non-fixed strings, the current length is returned. To retrieve the length of FIXED strings, excluding trailing spaces, use strip$().


Arguments
string str_expr

Return values
This returns the number of characters in string_expr. For strings declared as FIXED, the total length of the string is returned. For non-fixed strings, the current length is returned. To retrieve the length of FIXED strings, excluding trailing spaces, use strip$().
Code:
// pseudo code
lot = "F-43797UQ01-32-32"
formatted.lot = str.substring$(lot, 3, len(lot)-6)
This will work only when the number of characters in prefix and suffix is equal to the given examples, which are "F-xxxxxx-32-32", and "F-xxxxxx-11-11".


The magic is in this function
Code:
str.substring$(lot, 3, len(lot)-6)
It will perform a substring function that will take only a part of the given string starting from 3 (skip prefix "F-") to string length minus 6 (ignore "-11-11" and "-32-32").

So if your prefix and suffix are not complimenting this method then this part needs to be changed accordingly.
Reply With Quote
  #3  
Old 19th March 2020, 09:42
smusba smusba is offline
Senior Member
 
Join Date: Apr 2008
Posts: 182
smusba is on a distinguished road
Baan: Baan 1V - DB: Oracle 9i - OS: Windows xp
8

Sometimes the length after F-XXXXXX-100-100 can be 8 or 6.
Reply With Quote
  #4  
Old 19th March 2020, 10:04
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Bangkok, Thailand
Posts: 274
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
Quote:
Originally Posted by smusba View Post
Sometimes the length after F-XXXXXX-100-100 can be 8 or 6.
With that requirement, you will want to change the ending part to pos() instead.

Quote:
Syntax:
function long pos (string source, string part [, long offset])

Description

This returns the start position of a specified substring ( part) in a specified string ( source). source and part can be either strings or string expressions.

pos() starts searching for the substring at the first position in the source string. It returns the start position relative to the beginning of the source string. To start searching at the last position instead, use rpos().

As of TIV 1700, pos() can start the search at the specified offset. In this way it is possible to not only find the first occurrence of a substring, but also the next one(s). The returned start position is also in this case relative to the beginning of the source string. See the example below for how to use this optional parameter.


Arguments
string source The string to search in

string part The part to search

[long offset] Optional search starting position; when not specified the search starts at position 1. Note that:

If offset <= 1, then searching start at position 1.
If offset > len(source), then 0 is returned.
This parameter can be used as of TIV 1700.


Return values
The start position of the substring in the string. Or 0 if the substring is not found.
This will give you the position of the first "-" in your suffix because of the offset "3", which will skip the first "-" in the prefix.
Code:
pos(lot, "-", 3)
Therefore, the end result should now be
Code:
str.substring$(lot, 3, pos(lot, "-", 3))
The code is not tested though. It is just an idea. Feel free to adjust where it is necessary.
Reply With Quote
  #5  
Old 19th March 2020, 10:40
smusba smusba is offline
Senior Member
 
Join Date: Apr 2008
Posts: 182
smusba is on a distinguished road
Baan: Baan 1V - DB: Oracle 9i - OS: Windows xp
rcisli244575520( 137): Error: Illegal argument 3 for function 'pos'
rcisli244575520( 137): Error: 2 arguments expected for function 'pos'

I used as :

clot = whinh431.clot
s.clot = shiftl$(strip$(whinh431.clot))
f.lot = str.substring$(s.clot, 3, pos(s.clot,"-",3))
Reply With Quote
  #6  
Old 19th March 2020, 10:53
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Bangkok, Thailand
Posts: 274
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
Quote:
Originally Posted by smusba View Post
rcisli244575520( 137): Error: Illegal argument 3 for function 'pos'
rcisli244575520( 137): Error: 2 arguments expected for function 'pos'

I used as :

clot = whinh431.clot
s.clot = shiftl$(strip$(whinh431.clot))
f.lot = str.substring$(s.clot, 3, pos(s.clot,"-",3))
It is because your version of BaaN does not support the (latest) pos() function. So, I suggest you try string.scan() instead.

Quote:
Syntax:
function long string.scan (string value, string format [, void ...])

Description

This scans an input string ( value) for one or more fields and stores each individual field found in the first available variable argument. The format argument contains conversion symbols that the function uses to interpret the input string and retrieve the individual field values. The conversion symbols indicate the types of values expected:

%s expects a single-byte or multibyte string

%f expects a double

%d expects a long

An input field is defined as all characters up to the next separator character or up to the next character that does not match the type of the corresponding conversion symbol.

A separator character is a single character used to separate individual values in the input string. It can be a space character, or any other character that is not used within individual fields in the input string. You cannot use multibyte characters as separators.

The string.scan() function scans the input string using each conversion symbol in the argument in turn. For each conversion symbol, it scans the input string for characters that match the specified format. It stops scanning when it meets a separator character or a character that does match the expected type.

For example, consider the following function call:

string.scan( input_string, "%d|%f",long,double )

In this case, the function expects input_string to contain two separate numeric values. It reads the input string until it meets a pipe [|] character (this is the separator specified in the format argument). It then converts the characters read (excluding the separator) to a long value and stores that value in the long variable. The function then continues scanning the input string using the next conversion symbol in the format argument.

Note that if two conversion symbols are separated by more than one separator character, the function ignores those characters unless they match the input.


Arguments
string value Input string

string format contains zero or more ordinary characters and substitution symbols

[void ...] References to variables to which the values scanned from the string must be assigned.

For each substitution symbol in the format string, implicit conversion of the currently matched sub-string of the input string to the type of the corresponding reference argument is performed.

Typical (but not enforced) usage is to supply a reference variable of type string for conversion symbol %s, a reference variable of type double for conversion symbol %f and a reference variable of type long for conversion symbol %d.


Return values
The function returns the number of scanned fields.
You might want to try something like:
Code:
string formatted.lot(100)
string suffix(10)
string.scan(lot, "F-%s-%s", formatted.lot, suffix)
where you can ignore the variable suffix after that.
Reply With Quote
Sponsored Links
  #7  
Old 25th March 2020, 07:54
smusba smusba is offline
Senior Member
 
Join Date: Apr 2008
Posts: 182
smusba is on a distinguished road
Baan: Baan 1V - DB: Oracle 9i - OS: Windows xp
string.scan

PHP Code:
function main()
{
    
string    string.variable(100)
    
long    ret
    long    number
.of.fields
    string    a
(10)
    
string    b(10)
    
string    c(10)
    
string    format$(20)
    
    
string.variable "123 %cd% ef"
    
format$ = "%s|%s|%s"
    
    
while true
        ret 
pos(string.variable"%")
        if 
ret 0 then
            
break
        endif
        
string.variable(ret;1) = "|"
    
endwhile

    
number.of.fields string.scan(string.variableformat$ , abc)


Last edited by smusba : 25th March 2020 at 07:55. Reason: php
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ue.before.after.destroy.object pralash Tools Development 8 6th August 2018 13:37
Extract fixed position out of a string with sprintf$() BaBernd Tools Development 2 5th January 2018 10:38
Logic Required for opening balance Sarath Blogs and Web links 0 29th September 2016 07:31
How to extract the solution file? jeffersyuan Tools Administration & Installation 6 22nd August 2007 10:09


All times are GMT +2. The time now is 13:10.


©2001-2018 - Baanboard.com - Baanforums.com