Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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,


Hi all friend, Could Any body send me the code (with coding) of this senario because I have tried but I am stucking somewhere so Please reply ASAp with coding. senario:Q: I have to write the flat file(FLAT1) into the three different PFS (PF1,PF2 and PF3) with the respect of H line data, D line data and Z line data of flat file. where I have different data in flat file(FLAT1) which is mentioned below with data. H0929200909282009092820095529420003000073 D2222220006765555webservi001633.9909222009092820090924200951 8564380134049ROSNER TOYOTA OF FREDE FREDERICKSBURVA 224080000USA840840001633.99001633.99851856492689800208001915 511001633.990408490000000.0000000003446048 1,3 110793145 09070700351 372367 Rosner Motors D3333320006774444webservi000271.2409222009092820090924200951 8564380134049ROSNER TOYOTA OF FREDE FREDERICKSBURVA 224080000USA840840000271.24000271.24851856492689800208001835 511000271.240930680000000.0000000003450293 1 110793254 09072100079 373933 Rosner Motors Z0929200900000020001905.25 FLAT1 has the three pf data H line-represents the header pf data,D-Represent Details pf data,Z-Represents the trailer pf data Now I have to write H line data of flat file into Header pf (PF1),D line data of flat into datails pf(PF2) and Z line data of flat file into pf(PF3) with the spefic position(H,D and Z data of flat file into PF1, PF2 and PF3) of flat file.

4 Answers   IBM,


What is Multi Occurrence Data Structure(MODS)?

1 Answers   CTS,


As Packed veriable store 2 digits in 1 byte and ZONE variable store 1 digit in 1 byte... Please tell me when we have to use Packed and Zone variable...?

1 Answers  


What is the difference between copybooks and subprocedures in as400?

0 Answers  


How do you proceed in case your active AS400 session has got disconnected suddenly, how can you get back to your session ? Is it possible??

1 Answers  


what is mean by *MAP and *DROP?what commands use these two keywords?why are they used?

4 Answers  


How to write record if no field or the field are different in physical file in rpgle ?

0 Answers  


In how many ways a session/device error occurs,,, and what is the remedy for it?

3 Answers  


1.WHAT IS WRONG WITH THE CODE BELOW? C CUSTNO CHAIN CUSTMAST IF %ERROR can any body find the wrong please? 2.What builtin function will you use to achieve the following functionality? C QTY IFLT *ZERO C QTY MULT-1 QTY ENDIF

5 Answers   CTS,


what is the necessary keyword needed to scroll subfile records?

0 Answers   IBM,


If record-format name in an externally-described file has already been defined as a file-name.how to solve this?

2 Answers   CTS,


Categories