how can i convert the following to their right types

magnifiquemagnifique Member Posts: 43
am importing data from a comma separeted text file using this code

Table.AC_CODE := COPYSTR(Txt,1,STRPOS(Txt,',') - 1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.CC_CODE := COPYSTR(Txt,1,STRPOS(Txt,',') - 1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.NAME := COPYSTR(Txt,1,STRPOS(Txt,',') - 1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.DESC := COPYSTR(Txt,1,STRPOS(Txt,',') - 1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.AMOUNT := COPYSTR(Txt,1,STRPOS(Txt,', ') + 7);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.VOUCHER_NO := COPYSTR(Txt,1,STRPOS(Txt,',') - 1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.LEVEL1 := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.LEVEL2 := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.LEVEL3 := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.LEVEL4 := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.LEVEL5 := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.TRANS_TYPE := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.DEB_CRED := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.CURRENCY := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.AMOUNT1:= COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.TRNUM := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.DATE := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.RATE := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.PERIOD := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.B_NO := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.WHO := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.TODAY := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.TIME := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.POSTNO := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.RECODE := COPYSTR(Txt,1,STRPOS(Txt,',') -1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
Table.STRANS := COPYSTR(Txt,1,STRPOS(Txt,',') +1);
Txt := COPYSTR(Txt,STRPOS(Txt,',') + 1);
the TXT variable is of type text therefore when i try to import the data to decimal and date fields in my table ,it doesn't work .can anybody help as soon as possible

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi magnifique

    Use EVALUATE statement for this. O:)
  • FPulsfortFPulsfort Member Posts: 43
    To put Text into a decimal oder integer oder date you have to use EVALUATE. Have a look at the online-help.

    Regards,
    Frank
  • FPulsfortFPulsfort Member Posts: 43
    Too slow. :P
  • magnifiquemagnifique Member Posts: 43
    i tried to use EVALUATE even before my first post so if you can please help me with a sample code because i seem not to find my way around it.
    i want to convert the Amount field to Decimal and Date Field to Date
  • AlbertvhAlbertvh Member Posts: 516
    To use the EVALUATE statement

    EVALUATE(Table.AMOUNT,COPYSTR(Txt,1,STRPOS(Txt,', ') + 1);

    From online help
    This example shows how the EVALUATE function works when called with three different types of variables.

    Value := '010196';
    Ok1 := EVALUATE(VarInteger, Value);
    Ok2 := EVALUATE(VarDate, Value);
    Ok3 := EVALUATE(VarYesNo, Value);
    MESSAGE(Text000 + Text001 + Text002,
    VarInteger, Ok1, VarDate, Ok2, VarYesNo, Ok3)

    Create the following text constants in the C/AL Globals window:

    Text Constant
    ENU Value

    Text000
    'VarInteger = #1######, and the return code is: %2\'

    Text001
    'VarDate = #3######, and the return code is: %4\'

    Text002
    'VarYesNo = #5######, and the return code is: %6'


    The message window shows:

    VarInteger = 10196 , and the return code is: Yes
    VarDate = 01/01/96, and the return code is: Yes
    VarYesNo = No , and the return code is: No
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    IF EVALUATE(Table.AMOUNT,COPYSTR(Txt,1,STRPOS(Txt,', ') + 7)) THEN;
    ...
    IF EVALUATE(Table.DATE,COPYSTR(Txt,1,STRPOS(Txt,',') -1)) THEN;
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
Sign In or Register to comment.