how to add a number of blank-spaces in free-format RPG

My requirement is: I need to concatenate different fields having different values into the flat-string(blank initially), separated by a number of blanks(spaces), which may vary from field to field.
for e.g.
MyStr = 'FIRST_NAME LAST_NAME 20060101 STREET1 CITY11 STATE111 ... ' and so on
where MyStr = Flat String, FIRST_NAME, LAST_NAME, 20060101 etc., are my field-values which i need to concatenate to MyStr.
please note that FIRST_NAME & LAST_NAME are seperated exactly by 10-spaces and LAST_NAME & 20060101 are seperated exactly by 5-spaces, STREET1 & CITY11 are seperated exactly by 3-spaces etc., which will vary fld to fld.
Iam using free-format RPG & if I use a work var to loop through & concatenate each field as below
WrkStr = ' ';
Loop;
WrkStr = WrkStr + Fname;
End-Loop;
MyStr = WrkStr;
and when i finally move this WrkStr into Mystr as above, to my surprise i don't see anything in MyStr(i.e. it's blank). Iam not getting what to do.
Please help.
Thanks in Advance

Answer Wiki

Sorry Guys, Here above, Iam unable to show the number of spaces the fields are separated by, as it is taking only 1 space, when i save, no matter how many spaces i give.
pls. assume that the fields are seperated by those no. of spaces as mentioned in the question. …Thanks

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your response...

Discuss This Question: 8 &nbspReplies

There was an error processing your information. Please try again later.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

...when i finally move this WrkStr into Mystr as above, to my surprise i don't see anything in MyStr(i.e. it's blank).
We need to see the definitions of WrkStr, Mystr and Fname in order to guess.
To preserve spaces, surround the RPG instructions with the "code" and "/code" tags from the selections above the entry box.
Tom

As in your previous question, I can't see why you don't create a data structure that positions your fields exactly the way you want them.
However, Littlepd probably provided the technical answer to this problem. The reason is that WrkStr has some length attribute, we'll say 100 bytes. It starts with a value of all blanks. You then execute this statement:

WrkStr = WrkStr + Fname;

That statement takes the 100 blanks from WrkStr and concatenates the characters from Fname to it. If Fname is 20 bytes long, the resulting value is 120 bytes long (100 + 20). Then those 120 bytes are assigned to WrkStr again.
But since WrkStr is only 100 bytes long, only the first 100 bytes can fit in WrkStr. And the first 100 bytes are all blanks.
By using %TRIM() or %TRIMR(), the previous blanks are trimmed before Fname is concatenated. That allows Fname to be put into the first bytes of WrkStr.
Note that this trimming will happen every time through the loop. The trailing blanks will be removed each time. If you need an exact number of blanks between each field and you insist upon concatenating, you will need to include the exact number of blanks each time. For example:

You can use a variable to choose a substring length if different lengths are needed between fields. Note that you can do this in a loop, but you'll probably need to set WrkStr to the value of your first sub-field before the loop.
This question has become different from your previous one. In this one, the sub-fields are separated by an exact number of spaces and different sub-fields are separated by different numbers of spaces, which makes very little sense to me. Do you need each sub-field trimmed and then a fixed number of spaces after it?
Tom

Guys, I apologize for late reply.
LittlePD,
Thanks very much for the reply.
Tom,
Thanks a lot for the reply
As u said ..."Do you need each sub-field trimmed and then a fixed number of spaces after it?"
Yes Tom!
You are exactly right. I need it this way only. pls. let me know.

That kind of makes it easier to see exactly how many spaces are needed between each sub-field. You would define myBlanks to be at least as long as the longest set of blanks that you needed. I chose 50 bytes because I didn't know what the maximum should be. The longest that you mentioned was only 10 bytes, so that might be enough.
But be aware that this will not make it easy for another program to access the sub-fields in any kind of data structure. It will make it more difficult for another program to handle the data. So far, it's not making sense to do this.
Tom

Just a note, My method will figure out automatically exactly how many blanks you need inserted in front of the word no matter how long or short the word is, each and every time. all you have to do is initialize the field with a value. it does so by taking the (field size - portion used) = unused amount of spaces. Then Adds unused spaces to the beginning of the initialized value making a full variable. unless the field's value will be the same length everytime, in that case, shorten your field

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your reply...

Ask a Question

Free Guide: Managing storage for virtual environments

Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!

To follow this tag...

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy