Options

Padding in Dataport

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hi Friends,

I am designing a dataport where I need to pad the Amount field (in output text file) taking from Vendor Ledger Entry with zeros in the front. The fixed length of Amount field is 18.

Eg: 4325.80 should be displayed as 000000000004325.80

How to do this? I defined Amount in dataport fields and I tried with the following piece of coding where AmountPay is text field.

AmountPay := FORMAT(Amount);
AmountPay := PADSTR('',18 - STRLEN(AmountPay),'0') + FORMAT(AmountPay);
message('%1', AmountPay);

I am getting the zero value as output like "000000000000000000', but my expected output is 000000000004325.80 in text file. Please anyone point out me where I am going wrong.

Thanks and Regards,
Aravindh

Answers

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    I tries like this

    AmountPay := FORMAT(4325.80);
    AmountPay := PADSTR('',18 - STRLEN(AmountPay),'0') + FORMAT(AmountPay);
    message('%1', AmountPay);
    

    and output is


    Please check the value of Amount in your case..
  • Options
    Aravindh_NavisionAravindh_Navision Member Posts: 258
    Hi Mohana,

    Thanks a lot for your response. It displays the value in normal condition, but I need to get in text file in dataport.

    Thanks,
    Aravindh
  • Options
    xinxin Member Posts: 10
    Hi,

    I think you can try this:-

    AmountPay := FORMAT(Amount,0,'<Precision,2:2><Standard Format,0>');
    AmountPay2 := PADSTR('',18 - STRLEN(AmountPay),'0') + FORMAT(AmountPay);
    message('%1', AmountPay2);

    But declare another global variable for AmountPay2 and both of them datatype = Code, so the decimal places .80 will be show.

    Thanks.
  • Options
    Aravindh_NavisionAravindh_Navision Member Posts: 258
    Hi Xin,

    In which trigger I need to write this code? Because I am getting zeros as output... :(

    Thanks,
    Aravindh
  • Options
    xinxin Member Posts: 10
    Hi,

    You can put on OnBeforeExportRecord() & for the Dataport Fields, put variable AmountPay2 instead of Amount.
    Also make sure you've write the code CalcFields(Amount) (if amount is flow field) before the code.

    Thanks.
  • Options
    Aravindh_NavisionAravindh_Navision Member Posts: 258
    Hi Xin,

    Great.. It works perfectly. :D

    Thanks a lot,
    Aravindh
  • Options
    xinxin Member Posts: 10
    Hi,
    You are welcome. :wink:
Sign In or Register to comment.