• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Wrapping Free Form Text

    October 31, 2007 Michael Sansoterra


    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 you have the following DDS defined legacy table called ORDCOMT that is designed to store the comments for a customer order:

    Column

    Data
    Type

    Description

    ORDID

    7P,0

    Order Id

    CMTSEQ

    3P,0

    Comment
    Sequence

    CMTTXT

    25A

    Comment
    Text

    In the legacy application, a customer service representative enters the customer’s comments line by line in a green screen where the entry fields are limited to 25 characters. Now you bolt a Web front end on your legacy order entry system, but there is a small problem–who in the Web world wants to enter order comments 25 characters at a time? No one. Typically, Web-based front ends allow the user to type their comment(s) in one large free form box.

    Enter the “WrapText” RPG subprocedure (code is available at the beginning of article). The prototype for the subprocedure is as follows:

    D	WrapText	PR	12288 
    D	UnfText		8192	Varying Const Options(*VarSize)
    D	LineLen		5 	0 Const
    D	LineBreak		10	Varying Const Options(*NoPass)
    

    “WrapText” will receive up to 8K of unformatted text and “wrap” it into multiple lines based on a specified line length. If the free form text allows embedded line break codes (such as carriage return and line feed), the new line indicator can be passed as an optional parameter. The utility will generate new lines automatically when it encounters a line break code.

    The utility returns a fixed length text field (12K) containing pseudo-lines formatted at the specified line length. The calling program will need to process this text field either by overlaying an array of the appropriate element size on the returned data or by parsing the data manually.

    For example, if variable “FmtText” holds the result of the “WrapText” procedure for a line length of 25 characters, you could extract line two from the variable as follows:

    Line2=%Subst(FmtText:26:25);
    

    Or in general, extract any line using variables:

    (LineNo=line to extract, LineLen=length of line):
    AnyLine=%Subst(FmtText:(LineNo-1)*LineLen+1:LineLen);
    

    As an added goodie, I created an SQL table function wrapper, (subprocedure WrapText_TF), that allows “WrapText” to be used by SQL (see code at the beginning of this article for the required CREATE FUNCTION statement to use WRAPTEXT with SQL).

    For example, the following query converts free text into a tabular format, with each wrapped line being assigned its own row:

    Select * 
    From Table(WrapText( 
    'The quick brown fox jumps over the lazy dog',25,'')) A
    

    The result set returned is as follows:

    LINENO	LINETEXT 
    1	The quick brown fox jumps 
    2	over the lazy dog 
    

    Wrapping at 15 characters per line instead of 25, the results are adjusted accordingly:

    LINENO 	LINETEXT
    1	The quick brown
    2	fox jumps over 
    3	the lazy dog 
    

    For one more example, the following sample free form comment has an embedded carriage return and line feed (EBCDIC X’0D25′) that causes an additional break to be inserted:

    Select * 
    From Table(WrapText( 
    'The quick brown fox jumps over'||x'0D25'||'the lazy dog',25,
    x'0D25')) A 
    

    The above query returns the following (including a forced new line after the word “over”):

    LINENO	LINETEXT
    1	The quick brown fox jumps
    2	over 
    3	the lazy dog 
    

    This table function can ease the conversion of free form text into the ORDCOMT DB2 table mentioned above as follows:

    Insert Into OrdComt
    Select :OrdId, LineNo*10 As Seq, LineText
    From Table(WrapText(:Comment,25,X'0D25')) Comments
    

    As a final thought, this utility has other uses. I’ve used it to display free form comments from a database table on the good old fixed width green screen. I’ve also used this utility to wrap computer generated SQL statements into a more readable format (just a warning, this utility is not smart enough to consider constants with embedded spaces as a single “word,” so the wrapping may not occur correctly.) A little imagination can find many uses.

    Michael Sansoterra is a programmer/analyst for i3 Business Solutions, an IT services firm based in Grand Rapids, Michigan. You can email him at the IT Jungle contact page.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    SafeData:  The iSeries HA Solution that’s Guaranteed
    COMMON:  Join us at the annual 2008 conference, March 30 - April 3, in Nashville, Tennessee
    NowWhatJobs.net:  NowWhatJobs.net is the resource for job transitions after age 40

    IT Jungle Store Top Book Picks

    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket Developers' Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    iSeries Express Web Implementer's Guide: List Price, $59.00
    Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    WebFacing Application Design and Development Guide: List Price, $55.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    The All-Everything Machine: List Price, $29.95
    Chip Wars: List Price, $29.95

    Abacus Expands System i Services IBM Brags About Its Power6 Server Shipments

    Leave a Reply Cancel reply

Volume 7, Number 38 -- October 31, 2007
THIS ISSUE SPONSORED BY:

Profound Logic Software
Guild Companies
ARCAD Software

Table of Contents

  • Use PHP to Bring i5/OS Resources to the Web
  • Wrapping Free Form Text
  • Admin Alert: Limiting System i User Sign-ons the Smart Way
  • Controlling System i Shutdown Activities Using an Intelligent Power-Handling Program, Part I
  • Programmatically Import Excel Worksheets Using IBM’s ActiveX Object Library
  • Admin Alert: Remotely Accessing an HMC System Console, Part 2

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle