Page 1 of 1

Help needed

PostPosted: Sat Dec 22, 2012 1:39 pm
by naren123
I am trying to develop a rexx code which will give the age of the person when i enter his/her name.

The flat file will be as follows:

david 20
anjan 23
hari 22
so on.....

the age starts at, say, 10th column.

When i enter a name, i want the REXX code to do the following :
1. Refer the PS file.
2. Search for the name in the flat file.
3. If found, then give only his/her age as the output.

i am confident of the 1st and 3rd. can anyone help me with the 2nd one?

Re: Help needed

PostPosted: Sat Dec 22, 2012 2:08 pm
by enrico-sorichetti
when posting, good manners dictate to use an intelligent title...
it is obvious that You are asking for help, otherwise You would not have posted.

post what You have done ...

meditate on how to ...
extract/process the arguments
read the records into a stem
loop over the stem
extract part of a string using SUBSTR / WORD
compare <things>
...
...
...

to speed up the rexx learning process it would be a good thing to install on Your PC (*)
the current version of ooRexx from
http://sourceforge.net/projects/oorexx/

apart some I/O differences ( EXECIO is anyway available)
all the REXX facilities can be exercised without the hassle of a MF connection available

(*) YOUR OWN PC, NOT THE WORK ONE.
installing unauthorized software on Your employer PC can be cause for lawful termination

Re: Help needed

PostPosted: Thu Dec 27, 2012 3:45 am
by c62ap90
Something like this should do it with some minor changes...
/* REXX */
/********************************************************************/
/*** AUTHOR:  XXX                                                 ***/
/*** CREATED: 12/2012                                             ***/
/*** DESC:    -BROWSE TO GET AGE BY ENTERING NAME                 ***/
/*** NOTES:   -ON TSO/COMMAND LINE DO...TSO NAMEAGE < NAME >      ***/
/***                               IE...TSO NAMEAGE DAVID         ***/
/***                                    TSO NAMEAGE ANJAN         ***/
/*** CLIST:   XXXXXXXX.XXXXXXXX.CLIST(NAMEAGE)                    ***/
/*** PANEL:   NONE                                                ***/
/***  HELP:   NONE                                                ***/
/********************************************************************/
   PARSE UPPER ARG P_ARG
   P_ARG = STRIP(P_ARG)
   IF LENGTH(P_ARG) = 0 THEN DO
      SAY "==> OOPS: YOU MUST SUPPLY SEARCHABLE ARGUMENT < NAME >"
      EXIT
   END
   S_DSN = 'DATASET.NAME.HERE'
   "ALLOC F(NAMEAGE) DA('"S_DSN"') SHR REUSE"
   "EXECIO * DISKR NAMEAGE (FINIS STEM NAMEAGE."
   IF RC <> 0 THEN DO
      SAY "==> ERROR: READING "S_DSN", RC="RC
      EXIT
   END
   "FREE F(NAMEAGE)"
   B_FND = 0
   SP1 = " "
   CLRSCRN
   SAY "--NAME-- AGE   "
   DO I=1 TO NAMEAGE.0
      IF POS(P_ARG, NAMEAGE.I) > 0 THEN DO
         B_FND = 1
         PARSE VAR NAMEAGE.I 1 C1 15
         SAY C1
      END
   END
   IF B_FND = 0 THEN
      SAY " "P_ARG" NOT FOUND IN "S_DSN
   RETURN


Test Data Example:
----+----1----+----2-
*********************
DAVID    20         
AHJAN    23         
HARI     22         
NAREN123 23         

Change "DATASET.NAME.HERE' to your dataset.
I just noticed I have Name and Age; you can take "Name" out of 'SAY', and "1 C1 15" to "10 C1 15"

Example Execution:
tso nameage david
--NAME-- AGE 
DAVID    20   
***

Just play with it to get it exactly the way you want it.