1.find most occurrences of a character.
for exm: input:aaabbbbdddddyyy
output: d 5 times
how can i get that?
Answers were Sorted based on User's Feedback
Answer / manish dwivedi
By using SCAN OP- Code we can find out the most occurrences
of a character.
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / kamlesh
you need to write dow loop ,initialize counter variable=0
and use scan opcode
when first occur of 'd' finds scan returns its position
in string , increment counter=counter+1 then you have to
use substr(yrstring:pos+1:'d')now again same process
is done and if 'd' char found increment counter by 1
this process is continue until complete yrstring is scaned.
finally total number of 'd' is accumulate in COUNTER
variable.
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / bharatiya
I was trying it last night and wrote the below code that works for this scenario, please have a look----
DArr1 S 1 DIM(10)
DArr2 S 1 DIM(10)
DCnt S 2 0
Dn1 S 2 0 Inz(1)
Dn2 S 2 0 Inz(1)
DFld1 S 15 Inz('aaabbbbdddddyyy')
C
C Do 15
C EVAL Arr1(n1) = %subst(FLD1:n1:1)
C If Arr1(n1) = 'd'
C Eval Arr2(n2) = Arr1(n1)
C Eval n2 = n2 +1
C Endif
C Eval n1 = n1+1
C Enddo
C Eval cnt = n2 - 1
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / kar
Use Scan Opcode, and give the result field as array name
instead of a ordinary field.
After the execution of statement, display array values, and
you can find the all occurrences.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / ssss
fld1 = aaabbbbdddddyyy
res = %check('d':fld1:8) ;
If res > 0;
Cnt = res-8;
Endif;
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / vipul dixit
With the help of %Scan built in function or Scan op-code we
can do this.
we should define a data structure and write like this way:-
DDs s
C Eval Ds = %Scan('d':Source:1).
It will fetch the position of the scanned character,and
after that we will count all the positions as DS elements.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manoj
As per my understanding using Scan opcode we can't find out
most occurrences of a character.
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / deepak
D:a 15a inz('aaabbbbdddddyyy')
D:b 1a
D:c 15a
D:i 2p 0
D:e 2p 0 inz(1)
C: Eval b=%sst(a:e:1)
C: eval c *cat b
C: If b='d'
C: eval replace(d:x)
C: eval i=i+1
C: eval e=e+1
C: i dsply
C: seton lr
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / prasanna
You can find it with opcode scan and in the result field we
should have an array
Is This Answer Correct ? | 0 Yes | 2 No |
what is estimation? and what is the level identifier parameter in PF?
this is rpg3 code W0RTN IFEQ @CN,002 what is the means @CN,002
how can we know running job is batch or intractive ? i need all the possibilites.........plz help me
Anyone help me for the below question:- If problem/error occur in *PSSR subroutine,how should I handel it in RPG program.
1) How to define keyed file in CL pgm. 2) How can i read particular records in CL pgm from database file.
when will come session device error?
I have a file .In that file i have 3 fields. Those fields are eno, ename, esal.Keyfield is eno. In that file i have data like this for eno 1,2,3,4,5. Now i need to display 2nd record. That means i need to set the pointer on 2nd record... Then, write the complete rpg program using setll.
Suppose we have one database file and it is used by 5 programs and in 3 program we have to add some records in datbase file s what is the impact on other program?
What would be the result on writing a data record to a PF file using the "WRITE" opcode after the SETON *ON *INLR statment?
I have 1000 records in a file. I would like to generate 10 identical reports from this record with same format (structure of records) how do I do this?
what is meant by record lock.how records are locked.what is the purpose of record lock.if records are locked what happens.how to find out which record is locked.
can any body correct the following code? Following a procedure which returns the maximum of two numbers.Correct the following code. P GETMAX B D GETMAX PI D NUM1 35 0 D NUM2 45 0 C IF NUM1 > NUM2 C RETURN NUM1 C ELSE C RETURN NUM2 C ENDIF P GETMAX E