Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sting type ifeq

Status
Not open for further replies.

jmd0252

Programmer
May 15, 2003
667
0
0
OK,,Problem is..

I have a 12 byte field,,,, alphaneric, in this field, are "job numbers", mixed numbers and letter, left justified. I need to do an IFEQ statement,, so that IFEQ to T****,, your get the idea,, it will fall thru the rest of the program.. So I know that somewhere,, out there,,,, someone knows the answer,,, Thanksahead of time..

 
Try this. (I'm using free form RPG)
Code:
If %Subst(JobNbr:1:1) = 'T';
  // do something here
EndIf;

If I remember correctly, this is how I would do it in fixed (without using BIF's).

Code:
C     1             SubSt     JobNbr:1  Field             1
C                    
C     Field         IfEq      'T'
C*              
C*  Do something here 
C*                    
C                   EndIf

How does this sound?

RedMage1967
IBM Certifed - RPG IV Progammer
 
Well,, I pulled the "book",, and came up with the following.

What do you think,,,

I '0123456789' C DIGITS

C CLEAR*IN03
C CLEAR*IN04
C 'T' CHECKGLMCU:8 03
C DIGITS CHECKGLMCU:9 04
C *IN03 IFEQ *ON
C *IN04 IFEQ *ON
C GLDGJ IFGE 103251
C MOVE *BLANKS GLBC
C UPDATI0911
C END
C END
C END

This is the complete code,, along with the other items I need to check,, looking at positions, 8, and 9 to verify that they contain a "T", and a number




 
I'm not sure if you've completely grasped how CHECK works. But that's not surprising as it's a tricky one [ponder]

The position you specify after the colon is the START position, not the absolute position, so if you said "FLD:8" and your field was 10 chars long you'd be comparing positions 8-10, not just 8.

The result indicator =ON tells you if any INCORRECT characters are found, not that the result is all okay.

Referring back to your original post, where you said you just wanted to check for the first char ='T'... back in RPG III I would probably have coded something like:

Code:
C                     MOVELJOBNBR    CHAR1   1
C           CHAR1     IFEQ 'T'
C                     ....
C                     ENDIF
 
making a long story short,,, when in a pinch,,, you fall back on what is comfortable,,, and what you know will work..

 
KRG400,,

opps,,, that is an interesting bit of info,, so we start checking at that location, instead of "just" that location.. HUMMMMMMMM,,, very interesting..

 
Why not do this (in free form)
Code:
D Nbrs        C             '01234567890'
//--------------------------------------------------
/Free

 If %Subst(Glmcu:8:1) = 'T' 
   and %Check(Nbrs:%Subst(Glmcu:9:1)) > 0
   and Gldgj > 103251;
  Glbc = *Blanks;
  Update I0911;
 EndIf;

/End-Free
//--------------------------------------------------
To me, that just seems easier to read, because you keep it down to just one "IF" statement.

RedMage1967
IBM Certifed - RPG IV Progammer
 
OH MY,,,, that does look nice I like that very much...

Very good solution...

 
jmd0252

If you decide to convert your application to RPG IV (Free Form), make sure you read up on the Built In Functions (BIF's). (The commands that begin with a "%".

RedMage1967
IBM Certifed - RPG IV Progammer
 
BIFs are almost fun to work with. It is easy to detrimine the length of field with them for the API QCMDEXC. Here is a sample:

Code:
D cmd         S      1024
d len         S        15  5


 /free
  cmd = 'DSPLIBL *PRINT';
  len = %len(%trim(cmd));
 /end-free

BTW can you do calls in /free? 

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
[URL unfurl="true"]http://www.koldark.net[/URL]
See my progress to converting to linux. [URL unfurl="true"]http://linux.koldark.net[/URL]
 
Yes. If I'm calling a program, I prototype the call.
example of a prototyped call for QCMDEXC:

Code:
D CmdLine       PR                 ExtPgm('QCMDEXC')
D  Cmd                       200   Const Options(*VarSize)
D  Len                        15 5 Const
D
D CopyFile      S             80   Inz(*Blanks)
//--------------------------------------------------
/Free

 CopyFile = 'CpyF FromFile(Input) +
                  ToFile(Output) +
                  MbrOpt(*Replace)';
 CmdLine(CopyFile:%Len(CopyFile));

/End-Free
//--------------------------------------------------

This prototypes the call to pgm QCMDEXC, which has two parameters, the command and the length of the command.


RedMage1967
IBM Certifed - RPG IV Progammer
 
You can prototype the call to any program the same way I did for QCMDEXC.

RedMage1967
IBM Certifed - RPG IV Progammer
 
If you need help, just let me know. That's how I've learned RPG IV, rewriting my old RPGIII aps to RPG IV.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top