Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2013
    Posts
    14

    Unanswered: COMP-3 equivalent in DB2

    Hi All,

    I am using DB2 v9.7.2 on Windows machine.

    Requirement is to convert COBOL program code into DB2 stored procedure. While doing so I am facing problem in below piece of code.

    IDENTIFICATION DIVISION.
    PROGRAM-ID. TEST.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 WS-CONVERT.
    10 WS-CVT-HEX PIC 9(12) USAGE COMP-3.
    10 WS-CVT-CHAR REDEFINES WS-CVT-HEX PIC X(07).
    10 WS-CVT-NUM PIC 9(12).
    10 WS-NUM PIC X(12).
    10 WS-NUM-OUT PIC X(12).
    PROCEDURE DIVISION.
    MOVE 'A12345689012' TO WS-NUM.
    IF (WS-NUM(1:7) IS NOT NUMERIC)
    AND (WS-NUM NOT EQUAL SPACES )
    MOVE WS-NUM TO WS-CVT-CHAR
    MOVE WS-CVT-HEX TO WS-CVT-NUM
    MOVE WS-CVT-NUM TO WS-NUM-OUT
    ELSE
    MOVE WS-NUM TO WS-CVT-CHAR
    END-IF
    DISPLAY WS-NUM-OUT.
    STOP RUN.

    I am not sure how to check for Not Numeric condition on variable WS-NUM in DB2 and if it is not numeric then how implement the mentioned conversion.

    Would appreciate any help on this. Let me know if any other information is required.

    Thanks in anticipation!
    Last edited by Kapil006; 03-31-14 at 03:22. Reason: Clarification

  2. #2
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    What is this cobol code 'suppose' to do? Which cobol compiler do you use? Do you ever see output in WS-NUM-OUT?
    Somewhere between " too small" and " too large" lies the size that is just right.
    - Scott Hayes

  3. #3
    Join Date
    Aug 2013
    Posts
    14
    COBOL code is displaying value that is coming in variable WS-NUM on application. This value is coming from a table. Here, for simplicity I have hardcoded value of WS-NUM as 'A123456789012'.
    Then it is checking whether first 7 bytes of WS-NUM are numeric or not. If not numeric (characters or any junk characters) , it is converting that into number using COMP-3 variable.

    My requirement is to convert this logic into DB2 stored procedure that will run on UDB v9.7.2.

    I am not sure of the COBOL compiler and also the output of WS-NUM-OUT as I have given COBOL code only to convert it into stored procedure.

    I hope that helps.

  4. #4
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    Step by step:
    - get first 7 bytes: SUBSTRING(variable, 1, 7)
    - check if it is numeric: LENGTH(RTRIM(TRANSLATE(test_str, '*', ' 0123456789'))) = 0
    - convert a char into a number: CAST
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  5. #5
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    The equivalent of COBOL COMP-3 in DB2 LUW is DECIMAL.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  6. #6
    Join Date
    Aug 2013
    Posts
    14
    Thanks for reply Florin and Marcus!

    I looked for CAST to convert char into number but didn't find a way to do that.

    I am trying below query but it is giving SQL code -420 (Invalid character found in a character string argument of the function "INTEGER". SQLSTATE=22018)

    select cast('a1234' as int) from sysibm.sysdummy1
    or
    select cast('a1234' as decimal) from sysibm.sysdummy1

    How else we can CAST input string having not numeric characters into number?

    Please suggest.

  7. #7
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    It works like this:
    - CAST('1234' AS INT)
    - CAST(SUBSTR('a1234',2,4) AS INT)
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  8. #8
    Join Date
    Aug 2013
    Posts
    14
    Thanks!
    But we don't want to remove not numeric data. If you see COBOL code, they are converting not numeric data in numbers. This is exactly what we have to replicate in DB2.

  9. #9
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Quote Originally Posted by Kapil006 View Post
    Thanks!
    But we don't want to remove not numeric data. If you see COBOL code, they are converting not numeric data in numbers. This is exactly what we have to replicate in DB2.
    Looks like COBOL program is treating the literal as a hex value. This can be converted to a number in DB2 LUW, but x'(A1)' is not a valid hex number in ASCII (or ECIDIC). x'A1' represents a tilde (~).
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •