× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Good evening
To understand the error, we must know that:
1) Every program RPG(Version RPG400, RPGILE, RPG FREE AND FULL FREE),
COBOL(Version COBOLSQL, COBOLILESQL),
first evaluates the SQL statements
2) If the SQL code is correct, it performs the validation of the RPG, COBOL
language instructions
3) All variables used in an internal procedure must be defined in the main
body of the program. If the procedure
is a Service Program that contains a procedure, the variables it uses must
be defined in the procedure.

At first your program had a language error, I attach a program that does
work using the attributes of the fields
of my test file

*Debug Program*
[image: image.png]

[image: image.png]

[image: image.png]


[image: image.png]

*Program*

**free

ctl-opt dftactgrp(*no);

exec sql set option commit = *none;

dcl-f OrderFile disk usage(*input) keyed;



dcl-s tmp_count zoned(5:0) template;

dcl-s message char(50);

dcl-s count Like(tmp_count);



*dcl-ds RecOrder ExtName('ORDERFILE') Qualified end-ds; ****



dcl-pr UpdFile Like(tmp_count);

pOrderNbr *Like(RecOrder.OrderNbr); ****

pCustomer *Like(RecOrder.Customer); *** *

end-pr;



read OrderFile;

if not %eof;

message = '1-' + %trim(OrderNbr) + '-' + %trim(Customer);

dsply message ' ';

count = UpdFile(OrderNbr:Customer);

message = 'select rows: ' + %char(count);

dsply message ' ';

endif;

*inlr = *on;



dcl-proc UpdFile;

dcl-pi *n Like(tmp_count);

pOrderNbr *Like(RecOrder.OrderNbr); ****

pCustomer *Like(RecOrder.Customer); *** *

end-pi;



// dcl-s count like(tmp_count) inz(0);



message = '4-' + %trim(pOrderNbr) + '-' + %trim(pCustomer);

dsply message ' ';

exec sql

select count(*)

into :count

from Orderfile

where ORDERNBR = :pOrderNbr and CUSTOMER = :pCustomer;



return count;

end-proc;



The problem was variable scope, the required solution, Define an external
structure, Qualify and Define
the parameters of the Procedure using fields of the qualified structure.

*Note*
*The lines with *** are the changes you must make*

Regards

Sergio L Puentes Valladares
Developer SR IBM i RPG/COBOL




El jue, 29 dic 2022 a las 5:21, Maria Lucia Stoppa (<mlstoppa@xxxxxxxxx>)
escribió:

Hi all,
Thank you for your time and expertise!
To recap:
1) Yes, using the right definitions of variables in terms of data type and
length works fine, but I don't want to act that way because I would lose
the database fields' definition inheritance in case of changes. I'd rather
be able to recompile the program as-is instead of changing definitions in
tons of code whenever a field definition changes;
2) Also, I need to have DS having subfields with the same name as database
fields because I will use them as key DS;
3) Yes, the presence of a DS with subfields as described before produces a
double definition of the same field which inherits the length from the
database but not the data type. To me, this is an error, and it's not what
the RPG reference V7R3 and V7R4 state;
4) I can't use the qualified DS for the very same reason as before;
5) The only valid solution I found to preserve all of the previous
constraints is to define a template file, only used at compilation time, to
get prefixed fields' names to refer to when needed.

In case any of you will encounter a new and different solution feel free to
go on with the discussion, I will appreciate any news.

Thank you very much and happy new year!
Lucia





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.