#39 MULTIPLY GIVING PIC $$$,$$9.99

GC 1.1
closed
None
5
2015-02-19
2012-07-27
Ron Norman
No

Test program:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    tsty.
       DATA  DIVISION.
       WORKING-STORAGE SECTION.
       01  TST.
           05 DEPT-SUB        PIC 9(6)V999 VALUE 18536.232.
           05 DEPT-COST-YTD   PIC 9(6)V999 VALUE 18536.232.
           05 DL-PROD-COST    PIC $$$,$$9.99.
       77  WFLT  PIC $$$,$$9.99.

       PROCEDURE DIVISION.
           MOVE 18536.23 TO WFLT.
           DISPLAY "WFLT IS " WFLT.
           MULTIPLY DEPT-COST-YTD BY 1 GIVING DL-PROD-COST ROUNDED.
           DISPLAY "COST IS " DL-PROD-COST.
           MULTIPLY DEPT-COST-YTD BY 1 GIVING DEPT-SUB ROUNDED.
           MOVE DEPT-SUB TO DL-PROD-COST.
           DISPLAY "COST IS " DL-PROD-COST.
           STOP RUN.

Micro Focus output:

WFLT IS $18,536.23
COST IS $18,536.23
COST IS $18,536.23

OC 1.1 output:

WFLT IS $18,536.23
COST IS  $8,536.23
COST IS $18,536.23

So the problem has something to do with a formatted PIC clause which is moved to via MULTIPLY GIVING.

Related

Discussion: Opencobol-1.1 Install Tests Suite Failures..

Discussion

  • Ron Norman

    Ron Norman - 2012-10-14

    The problem was in libcob/numeric.c in the routines cob_decimal_get_field for the default case it creates a 'temp' but makes the size too small to hold the result of the multiply.
    I added code to set temp.size = 18; and that fixed this problem.
    This was for OpenCOBOL 1.1

     
  • Simon Sobisch

    Simon Sobisch - 2012-10-15

    Good catch, but the fix seems wrong. temp.size is correctly set to the size of the target field "temp.size = COB_FIELD_DIGITS(f)", therefore I guess the computation of the FIELD-DIGITS for formatted PICs (you can see this if you use compile switch -Wall), too.
    Do you want to give "fixing the parser" a try?

    Simon

     
  • Ron Norman

    Ron Norman - 2012-10-15

    I see that it is giving a warning when it should not.
    I'll have a look at the parser later.
    In the short term, just making the size of the temp.size to be 18 at least gets the program to execute correctly.

    --
    Cheers
    Ron Norman

     
    Last edit: Simon Sobisch 2012-10-16
  • Ron Norman

    Ron Norman - 2012-10-16

    How about this fix?

    In cobc/tree.c in the routine cb_build_picture.
    In the default case of scanning the picture clause change the code to read:

            default:
                if (c == current_program->currency_symbol) {
                    category |= PIC_NUMERIC_EDITED;
                    if(c_count == 0) {
                        digits += n - 1;
                        c_count = n - 1;
                    } else {
                        digits += n;
                        c_count+= n;
                    }
                    break;
                }
    

    You also have to add int c_count and set it to 0 at the start of the
    routine.
    It was the $$,$$$ that caused it to compute digits too low.
    I also think under the case '+': case '-': the code should be:

            case '+':
            case '-':
                category |= PIC_NUMERIC_EDITED;
                if (category & PIC_ALPHABETIC) {
                    goto error;
                }
                if (s_char_seen || p_char_seen) {
                    goto error;
                }
                if(s_count == 0)
                    digits += n - 1;
                else
                    digits += n;
                s_count++;
    

    --
    Cheers
    Ron Norman

     
    Last edit: Simon Sobisch 2014-03-11
  • Sergey Kashyrin

    Sergey Kashyrin - 2012-10-24

    Sounds right.
    Committed to CE SVN.

     
  • Brian Tiffin

    Brian Tiffin - 2012-12-15
    • status: open --> closed
    • assigned_to: Sergey Kashyrin
    • milestone: --> open
     
  • Ron Norman

    Ron Norman - 2012-12-15

    Hi,

    I think I also posted the fix for this problem a while after posting the
    problem.
    The issue was in the code that counts how many digits are represented by
    the numeric edit picture clause.
    In the module numeric.c it was counting $$$ as 2 digits to leave room for the $ sign but then when it hi comma and $$ it again computed $$ as just space for 1 digit when it should have remembered that it previous subtracted 1 to leave room for the dollar sign.
    the fix was to add a flag to remember that it had already done one subtract 1.

    --
    Cheers
    Ron Norman

     
    Last edit: Simon Sobisch 2014-03-11
  • Simon Sobisch

    Simon Sobisch - 2015-01-27

    Fixed in CE and GnuCOBOL 1.1 release.

     
  • Simon Sobisch

    Simon Sobisch - 2015-01-27
    • Group: unclassified --> GC 1.1
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks