SORT – PARSE – READ EXCEL (CSV) FILE IN MAINFRAMES (REFORMAT VARIABLE FIELDS)
Sometimes you will have your input data as provided below, when you import from Excel (CSV) to Mainframes. To use this file in a COBOL program, you will need fields to be in a format. Each field will not start at a particular column. To reformat these records, you can make use of PARSE parameter.
RAJESH,M,111,AAAA
RAMS,M,22,BBB
SURESH,M,3333,CCCC
SUNIL,M,4,DDDDDDD
OUTPUT
RAJESH 111 AAAA
RAMS 22 BBB
SURESH 3333 CCCC
SUNIL 4 DDDDDDD
SORT CARD
OUTREC PARSE=(%01=(ENDBEFR=C’,’,FIXLEN=8),
%=(ENDBEFR=C’,’),
%03=(ENDBEFR=C’,’,FIXLEN=5),
%04=(FIXLEN=10)),
BUILD=(%01,X,%03,X,%04)
- The %01 parsed field is used to extract the first variable field into an 8-byte fixed parsed field. ENDBEFR=C’,’ tells DFSORT to stop extracting data at the byte before the next comma (the comma after the first variable field). FIXLEN=8 tells DFSORT that the %01 parsed field is 8 bytes long.
- The % parsed field is used to skip the second variable field without extracting anything for it
- The %03 parsed field is used to extract the third variable field into a 5-byte fixed parsed field. ENDBEFR=C’,’ tells DFSORT to stop extracting data before the next comma (the comma after the third variable field). FIXLEN=5 tells DFSORT that the %03 parsed field is 5 bytes long.
- The %04 parsed field is used to extract the fifth variable field into a 10-byte fixed parsed field. FIXLEN=10 tells DFSORT that the %04 parsed field is 10 bytes long.
PARSE Parameters
You can use the following parameters in PARSE to define the rules for extracting variable position/length data to %nn fixed parsed fields:
- FIXLEN=m: Specifies the length (m) of the fixed area to contain the extracted variable data for this %nn fixed parsed field.
- ABSPOS=p: Start extracting data at input position p.
- ADDPOS=x: Start extracting data at the current position + x.
- SUBPOS=y: Start extracting data at the current position – y.
- STARTAFT=string: Start extracting data at the byte after the end of the character or hexadecimal string.
- STARTAFT=BLANKS: Start extracting data after the end of the next group of blanks.
- STARTAT=string: Start extracting data at the first byte of the character or hexadecimal string.
- STARTAT=BLANKS: Start extracting data at the start of the first group of blanks.
- STARTAT=NONBLANK: Start extracting data at the next nonblank.
- ENDBEFR=string: Stop extracting data at the byte before the start of the character or hexadecimal string.
- ENDBEFR=BLANKS: Stop extracting data at the byte before the next group of blanks.
- ENDAT=string: Stop extracting data at the last byte of the character or hexadecimal string.
- ENDAT=BLANKS: Stop extracting data at the end of the next group of blanks.
- PAIR=APOST: Do not search for strings or blanks between apostrophe (‘) pairs.
- PAIR=QUOTE: Do not search for strings or blanks between quote (“) pairs
——————————————————————————————————–
In United States, If you would like to Earn Free Stocks, Credit card Points and Bank account Bonuses, Please visit My Finance Blog
——————————————————————————————————–
You may also like to look at:
Working on Mainframes – Is Change to a different technology necessary |