sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Data structure not initializing

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

  • Data structure not initializing

    My table CAT is defined with 6 groups of columns (i.e. curr month, months 1-24, prev 12, prev 24 repeated 6 times as table layout with different names of course). I am using the DIM array so I can process those months just using a loop, not quite sure if the DS are defined correctly and if there are better way to do this please let me know.
    I have following DS defined over my table CAT and trying to initialize, when I run the record format fields are initialized but the DIM fields are not.
    Doesn't Clear handle this?

    DCL-DS wSkuO Qualified;
    wSkuOld LikeRec(CATr:*input);
    wSrcReqMonO Zoned(5:0) Dim(24) POS(25) Inz(0);
    wFreeReqMonO Zoned(5:0) Dim(24) POS(108) Inz(0);
    wOrdVndMonO Zoned(5:0) Dim(24) POS(191) Inz(0);
    wOrdT1MonO Zoned(5:0) Dim(24) POS(274) Inz(0);
    wOrdT2MonO Zoned(5:0) Dim(24) POS(357) Inz(0);
    wDCOutMonO Zoned(5:0) Dim(12) POS(440) Inz(0);
    END-DS;

    DCL-DS wSkuN Qualified;
    wSkuNew LikeRec(CATr:*input);
    wSrcReqMonN Zoned(5:0) Dim(24) POS(25) Inz(0);
    wFreeReqMonN Zoned(5:0) Dim(24) POS(108) Inz(0);
    wOrdVndMonN Zoned(5:0) Dim(24) POS(191) Inz(0);
    wOrdT1MonN Zoned(5:0) Dim(24) POS(274) Inz(0);
    wOrdT2MonN Zoned(5:0) Dim(24) POS(357) Inz(0);
    wDCOutMonN Zoned(5:0) Dim(12) POS(440) Inz(0);
    END-DS;

    DCL-DS wSku Qualified;
    wSkuOut LikeRec(CATr:*output);
    wSrcReqMonOut Zoned(5:0) Dim(24) POS(25) Inz(0);
    wFreeReqMonOut Zoned(5:0) Dim(24) POS(108) Inz(0);
    wOrdVndMonOut Zoned(5:0) Dim(24) POS(191) Inz(0);
    wOrdT1MonOut Zoned(5:0) Dim(24) POS(274) Inz(0);
    wOrdT2MonOut Zoned(5:0) Dim(24) POS(357) Inz(0);
    wDCOutMonOut Zoned(5:0) Dim(12) POS(440) Inz(0);
    END-DS;


    Clear wSku;
    Clear wSku.wSkuOut;
    Clear wSkuN;
    Clear wSkuN.wSkuNew;
    Clear wSkuO;
    Clear wSkuO.wSkuOld;

  • #2
    It is not clear to me exactly what you are hoping to achieve here. The way you are doing the positioning (via absolute positions) is a really bad idea and there are better ways - but I'm loathe to make suggestions without knowing what you are doing.

    It _looks_ as if you are creating three copies of the same record image but with different name. Is that the case?

    If you show your actual record layout I can work it out easily.

    Comment


    • #3
      Jon, yes I am going to have 3 copies of same rec, an old rec, new rec, and output rec. I am chaining to to same table with old rec key, new rec key, and then using that info to calc an output rec.

      Chain (dsStore:dsOldLine:dsOldItem) CAT wSkuO.wSkuOld;
      Chain (dsStore:dsNewLine:dsNewItem) CAT wSkuN.wSkuNew;

      Here is part of the CAT table, the next set of columns(5) match this just named different and keyed by store/line/item, and I am trying to put the 24 monthly buckets in an array so I can loop thru much easier when calculating:

      Store DECIMAL(6,0) NOT NULL,
      Line CHAR(3) NOT NULL,
      Item CHAR(14) NOT NULL,
      Source_Requests FOR COLUMN SrcReq DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests1 FOR COLUMN SrcReq1 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests2 FOR COLUMN SrcReq2 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests3 FOR COLUMN SrcReq3 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests4 FOR COLUMN SrcReq4 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests5 FOR COLUMN SrcReq5 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests6 FOR COLUMN SrcReq6 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests7 FOR COLUMN SrcReq7 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests8 FOR COLUMN SrcReq8 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests9 FOR COLUMN SrcReq9 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests10 FOR COLUMN SrcReq10 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests11 FOR COLUMN SrcReq11 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests12 FOR COLUMN SrcReq12 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests13 FOR COLUMN SrcReq13 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests14 FOR COLUMN SrcReq14 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests15 FOR COLUMN SrcReq15 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests16 FOR COLUMN SrcReq16 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests17 FOR COLUMN SrcReq17 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests18 FOR COLUMN SrcReq18 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests19 FOR COLUMN SrcReq19 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests20 FOR COLUMN SrcReq20 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests21 FOR COLUMN SrcReq21 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests22 FOR COLUMN SrcReq22 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests23 FOR COLUMN SrcReq23 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests24 FOR COLUMN SrcReq24 DECIMAL(5,0) NOT NULL DEFAULT 0,
      Source_Requests_Prev_12Mo FOR COLUMN SrcReqPV12 DECIMAL(7,0)
      NOT NULL DEFAULT 0,
      Source_Requests_Prev_13_24Mo FOR COLUMN SrcReq1324 DECIMAL(7,0)
      NOT NULL DEFAULT 0,

      Comment


      • #4
        Let me know if need any other info, thanks

        Comment


        • #5
          Since you're using qualified data structures I'd create the main one - the use LIKEDS to create the copy - same field names but within a different data structure name. That will streamline your code and be more obvious to intent down the road.

          Since you're chaining I'd use the file for the creation of the first data structure....

          Comment


          • #6
            Thanks Rocky, probably a good idea. but my main concern is current setup like Jon said using POS not a good idea and been a while since I've coded an RPG pgm so I'm not familiar with using some of the newer free format declarations. THe original issue is upon initializing the DIM array is blank looking for better example of settting up my data structures based on above info where I need to define a 24 month array to be able to loop thru for calculating

            Comment


            • #7
              OK - something like this: (not tested 'cos I'm in a rush!)

              Code:
              dcl-ds  Old  extname('CAT')  Qualified;
                   SrcReqArray      Like(SrcReq)  Dim(24)  SamePos(SrcReq);
                   SrcReqPV12Array  Like(SrcReqPV12)  Dim(24)  SamePos(SrcReqPV12);  
                   etc.
              end-ds;
              
              dcl-ds  New  extname('CAT')  Qualified;
                   SrcReqArray      Like(SrcReq)  Dim(24)  SamePos(SrcReq);
                   SrcReqPV12Array  Like(SrcReqPV12)  Dim(24)  SamePos(SrcReqPV12);  
                   etc.
              end-ds;
              You could add INZ to the dcl-ds entry - that would set everything up cleanly - then Reset should work just fine when you need it.

              Then you simply reference Old.SrcArray(n) and New.SrcArray(n) etc.

              That should be good.

              Good luck.

              Comment


              • JonBoy
                JonBoy commented
                Editing a comment
                P.S. Doing it this way also allows you to use Eval-Corr if you need as all the data names will match. In your case I doubt this is useful as you can simply do New = Old; but for future reference ...

                P.P.S. You could also add ALIAS to the DS definition if you wished - that would let you use the long SQL names rather than the short RPG ones. No real benefit here because you have decent names for the short names - but in cases where the short name was defaulted and has the god awful ones that the system makes up it is a real advantage.

            • #8
              Thanks Jon, can I still use *input or *output on ExtName so I can Chain directly into the DS? Also the compiler is telling me samepos is not valid 'keyword name not valid

              DCL-DS wSkuO ExtName('CAT':*input) Qualified Inz;
              wSrcReqMonO Like(SrcReq) Dim(24) SamePos(SrcReq);
              wFreeReqMonO Like(Free24HR) Dim(24) SamePos(Free24HR);
              wOrdVndMonO Like(OrdVend) Dim(24) SamePos(OrdVend);
              wOrdT1MonO Like(OrdTier1) Dim(24) SamePos(OrdTier1);
              wOrdT2MonO Like(OrdTier2) Dim(24) SamePos(OrdTier2);
              wDCOutMonO Like(DCOutStk) Dim(12) SamePos(DCOutStk);
              END-DS;

              Comment


              • #9
                apparently we are on version 7.2 and cant use samepos, what would this look like usng Overlay?

                Comment


                • #10
                  I was going to say you can still do the Chain without *Input/*Output - but now I see you are on an old release so I'm not sure when that became available. You can certainly add the * designations - it is just a question of whether they are required or not. On 7.2 the relaxed rules require a PTF. Even if that becomes a problem there are other ways of handling it.

                  As to the SamePos - that's annoying. It only goes back to 7.3.

                  So - it can still be done but it is clumsier and either requires the use of pointers or absolute positions.

                  I'd be inclined to do it this way:
                  Code:
                  // Include the DS definition as before but _just_ the extname bit. The add these lines below the DS.
                  
                  dcl-s  wSrcReqMonO Like(SrcReq) Dim(24)  Based(pSrcReq);
                  dcl-s  pSrcReq  pointer  inz(%Addr(SrcReq));
                  
                  dcl-s wFreeReqMonO Like(Free24HR) Dim(24) Based(pFree24HR);
                  dcl-s pFree24HR  pointer inz(%Addr(Free24HR));
                  
                  etc. etc.
                  This way you are not position dependent and should the layout of the data change then all will still work. As long as the fields remain contiguous anyway!

                  There's no pointer manipulation involved - so no risk of that being screwed up. I would however document what you've done! Also maybe include as comments the "better way" with SamePos as discussed.

                  Comment


                  • #11
                    Thanks Jon, looks to be working well

                    Comment


                    • JonBoy
                      JonBoy commented
                      Editing a comment
                      Glad to hear it.

                  • #12
                    Jon, I did run into some intializing issues when I put thru debug, this is what I have right now. RDi flags these as not being used in the pgm do they no longer need to be qualified?

                    DCL-DS wSkuO ExtName('CAT':*input) Qualified Inz;
                    dcl-s wSrcReqMonOld Like(SrcReq) Dim(24) Based(pSrcReq);
                    dcl-s pSrcReq pointer inz(%Addr(SrcReq));
                    dcl-s wFreeReqMonOld Like(Free24HR) Dim(24) Based(pFree24);
                    dcl-s pFree24 pointer inz(%Addr(Free24HR));
                    dcl-s wOrdVndMonOld Like(OrdVend) Dim(24) Based(pOrdVnd);
                    dcl-s pOrdVnd pointer inz(%Addr(OrdVend));
                    dcl-s wOrdT1MonOld Like(OrdTier1) Dim(24) Based(pOrdT1);
                    dcl-s pOrdT1 pointer inz(%Addr(OrdTier1));
                    dcl-s wOrdT2MonOld Like(OrdTier2) Dim(24) Based(pOrdT2);
                    dcl-s pOrdT2 pointer inz(%Addr(OrdTier2));
                    dcl-s wDCOutMonOld Like(DCOutStk) Dim(12) Based(pOrdDC);
                    dcl-s pOrdDC pointer inz(%Addr(DCOutStk));
                    END-DS;

                    Comment


                    • #13
                      or can I just do something like this? May make it easier right now for others until we get upgraded version, where the file is prefixed with "c"

                      DCL-DS wSkuO ExtName('CAT':*input) Qualified Inz;
                      wSrcReqMonOld Like(c_SrcReq) Dim(24) POS(25) Inz(0);
                      wFreeReqMonOld Like(c_Free24HR) Dim(24) POS(108) Inz(0);
                      wOrdVndMonOld Like(c_OrdVend) Dim(24) POS(191) Inz(0);
                      wOrdT1MonOld Like(c_OrdTier1) Dim(24) POS(274) Inz(0);
                      wOrdT2MonOld Like(c_OrdTier2) Dim(24) POS(357) Inz(0);
                      wDCOutMonOld Like(c_DCOutStk) Dim(12) POS(440) Inz(0);
                      END-DS;

                      Comment


                      • #14
                        1) Qualified is not needed unless you have a need to access the individual fields of the main DS.

                        2) Your end-ds is mis-placed. It should be immediately after the dcl-ds. I'm actually surprised that the compiler accepts it.

                        3) "I did run into some intializing issues" - what issues? There are none there that I can see.

                        4) You could use the POS approach - but as I said before it is an approach that is going to cause problems in the end as the layout of the table changes. With RPG IV we gave up on From/To notation - using POS really just goes backwards to that stage.

                        Comment

                        Working...
                        X