Page 1 of 1

Combine data from different columns in file using ISPF command.

Posted: Mon Oct 03, 2016 3:03 pm
by Rabindra Kumar
Hi,

Suppose in a PS file, I have data in columns 5-20, 50-60 and in between there are spaces. How can I bring the data from columns 50-60 to 21-31? All the records, across, the columns are of same length. Do we have any ISPF command for this? Please share the command if there is any.

Re: Combine data from different columns in file using ISPF command.

Posted: Mon Oct 03, 2016 3:05 pm
by Moumita Singh
Hi,

I think you can use SORT too for this. SQUEEZ fucntion should work for your case.

Re: Combine data from different columns in file using ISPF command.

Posted: Mon Oct 03, 2016 3:13 pm
by enrico-sorichetti
not natively ...
the approach to be used depends on the size of the data being edited,
sort will be the preferred way for large amount of data

but ...

here is a sample rexx edit macro which will MOVE and swap colums
save it two times in a library in the sysproc or sysexec concatenation
one time with a name like MOVECOLS ... anything You like
the second time with a name like SWAPCOLS ... anything You like as long as it contains the string SWAP

Code: Select all

 ****** ***************************** Top of Data ******************************
 000001 /*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 000002 /*                                                                   */
 000003 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 000004 Trace "O"
 000005
 000006 _safemode = 0
 000007
 000008 Parse Source _sys _how _cmd .
 000009
 000010 If Sysvar(SYSISPF) \= "ACTIVE" Then Do
 000011    Say left(_cmd,8)"- Ispf is not active. Command not executed"
 000012    exit 4
 000013 End
 000014
 000015 call $ispex "CONTROL ERRORS RETURN"
 000016
 000017 if $isred("MACRO (ARGS) NOPROCESS ") \= 0 then do
 000018    zedsmsg = "Invocation ERROR"
 000019    zedlmsg = left(_cmd,8)"- Must be invoked as a MACRO"
 000020    call $ispex "SETMSG MSG(ISRZ001)"
 000021    exit 4
 000022 end
 000023 args = space(translate(args," ",","))
 000024 if words(args) \= 3 then do
 000025    zedsmsg = "Operands   ERROR"
 000026    zedlmsg = left(_cmd,8)"- missing From,Length,Dest operands"
 000027    call $ispex "SETMSG MSG(ISRZ001)"
 000028    exit 4
 000029 end
 000030 parse var args from len1 dest
 000031 if datatype(from) \= "NUM" | ,
 000032    datatype(len1) \= "NUM" | ,
 000033    datatype(dest) \= "NUM" then do
 000034    zedsmsg = "Operands   ERROR"
 000035    zedlmsg = left(_cmd,8)"- From,Length,Dest must be numeric"
 000036    call $ispex "SETMSG MSG(ISRZ001)"
 000037    exit 4
 000038 end
 000039
 000040 
 000041 if  pos("SWAP",_cmd) > 0 then ,
 000042     len2 = len1
 000043 else ,
 000044     len2 = 0
 000045
 000046 if  from > dest then do
 000047     temp = from; from = dest; dest = temp
 000048     temp = len1; len1 = len2; len2 = temp
 000049 end
 000050
 000051 call $isred "(BND1 BND2) = BOUNDS"
 000052 if ( from < bnd1 ) | ,
 000053    ( bnd2 < dest+len2) then do
 000054    zedsmsg = "Bounds     ERROR"
 000055    zedlmsg = left(_cmd,8)"- From,Length,Dest outside BOUNDS"
 000056    call $ispex "SETMSG MSG(ISRZ001)"
 000057    exit 4
 000058 end
 000059
 000060 call $isred "PROCESS RANGE S"
 000061 if $isred("(LN1) = LINENUM .ZFRANGE") \= 0 then do
 000062    call $ispex "SETMSG MSG(ISRE040) "
 000063    exit 4
 000064 end
 000065 call $isred "(LN2) = LINENUM .ZLRANGE"
 000066 Do  l = ln1 to ln2
 000067     call $isred("(BUFF) = LINE" l )
 000068     str1 = substr(buff,from,len1)
 000069     str2 = substr(buff,dest,len2)
 000070     temp = ""
 000071     temp = temp || substr(buff,1,from-1)
 000072     temp = temp || str2
 000073     temp = temp || substr(buff,from+len1,dest-(from+len1))
 000074     temp = temp || str1
 000075     temp = temp || substr(buff,dest+len2)
 000076     if  _safemode then ,
 000077         call $isred "LINE_AFTER .ZLAST = DATALINE (TEMP)"
 000078     else ,
 000079         call $isred "LINE "l" = (TEMP)"
 000080  
 000081 End
 000082
 000083 zedsmsg = left(_cmd,8)"- Ended"
 000084 zedlmsg = ln2-ln1+1 " Lines changed"
 000085 call $ispex "SETMSG MSG(ISRZ001) "
 000086
 000087 Exit 0
 000088
 000089 /*  */
 000090 $tsoex:
 000091    tso_0tr = trace("O")
 000092    Address TSO arg(1)
 000093    tso_0rc = rc
 000094    trace value(tso_0tr)
 000095    return tso_0rc
 000096
 000097 /*  */
 000098 $ispex:
 000099    isp_tr = trace("O")
 000100    Address ISPEXEC arg(1)
 000101    isp_rc = rc
 000102    trace value(isp_tr)
 000103    return isp_rc
 000104 /*  */
 000105 $isred:
 000106    isr_tr = trace("O")
 000107    Address ISREDIT arg(1)
 000108    isr_rc = rc
 000109    trace value(isr_tr)
 000110    return isr_rc
 000111
 ****** **************************** Bottom of Data ****************************
TESTED AND WORKING
but ... remember UNDO is Your friend

it must be invoked as <macroname> FromColumn,FromLength,ToColumn
for the swap the From and the To columns meaning is clear
for a move its a bit more difficult to explain
the from is clear ...
the to/dest is a bit murky , the macro will shift things starting from that column
movecols xx,1,1
will start shifting from column 1 an makes things look as data inserted before that column
the look is natural for a move left, not the same for a move right
the column used is the one before the move, and after that everything will be shifted left
just pay attention in not being confused by the look of the data after using the macro

Re: Combine data from different columns in file using ISPF command.

Posted: Mon Oct 03, 2016 6:48 pm
by nicc
Simply?

Code: Select all

C " " "" 21 59 ALL
Or set the left bound at column 21 and do a block shift left("((/((" of 39 columns. Remember to reset the bounds afterwards.

Re: Combine data from different columns in file using ISPF command.

Posted: Fri Oct 07, 2016 2:11 pm
by Moumita Singh
Thanks all for this thread. Helped me too.

Re: Combine data from different columns in file using ISPF command.

Posted: Sat Oct 08, 2016 12:53 pm
by Rabindra Kumar
Thanks All! BNDS is an amazing command.

Re: Combine data from different columns in file using ISPF command.

Posted: Sat Oct 08, 2016 5:14 pm
by nicc
I suggest you take the time to read about all the primary and line commands via the tutorial and manual and practice with them.