Theju112
Theju112

Reputation: 167

Fully free RPG data structure

I came across the below code in a fully free RPG program.

  dcl-ds *N;
    *N char(2) inz('PR');
    //STR0037123 - start
    *N char(2) inz('ER');
    *N char(2) inz('MP');
    *N char(2) inz('PC');
    *N char(2) inz('PT');
    *N char(2) inz('RB');
    *N char(2) inz('RG');
    *N char(2) inz('RL');
    *N char(2) inz('RT');
    *N char(2) inz('TB');
    *N char(2) inz('TO');
    *N char(2) inz('TP');
    *N char(2) inz('TV');
    //STR0037123 - end
    wPRGroupDOM char(2) dim(13) pos(1);
  end-ds;   

   

Can someone please help me to understand what this means? To me it seems like a compile time array but I am not sure why it seems to be declared like a data structure.

This has been used in the code as below:

if %lookup(Ipl9022L(wIdx).RIGHTCODE : wPRGroupDOM) > *zero;  

Can someone please help with the equivalent fixed format declaration of this??

Upvotes: 3

Views: 1727

Answers (3)

Barbara Morris
Barbara Morris

Reputation: 3664

Here's the equivalent fixed-form declaration of the data structure (but with only a few subfields, to keep it small).

I hope nobody is actually required to code in fixed-form any more. But I'll post this anyway, in case it helps to understand the free-form code.

D ds              ds                                 
D                                2a   inz('PR')      
D                                2a   inz('ER')      
D                                2a   inz('MP')      
D                                2a   inz('PC')      
D  wPRGroupDDM                   2a   DIM(4)        
D                                     overlay(ds:1)   

Upvotes: 4

RockBoro
RockBoro

Reputation: 2473

the code is declaring an unnamed data struct, which is used to declare a set of unnamed 2 char codes. Then the named array is defined over the set of 2 char codes.

    domArr char(2) dim(13) pos(1);

the %lookup opcode returns the index location of the code in the array.

      vDom        = 'PT' ;
      fx          = %lookup( vDom: domArr ) ;
  dcl-ds *N;
    *N char(2) inz('PR');
    *N char(2) inz('ER');
    *N char(2) inz('MP');
    *N char(2) inz('PC');
    *N char(2) inz('PT');
    *N char(2) inz('RB');
    *N char(2) inz('RG');
    *N char(2) inz('RL');
    *N char(2) inz('RT');
    *N char(2) inz('TB');
    *N char(2) inz('TO');
    *N char(2) inz('TP');
    *N char(2) inz('TV');

    domArr char(2) dim(13) pos(1);
    domBuf char(26) pos(1) ;
  end-ds;

  dcl-s vDom char(2) ;
  dcl-s fx int(10) ;
  dcl-s msg char(52) ;

 /free
      vDom        = 'PT' ;
      fx          = %lookup( vDom: domArr ) ;
      if          fx > 0 ;
      msg  =      'found ' + vDom + ' at index ' + %char(fx) +
                  ' of domArr.' ;
      dsply       msg ;
      else ;
      msg         = vDom + ' not found in domArr. ' + domBuf ;
      dsply       msg ;
      endif ;

      vDom        = 'Z1' ;
      fx          = %lookup( vDom: domArr ) ;
      if          fx > 0 ;
      msg  =      'found ' + vDom + ' at index ' + %char(fx) +
                  ' of domArr.' ;
      dsply       msg ;
      else ;
      msg         = vDom + ' not found in domArr. ' + domBuf ;
      dsply       msg ;
      endif ;
 /end-free

Upvotes: 2

Charles
Charles

Reputation: 23783

You are correct, basically a compile time array.

Just a more modern way of doing it, biggest advantage is that the array and the data are declared in one place. Rather than having the array declared at the top of the source and the data at the bottom.

I first saw the practice proposed in Jon Paris' D-spec Discoveries article published in Feb 2003.

Upvotes: 3

Related Questions