REC-INFO = XXXX ,AAAA ,SSSSSSS-DDDDD ,00/0/0000, -000000.00, 0.000000, ,
Can this be done in COBOL in any way???
Aki88 wrote:Hi Venky,
Yes, COBOL is very much capable of handling such conditions and more; there are various methods to achieve this, depending on your comfort level with COBOL.
Two quick methods are either by using 'INSPECT' or by using a well-coded 'PERFORM VARYING' construct with logic built to handle your requirement.
Try looking up the both of these in the COBOL programming manuals (link to manuals is at the top of page, or you can click here).
Try a small code piece using the same, if you get stuck, let us know and we might be able to help you.
Hth!
Regards.
Aki88 wrote:Hello Venky,
Here is a fairly simple (and a li'l badly coded) PERFORM loop to get this requirement done:016600 PERFORM VARYING X-COUNTER FROM 1 BY 1
016700 UNTIL X-COUNTER > LENGTH OF INPUT-VAR
016800 IF INPUT-VAR (X-COUNTER:1) = ' '
016900 CONTINUE
017000 ELSE
017100 MOVE INPUT-VAR (X-COUNTER:1) TO
017200 OUTPUT-VAR (X-OP-COUNTER:1)
017300 ADD 1 TO X-OP-COUNTER
017400 END-IF
017500 END-PERFORM.
017600 DISPLAY 'OUTPUT-VAR:' OUTPUT-VAR.
The variables are as below:009510 01 VARIABLE-DEFINITIONS.
009600 03 INPUT-VAR PIC X(101) VALUE
009700 ' XXXX ,AAAA ,SSSSSSS-DDDDD ,00/0/0000, -
009800- '000000.00, 0.000000, ,'.
009900 03 OUTPUT-VAR PIC X(101).
010000 03 COUNTER-VARIABLES.
010010 05 X-COUNTER PIC 9(3) VALUE ZEROS.
010100 05 X-OP-COUNTER PIC 9(3) VALUE 1.
The output is as below:OUTPUT-VAR:XXXX,AAAA,SSSSSSS-DDDDD,00/0/0000,-000000.00,0.000000,,
Regards.
venky720 wrote:BillyBoyo wrote:I'd like to see code with INSPECT removing spaces as well, please
venky720, can you show how you constructed that field. The best way to get rid of the spaces is not to put them there in the first place.