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



1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

Answer / ssss

fld1 = aaabbbbdddddyyy
res = %check('d':fld1:8) ;
If res > 0;
Cnt = res-8;
Endif;

Is This Answer Correct ?    1 Yes 1 No

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

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

1.find most occurrences of a character. for exm: input:aaabbbbdddddyyy output: d 5 times h..

Answer / hummn

It can easily be done by using the BIF %ELEM.

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More RPG400 Interview Questions

If I have a file with 5 record and that file has 2 Key field and I want to read the unique record of the file then how can we achieve it?

1 Answers  


How to print Superscript / Subscript from RPG400

1 Answers  


How I can reread the physical file in CL program once the end of file reached in same CL program.

20 Answers   IBM,


What is use of IMPORT and EXPORT in RPGLE ? What is activation Group ? What is Service Program ???? How to call another program in RPGLE ?

1 Answers  


In case if I want to know whether a record exists in a file, which one do you prefer CHAIN or a SETLL and why ?

1 Answers  






CAN WE READ RECORDS WITHOUT USING SETLL,READ,CHAIN IN RPG?

6 Answers   Satyam,


How to handle duplicate error handling in RPG?

0 Answers  


Hi,This is raju.Can any body give me the real experience answer for this question? 1.What is the significance of *MAP and *DROP in the CPY command?

3 Answers  


what is overlay? how can we pass parameters in cl or rpg programing? how can we get data area value in cl or rpg programming?

2 Answers   IBM, Patni,


list down and describe the sub systems vailable

5 Answers   IBM,


can anyone explain aboutovrOVRDBF,OPNQRYF, OVRSCOPE and OPNSCOPE?

2 Answers   TCS,


please help me answer to this question what is the difference between the binding and srvpgm in ilerpg?

4 Answers   HCL,


Categories