Array concatenation: Difference between revisions

→‎{{header|COBOL}}: specified version
(→‎{{header|Zig}}: fix, add deinit() where appropriate, use std.mem.concat)
imported>Acediast
(→‎{{header|COBOL}}: specified version)
Line 1,210:
 
=={{header|COBOL}}==
{{works with|COBOL 2014}}
<syntaxhighlight lang="cobol"> identification division.
<syntaxhighlight lang="cobolfree">IDENTIFICATION DIVISION.
programPROGRAM-idID. array-concat.
 
DATA DIVISION.
environment division.
WORKING-STORAGE SECTION.
configuration section.
01 table-one.
repository.
05 05 int-field picPIC 999 occursOCCURS 0 toTO 5 dependingTIMES DEPENDING onON t1.
function all intrinsic.
01 table-two.
05 05 int-field picPIC 9(4) occursOCCURS 0 toTO 10 dependingTIMES DEPENDING onON t2.
77 tally USAGE IS INDEX.
77 t1 77 t1 picPIC 99.
77 t2 77 t2 picPIC 99.
77 show PIC Z(4) USAGE IS DISPLAY.
 
PROCEDURE DIVISION.
data division.
array-concat-main.
working-storage section.
PERFORM 01 tableinitialize-one.tables
PERFORM concatenate-tables.
05 int-field pic 999 occurs 0 to 5 depending on t1.
PERFORM 01 tabledisplay-two.result
GOBACK.
05 int-field pic 9(4) occurs 0 to 10 depending on t2.
 
initialize-tables.
77 t1 pic 99.
MOVE 4 TO .t1
77 t2 pic 99.
PERFORM perform varyingVARYING tally fromFROM 1 byBY 1 untilUNTIL tally > t1
computeCOMPUTE int-field ofOF table-one(tally) = tally * 3
END-PERFORM
MOVE 3 TO .t2
PERFORM perform varyingVARYING tally fromFROM 1 byBY 1 untilUNTIL tally > t2
computeCOMPUTE int-field ofOF table-two(tally) = tally * 6
END-PERFORM.
 
perform concatenate-tables.
77 show pic z(4).
PERFORM perform varyingVARYING tally fromFROM 1 byBY 1 untilUNTIL tally > t1
addADD 1 toTO t2
moveMOVE int-field ofOF table-one(tally)
toTO int-field ofOF table-two(t2)
END-PERFORM.
 
display-result.
procedure division.
PERFORM perform varyingVARYING tally fromFROM 1 byBY 1 untilUNTIL tally = t2
array-concat-main.
moveMOVE int-field ofOF table-two(tally) toTO show
perform initialize-tables
DISPLAY FUNCTION TRIM(show) ", " WITH NO ADVANCING
perform concatenate-tables
END-PERFORM
perform display-result
moveMOVE int-field ofOF table-two(tally) toTO show
goback.
DISPLAY FUNCTION TRIM(show).
 
END end programPROGRAM array-concat.</syntaxhighlight>
initialize-tables.
move 4 to t1
perform varying tally from 1 by 1 until tally > t1
compute int-field of table-one(tally) = tally * 3
end-perform
 
move 3 to t2
perform varying tally from 1 by 1 until tally > t2
compute int-field of table-two(tally) = tally * 6
end-perform
.
 
concatenate-tables.
perform varying tally from 1 by 1 until tally > t1
add 1 to t2
move int-field of table-one(tally)
to int-field of table-two(t2)
end-perform
.
 
display-result.
perform varying tally from 1 by 1 until tally = t2
move int-field of table-two(tally) to show
display trim(show) ", " with no advancing
end-perform
move int-field of table-two(tally) to show
display trim(show)
.
 
end program array-concat.</syntaxhighlight>
{{out}}
<pre>prompt$ cobc -xjd array-concatenation.cob --std=cobol2014 # COBOL 2014 needed for FUNCTION TRIM
6, 12, 18, 3, 6, 9, 12
</pre>
Anonymous user