Q
Problem solve Get help with specific problems with your technologies, process and projects.

Why does IBM make CL so difficult?

Why does IBM make CL so difficult? It takes a meeting of the minds to figure out one little CL program. Problem:

 CHGVAR    VAR(&QSEL)   VALUE('VOPYDT = %RANGE(' || &NUM1 || ' ' || &NUM2 ||')') 

CPD0712 OPERAND DOES NOT HAVE VALID TYPE FOR OPERATOR. CPD0711 OPERANDS IN EXPRESSION NOT THE SAME TYPE.

I've been in RPG for 3 years and I'm working with a couple of guys that have been doing it 16 and 20 years. Every time I go to write a CL with new stuff, or existing methods, I get errors and have to get there help. Well I've got the experts stumped over here...what do you guys say?


I don't think CL is difficult! It is a fairly easy way of running commands, even though some purists say now that CL should be given up altogether and replaced by the use of C functions such as 'system'.

Your case though is not as difficult as it sounds. &num1 and &num2 are clearly numerical fields and &QSEL is to be used for an OPNQRYF. Just like in RPG, you can not concatenate numerical fields with alphabetical fields. You need to have alphabetical fields in which to dump your numerical comparands.

dcl &char1 *char 8 /* or whatever length is required */ dcl &char2 *char 8 /* or whatever length is required */

chgvar &char1 &num1 chgvar &char2 &num2

But the fun does not stop there as your OPNQRYF will try to compare numerical with alphabetical.

You will need to declare mapped fields in your OPNQRYF to transform VOPYDT from a packed field to a zoned field and then from a zoned field to a character field.

Please find such an example:

chgvar &qryslt (' alphabks = %range("' *tcat &alpha1 *tcat '" "' *tcat &alpha2 *tcat '"')

 OPNQRYF FILE((GTD53P))
        QRYSLT(&qryslt)
        MAPFLD((ZONEBKS 'd53bks' *ZONED) (ALPHABKS 'zonebks' *CHAR))

There are other ways, such as entering the whole of your OPNQRYF in a string and then using QCMDEXC to run the OPNQRYF. Doing so may save you from using mapped fields.


Dig Deeper on iSeries CL programming

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close