Subscribe to keep this site alive! Under new management but as always, still 100% FREE. Anyone with the IBM i is a friend of ours.
The Challenge: How do I split and post a 1024 long text (MTX Segment) to several records in a file to a field only 256 bytes long?
VariatIion: Only post empty portions when the succeeding portions are non-blank.
The Solution (Main):
Determine the field size to contain the split message. Let say it will be 256 long.
Create 4 work fields 256 long (1024 divided by 256 = 4). The work field length should be the same as the field size in your target file. (MTX2561, MTX2562, MTX2563, MTX2564).
Add the target file to the UFD with a record ID easily recognizable, let us say: H11.
Add the same target file to the UFD with another record format until you achieve as many as the number in #2 (H12, H13, H14).
Create a record association on the MTX segment to the H11 record ID - as primary and the other three as secondary.
The Strategy (Main): You can not instruct the software to make the three extra writes to the file. There is only one way to instruct an add-a-record to a file, that is via record association. By this, you are concurrently adding 1 record for each of the 4 files with a different portion of the text read.
Mapping instructions, when reading the MTX segment:
Substring the four 256 sections to their corresponding work fields.
Map the work fields to the corresponding record ID-common field.
If a sequence number is needed to be posted to a field, this can be achieved by mapping a constant relative to the position of the portion being posted. (1-256 will have 1, 257-512 will have 2 etc.)
The Solution (Variation):
Determine the field size to contain the split message. Let say it will be 256 long.
Create 4 work fields to contain the sections of the text: 256 long (1024 divided by 256 = 4). The work field length should be the same as the field size in your target file. (MTX2561, MTX2562, MTX2563, MTX2564).
Create 3 more work fields to contain trailing data:
One with the length of the remaining/Trailing Data from position 257 to the end (TRL2 - length 768).
One with the length of the remaining/Trailing Data from position 513 to the end (TRL3 - length 512).
One with the length of the remaining/Trailing Data from position 769 to the end (TRL4 - length 256).
Define condition on the Trailer Data work fields for NON <Blanks>.
Add the target file to the UFD with a record ID easily recognizable, let us say: H11.
Add the same target file to the UFD with another record format until you achieve as many as the number in #2 (H12, H13, H14).
Create a record association on the MTX segment to the H11 record ID - as primary and the other three as secondary.
The Strategy (Variation): You can not instruct the software to make the three extra writes to the file. There is only one way to instruct an add-a-record to a file, that is via record association. By this, you are concurrently adding 1 record for each of the 4 files with a different portion of the text read. The record is added when the first mapping instruction is executed. Hence, if you condition all the mapping instructions for a certain record ID; there will be no record added for that record ID when the condition is NOT met.
Mapping instructions, when reading the MTX segment:
Substring the four 256 sections to their corresponding work fields.
Map the Trailing Data as described in#2.
Map the work field MTX1256 to the field in H11 unconditionally.
Map the work fields MTXx256 to the corresponding field in H1x conditionally when TRLx is not blank.
If a sequence number is needed to be posted to a field, this can be achieved by mapping a constant relative to the position of the portion being posted. (1-256 will have 1, 257-512 will have 2 etc.)