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 / sagar wagh

Dcl-S inputString Char(30) Inz('aaabbbbdddddyyy');
Dcl-S charCount Int(10);
Dcl-S maxCount Int(10) Inz(0);
Dcl-S maxChar Char(1);
Dcl-S i Int(10);
Dcl-S j Int(10);

For i = 1 to %Len(%TrimR(inputString));
charCount = 0;
For j = 1 to %Len(%TrimR(inputString));
If %Subst(inputString: j: 1) = %Subst(inputString: i: 1);
charCount += 1;
EndIf;
EndFor;
If charCount > maxCount;
maxCount = charCount;
maxChar = %Subst(inputString: i: 1);
EndIf;
EndFor;

Dsply ('Character ' + maxChar + ' occurs ' + %Char(maxCount) + ' times');
*InLR = *On;

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

Post New Answer

More RPG400 Interview Questions

In a particular program one file is used where override command is applied to a file, now this program calls another program where we want to use the same file but without override.How it can be done?

6 Answers   Hexaware,


what is the procedure and explain about real time scenario.

0 Answers   Adhoc Technologies, Hanuman Automation, HSBC, IBM,


This is my Physical file 'EMPS' existing in library "TAMIL1" and its record format is 'EMPRCD" a)its source is R EMPRCD ENO 4 0 ENAME 10 EADD 10 b)The records present in EMPS are as follows ENO ENAME EADD 0001 tamil coimbatore 0002 kumar bangalore 0003 sunder bangalore 0004 arunkumar chennai 0005 pandi hyderabad 0006 santhosh hyderabad 0007 sasi salem 0008 kalai chennai 0009 suresh hyderabad 0010 vijay bangalore 0011 Arul chennai 0012 velu chennai 0013 khan bangalore 0014 praba chennai 0015 praba.p coimbatore 0016 anand ooty 0017 raja erode 0018 sankar erode 0019 vadivel namakkal 0020 anbu chennai 0021 Ajith mumabi c)now i want to select the 'ENAME' field records starting with 'S' for that i have created a RPG program its source code is PGM DCLF FILE(TAMIL1/EMPS) DCL VAR(&MYENO) TYPE(*CHAR) LEN(4) OVRDBF FILE(EMPS) SHARE(*YES) OPNQRYF FILE((TAMIL1/EMPS)) QRYSLT('ENAME *EQ %WLDCRD("S *")') READ: RCVF RCDFMT(EMPRCD) MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END)) CHGVAR VAR(&MYENO) VALUE(&ENO) SNDUSRMSG MSG(&MYENO) SNDUSRMSG MSG(&ENAME) SNDUSRMSG MSG(&EADD) GOTO READ END: CLOF OPNID(EMPS) DLTOVR FILE(EMPS) ENDPGM Is this coding correct sir,the program gets compiled,and if i call it it says query running but records are not displayed.please help me out

4 Answers   Virtusa,


What is the difference between ITER and DO ? I know both are used to execute set of statements repeatedly, but what is the main difference?

2 Answers   CGI, Wipro,


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 can we find out whether the job is interactive or Batch through RPG program? 2) How can we find out through CL program?

6 Answers   CSC,


Interviewer asked me write down DDS for load all subfile .can anybody write dds

0 Answers  


What will be your approach in going either for OPNQRYF or Logical files. Which one to go for?

2 Answers  


In RPG program one file using as a PRIMARY file while running program some of the records reading twice any body know why its happening

2 Answers  


explain sflclr, sflend, sfldlt, and sflcsrrrn?

0 Answers   IBM,


How do you do indexing in a physical file?

2 Answers  


Suppose we have 10 records with same name and we are reading using READE,after 4 record i have to use CHAIN what is the output

3 Answers  


Categories