View previous topic :: View next topic |
Author |
Message |
Allenantony Beginner
Joined: 05 Nov 2006 Posts: 9 Topics: 4
|
Posted: Mon Mar 17, 2008 4:44 pm Post subject: Dynamically allocate the length of a field |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Mar 17, 2008 5:08 pm Post subject: |
|
|
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 |
|
 |
Allenantony Beginner
Joined: 05 Nov 2006 Posts: 9 Topics: 4
|
Posted: Mon Mar 17, 2008 6:07 pm Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Mar 17, 2008 7:00 pm Post subject: |
|
|
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 |
|
 |
Allenantony Beginner
Joined: 05 Nov 2006 Posts: 9 Topics: 4
|
Posted: Mon Mar 17, 2008 10:19 pm Post subject: |
|
|
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 |
|
 |
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Mar 18, 2008 4:10 am Post subject: |
|
|
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 |
|
 |
|
|