Varying length fields in a data structure

25 pts.
Tags:
AS/400
RPGLE
So I’m not sure if this has been asked before but cannot seem to find the information anywhere. I am wondering if it is possible to create a data structure that has trimmed Vars within the data structure. I'm looking to create a data structure like below.
dTest_ds
ds

dTestF1                          6    Inz('TEST (')

dTestF2                        10

dTestF3                          5    Inz(')')
The if I set TESTF2 to ‘HELLO’ and eval Test_ds to a field (Char(100)) the result of the field is “TEST(HELLO)” and not  “TEST(HELLO     )” Any thoughts?


Software/Hardware used:
RPGLE,AS400,iSeries,IBMi
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 4  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.
  • bvining
    My thought is that there's something you're not telling us (though not intentionally).

    Below is a test program based on what you said (as I couldn't believe what you were saying really happened :)) and then the results of a debug eval after the assignment to TestFld. You'll see that the trailing blanks are there.

    d Test_ds         ds                                    
    d  TestF1                        6    inz('TEST (')     
    d  TestF2                       10                      
    d  TestF3                        5    inz(')')          
                                                            
    d TestFld         s            100                      
                                                            
     /free                                                  
                                                            
      TestF2 = 'HELLO';                                     
      TestFld = Test_ds;                                    
                                                            
      *inlr = *on;                                          
      return;                                               
                                                            
     /end-free                                             
     
    > EVAL testfld                                                            
      TESTFLD =                                                               
                ....5...10...15...20...25...30...35...40...45...50...55...60  
           1   'TEST (HELLO     )                                           ' 
          61   '                                        '                  
     

    Bruce Vining
    7,070 pointsBadges:
    report
  • MikeKnight
    Hi Bruce,

    Sorry i was not clear.

    I am looking for a way for test field to end up as TEST(HELLO) and not have the trailing blanks.

    Let me show you a more practical example and maybe you will see my reasoning.

      //  Data Structures                                        
    dSendMsg          ds                                         
    DSendMsgP1                      12    Inz('SNDMSG MSG(''')   
    DMessage                       400                           
    dSendMsgP2                       9    Inz(''') TOUSR(')      
    dUser                           10                           
    DSendMsgP3                       1    Inz(')')                

    now setting Message to your message. E.G. "Hello my name is Michael'

    And User to the user you want to receive the message.

    you could Execute the command SendMsg but the user would receive a message with about 380 trailing blank spaces. 

    And i know I could just do the following in Control.

    CommandString = SendMsgp1 + %trim(Message) + SendMsgp2 + %trim(User) + SendMsgP3

    But i am looking for a neater way of doing it Thus the DS 

    Michael Knight.
    25 pointsBadges:
    report
  • bvining
    Your example of building the CommandString variable is just what I would do in a similar situation (well, other than defining the fields as standalone fields rather than data structure subfields).

    In the data structure example you have defined SendMsgP2 such that it is going to be starting at position 413 of SendMsg and continue for a length of 9 bytes (period). There's no magic (I'm aware of anyway) to have SendMsgP2 "float" behind Message other than through run time concatenation such as you're doing with CommandString.

    Bruce Vining
    7,070 pointsBadges:
    report
  • MikeKnight
    Thanks, But yes it is that "Magic" i was looking for.

    I would normally define them as standalone fields was just using the example provided. 

    Thanks so much for you input.
    25 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.

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

Following

Share this item with your network: