Page 1 of 1

Alias

Posted: Mon Feb 24, 2014 2:55 pm
by pshuey@dasinc.com
Can you show an example of how, exactly, the Alias keyword is used in the RPG program in order to take advantage of the longer field names from the display?

Re: Alias

Posted: Mon Feb 24, 2014 3:06 pm
by David
I've attached 2 simple examples, based on our 'Hello World' sample program. There is 1 display file, and 2 RPG programs showing a couple of different techniques. See the notes in the RPG source members.

Due to limitations with the RPG compiler, an EXFMT operation is the only one that can work from a DS with *ALL fields from the record format. For other operations like WRITE, READ, CHAIN, READC, etc., you need to have 1 DS declared with *INPUT fields, and another one declared with *OUTPUT fields, depending on the operation.

The easiest way to manage this requirement is probably to use an EVAL-CORR operation to move the data between the input/output DS as needed.

Re: Alias

Posted: Mon Feb 24, 2014 3:14 pm
by Alex
If you did not have a chance to watch the following webinar, I would recommend it:
http://info.profoundlogic.com/acton/fs/ ... /page/fm/0

In this link, there is a video recording of the webinar as well as code samples. The ALIAS keyword is demonstrated.

Re: Alias

Posted: Fri Feb 28, 2014 11:03 am
by DaveLClarkI
David wrote:Due to limitations with the RPG compiler, an EXFMT operation is the only one that can work from a DS with *ALL fields from the record format. For other operations like WRITE, READ, CHAIN, READC, etc., you need to have 1 DS declared with *INPUT fields, and another one declared with *OUTPUT fields, depending on the operation.

The easiest way to manage this requirement is probably to use an EVAL-CORR operation to move the data between the input/output DS as needed.
I was taught from way back to avoid using EXFMT and just use READ/CHAIN and WRITE/UPDATE for my workstation files -- so this "limitation" fits right in with my mindset. It gets annoying when other programmers look down their noses at me for not using EXFMT. ;-)

So, I defined my file this way:

Code: Select all

      * workstation file
     FACTMTBLD  CF   E             WORKSTN usropn alias qualified
     F                                     indds(wsi) infds(dspfbk)
     F                                     sfile(ACTMTBLS: sflrrn)
     F                                     HANDLER('PROFOUNDUI(HANDLER)')
and my data structures this way:

Code: Select all

      * workstation data structures
     D Screen          DS                  likerec(ACTMTBLD.ACTMTBLC:*input)
     D Screen_Out      DS                  likerec(ACTMTBLD.ACTMTBLC:*output)
     D Grid            DS                  likerec(ACTMTBLD.ACTMTBLS:*input)
     D Grid_Out        DS                  likerec(ACTMTBLD.ACTMTBLS:*output)
From there it works well for me -- for example:

Code: Select all

       more_input = *on;               // insure first-time entry into loop
       rebuild_screen = *on;

       dow more_input                  // do until told otherwise
       and pPgmName = PROC_PGM;        // or requested program changes
         callp DisplayTheScreen();     // send display to workstation
         read ACTMTBLD.ACTMTBLC Screen; // wait for input
         callp ProcessTheScreen(pPgmName: pKeyData); // process input from workstation
       enddo;
and this abbreviated code for writing the subfile record:

Code: Select all

       clear Screen;                   // clear subfile control data structure
       clear Grid;                     // clear subfile data structure

       wsi.SFLInds = SFL_Clear;        // request subfile clear
       eval-corr Screen_Out = Screen;  // move corresponding input data to output
       write ACTMTBLD.ACTMTBLC Screen_Out; // clear subfile
       wsi.SFLInds = SFL_DisplayAll;   // request subfile display

       sflrrn = *zero;                 // initialize subfile record number
       dow TmgTbl_GetTableData( Caller: TmgTbl_View2: TmgTbl_IndAry );
         sflrrn += 1;                  // increment subfile record number

         Grid.S1ID   = TmgTbl_View2.ACTMTABTID;  // set the blind key
         Grid.S1TBLNME = TmgTbl_View2.TBLNME;    // set the table name
         Grid.S1LIBCDE = TmgTbl_View2.LIBCDE;    // set the library code
         Grid.S1TRGENA = TmgTbl_View2.TRGENAFLG; // set the enabled flag
         Grid.S1RMVTRG = TmgTbl_View2.RMVTRGFLG; // set the remove flag
         Grid.S1TBLDSC = %xlate( CrsApp_InvChrs: CrsApp_Periods
                       : %trimr(TmgTbl_View2.TBLDSC) ); // set the table description

         eval-corr Grid_Out = Grid;    // move corresponding input data to output
         write ACTMTBLD.ACTMTBLS Grid_Out; // write to subfile

       enddo;                          // loop for more master rows
       TmgTbl_GetTableData('*CLOSE');  // close the lookup table

       maxrrn = sflrrn;                // save last record number as max
       wsi.SFLEnd_52 = *on;            // set subfile end indicator on
and this for writing the subfile control record:

Code: Select all

       if (maxrrn = *zero);            // if no subfile records present
         wsi.SFLInds = SFL_CtlOnly;    // turn off display of subfile
       endif;

       eval-corr Screen_Out = Screen;  // move corresponding input data to output
       write ACTMTBLD.ACTMTBLC Screen_Out; // write subfile control format
My next step is to go full 100% free RPG. ;-)