Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable length output 1

Status
Not open for further replies.

LUEBBKEVIN

Programmer
Apr 30, 2002
35
US
I'm working on a project to create a file that will be sent to a client (via ftp I suppose).
The output specs I have state that each record can only be a max of 80 char. However the number of required fields easily exceeds 300 char. Each instance may or may not contain data for each field (and they don't want the field if there is no data). Each record will be prefixed with a hex AA so that the client can find the beginning of each new record.

How can I create the output? The hex thing is not a big deal but the variable length output???
 
This gets a bit more involved:

Each field is also variable length. for example a field
call user id will have a prefix of *UserID=
followed by data provided by my program. that data can
be any length (possible from 1 to ???). The way that the client is determining the end of a field apparently is by a combination of a space and * (each field has a prefix associated with it that begins with *).
Right now it appears that I will need to count each character as I load them, keeping track that the count is 80 or less. I can't have wraparound either.
So if anyone has ANY suggestions please let me know.
 
LUEBBKEVIN:

I'm not real clear on what needs to happen on lines > 80, since you said that wraparound isn't allowed. Does that mean that you truncate, start a new line with X'AA' and continue, or what? Also, it appears that they identify each field with "Field=".

The variable length is not an issue. The data format sounds a lot like EDI data. Create a file with two fields, 1 for the X'AA' and 1 for the actual data. Hopefully you are using RPGLE. If so, you can easily construct a data line by using the %Replace function. Here's a simple example that trims the fields & concatenates the delimeters (' *'):
Eval Strpos = %Len(%Trim(Workline)) + 1 'first time=1
If UserID <> *Blanks
Eval Workline =
%Replace('USERID=' + %trim(UserID) + ' *':
Workline:Strpos:Fldlen)
EndIf
Eval Strpos = %Len(%Trim(Workline)) + 1
If Anotherfield <> *Blanks
Eval Workline =
...
...
Do this for every field. The strpos field is determined by the length of the workline you are building. The &quot;fldlen&quot; can be hardcoded, but represents how many characters you are replacing on your workline (in the USERID example, if the trimmed length of USERID is 10, then this value will be 19. You get the idea.

Workline is a text field with a length of (300?), depending on what you need to do with the 80-byte limitation. If you define sub-elements of workline (as 80, and in a array if you wish), you can move these to the data field in your record. When writing these records, you can check the length of these 80-byte elements and only write the record if the trimmed length is > 0. So, if the finished variable record is 142 chars long, you will have two elements with length > 0 (80 & 62), and write two records.

Good luck,
K.Hood
 
each record I process and place into my workfile will contain in excess of 600 bytes of info. I build a send file from this data. According to the specs the file I send has a record length of 80. Where the record I'm writing to the send file exceeds 80 I need to start a new record but cannot divide the prefix from the data in a field.

@ctrl *userid=Rover *usernbr=11111 (to 80)
*userloc=here
@ctrl

the @ctrl would designate to the client the start of a new record in their system.

To make matters a bit more complex, if a field contains no data then they don't want me to send it. So basically each record would be unique based upon content.

I'm sort of kicking around the idea of creating workfields for each required field. In the D spec I would use the keyword varying. Then after checking for content I would use %len to determine if it's 80 or over. If it's ok I'd just write it. Not sure this morning how to handle if it's over 80.
 
LUEBBKEVIN,

You can use the keyword varying, but you will still have to keep track of the total length of the record by combining the lengths of all of your (trimmed) fields. That's why I was suggesting that you &quot;assemble&quot; the record as you go. This way, once you reach a point that will necessitate starting a new line, you can check before adding the next field. For example, if the length of your combined workline is 72 and the length of the field & delimeter you are about to &quot;tack on&quot; is over 8, then write a record and start a new one with the new field.

If there are a lot of fields, you can even setup an array that contains the delimited fields. Then you can do the following:
Eval EL = %Elem(varfield)
Do EL X
If %len(Workline + varfield(X)) > 80
Exsr WriteRec
Clear Workline
Endif
Eval Workline = Workline + varfield(X)
Enddo

If %len(Workline) > 0
Exsr WriteRec
Endif

I'm not sure that var-length fields can be used in arrays - if not replace the 'varfield(X)' with '%trim(varfield(X))', and make sure that WORKLINE is a var-length field. The Varfield(X) will contain 'USERID=SMITH *' for example.


K. Hood
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top