How do I break a field out into multiple fields based on type with LANSA?

Date:1 March 2004
Product/Release:LANSA for iSeries
Abstract:How do I break a field out into multiple fields based on type? In RPG I would use a data structure. How do I do this in LANSA?
Submitted By:LANSA Services
Last Review:November 2010

Question:

I am an RPG programmer that is now using LANSA. I have a situation where, if I were using RPG, I would use a data structure. Here is the situation:

Incoming field = INC1 256 character field

I need to break this field out into multiple fields that will differ according to the type of information in the incoming field. In RPG this is how it would be accomplished:

If character 1 in INC1 equals 1, use data structure SC1:

Data structure SC1 is defined like this:

1-256 SC1
1-5 TYPE
6-50 DATAIN
51-200 CITY INFO
201-256 N/A

All I have to do is move INC1 into data structure SC1 and I can use the fields in my program.

Now if character 1 in INC1 equals 2, use data structure SC2

Data structure SC2 is defined like this:

1-256 SC2
1-5 TYPE
6-10 EXCHANGE
11-80 EXCHANGE DATA
81-100 N/A
101-210 REPAIR DATA
211-256 REPAIR NOTES

Now, if I move INC1 into data structure SC2 I would have these fields to use in my program.

I'm sure there must be a fairly simple way to accomplish this in LANSA, I just haven't been able to figure it out. It doesn't appear that DEF_ARRAY will quite do what I need. Can you help me?

Answer:

Instead of using a data structure in RPG, you can use the TO_OVERLAY option when you define the field in LANSA. The TO_OVERLAY parameter is a very powerful facility that allows a field to occupy the same storage (ie: memory locations) as another field. Please review the notes and comments in the "DEFINE Parameters" section of the Technical Reference Guide before using this parameter:

There are many examples that use the TO_OVERLAY option in the LANSA Guides and the SET material available on the Documentation and SET sections on this Web site or the LANSA Encyclopedia CD.

For example:

Firstly, define a 256-character-long field INC1.

For situation #1

  1. Define a 5-character-long field WK_TYPE which is to overlay the field INC1 starting from position 1 TO_OVERLAY(#INC1 1)
  2. Define a 45-character-long field WK_DATAIN which is to overlay the field INC1 starting from position 6 TO_OVERLAY(#INC1 6)
  3. Define a 150-character-long field WK_CITY which is to overlay the field INC1 starting from position 51 TO_OVERLAY(#INC1 51)

For situation #2

  1. Define a 5-character-long field WK_EXCH which is to overlay the field INC1 starting from position 6 TO_OVERLAY(#INC1 6)
  2. Define a 70-character-long field WK_DATA which is to overlay the field INC1 starting from position 11 TO_OVERLAY(#INC1 11)
  3. Define a 110-character-long field WK_RDATA which is to overlay the field INC1 starting from position 101 TO_OVERLAY(#INC1 101)
  4. Define a 46-character-long field WK_RNOTE which is to overlay the field INC1 starting from position 211 TO_OVERLAY(#INC1 211)

Please note the field WK_TYPE can be shared for both situations.

The Search facility in the Global Guide (BeginHere.chm) shows you where your word or phrase is found in every document listed in the Contents. To search only one guide, go to the LANSA Online Documentation Directory and select the document you require.