Since the primary key values for a VSAM file must be unique, either your input is wrong:
input data
x1 abc
x1 def
x2 efr
x2 gre
or you are not telling us everything. With only partial information, we can only provide partial solutions. You need to create a variable in working storage with your key value and room for each value you need to output. What is the maximum number you can have? Are they all three bytes long? Do you need a space separating them?
Pseudocode (untested) to do this:
Read first record and move key, data to hold area
Loop
Read record
If key matches hold key, append data to end of hold record
Otherwise, output record and move key, data to hold area
until end-of-file