Sorry, you do not have permission to ask a question, You must login to ask a question.

Sorry, you do not have permission to ask a question.

brainchime.com

brainchime.com

brainchime.com Navigation

  • Home
  • About Us
  • Contact Us

Mobile menu

Close
  • Home
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags

brainchime.com Latest Questions

Admin
Admin
Asked: October 6, 20242024-10-06T21:32:31+05:30 2024-10-06T21:32:31+05:30In: IBM i

Why do we use OVERLAY keyword in data structure subfields in RPGLE?

In some places, I saw the use of the OVERLAY keyword in the RPGLE program in data structure sub-fields. For the sub-fields defined using the OVERLAY keyword, there was no definition defined in the definition specs in the RPG program instead the start and end positions were defined on the previous sub-fields. Why do we use this OVERLAY keyword with data structures?

as400rpg
  • 0
  • 0
  • 1212
  • 10
  • Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp

Related Questions

  • what is level check error and how to resolve level check error?
  • What are AS400 systems. Please provide a introduction of AS400 systems?
  • Is there any online server available for practicing on AS400 system?
  • What are the menus available in AS400?
  • What is subsystem in AS400?
  • How to copy a save file from IFS to a library?
  • How to transfer savf from as400 to pc?
  • How to copy ifs file to another directory?
  • How to copy savf from ifs to pc?
  • How to copy ifs file to physical file?
  • How to copy save file to ifs?
  • How to copy spool file to ifs?
  • How to copy physical file to ifs?
  • How to copy file from pc to IFS?
  • How to download spool file from AS400?
  • How do I delete a library in AS400?
  • How do I copy data from AS400 to excel?
  • What is library in AS400?
  • How to find all the source physical file available in AS400?
  • How to find all libraries in AS400?
  • How to change the library list in AS400?
  • What is access path in AS400?
  • What is the difference between source physical file and physical file in as400?
  • how to find the source file of an object in as400?
  • how to change record length of source physical file in as400?
  • What is cpf4174 error in as400?
  • What is the use of varying keyword in rpgle?
  • What is DDS in AS400?
  • What is the difference between PF and LF in as400?
  • Why do we use CHGPF command in AS400?
  • how to create physical file in as400?
  • What are the data types supported by physical files in AS400?
  • how to add data in physical file in as400?
  • how to view journal entries in as400?
  • what is the use of ovrdbf in as400?
  • What is an array in AS400?
  • what is a data queue in as400 and why do we use data queue?
  • How to run stored procedure in AS400?
  • How to resolve session and device error in AS400?
  • how to check as400 system values?
  • How to check triggers on a file in as400?
  • How to find damaged objects in AS400?
  • what is module in as400?
  • How to create binding directory in as400?
  • how to create ifs folder in as400?
  • What is ASP in AS400?
  • What is JOBQ and how to create a JOBQ in AS400?
  • What is PSDS in AS400?
  • What is SEU in AS400 and why do we use it?
  • What is the multi-format logical file in AS400?
Leave an answer

Leave an answer
Cancel reply

Browse
Browse

Choose from here the video type.

Put Video ID here: https://www.youtube.com/watch?v=sdUUx5FdySs Ex: "sdUUx5FdySs".

12 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Admin
    Admin
    2024-10-06T21:53:27+05:30Added an answer on October 6, 2024 at 9:53 pm

    Another example with mixed data type using the OVERLAY keyword in DS.

         D DS1             DS
         D FLD1                          12A 
         D  FLD11                        10I 0 OVERLAY(FLD1:1)
         D  FLD1111                       2A   OVERLAY(FLD1:5)
         D  FLD11111                      3A   OVERLAY(FLD1:7)
         D  FLD111111                     3A   OVERLAY(FLD1:10)
         D FLD2                          10U 0 
         D KeyDS           DS
         D Keys                    1      5A 
         D  key1                          1A   OVERLAY(Keys:1)
         D  Key2                          1A   OVERLAY(Keys:*NEXT)
         D  Key2                          1A   OVERLAY(Keys:*NEXT)
         D  Key2                          1A   OVERLAY(Keys:*NEXT)
         D  Key2                          1A   OVERLAY(Keys:*NEXT)
         D                 DS
         D number                        15p 0 
         D  numC                          5A   OVERLAY(number:1)
         D NumChar                        5A   
         D Num                            5s 0 OVERLAY(NumChar)
         D Cmd                      1    100A    
         D CmdChar                        1A   DIM(100) overlay(Cmd)
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  2. Admin
    Admin
    2024-10-06T22:07:27+05:30Added an answer on October 6, 2024 at 10:07 pm

    Another good example of DS OVERLAY would be creating a DS on named indicators:

         D Indptr          S               *   inz(%addr(*IN))
         D                 DS                  based(Indptr)
         D Indicators                    99A    
         D  F03                            n   OVERLAY(Indicators:03)
         D  F05                            n   OVERLAY(Indicators:05)
         D  F06                            n   OVERLAY(Indicators:06)
         D  F09                            n   OVERLAY(Indicators:09)
         D  F12                            n   OVERLAY(Indicators:12)
         D  sflclear                       n   OVERLAY(Indicators:30)
         D  sfldisplay                     n   OVERLAY(Indicators:31)

    Line 1: Declaring a pointer variable named Indptr and initializing it with the address of *IN, the indicator array.
    Line 2: Declaring an unnamed DS which is based on a pointer Indptr using BASED keyword.
    Line 3: Declare a subfield named Indicators of 99 characters instead of an array.
    Line 4: Declared indicator subfield named F03 that overlays Indicators subfield storage position 3.
    Line 5: Declared indicator subfield named F05 that overlays Indicators subfield storage position 5.
    Line 6: Declared indicator subfield named F06 that overlays Indicators subfield storage position 6.
    Line 7: Declared indicator subfield named F09 that overlays Indicators subfield storage position 9.
    Line 8: Declared indicator subfield named F12 that overlays Indicators subfield storage position 12.
    Line 9: Declared indicator subfield named sflclear that overlays Indicators subfield storage position 30.
    Line 10: Declared indicator subfield named sfldisplay that overlays Indicators subfield storage position 31.

      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  3. Admin
    Admin
    2024-10-06T22:02:37+05:30Added an answer on October 6, 2024 at 10:02 pm

    This is a unique example of a DS OVERLAY.

      D                 DS
         D months                        36A   inz('JanFebMarAprMay-
         D                                     JunJulAugSepOctNovDec')     
         D  month                         3A   DIM(12) OVERLAY(months)

    Explanations:
    Line 1: Declared an unnamed DS.
    Line 2-3: Declared subfield named months of length 36 characters and initialized the subfield with starting 3 letters of each month like this JanFebMarAprMayJunJulAugSepOctNovDec.
    Line 4: Declared another subfield named month of length 3 characters and used OVERLAY keyword with parameter month to allocate storage of subfield months from the start, the position defaults to 1 and also makes it an array of 12 elements using the DIM keyword.

    Outcome:
    Month array each element would contain:

    > Eval month
    month(1) = 'Jan'
    month(2) = 'Feb'
    month(3) = 'Mar'
    month(4) = 'Apr'
    month(5) = 'May'
    month(6) = 'Jun'
    month(7) = 'Jul'
    month(8) = 'Aug'
    month(9) = 'Sep'
    month(10) = 'Oct'
    month(11) = 'Nov'
    month(12) = 'Dec'
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  4. Admin
    Admin
    2024-10-06T21:45:26+05:30Added an answer on October 6, 2024 at 9:45 pm

    Here is an example of using the OVERLAY keyword in data structure subfields.
    Defining OVERLAY keyword in DS in Fixed form RPG:

         D                 DS
         D FLD1                          10A 
         D FLD2                           5A   OVERLAY(FLD1:1)
         D FLD3                           5A   OVERLAY(FLD1:6)

    Line 1: I declared an unnamed data structure
    Line 2: I declared a subfield named FLD1 of length 1o characters.
    Line 3: I declared a subfield named FLD2 of length 5 characters, used the OVERLAY keyword with this subfield, and specified FLD1 as the overlaid subfield and start position as 1. Therefore, FLD2 occupies the storage of FLD1 from positions 1 to 5.
    Line 4: I declared a subfield named FLD3 of length 5 characters, used the OVERLAY keyword with this subfield, and specified FLD1 as the overlaid subfield and start position as 6. Therefore, FLD3 occupies the storage of FLD1 from positions 6 to 10.

    Defining the OVERLAY keyword in DS in free-form RPG:

    DCL-DS *N;
    DCL-SUBF FLD1 CHAR(10);
    DCL-SUBF FLD2 CHAR(5) OVERLAY(FLD1:1);
    DCL-SUBF FLD3 CHAR(5) OVERLAY(FLD1:6);
    END-DS;

    or

    DCL-DS *N;
    FLD1 CHAR(10);
    FLD2 CHAR(5) OVERLAY(FLD1:1);
    FLD3 CHAR(5) OVERLAY(FLD1:6);
    END-DS;
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  5. Admin
    Admin
    2024-10-06T21:46:58+05:30Added an answer on October 6, 2024 at 9:46 pm

    You can define the OVERLAY keyword in DS like below:

         D DS1             DS
         D FLD1                           5A 
         D FLD2                           2A   OVERLAY(FLD1)

    Line 1: Here, I define the data structure named DS1.
    Line 2: Declared subfield FLD1 of 5 characters in length.
    Line 3: Declared subfield FLD2 of 2 characters and overlaid FLD1 and start position defaults to 1. Therefore, FLD2 occupies positions from 1 to 2 in the FLD1 subfield.

      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  6. Admin
    Admin
    2024-10-06T21:40:18+05:30Added an answer on October 6, 2024 at 9:40 pm

    This is the free-form declaration of the above DS subfield that gets allocated using the DIM and OVERLAY keywords.

    DCL-DS *N;
    DCL-SUBF word CHAR(20);
    DCL-SUBF letter CHAR(1) OVERLAY(word:1) DIM(20);
    END-DS;

    Or

    DCL-DS *N;
    word CHAR(20);
    letter CHAR(1) OVERLAY(word:1) DIM(20);
    END-DS;
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  7. Admin
    Admin
    2024-10-06T21:42:11+05:30Added an answer on October 6, 2024 at 9:42 pm

    As we all have seen sometimes we use the OVERLAY keyword in data structure subfields to overlay the storage of one subfield with that of another subfield.

    OVERLAY keyword in DS syntax is as follows:
    OVERLAY(fieldName:startposition | *NEXT})

    Here 2nd parameter startposition | *NEXT is optional to use if not specified then it defaults to 1. Start_pos is specified in terms of bytes, regardless of the subfield type.

    If specified OVERLAY(fieldname:startposition) then that subfield definition overlays the fieldname parameter storage at the position specified by the startposition Optional parameter.

    If specified OVERLAY(fieldname:*NEXT) then it positions the subfield at the next available position within the overlay field.

      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  8. Admin
    Admin
    2024-10-06T21:48:37+05:30Added an answer on October 6, 2024 at 9:48 pm

    Defining Subfield Overlay Positions with *NEXT:

         D                 DS
         D FLD1                          10A 
         D FLD2                           5A   OVERLAY(FLD1)
         D FLD3                           5A   OVERLAY(FLD1:*NEXT)

    Line 1: I declared an unnamed data structure.
    Line 2: I declared a subfield named FLD1 of length 1o characters.
    Line 3: I declared a subfield named FLD2 of length 5 characters used the OVERLAY keyword with this subfield and specified FLD1 as the overlaid subfield and the start position defaults to 1. Therefore, FLD2 occupies the storage of FLD1 from positions 1 to 5.
    Line 4: I declared a subfield named FLD3 of length 5 characters and used the OVERLAY keyword with this subfield specified FLD1 as the overlaid subfield and specified *NEXT instead of the start position. Therefore, FLD3 occupies the storage of FLD1 from position 6 to 10 which is available after FLD2 use.

      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  9. Admin
    Admin
    2024-10-06T21:37:34+05:30Added an answer on October 6, 2024 at 9:37 pm

    You can also allocate storage of subfields with Keywords DIM and OVERLAY. Here is an example.

         D                 DS
         D word                          20A 
         D  letter                        1A   DIM(20) OVERLAY(word:1)
          /Free
           word = 'abcdefghijklmnopqrst';
           return;
          /End-Free  

    Explanation of the above source code:

    Line 1: Declared an unnamed DS.
    Line 2: Declared subfield word of length 2o characters.
    Line 3: Declared another subfield letter of length 1 character and used DIM(20) keyword to make it an array of 20 elements and also used OVERLAY keyword with parameter word to allocate storage of subfield word from start position 1.
    Line 4: Start of /Free block so I can write the code in free-form RPG.
    Line 5: Evaluate the DS subfield word as abcdefghijklmnopqrst.
    Line 6: return from the program.
    Line 7: End of /free block using /end-free block to specify the end of writing the RPG-free code.

    Final Outcome:
    Since ds subfield word = ‘abcdefghijklmnopqrst’ therefore, the subsequent subfield letter of length 1 and 20 array elements are overlaid on the word subfield and it would contain:

    > Eval letter
      letter(1) = 'a'
      letter(2) = 'b'
      letter(3) = 'c'
      letter(4) = 'd'
      letter(5) = 'e'
      letter(6) = 'f'
      letter(7) = 'g'
      letter(8) = 'h'
      letter(9) = 'i'
      letter(10) = 'j'
      letter(11) = 'k'
      letter(12) = 'l'
      letter(13) = 'm'
      letter(14) = 'n'
      letter(15) = 'o'
      letter(16) = 'p'
      letter(17) = 'q'
      letter(18) = 'r'
      letter(19) = 's'
      letter(20) = 't'
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  10. Admin
    Admin
    2024-10-06T21:50:20+05:30Added an answer on October 6, 2024 at 9:50 pm

    This can be a good example of defining the OVERLAY keyword in DS.

         D DS1             DS
         D FLD1                           5A 
         D FLD11                          2A   OVERLAY(FLD1:1)
         D FLD111                         3A   OVERLAY(FLD1:3)
         D FLD2                           5A 
         D FLD22                          2A   OVERLAY(FLD2:1)
         D FLD222                         3A   OVERLAY(FLD2:3)
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  11. Admin
    Admin
    2024-10-06T21:49:40+05:30Added an answer on October 6, 2024 at 9:49 pm

    Defining the OVERLAY keyword using *NEXT in DS in free-form RPG:

    DCL-DS *N;
      DCL-SUBF FLD1 CHAR(10);
      DCL-SUBF FLD2 CHAR(5) OVERLAY(FLD1);
      DCL-SUBF FLD3 CHAR(5) OVERLAY(FLD1:*NEXT);
    END-DS;
    
    --Or--
    
    DCL-DS *N;
      FLD1 CHAR(10);
      FLD2 CHAR(5) OVERLAY(FLD1);
      FLD3 CHAR(5) OVERLAY(FLD1:*NEXT);
    END-DS;
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  12. Admin
    Admin
    2024-10-06T21:59:16+05:30Added an answer on October 6, 2024 at 9:59 pm

    You can also look at this example of DS OVERLAY which is complex.

         D wordDS          DS
         D word                          10A   dim(5) 
         D  lastChar                      1A   OVERLAY(word:10)
          /free
           word(1) = 'abcdefghij';
           word(2) = 'klmnopqrst';
           word(3) = 'uvwxyzabcd';
           word(4) = 'efghijklmn';
           word(5) = 'opqrstuvwx'; 
           return; 
          /end-free

    Explanation of the above source code:
    Line 1: Declared a DS named wordDS.
    Line 2: Declared subfield named word of length 10 characters and used DIM(5) keyword to make it an array of 5 elements.
    Line 3: Declared another subfield named lastChar of length 1 character and used OVERLAY keyword with a parameter word to allocate storage of subfield array word from the start position 10 i.e. getting the last character of each array element in this subfield lastChar. Please note that this lastChar subfield is now treated as an array as well since overlaid an array character field.
    Line 4: Start of /Free block so I can write the code in free-form RPG.
    Line 5-9: Evaluate the DS subfield array word elements 1 through 5 with some values.
    Line 6: return from the program.
    Line 7: End of /free block using /end-free block to specify the end of writing the RPG-free code.

    Final Outcome:
    Since the DS subfield array word contains

     > Eval Word
       word of WordDS(1) = 'abcdefghij'
       word of WordDS(2) = 'klmnopqrst';
       word of WordDS(3) = 'uvwxyzabcd';
       word of WordDS(4) = 'efghijklmn';
       word of WordDS(5) = 'opqrstuvwx'; 

    therefore, the subsequent subfield lastChar of length 1 and 5 array elements are overlaid on the word subfield array from position 1o i.e. the last position of each element of the array and it would contain:

     > Eval Word
       lastChar of WordDS(1) = 'j'
       lastChar of WordDS(2) = 't';
       lastChar of WordDS(3) = 'd';
       lastChar of WordDS(4) = 'n';
       lastChar of WordDS(5) = 'x'; 
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp

Sidebar

Statistics

  • Questions 143
  • Answers 177
  • Comments 0
  • Popular
  • Answers
  • Admin

    Why do we use OVERLAY keyword in data structure subfields ...

    • 12 Answers
  • Admin

    How to call sql stored procedure with output parameter from ...

    • 6 Answers
  • Admin

    How to use declare global temporary table statement in RPGLE?

    • 5 Answers
  • Admin
    Admin added an answer CPF4131 is a record format level check error. This indicates… October 18, 2024 at 1:58 am
  • Admin
    Admin added an answer To open the command prompt with administrator rights you can… October 17, 2024 at 12:27 am
  • Admin
    Admin added an answer In AS400, "AS" stands for Application system. This article discusses… October 13, 2024 at 12:49 pm

Related Questions

  • Admin

    what is level check error and how to resolve level ...

    • 1 Answer
  • Admin

    What are AS400 systems. Please provide a introduction of AS400 ...

    • 1 Answer
  • Admin

    Is there any online server available for practicing on AS400 ...

    • 1 Answer
  • Admin

    What are the menus available in AS400?

    • 1 Answer
  • Admin

    What is subsystem in AS400?

    • 1 Answer

Trending Tags

.htaccess (1) as400 (123) bing-webmaster (2) control-language (12) db2 (33) ftp (8) google-adsense (1) google-search-console (3) https-redirect (1) iasp (4) ifs (22) jar (4) operations (3) php-my-admin (1) qshell (3) robots.txt (4) rpg (26) stored-procedure (3) stroed procedure (1) triggers (1) yoast (4)

Explore

  • Home
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags

Footer

BrainChime

BrainChime is a blog that posts question-and-answer-based format articles on diverse topics and engages in discussions by allowing people to provide answers/comments without the need to register and log in.

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • FAQs
  • Categories
  • Tags

© 2024 BrainChime. All Rights Reserved
by BrainChime.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.