.st0{fill:#FFFFFF;}

sqlrpgle select into extname using freeform 

 June 17, 2017

By  NickLitten

AKA – Why does this compile fail using SQLRPGLE and QUALIFIED data structures?

Sometimes I find a problem and scratch my head and just cannot figure it out. I swear a lot. Then I discover the solution by climbing out of my little box, turning my head at a funny angle, squinting and thinking a bit differently. Then I swear even more.

Problem

I converted a column based piece of SQLRPGLE from this:

d S21uservalues... 
d e ds qualified 
d extname('APG05PHY') 

to this:

dcl-ds S21uservalues qualified extname('APG05PHY') end-ds; 

The SQL to read this looks like this:

exec SQL fetch next from cursorAPG05 into :S21uservalues;

and then it just will not compile!

Compile error is: SQL0312 30 798 Position 52 Variable S21STOCKROOMNAME not defined or not usable.

“But that is completely valid new free format RPG syntax” I scream at the compiler. /me then goes on to waste more time than I am prepared to admit trying every combination of code to figure out whats going on

Solution

The bloody DCL-DS statement is just too long and over-runs the available area into the //text area of this source member. Because I am using SEU (this client does not use any modern code editors and have blocked the ports to use RDi, Mi Workplace or even good old WDSC) the line is highlighted as in error – but I incorrectly assumed it was an error because SEU doesnt know about modern freeformat commands.

So, change it to a shorter and neater layout like this:

sqlrpgle select into extnamedcl-ds S21uservalues
 qualified
 extname('APG05PHY')
end-ds;

and boom it compiles and works.

Annoying — but obvious — once I figured it out anyway.

This wouldnt have been a problem if I had been coding correctly using **FREE

*sigh*

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

  • Aaaaggghhhh!!!
    My mistake, I forgot to define a variable in the dcl-pr for the program that was used later in the code.
    For some reason this caused the errors with the data structures.
    All fixed now though šŸ™‚

    Hi Nick,

    Finally I found a post where someone (you!) are experiencing exactly the same problem as I am, however your solution doesn’t work for me for some reason. I’m wondering if it’s because we are on 7.1 and maybe we need a PTF applying.

    The relevant sections of the code I have (generated in RDI) is as below:

    Data structure definition from external file

    // Stock master data structure
    dcl-ds stkmstpfDS extname(stkmstpf) qualified;
    end-ds;

    Note: Unlike your code, mine compiles without quotes around the external file name, but fails if I add them.

    SQL select

    exec sql
    select * into :stkmstpfDS
    from stkmstpf
    where skmno = :pStkItem;

    SQL insert

    exec sql
    insert into stkmstpf
    values(:stkmstpfDS)
    with NC;

    I am using this to retrieve a record from this file. I then want to create a new record, updating and resetting a number of the fields (including the key) before doing the insert.

    On both the select and insert statements I get this error:

    SQL0312: Position 18 Variable STKMSTPFDS not defined or not usable.

    I wondered if you or anyone else who reads this has any thoughts.

    Thanks in advance.
    Tony Payne

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    __CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

    Get In Touch

    Iā€™m always looking for awesome input, feedback and critique!

    >