MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamically allocate the length of a field

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Allenantony
Beginner


Joined: 05 Nov 2006
Posts: 9
Topics: 4

PostPosted: Mon Mar 17, 2008 4:44 pm    Post subject: Dynamically allocate the length of a field Reply with quote

Dear all,

I would like to hear your suggestions on how to dynamically allocate the size of a field in an output record.

Scenario:-

I have a Header Record which has a field named TOTAL-COUNT (which is allocated as PIC ZZZZZZZ9 ). This field needs to be populated with the total count of Detail-Records. I am able to get the count and update the Header record. But my problem happens here... Say for example, the count is 53834. Because of my allocation I am populating a value as XXX53834 where 'X' stands for spaces. Could you please help me to find an alternate way of doing this so that only 53834 is populated into the TOTAL-COUNT field. If you could explain me the same with an example that will be really helpful as I am doing his for the first time. My main concern is how to allocate TOTAL-COUNT with the appropriate PIC value.

Thanks for your helps in advance.

Regards,

Allen
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Mar 17, 2008 5:08 pm    Post subject: Reply with quote

Allenantony,

You simply want to left justify? use Unstring verb and remove the leading space and move the value to a character fields before you print the header line
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Allenantony
Beginner


Joined: 05 Nov 2006
Posts: 9
Topics: 4

PostPosted: Mon Mar 17, 2008 6:07 pm    Post subject: Reply with quote

Hi Kolusu,

Thanks for your reply.

My concern is not with related to justification of the value. I am facing difficulty in dynamically allocating the size vale for the TOTA-COUNT variable. Because the length/size of this value can vary on each run and based on the size of the count I need to allocate a field in the output record, that can hold this retrieved value.

Regards,

Allen
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Mar 17, 2008 7:00 pm    Post subject: Reply with quote

Allenantony,

You dont have to dynamically allocate the size of the header variable. just define it with max and use left justify it using the following code.

Code:


 WORKING-STORAGE SECTION.                                   
 01 WS-INPUT     PIC ZZZZZZZ9.                               
 01 WS-OUTPUT    PIC X(08).                                 
 01 WS-LENGTH    PIC S9(04) COMP.                           
 01 WS-TALLY     PIC S9(04) COMP.                           
                                                             
 PROCEDURE DIVISION.                                         
                                                             
     MOVE 56782 TO WS-INPUT                                 
     INITIALIZE  WS-OUTPUT                                   
                 WS-LENGTH                                   
                 WS-TALLY                                   
                                                             
     INSPECT WS-INPUT TALLYING WS-TALLY FOR LEADING SPACES   
     MOVE WS-INPUT(WS-TALLY + 1 : ) TO WS-OUTPUT             
     DISPLAY 'WS-INPUT  : ' WS-INPUT                         
     DISPLAY 'WS-OUTPUT : ' WS-OUTPUT                       
     GOBACK.                                                 


_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Allenantony
Beginner


Joined: 05 Nov 2006
Posts: 9
Topics: 4

PostPosted: Mon Mar 17, 2008 10:19 pm    Post subject: Reply with quote

Hi Kolusu,

But in my case there are few more fields that will immediately follow the Count Value. Say for example, H0310200812345|BOEING|LOCKHEED where 12345 is the Count Value.

So I dont think I can assign a value,
01 WS-OUTPUT PIC X(08) as given in your example in order to store the Count. Because this will allocate a variable of size 8 and after justification the succeeding values after the Count Value are going to start after the 8th position. Say, H0310200812345 |BOEING|LOCKHEED. But my requirement is that the succeeding values (after the Count value) should start immediately after irrespective of the spaces.

Thanks,

Allen
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Mar 18, 2008 4:10 am    Post subject: Reply with quote

So how does the next program know where one field ends and the next starts?

Anyway, just have one large output field and concatenate your data together before assigning it.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group