0

I work with COBOL using RPP EDI(It uses Eclipse as environment). The task is simple but, for some reason, it is not working in RPP (If I do it using COBOL in Mainframe direcyly, it does work). I need to add +1 to a variable (called: File Sequence Number) of a table. The field of the table is set as Char (who knows why?) and the temporary variable of the sequence number is defined as Numeric:

DB30-BA3511         PIC X(10) ->this is the DB field
WS-FILE-SEQ-NUM     PIC 9(10) ->this is the temporary variable

The tasks is simple and it would work in almost every language, but for some reason here it is not behaving as expected. This is what it does in RPP: When I move the DB field value (currently as '1' in the DB) to the local variable WS-FILE-SEQ-NUM, it is saved as 1000000000 instead of 0000000001 so when I add +1 the result is: 1000000001 instead of 0000000002 (or just 2)

MOVE        DB30-BA3511 TO WS-FILE-SEQ-NUM
ADD         +1 TO WS-FILE-SEQ-NUM
MOVE        WS-FILE-SEQ-NUM TO DD30-BA3511

I tried the following without success:

  • Using REDEFINES
  • Instead of using PIC 9 I tried with PIC S9 (with and without COMP)

and some other things that I don't even remember because I've been struggling with this for days

Any ideas ? thank you in advance!

2

2 Answers 2

1

Bruce is correct, you need to move only the numeric data. First you need to find out if the data is padded with spaces in the front or the back. Based on what you said so far, I would say the spaced are at the back. Nonetheless here is an example for both cases:

Leading Spaces

DB30-BA3511         PIC X(10).
WS-FILE-SEQ-NUM     PIC 9(10).
WS-FORMATTED-SEQ    PIC ZZZZZZZZZZ.
WS-SPACE-COUNT      PIC 99 COMP.

INSPECT DB30-BA3511 TALLYING WS-SPACE-COUNT FOR LEADING SPACES
MOVE DB30-BA3511(WS-SPACE-COUNT + 1:) TO WS-FILE-SEQ-NUM 
ADD 1 TO WS-FILE-SEQ-NUM
MOVE WS-FILE-SEQ-NUM TO WS-FORMATTED-SEQ
MOVE WS-FORMATTED-SEQ TO DB30-BA3511

This will get a leading space count, then only move the data after the leading spaces to the numeric field. After that, we add 1 to the numeric field then move it to a formatted number field. This will remove the leading zeroes before finally moving it back to the original alpha numeric field. The process is almost identical for trailing spaces

Trailing Spaces

DB30-BA3511         PIC X(10).
WS-FILE-SEQ-NUM     PIC 9(10).
WS-FORMATTED-SEQ    PIC ZZZZZZZZZZ.
WS-SPACE-COUNT      PIC 99 COMP.
WS-LENGTH           PIC 99 COMP.

INSPECT DB30-BA3511 FUNCTION REVERSE TALLYING 
   WS-SPACE-COUNT FOR LEADING SPACES
COMPUTE 
   LENGTH = 10 - WS-SPACE-COUNT
END-COMPUTE
MOVE DB30-BA3511(1:WS-LENGTH) TO WS-FILE-SEQ-NUM 
ADD 1 TO WS-FILE-SEQ-NUM
MOVE WS-FILE-SEQ-NUM TO WS-FORMATTED-SEQ
MOVE WS-FORMATTED-SEQ TO DB30-BA3511
Sign up to request clarification or add additional context in comments.

4 Comments

As a side note, you should really talk to your database people and have them change that field to an int of some kind. A sequence number should NEVER be a char field that is crazy.
Thank you! I will try this!
Ya se pudo resolver el problema! Muchas gracias por tu ayuda (Y a la ayuda de todos!)
... I don't speak Spanish, but if this answer helped you, consider accepting it
1

As Simon said the problem is probably with the DB30-BA3511 field. I would imagine it holds not 1 but "1 " (1 followed by 9 spaces). When you move DB30-BA3511 to a numeric field, the spaces are interpreted as 0's (from memory can happen on the mainframe).

Possible solutions

  • look at Data Base connection definition
  • Only move the data:
    • Count the number of trailing spaces
    • Move DB30-BA3511 (1:data-length) to ...

3 Comments

Thanks a lot! I will give it a try
@Bruce: Are you sure that "When you move DB30-BA3511 to a numeric field, the spaces are becoming 0's (fairly normal cobol behavior)." is correct? I'd say the MOVE shouldn't do any conversion as no field definition claims for (de-)editing or internal storage conversion (both are USAGE DISPLAY). I'd say that the ADD may "interpret" the spaces as zeroes (implementor-defined, non-(COBOL-)standard behavior), please elaborate on your note.
Simon, you are correct, the space gets interpreted as zero in certain situations. Its been 10 years since I worked in Cobol on the mainframe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.