ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Sub string and break word with different fields

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

  • Sub string and break word with different fields

    Hi, I have encounter issues about sub string with from input and store in destination fields with different field length.

    I have four 35A input fields condition with if character at position 35A of input line 1 is not a space and first character of input line 2 is not space,
    then will move last word of input line field 1 to destination field 2.Same rules will applied to destination field with line 2 ,3,4. It also will prompted error
    after movement input word if the destination fields length no enough long to store total four input fields.

    Scenario 1:
    Code:
    [FONT=courier new]Input 1 35A: |No. 1241,Old Klang road,  Tom Cater| 
    Input 2 35A: |rried ,58785 Windfall Stand  Johnan| 
    Input 3 35A: | Stress bay   White hall     CHIGNA|
    Input 4 35A: |LL ST JAMES                        |[/FONT]
    Expected result store to 4 line destination fields with 40A each of line.
    Code:
    [FONT=courier new]Destination Field 1 40A: |No. 1241,Old Klang road, Tom           |
    Destination Field 2 40A: |Caterrried ,58785 Windfall Stand       |
    Destination Field 3 40A: |Johnan Stress bay   White hall         |- The 'bay  ' world remain 
    Destination Field 4 40A: |CHIGNALL ST JAMES                      |[/FONT]

    Scenario 2:
    Code:
    [FONT=courier new, courier, monospace]Input 1 35A: |No. 1241,Old Klang road,  Tom Cater|[/FONT]
    [FONT=courier new, courier, monospace]Input 2 35A: |rried ,58785 Windfall Stand  Johnan|[/FONT]
    [FONT=courier new, courier, monospace]Input 3 35A: | Stress bay   White hall     CHIGNA|[/FONT]
    [FONT=courier new, courier, monospace]Input 4 35A: |LL ST JAMES TAXES STATES STAND CITY|[/FONT]
    Expected result store to 4 line destination fields with 40A each of line.
    Code:
    [FONT=courier new]Destination Field 1 40A: |No. 1241,Old Klang road, Tom           |
    Destination Field 2 40A: |Caterrried ,58785 Windfall Stand       |
    Destination Field 3 40A: |Johnan Stress bay   White hall         |- The 'bay  ' world with space remain 
    Destination Field 4 40A: |CHIGNALL ST JAMES TAXES STATES STAND CI|- Prompt error msg as the 'TY' no enough fit in the 40 length field  [/FONT]
    Appreciated with any help,Thanks

  • #2
    First, it doesn't help to submit the same post six times. The first one could be edited, though that could take a little experience to see (and might require 'Approval' by a forum moderator). The second one is nicely formatted and the rest were unnecessary.

    Second, it's not clear what your question is. That is, you apparently want words that were input to four 35-char fields to be distributed into four 40-char fields, with "word-wrap". But that's not always possible. Sometimes the words won't fit properly, so you need rules that describe how to handle extreme cases. What are your rules? Also, it seems likely that you want embedded spaces to be compressed. It looks like you point to an example ('bay ') where that doesn't happen, but we can't tell why not because you don't show any code. If we can't see your code, we can't see what might be a problem.

    I don't know if you can show a code sample before the post is 'Approved', so you might even need to post a seventh one.
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      I would concatenate all those strings into one varying length string and then perform word wrapping.

      Pseudo code:
      1. Concatenate strings into one long string.
      2. If position 35 is blank, use position 35.
      3. If position 35 not blank and pos 36 not blank, search back until a blank found.
      4. Substring from 1 to that position, save into array element.
      5. Trim that string from long string, trim leading spaces. Repeat from step 2.
      6. If array element 5 is not blanks, show user error.

      The business side will have to tell you what to do if no blanks are found in all 36 positions, so you don't have to guess what they want.

      Ringer

      Comment


      • #4
        The four 35-char fields might effectively be sub-fields in a DS so that "concatenation" is done automatically. For me, I'd then simply go word-by-word through the "concatenated" value, copying each 'word' with a blank-separator into the 40-char fields. Going word-by-word would handle compressing out multiple spaces.

        The 40-char fields would be elements in a DIM( 4 ) array. When adding a new word to one of the elements would result in breaking a 40-char limit, it'd be time to bump to the first position of the next element.

        But that should be varied according to what the rule is when word-wrap forces a word-break across fields.
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment


        • #5
          Check whether the following article will help:
          Note: The code accompanying this article is available for download here. One common integration problem encountered by those building client/server or Web-based interfaces to a legacy green-screen application is mapping a free form text field into a fixed width field. This tip presents a code segment I wrote to solve this problem. For example, say

          Comment

          Working...
          X