Overview:
This module enables the student to
understand various String Functions.
Outline:
Topics covered,
- IPN
- String
Handling Opcodes.
Objective:
By the end of this module, the student should be
able to:
- IPN
- Understand the various String Handling Opcodes like – MOVE,
MOVEL, CAT, SUBST, SCAN, CHECK, CHEKR and XLATE.
First we will study the IPN specification:
IPN is used to define the constant values. IPN Specification line is broken into following parts.
Positions
|
Name
|
Entry
|
1-5
|
Blank
|
|
6
|
Form type
|
I
|
7-20
|
Blank
|
|
21-42
|
Constant
|
Constant Value
|
43
|
Data Type
|
c, Blank
|
44-52
|
Blank
|
|
53-58
|
Constant Name
|
Name
|
59-74
|
Blank
|
Constant: Write the constant Values in this position.
Data Type: Write here ‘C’. C stands for constant.
Field Name: Write the name of the field, which hold the
constant values.
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA7
FMT *
..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+...
7
*************** Beginning of data
*************************************
0001.00 *DEFINING CONSTANT USING IPN PROMPT
0002.00 I 'WELCOME TO DUKESTAR' C FLD1
0003.00 C FLD1 DSPLY
0004.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . N
Sequence number . . .
0002.00
Data Field
Constant Type Name
'WELCOME TO DUKESTAR' C
FLD1
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
MOVE (Move Right to
Left)
Moves the character/numeric field in
Factor2 to character/numeric field in Result from right to left.
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA7
FMT *
..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+...
7
*************** Beginning of data
*************************************
0001.00 *DEFINING CONSTANT USING IPN PROMPT
0002.00 I 'WELCOME TO DUKESTAR' C FLD1
0003.00 C FLD1 DSPLY
0004.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . N
Sequence number . . .
0002.00
Data Field
Constant Type Name
'WELCOME TO DUKESTAR' C
FLD1
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
(C)
COPYRIGHT IBM CORP. 1981, 2002.
Columns . . . :
1 71 Edit PB01U01S/MYRPG
SEU==>
EXA8
FMT * ..... *. 1 ...+... 2 ...+... 3 ...+... 4
...+... 5 ...+... 6 ...+... 7
*************** Beginning of data *************************************
0000.01
*Define a constant & Display it.
0001.00
I 'WELCOME TO ' C FLD1
0002.00
C FLD1 DSPLY
0002.01 *Define a character variable.
0002.02
C MOVE
*BLANKS FLD2 8
0002.03
*Move string to a variable & Display it.
0003.00
C MOVE 'DUKESTAR'FLD2
0004.00
C FLD2 DSPLY
0004.01
*Define a Numeric variable.
0005.00
C Z-ADD1234.56 FLD3
62
0005.01
*Clear the Character variable.
0005.02
C MOVE
*BLANKS FLD2
0005.03
*Move numeric value to Character variable
0006.00
C MOVE
FLD3 FLD2
0007.00
C FLD2 DSPLY
0007.01
C MOVE
*BLANKS FLD2
0007.02
*Move from left numeric value to Character variable
0008.00
C
MOVELFLD3 FLD2
0008.01
C FLD2 DSPLY
0008.02
C MOVE *BLANKS
FLD2
0009.00
C MOVE
'1234.56' FLD2
0011.00
C FLD2 DSPLY
0012.00 C SETON LR
****************** End of data *****************************
F3=Exit F4=Prompt
F5=Refresh F9=Retrieve F10=Cursor
F11=Toggle
F16=Repeat
find F17=Repeat change F24=More keys
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA9
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C MOVEL'DUKESTAR'FLD1 4
0002.00 C FLD1 DSPLY
0003.00 C MOVE 'DUKESTAR'FLD2 4
0004.00 C FLD2 DSPLY
0005.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . C
Sequence number . . .
0001.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
MOVEL 'DUKESTAR' FLD1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
4
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
CAT(Concatenate two character strings)The CAT opcode is useful for
combining the values of two strings to form a third string. The two character
–data items to be combined are specified in factor 1 and factor2. The result
field entry specifies where the results of concentration are to be placed. You
can also specify the number of blanks between the non-blank characters of the
combined fields by appending a (:) to the factor 2 item followed by an integer
literal, field etc. Use P in H/N/P entry to indicate that result field should
be padded with blanks after concatenation. No indicators are used with
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA9
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C MOVEL'DUKESTAR'FLD1 4
0002.00 C FLD1 DSPLY
0003.00 C MOVE 'DUKESTAR'FLD2 4
0004.00 C FLD2 DSPLY
0005.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . C
Sequence number . . .
0001.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
MOVEL 'DUKESTAR' FLD1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
4
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
the CAT opcode.
Columns . . . :
1 71 Edit PB01U01S/MYRPG
SEU==>
EXA10
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data *************************************
0001.00
C MOVE
'DUKE' FLD1 4
0002.00
C MOVE
'STAR' FLD2 4
0003.00 *CONCATENATING FLD1 & FLD2
0004.00
C FLD1 CAT
FLD2 RES 10
0005.00
C RES DSPLY
0006.00
C SETON LR
****************** End of data ****************************************
Prompt type .
. . C Sequence number . . . 0004.00
Level N01N02N03
Factor 1 Operation Factor 2 Result
FLD1 CAT FLD2 RES
Decimal
Length Positions H/N/P
HI LO EQ
Comment
10
F3=Exit F4=Prompt
F5=Refresh F11=Previous
record
F12=Cancel F23=Select prompt F24=More keys
SUBST (Substring)
The
SUBST opcode extracts a portion of a character string into a different field.
Factor 1 required for this operation, represents the length of the string to be
copied. Factor2 is also required, contains the based character string or base
character string followed by colon followed by starting position. The result
field serves as the receiving field for the SUBST operation. An optional
indicator in position 56-57 (LO) comes on if an error during the SUBST
operation.
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA11
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C
MOVE
'DUKESTAR'FLD1 8
0002.00 *SUBSTRING FLD1 FROM FIRST POSITION AND
FOUR CHARACTERS
0003.00 C 4 SUBSTFLD1:1 RES1
4
0004.00 C RES1 DSPLY
0004.01 *SUBSTRING FLD1 FROM FIFTH POSITION AND
FOUR CHARACTERS
0005.00 C 4 SUBSTFLD1:5 RES2
4
0006.00 C RES2 DSPLY
0007.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . C
Sequence number . . . 0003.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
4 SUBST FLD1:1 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
4
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
SCAN (Scan Character String)
SCAN
operation allows us to look for a character or string of characters within a
character field. The direction is from left to right. Scan is case
sensitive.
Factor1
contains string to be searched called as compare string.
Factor2
contains string to be scanned called as base string.
Result
field contains the numeric value of the leftmost position of the compare
string, if found string. Otherwise result field is set to zero. If the SCAN succeeds
in finding the compare string within base string an indicator in EQ position
turns on.
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA12
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C
MOVE
'DUKESTAR'FLD1 8
0001.01 *LOOKING FOR STRING 'DUKE'IN FLD1
0002.00 C 'DUKE' SCAN FLD1 RES1
20
0003.00 C RES1 DSPLY
0004.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . C Sequence number . . . 0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
'DUKE' SCAN FLD1 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
2
0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA11
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C
MOVE
'DUKESTAR'FLD1 8
0002.00 *SUBSTRING FLD1 FROM FIRST POSITION AND
FOUR CHARACTERS
0003.00 C 4 SUBSTFLD1:1 RES1
4
0004.00 C RES1 DSPLY
0004.01 *SUBSTRING FLD1 FROM FIFTH POSITION AND
FOUR CHARACTERS
0005.00 C 4 SUBSTFLD1:5 RES2
4
0006.00 C RES2 DSPLY
0007.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . C
Sequence number . . . 0003.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
4 SUBST FLD1:1 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
4
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA12
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
*************** Beginning of data
*************************************
0001.00 C
MOVE
'DUKESTAR'FLD1 8
0001.01 *LOOKING FOR STRING 'DUKE'IN FLD1
0002.00 C 'DUKE' SCAN FLD1 RES1
20
0003.00 C RES1 DSPLY
0004.00 C SETON LR
****************** End of data
****************************************
Prompt type . . . C Sequence number . . . 0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
'DUKE' SCAN FLD1 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
2
0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
CHECK (Check Characters)
The
format of CHECK is similar to SCAN. However there are significant differences
between CHECK and SCAN. SCAN looks for the presence of the entire compare
string and notes down the location of occurrence whereas CHECK detects the
presence of non-specified characters. CHECK is useful for verification of
characters within base string. An indicator is positioned in 58-59(EQ). This
indicator turns on
if CHECK finds one or more unmatched characters in based
string.
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA13
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
************* Beginning of data ****************
0001.00 C MOVE
'DUKESTAR'FLD1 8
0002.00 C 'DUKE' CHECKFLD1:1 RES1
20
0003.00 C RES1 DSPLY
0004.00 C SETON LR
*************** End of data *******************
Prompt type . . C Sequence number . 0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
'DUKE' CHECK FLD1:1 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
2
0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Columns . . . : 1
71 Edit PB01U01S/MYRPG
SEU==>
EXA13
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
************* Beginning of data ****************
0001.00 C MOVE
'DUKESTAR'FLD1 8
0002.00 C 'DUKE' CHECKFLD1:1 RES1
20
0003.00 C RES1 DSPLY
0004.00 C SETON LR
*************** End of data *******************
Prompt type . . C Sequence number . 0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
'DUKE' CHECK FLD1:1 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
2
0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
CHEKR (Check Reverse)
CHEKR
works exactly like CHECK, except that it checks the based string from right to
left rather than left to right. This opcode can be used to locate the rightmost
invalid character in a string or to determine the length of string of non-blank
character within a field.
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA14
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
************* Beginning of data ******************
0001.00 C MOVE 'DUKESTAR'FLD1 8
0002.00 C 'DUKE' CHEKRFLD1:8 RES1
20
0003.00 C RES1 DSPLY
0004.00 C SETON LR
************** End of data **********************
Prompt type . . C Sequence number . . .
0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
'DUKE' CHEKR FLD1:8 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
2
0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
XLATE (Translate)
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA14
FMT C
.....CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++
************* Beginning of data ******************
0001.00 C MOVE 'DUKESTAR'FLD1 8
0002.00 C 'DUKE' CHEKRFLD1:8 RES1
20
0003.00 C RES1 DSPLY
0004.00 C SETON LR
************** End of data **********************
Prompt type . . C Sequence number . . .
0002.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
'DUKE' CHEKR FLD1:8 RES1
Decimal
Length
Positions H/N/P HI
LO EQ Comment
2
0
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Characters
in the source string (factor2 )are translated according to the ‘From’ and ‘To”
strings (both in factor 1) and put into a receiver field (result field). XLATE
starts translating the source from left
to right.
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA15
FMT N
.....I..............Namedconstant+++++++++C.........Fldnme....
************* Beginning of data *******************
0001.00 I 'ABCDEFGHIJKLMNOPQRST-C HI
0002.00 I 'UVWXYZ'
0003.00 I 'abcdefghijklmnopqrst-C LO
0004.00 I 'uvwxyz'
0005.00 C MOVE 'dukestar'FLD1 8
0006.00 C LO:H XLATEFLD1 FLD2 8
0007.00 C LD2 DSPLY
0008.00 C SETON LR
**************** End of data ************************
Prompt type . . . C Sequence number . .0006.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
LO:HI XLATE FLD1 FLD2
Decimal
Length
Positions H/N/P HI
LO EQ Comment
8
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
Columns
. . . : 1 71
Edit
PB01U01S/MYRPG
SEU==>
EXA15
FMT N
.....I..............Namedconstant+++++++++C.........Fldnme....
************* Beginning of data *******************
0001.00 I 'ABCDEFGHIJKLMNOPQRST-C HI
0002.00 I 'UVWXYZ'
0003.00 I 'abcdefghijklmnopqrst-C LO
0004.00 I 'uvwxyz'
0005.00 C MOVE 'dukestar'FLD1 8
0006.00 C LO:H XLATEFLD1 FLD2 8
0007.00 C LD2 DSPLY
0008.00 C SETON LR
**************** End of data ************************
Prompt type . . . C Sequence number . .0006.00
Level
N01N02N03 Factor 1 Operation Factor 2 Result
LO:HI XLATE FLD1 FLD2
Decimal
Length
Positions H/N/P HI
LO EQ Comment
8
F3=Exit
F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys
No comments:
Post a Comment