View previous topic :: View next topic
|
Author |
Message |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, it would have been nice to know that up front.
What exactly are you trying to do in your program? I don't understand from what you have said so far why you don't know how many fields you have. In your latest example you have limited both the string size and the number of fields. How does that work with what you are now saying?
From what you have said up to this point, I'd not use UNSTRING, but tell us what you are really trying to do (forget the programming-speak, tell us in words). |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
TS would prefer to loop thru UNSTRING and STRING statements,
than to do one UNSTRING
loop thru the populated,
finding the unpopulated,
populating the the unpopulated with the new stuff to be appended
and then do one STRING.
another example of a solution looking for a problem. |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Morning Guy's !
I would think, unstring with the use of pointers and count would easily solve the problem of separating the data in the whole input record.
This handling should nicely be packaged in a loop over the record until max-recsize is reached, or something like this.
To handle the number of bunstringed data, plse use the tallying option. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Manas Mazumder wrote: |
[...]
Code: |
WORKING-STORAGE SECTION.
01 WHOLE-RECORD PIC X(1000).
01 NAMEX PIC 9.
01 POS PIC 9(4) COMP.
01 OUT-REC.
02 VAR1 PIC X(100).
02 OUT-DATA OCCURS 100 PIC X(30).
01 OUT-POOS PIC 9999.
01 I PIC 9999.
PROCEDURE DIVISION.
* DISPLAY SPACES AT 0101.
MOVE 1 TO POS.
MOVE 'FIRST_NAME|MIDDLE_NAME|LAST_NAME|AGE|DEPT
- '|SEX|NATIONALITY|SALARY|CONTAC_No|'
TO WHOLE-RECORD.
MOVE 1 TO NAMEX.
MOVE 0 TO OUT-POOS
PERFORM 001-PARA UNTIL NAMEX = 0
PERFORM PRT-PARA VARYING I FROM 1 BY 1 UNTIL I > OUT-POOS.
STOP RUN.
PRT-PARA.
DISPLAY OUT-DATA(I).
001-PARA.
MOVE 0 TO NAMEX
UNSTRING WHOLE-RECORD
DELIMITED BY "|"
INTO VAR1
WITH POINTER POS ON OVERFLOW
MOVE 1 TO NAMEX.
IF NAMEX = 1
ADD 1 TO OUT-POOS
MOVE VAR1 TO OUT-DATA(OUT-POOS)
DISPLAY 'VAR1: ' VAR1. |
[...] |
Manas,
You have got yourself to a solution. If you do want to continue that way, pay close attention to what UmeySan has said (Hi UmeySan!). That means doing everything properly. If you only have a table which can store 30 items, make sure you don't exceed 30 and start stamping on the rest of your program. If you are unstrining to 100 bytes, don't then chop them down to 30 unthinglingly. Why use a numeric for your flag? PIC X, and arrange it so you don't have to set it to an illogical value just to get into your perform. Etc.
One problem that you may face is the "trailing" "pipe". It is unusual in a delimeted record to have a trailing delimeter. There is a danger that someone "fixes" this without telling you. If you are going to rely on a trailing delimeter, you are going to have to check that you actually have one! (This is the same for any condition in any program that you rely on).
Also, with the trailing pipe, if there is the "null" that you originally mentioned, your final field (which you have not emulated in your test), will consist of the "null".
Although there is a certain "neatness" to the correct implementation of your approach, I still prefer the "use UNSTRING once" approach. It does look uglier, but that is the fault of the syntax.
INSPECT TALLYING can tell you how many delimiters you have. Get the input file sorted out. UNSTRING all at once, and deal with the field starting with a null, like checking it is the last, etc. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
just a side note:
get into the habit of always using GOBACK instead of STOP RUN.
you will avoid to problem of RUN-UNIT Termination from a sub-module. |
|
Back to top |
|
|
Manas Mazumder
New User
Joined: 25 Jan 2011 Posts: 10 Location: Kolkata(India)
|
|
|
|
Thanks all of you for your valuable instructions.
Defiantly I must follow these things.
Regards,
Manas |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Manas Mazumder wrote: |
Thanks all of you for your valuable instructions.
Defiantly I must follow these things.
Regards,
Manas |
Is that defiantly or definitely? Either way, good luck. Let us know. |
|
Back to top |
|
|
|