javivi,
You can use a DFSORT job like the following to do what you asked for. I assumed your input was already in sorted order as shown in your example. If not, you'll need to replace OPTION COPY with a SORT statement. I wasn't sure of the positions of your fields, so I guessed. Adjust as needed.
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
aaaaaaaaaa pepe lopez 1111 00123.35
aaaaaaaaaa pepe lopez 2222 00100.12
bbbbbbbbbb luis sanche 1111 00222.34
cccccccccccc jose sanz 1111 12345.87
cccccccccccc jose sanz 2222 00345.76
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC IFOUTLEN=80,
IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,25),PUSH=(81:SEQ=8)),
IFTHEN=(WHEN=(81,8,ZD,GT,1),OVERLAY=(1:25X))
OUTFIL REMOVECC,
HEADER2=('PORTFOLIO NAME ACCOUNT SHARES',/,
'-------------- -------------- ------------ -------------'),
BUILD=(1,13,16:14,12,31:26,4,44:31,8,80:X)
/*
SORTOUT would have:
PORTFOLIO NAME ACCOUNT SHARES
-------------- -------------- ------------ -------------
aaaaaaaaaa pepe lopez 1111 00123.35
2222 00100.12
bbbbbbbbbb luis sanche 1111 00222.34
cccccccccccc jose sanz 1111 12345.87
2222 00345.76
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:
http://www.ibm.com/support/docview.wss? ... g3T7000080