ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Put printer record in a DS.

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

  • Put printer record in a DS.

    If I have a printer record like this:

    R TITLE
    POSITTION 7A 5
    FIELD01 10A +1
    FIELD02 10A +1
    FIELD03 10A +1
    ......
    FIELDNN 10A +1

    Its possible refer to that record with a DS or array

    jTitle.Field(2) <===> FIELD02 in printer external file

    or

    Field(02) <===> FIELD02 FIELD02 in printer external file


    Regards.

  • #2
    Re: Put printer record in a DS.

    if the print file is an actual print file you can use the extfile on a datastructure to auto populate...



    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


    • #3
      Re: Put printer record in a DS.

      Yes it's possible :

      Code:
      FBULLETIN  O    e             PRINTER                                       
      d MyPRTF          ds                  likerec(TITLE : *output) based(ptr)   
      d Ptr             s               *                                         
                                                                                  
      d MyDS            ds                                                        
      d   Position                          like(MyPRTF.Position)                 
      d   Field                             like(MyPRTF.Field01) dim(6)           
                                                                                  
       /Free                                                                      
           Ptr = %addr(MyDs);                                                     
           Field(1) = 'AAAAAA';                                                   
           Write Title MyPRTF;                                                    
        *inlr = *on;                                                              
       /End-Free
      Patrick

      Comment


      • #4
        Re: Put printer record in a DS.

        I used to do my reporting based on DS setup... something like:

        Code:
             DPrintLine        DS           132
             D  Field1                 1     30A
             D  Field2                35     42A
             D  Field3                45     55A
             D  Field4                33     40A
             D  Field5                45     65A
             D  Field6                70     80A
             D  Field7                83     90A
             D  Field8                91    132A
        Adjustments can be made based on whether you're displaying a "Column Header" or actual data. But all uses write the Data Structure "PrintLine". You can adjust your reporting based on the From/To Columns in the DS. You can also add spaces with the +1 in the middle if you don't want. Adding a hard coded field is easy as well.

        PHP Code:
        ExSR Write_Header;
        Read InFile;
        DoW NOT %Eof(InFile)

           
        ExSR Write_Detail;
           
        ExSR Total_Calcs;
           
        Read InFile;

        EndDO;

        ExSR Write_Totals;

        *
        InLR = *On;
        Return;

        BegSR Write_Header;
           
        Clear PrintLine;
           
        Field1 "Name";
           
        Field2 "Invoice#";
           
        EvalR Field3 "Units";
           
        EvalR Field4 "$/Cost";
           
        EvalR Field6 "$/Ext";
           
        Write PrintLine;

           
        Clear PrintLine;
           
        Field1 "------------------------------";
           
        Field2 "-------";
           
        EvalR Field3 "----------";
           
        EvalR Field4 "-------";
           
        EvalR Field6 "----------";
           
        Write PrintLine;
        EndSR;

        BegSR Write_Detail;
           
        Clear PrintLine;
           
        Field1 Customer_Name;
           
        Field2 Invoice_Number;
           
        EvalR Field3 = %EditCNum_Units 'Z' );
           
        EvalR Field4 = %EditCCost "J" );
           
        EvalR Field6 = %EditCNum_Units Cost "J" );
           
        Write PrintLine;
        EndSR;

        BegSR Write_Totals;
           
        Clear PrintLine;
           
        EvalR Field3 = %EditCTotal_Units 'Z' );
           
        EvalR Field4 = %EditCTotal_Cost "J" );
           
        EvalR Field6 = %EditCTotal_Gross "J" );
           
        Write PrintLine;
        EndSR
        PS: Yes .. I know it's Old Schuuuul -- But, it works and it's easy to use...
        Last edited by FaStOnE; November 25, 2009, 10:48 AM.

        Comment


        • #5
          Re: Put printer record in a DS.

          Originally posted by K2r400 View Post
          Yes it's possible :

          Code:
          FBULLETIN  O    e             PRINTER                                       
          d MyPRTF          ds                  likerec(TITLE : *output) based(ptr)   
          d Ptr             s               *                                         
                                                                                      
          d MyDS            ds                                                        
          d   Position                          like(MyPRTF.Position)                 
          d   Field                             like(MyPRTF.Field01) dim(6)           
                                                                                      
           /Free                                                                      
               Ptr = %addr(MyDs);                                                     
               Field(1) = 'AAAAAA';                                                   
               Write Title MyPRTF;                                                    
            *inlr = *on;                                                              
           /End-Free
          likerec? Thats a new one to me. What is it? My version of the documentation does not show it.

          Comment


          • #6
            Re: Put printer record in a DS.

            Originally posted by soup_dog View Post
            likerec? Thats a new one to me. What is it? My version of the documentation does not show it.
            It's like "likeds" but for record formats instead of data structures.
            "Time passes, but sometimes it beats the <crap> out of you as it goes."

            Comment


            • #7
              Re: Put printer record in a DS.

              Soup -- to clarify things

              From the ILE RPG Language Reference Redbook
              :

              LIKEREC(intrecname{:*ALL|*INPUT|*OUTPUT |*KEY})

              Keyword LIKEREC is used to define a data structure, data structure subfield, prototyped return value, or prototyped parameter like a record. The subfields of the data structure will be identical to the fields in the record. LIKEREC can take an optional second parameter which indicates which fields of the record to include in the data structure. These include:
              • *ALL All fields in the external record are extracted.
              • *INPUT All input-capable fields are extracted. (This is the default.)
              • *OUTPUT All output-capable fields are extracted.
              • *KEY The key fields are extracted in the order that the keys are defined on the K specification in the DDS.


              The following should be taken into account when using the LIKEREC keyword:
              • The first parameter for keyword LIKEREC is a record name in the program. If the record name has been renamed, it is the internal name for the record.
              • The second parameter for LIKEREC must match the definition of the associated record or file. *INPUT is only allowed for input and update capable records; *OUTPUT is only allowed for output capable records; *ALL is allowed for any type of record; and *KEY is only allowed for keyed files. If not specified, the parameter defaults to *INPUT.
              • For *INPUT and *OUTPUT, subfields included in the data structure occupy the same start positions as in the external record description.
              • If a prefix was specified for the file, the specified prefix is applied to the names of the subfields.
              • Even if a field in the record is explicitly renamed on an input specification the external name (possibly prefixed) is used, not the internal name.
              • A data structure defined with LIKEREC is a QUALIFIED data structure. The names of the subfields will be qualified with the new data structure name, DS1.SUBF1.
              • LIKEREC can be coded for subfields of a qualified data structure. When LIKEREC is coded on a data structure subfield definition, the subfield data structure is automatically defined as QUALIFIED. Subfields in a LIKEREC subfield data structure are referenced in fully qualified form: "ds.subf.subfa". Subfields defined with LIKEREC are themselves data structures, and can be used wherever a data structure is required.
              Philippe

              Comment


              • #8
                Re: Put printer record in a DS.

                :
                Originally posted by K2r400 View Post
                Yes it's possible :

                Code:
                FBULLETIN  O    e             PRINTER                                       
                d MyPRTF          ds                  likerec(TITLE : *output) based(ptr)   
                d Ptr             s               *                                         
                                                                                            
                d MyDS            ds                                                        
                d   Position                          like(MyPRTF.Position)                 
                d   Field                             like(MyPRTF.Field01) dim(6)           
                                                                                            
                 /Free                                                                      
                     Ptr = %addr(MyDs);                                                     
                     Field(1) = 'AAAAAA';                                                   
                     Write Title MyPRTF;                                                    
                  *inlr = *on;                                                              
                 /End-Free
                ...exactly what I was looking for.


                Thanks!

                Comment


                • #9
                  Re: Put printer record in a DS.

                  Originally posted by FaStOnE View Post
                  [CODE]
                  ** snip **

                  Field1 = "------------------------------";
                  Field2 = "-------";
                  EvalR Field3 = "----------";
                  EvalR Field4 = "-------";
                  EvalR Field6 = "----------";
                  Write PrintLine;
                  [/PHP]
                  Another method -- saves on having to count the number of dashes on the eval statement. (Of course, this only works if you are populating the entire field with dashes.)
                  Code:
                     Field1 = *ALL'-';
                     Field2 = *ALL'-';
                  etc

                  Originally posted by FaStOnE View Post
                  PS: Yes .. I know it's Old Schuuuul -- But, it works and it's easy to use...
                  Old Schuuuul or not, if it's easy to understand/maintain, I say go for it.
                  http://www.linkedin.com/in/chippermiller

                  Comment


                  • #10
                    Re: Put printer record in a DS.

                    great stuff guys! Thanks for the info. As soon as I get to work on Monday i'll have to see if my version of RPG supports it!

                    Comment


                    • #11
                      Re: Put printer record in a DS.

                      Hi,

                      if your fields are already defined (for example in the Printerfile) you do not need to specify the definition and length for the fields if you put them into a data structure. Just list the fields.

                      Also it is not necessary to use pointers. And K2r400's solution will only work if the fields are always defined one after the other. If an additional field will be added, the solution no longer works.
                      PHP Code:
                           D DSPrtLine        DS           
                           D  Field1                 
                           D  Field2                
                           D  Field3                
                           D  Field4                
                           D  Field5                
                           D  Field6                
                           D  Field7                
                           D  Field8                
                           D  ArrPrtLine                           Like
                      (Field1Dim(8
                                                                   
                      Overlay(DSPrLine)

                       /
                      Free
                          ArrPrtLine
                      (1) = 'AAAA';      
                          
                      Write Format;
                       /
                      End-Free 
                      Birgitta

                      Comment

                      Working...
                      X