ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

the world famous API QWCRDTAA Retrieve Data Area

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • the world famous API QWCRDTAA Retrieve Data Area

    I removed the Binary cause I know it makes some of ya MAD!

    Code:
        dQWCRDRTN         DS
         d QWCBAVL                       10i 0                                      Qwc Rdtaa Data
         d QWCBRTN                       10i 0                                      Bytes Available
         d QWCTVRTN                      10                                         Bytes Returned
         d QWCLIBN                       10                                         Type Value Return
         d QWCLVRTN                      10i 0                                      Library Name
         d QWCNBRDP                      10i 0                                      Length returned
         d QWCVALUE                     475                                         Number Decimal
           //
           //
           //
         dQUSEC            DS
         d QUSBPRV                       10i 0
         d QUSBAVL                       10i 0
         d QUSEI                          7
         d QUSERVED                       1
         d QUSED01                        1
    
         drcvvarsiz        s             10i 0 inz(512)
         ddtaaraname       s             20    inz('IN1BSIN   LBIFIL    ')
         dstrpos           s             10i 0 inz(-1)
         dstrlen           s             10i 0 inz(475)
    
          //
          //  Required Parameter Group:
          //
          //  1 Receiver variable Output Char(*)
          //  2 Length of receiver variable Input Binary(4)
          //  3 Qualified data area name Input Char(20)
          //  4 Starting position Input Binary(4)
          //  5 Length of data Input Binary(4)
          //  6 Error code I/O Char(*)
          //
    
         d $getdataarea    pr                  extpgm('QWCRDTAA')
         d   recieveVar                 475
         d   lengthRecvar                10i 0
         d   dataareaLib                 20
         d   startpositon                10i 0
         d   lengthofInp                 10i 0
         d   errorcode                   17
    
           //
           //  run the api and retrieve the data
           //  this is useful if you have same dataarea in *multiple
           //  libraries and need info from them all via RPG.
           //  just change the data in "dtaaraname" and rerun for
           //  other library/dataarea's
           //
    
          /free
                 QUSBPRV = 0;
                 $getdataarea(QWCRDRTN   :
                              rcvvarsiz  :
                              dtaaraname :
                              strpos     :
                              strlen     :
                              QUSEC
                                         );
    
                // The variable QWCVALUE now contains the *DTAARA value
                 dsply %subst(QWCVALUE:1:30)  ' ';
                 *inlr = *on;
    
          /end-free
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  • #2
    Re: the world famous API QWCRDTAA

    personally (and i am biased ) i like mine better:
    Code:
          * Program Name: CHKDTAARA        Author:  Tommy Holden      *
          * Create Date: 06/13/2006                                   *
          * Purpose:  Allow Interface To Retrieve Data Area Attributes*
          *___________________________________________________________*
    
          * Parameter Definition
         dMain             PR                  ExtPgm('CHKDTAARA')
         d DataArea                      20a   Const
         d DataType                      10a
         d Length                        10u 0
         d DecPos                        10u 0
    
          * Parameter Entry
         dMain             PI
         d DataArea                      20a   Const
         d DataType                      10a
         d Length                        10u 0
         d DecPos                        10u 0
    
          * Retrieve Data Area API
         dChkDtaAra        PR                  ExtPgm('QWCRDTAA')
         d ReturnVar                    255a   Options(*VarSize)
         d ReturnLen                     10i 0 Const
         d QualDataArea                  20a   Const
         d StartPos                      10i 0 Const
         d DataLen                       10i 0 Const
         d ErrorCode                    300a   Options(*VarSize)
    
          * Returned Data Structure
         D ReturnDS        ds                  Qualified
         d BytesAvail                    10i 0
         d BytesReturned                 10i 0
         d DataType                      10a
         d Library                       10a
         d RtnLength                     10i 0
         d DecPos                        10i 0
         d Data                         300a
    
          * Work Variables
         d ErrorCode       s            300a
    
          /free
    
            // Retrieve The Data Area Attributes
            ChkDtaAra( ReturnDS :
                       %Size(ReturnDS) :
                       DataArea :
                       -1:
                       32000:
                       ErrorCode);
    
            // Load Return Variables
            DataType = ReturnDS.DataType;
            Length = ReturnDS.RtnLength;
            DecPos = ReturnDS.DecPos;
    
            // Terminate
            *inlr=*on;
            return;
          /end-free
    oops forgot the CMD source:
    Code:
    /* TO COMPILE SPECIFY                                       */         
    /*  ALLOW(*IPGM *BPGM *IMOD *BMOD *IREXX *BREXX)            */         
    /* ON THE CRTCMD COMMAND                                    */         
    /*__________________________________________________________*/         
                CMD        PROMPT('Check Data Area Attributes')            
                PARM       KWD(DTAARA) TYPE(Q1) MIN(1) PROMPT('Data +      
                             Area:')                                       
                PARM       KWD(TYPE) TYPE(*CHAR) LEN(10) RTNVAL(*YES) +    
                             PROMPT('Data Type:')                          
                PARM       KWD(LEN) TYPE(*UINT4) RTNVAL(*YES) +            
                             PROMPT('Data Length:')                        
                PARM       KWD(DECPOS) TYPE(*UINT4) RTNVAL(*YES) +         
                             PROMPT('Decimal Positions:')                  
    Q1:         QUAL       TYPE(*NAME) LEN(10)                             
                QUAL       TYPE(*NAME) LEN(10) DFT(*LIBL) +                
                             SPCVAL((*LIBL) (*CURLIB)) PROMPT('Library:')
    i wrote this to determine the actual data area attributes not the data in them...so you can see why i didn't bother with checking the data value being returned
    Last edited by tomholden; January 23, 2008, 03:20 PM.
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: the world famous API QWCRDTAA

      As I am a very giving person and knowing it will make you feel special
      .... " I also like your version more."

      here is an example where the same data area is located in 5 different libraries
      and you need to display all on once screen. (in my case the intranet)

      Code:
            //
            // Variable Definition
            //
           d buyslips        s              5  0
           d cmpcount        s              3  0
           d company         s              2s 0
           d companynm       s              3
           d dataname        s             21
           d inqslips        s              5  0
           d rcvvarsiz       s             10i 0
           d strpos          s             10i 0 inz(-1)
           d strlen          s             10i 0 inz(475)
      
      
           d $retrievedta    pr                  extpgm('QWCRDTAA')
           d   QWCRDRTN                   512    const
           d   rcvvarsiz                   10i 0 const
           d   dataname                    20    const
           d   strpos                      10i 0 const
           d   strlen                      10i 0 const
           d   QUSEC                       17    const
      
           dQWCRDRTN         DS
           d QWCBAVL                       10i 0                                      Qwc Rdtaa Data
           d QWCBRTN                       10i 0                                      Bytes Available
           d QWCTVRTN                      10                                         Bytes Returned
           d QWCLIBN                       10                                         Type Value Return
           d QWCLVRTN                      10i 0                                      Library Name
           d QWCNBRDP                      10i 0                                      Length returned
           d QWCVALUE                     475                                         Number Decimal
      
           dQUSEC            DS
           d QUSBPRV                       10i 0
           d QUSBAVL                       10i 0
           d QUSEI                          7
           d QUSERVED                       1
           d QUSED01                        1
      
            /Free
      
              //--------------------------------------------------------
              // MAIN PROGRAM
              //--------------------------------------------------------
      
      
                    for cmpcount = 1 to 5;
                     select;
                      when cmpcount = 1;
                       dataname = 'DATAARA   LIBRARY1';
                       company = 15;
                       companynm = 'LSA';
                      when cmpcount = 2;
                       dataname = 'DATAARA   LIBRARY2';
                       company = 72;
                       companynm = 'GMC';
                      when cmpcount = 3;
                       dataname = 'DATAARA   LIBRARY3';
                       company = 20;
                       companynm = 'HSA';
                      when cmpcount = 4;
                       dataname = 'DATAARA   LIBRARY4';
                       company = 18;
                       companynm = 'LSN';
                      when cmpcount = 5;
                       dataname = 'DATAARA   LIBRARY5';
                       company = 30;
                       companynm = 'LSI';
                     endsl;
      
                     $retrievedta(QWCRDRTN   :
                                  rcvvarsiz  :
                                  dataname   :
                                  strpos     :
                                  strlen     :
                                  QUSEC
                                              );
                     buyslips =  %dec(%subst(QWCRDRTN:37:5):5:0);
                     inqslips =  %dec(%subst(QWCRDRTN:42:5):5:0);
                    endfor;
      
                    *inlr = *on;
      
            /End-Free
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: the world famous API QWCRDTAA

        both are nice... i just find it simpler to create a PF and in every pgm i use the dtaara in and then use extname keyword.

        Maybe it's just a bad habit, but S21 uses the LDA extensively for this purpose.
        To pass parameters, return codes, as well as store common fields such as internal date, external date, return codes etc.
        Regards

        Kit
        http://www.ecofitonline.com
        DeskfIT - ChangefIT - XrefIT
        ___________________________________
        There are only 3 kinds of people -
        Those that can count and those that can't.

        Comment


        • #5
          Re: the world famous API QWCRDTAA

          Kit, I agree I use the same here in most cases I only need the data area out of the
          current library.... However we have multiple companies and they each have their own
          libraries. I need to display data from all 5 on one webpage....so to do this I found it much
          easier to do it with the API.
          *all the "other" programs use the method you discribed as they only need to get the
          one dataara from the current library list.

          jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment

          Working...
          X