how to add a no. of blank-spaces in RPG/RPGLE

560 pts.
Tags:
AS/400
RPGILE
Dear all AS/400 Lovers! I need to add a pre-determined number of blank-spaces to each field, before adding it to a big flat-string. I need to keep on concatenating different field-values to this big string. But the field-values comes as "trimmed" values. (i.e. in a 60-char-length address field, I may receive only 15-char address). Hence i cannot concatenate them directly & send it. My requirement is: I need to pass the exact-length of each field into the flat-string, or else the data will get jumbled OR moved in hapazzard-way, as it is finnally moved into a Datastructure. Any suggestion would be of great help. pls. let me know. Thanks in advance, Svanky

Software/Hardware used:
AS/400, OS/400

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try to run this small pgm in debug-mode, and you will see that inputfields are positioned as requested. Constant ‘AB’ in from pos 1, ‘Ajax Inc.’ with startpos 3, ‘Somewhere Road’ with startpos 33 etc.
<pre>
d f1 s 30 inz(‘Ajax Inc.’)
d f2 s 15 inz(‘Somewhere Road’)
d f3 s 20 inz(‘Anytown’)
d longfield s 1024
c/free
%subst(longfield : 1) = ‘AB’;
%subst(longfield : 3) = f1;
%subst(longfield : 33) = f2;
%subst(longfield : 48) = ‘xx4711′;
%subst(longfield : 61) = f3;
*inLR = *on; </pre>
I hope this helps.
DanF

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
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
  • TomLiotta
    (i.e. in a 60-char-length address field, I may receive only 15-char address) It's not clear what you mean by using the word "receive". Receive how? Please show an example of "receiving" a field. Tom
    125,585 pointsBadges:
    report
  • svankipu
    Tom, "Receive" - means, I receive another flat-string(which is not of exact length of that of target-string, which i need to create) which i break down into different fields & receive them in respective work-fields. and finally concatenate them to create the "Final-String" to be sent. here is the catch:-.. But while sending, I need to pass the exact-length of each field into the flat-string, or else the data will get jumbled, as this string will be finally moved into a Datastructure in another program, which i dont have control on. Thanks, Svanky.
    560 pointsBadges:
    report
  • Teandy
    which i break down into different fields & receive them in respective work-fields. Make your work fields the same size as those needed in the final string, then concatenate them together to create the final string.
    5,860 pointsBadges:
    report
  • Splat
    DanTheDane has the best solution; it's a technique I've used to good effect.
    7,055 pointsBadges:
    report
  • TomLiotta
    Since the other program will use a DataStructure to access the fields, why not simply use the same DS definition in your program? Pass the DS as the parameter after you put the values in. Tom
    125,585 pointsBadges:
    report
  • Littlepd
     d f1              s             30    inz('Ajax Inc.')     
     d f2              s             15    inz('Somewhere Road')
     d f3              s             20    inz('Anytown')       
     d longfield       s           1024                         
     d space         s               1   inz(' ')
     c/free                                                     
             longfield = 'AB' + space + 
                           f1+ space +
                           f2 + space +
                           'xx4711' + space +
                           f3;                       
       *inLR = *on;       
    1,130 pointsBadges:
    report
  • TomLiotta
    A modified example using a DS to specify "exact lengths and positions":
         d myDS            ds
         d f1                            30    inz('Ajax Inc.')
         d f2                            15    inz('Somewhere Road')
         d f3                            20    inz('Anytown')
    
         d longfield       s           1024
    
          /free
                  longfield = myDS ;
                  *inLR = *on;
          /end-free
    If you need exact lengths and positions. then simply code them the way they need to be. It might even be simpler coding of the C-specs if longfield was defined as *BASED over the DS (or vice versa). Then it wouldn't even need to be in an assignment statement to copy the DS. Or simply pass the DS in place of longfield. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

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

REGISTER or login:

Forgot Password?
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

Thanks! We'll email you when relevant content is added and updated.

Following