Leading Zeros in Dataport

pengwenincpengweninc Member Posts: 38
I have a right justified field on a dataport export. I need leading zeros to the left of the field and I'm not sure how to do it.

Right now the field exports like this:
12345
12346
12347

I need it to look like:
012345
012346
012347

Comments

  • ta5ta5 Member Posts: 1,164
    You can use format command on the trigger onBeforeExport, for example
    myStr := FORMAT(myInt,0,'<Integer,6><Filler Character,0>')

    Hope this helps
    Thomas
  • pengwenincpengweninc Member Posts: 38
    I should have mentioned, this number is actually a code, not an integer.
  • TomasTomas Member Posts: 420
    I have used this one
    "myString" := PADSTR('',MAXSTRLEN("myString")-STRLEN("myString"),'0') + "myString";
    

    to fill in only "needed" zeros (which came from length of myString).
  • ta5ta5 Member Posts: 1,164
    In this case you have 2 possibilities:

    1) Convert the code to a number, then use format as mentioned
    2) prefix a string of 6 zeroes to the code and use the 6 rightmost characters only, in this case the padding to 6 should be ok. Maybe there is an easier way, but it works anyway...

    Hope this helps
    Thomas
  • TomasTomas Member Posts: 420
    I have just tried with code
    Name	DataType	Subtype	Length
    myCode	Code		10
    
    myCode := '1234';
    myCode := PADSTR('',MAXSTRLEN(myCode)-STRLEN(myCode),'0') + myCode;
    MESSAGE('%1',myCode);
    

    returns 0000001234
  • pengwenincpengweninc Member Posts: 38
    That did the trick! Perfect, thank you.
  • BeliasBelias Member Posts: 2,998
    anyway...format works,too
    cd := '1234'
    message(format(cd,0,'<Text,5><Filler Character,0>'));
    

    <Text,5> insert the lenght of the string you want
    but be careful: if the variable is text instead of code (or the code contains a letter or symbol), the 0s will be trailing instead of leading
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.