Page 1 of 2

Give me some ideas .. how to solve this problem

PostPosted: Mon Feb 06, 2012 10:20 pm
by deen67
hi there. i need to write a cobol program to split file contains fix part & variable part. the length of file is 10k. 204byte is fix part the rest is var part. the contains of the file some sort like this

CICSJCMIC42DMQ11W6ph5Mm5Pz8GgiULbPgzG37mj9g= 101010180120802500120110805150736CMNOWC01ENF03001N101 ^^CMNOWC01~~CMNOW_REF_NO=1820101010101~CMNOW_CATEGORY=1~CMNOW_NEW_ID=820101010101~CMNOW_OLD_ID=A181814~CMNOW_POLICE_ID=X~CMNOW_ARMY_ID=X~CMNOW_PR_ID=X~CMNOW_CERT_ID=X~CMNOW_STATUS=0~CMNOW_NAME=RAZALIBINAHAMD~CMNOW_ADDRESS1=JALAN1~CMNOW_ADDRESS2=JALAN2~CMNOW_ADDRESS3=JALAN3~CMNOW_POSTCODE=40540~CMNOW_CITY_CODE=0101~CMNOW_STATE_CODE=01

Fix part & var part is separated with '~~'
Column Name & value of the column name is separated with '='. Ex CMNOW_NEW_ID=820101010101
Each Column Name & value separated with '~'. Ex CMNOW_NEW_ID=820101010101~CMNOW_OLD_ID=A181814

My task is, how to split the file into column name/value of the column. what is the best method to solve this?. Already try used UNSTRING but doesn't work because the total column/value is not fix. Maybe can contains 10/15/20 column/value.

Can somebody give me some ideas to solve this problems.

Re: Give me some ideas .. how to solve this problem

PostPosted: Mon Feb 06, 2012 10:34 pm
by deen67
due to i'm not able to edit my post. add additional info

For example
Column name = CMNOW_NEW_ID
the value of this column =820101010101
Column name = CMNOW_OLD_ID
the value of this column =A181814

if column-name = 'CMNOW_NEW_ID'
move '820101010101' to TNOW.CMNOW_NEW_ID
else if column-name = 'CMNOW_OLD_ID'
move 'A181814' to TNOW.CMNOW_OLD_ID
end-if

Re: Give me some ideas .. how to solve this problem

PostPosted: Mon Feb 06, 2012 10:55 pm
by BillyBoyo
Are you saying you have record which can be up to 10k in length, or that your file is 10k (it doesn't matter how much space a file occupies)?

Can you show us your record definition, and be clearer about the problem that you have in using UNSTRING, please.

Re: Give me some ideas .. how to solve this problem

PostPosted: Tue Feb 07, 2012 1:39 am
by enrico-sorichetti
most probably the best way is to use REFERENCE modification

to initialize the whole shebang
scan until You find the ~~ delimiter ( beginning of the new <key name>/<key group > )
unless the first ket starts at a fixed position

scan scan until You find the = delimiter ( end of the <key> name )
scan until You find the ~~ delimiter ( end of the old <key value> value beginning of the new <key name>/<key group > )

Re: Give me some ideas .. how to solve this problem

PostPosted: Tue Feb 07, 2012 7:39 am
by deen67
thanks for the quick reply. got the message data from DFHCOMMAREA.

***** tot length 10K (max) *****
01 message-data.
***** fix part total length 204 *****
05 fix-part.
10 cics-transid pic x(04).
10 cics-reg-code pic x(08).
10 pc-id pic x(50).
10 char branch-code pic x(07).
10 tran-create-id pic x(12).
10 tran-create-date pic x(08).
10 tran-create-time pic x(06).
10 tran-code pic x(08).
10 origin-tran-code pic x(08).
10 txn-mode pic x(01).
10 session pic x(01).
10 channel-code pic x(02).
10 reffered-msg-id pic x(25).
10 reference-no pic x(40).
10 CorrelId pic x(24).
***** var part total length 9796 *****
05 var-part pic x(9796).

remarks.
this var part may contains many column name & its value. maybe 10 colum/10 value or 20 colum/20value.
for example if this var part contain 1 colum/value own-id-no=670319085425. the rest will be fill by spaces.

unstring var-part delimeted by '='
into ws-colum-name1
ws-value1

if use unstring how many ws-colum-name/ws-value need to be declare bcoz we dont know the total colum/value may contains in var-part.

Re: Give me some ideas .. how to solve this problem

PostPosted: Tue Feb 07, 2012 2:55 pm
by BillyBoyo
Just to start with a technicality, you don't have a variable part as far as the field is concerned. You have a fixed field with variable-length content with trailing blanks. In that, it is no different from:

01  some-name PIC X(20).


Which sometimes contains "A=B" and other times "C=D,E=F" and sometimes other combinations.

I am surprised that you have nothing which tells you how many "things" there are. Means if you lose any, you'll never know. Not good.

You can do it with UNSTRING, either if you know how many "things" there are as an absolute maxium, or if you do the UNSTRING in a loop, one group of data at a time. Things do get to look a little cluttered the first way, and lots of UNSTRINGs the second way.

Other possibilities are the REFERENCE MODIFICATION already mentioned by enrico. If you go this way, choose very good names, as reference modification can be a shortcut to obscure code.

And Occurs Depending On.

Find out from your colleagues/maintenance/application support how they would prefer it, because they (and you) are going to be the ones dealing with the code in the future. It is a team effort, not a whole bunch of individuals coming up with individual solutions.

Re: Give me some ideas .. how to solve this problem

PostPosted: Tue Feb 07, 2012 5:11 pm
by Nik22Dec
Not sure how feasible it would be in your case but, have you considered using SORT Parsing function for the same. It might give you a better way of arranging your file & then the cobol program can simply read it as a normal PS file.

Re: Give me some ideas .. how to solve this problem

PostPosted: Tue Feb 07, 2012 5:54 pm
by BillyBoyo
deen67, are you processing a file of what was DFHCOMMAREA or are you doing it in CICS?

Re: Give me some ideas .. how to solve this problem

PostPosted: Tue Feb 07, 2012 9:54 pm
by ronners
read a record
do while not end-of-file
/* process the record */
process the fixed part
determine the position of the remainder (the variable part) of the record
do while the remainder <> spaces
find the end of the keyword=value (the next ~ char or last non-blank)
find the 'equals' sign
/* now you know where and how long your keyword and value are */
process your keyword and value
determine the position of the remainder (the variable part) of the record
end
read a record
end

This is called a read-ahead loop. You read before doing a loop, and in the loop you process the record. At the end of the loop you read the next record.

You seen there's a similar do-loop construct to process the variable part of the record. Happy coding.

Re: Give me some ideas .. how to solve this problem

PostPosted: Wed Feb 08, 2012 5:03 am
by BillyBoyo
Welcome to the forum.

When replying to a request, it is good to have read the request and address your response to it. The TS is having trouble with the "find" part, for which you have supplied no elaboration. If you had read the contributions already made, you'd see that you add nothing to what enrico has already suggested, and, unlike him, provide no method for the "find" part.

You have gone to the bother of formatting your pseudo-code, and then not gone to the bother of preserving the formatting. Here is what your code looks like:

ronners wrote:
read a record
do while not end-of-file
  /* process the record */
  process the fixed part
  determine the position of the remainder (the variable part) of the record
  do while the remainder <> spaces
    find the end of the keyword=value (the next ~ char or last non-blank)
    find the 'equals' sign
    /* now you know where and how long your keyword and value are */
    process your keyword and value
    determine the position of the remainder (the variable part) of the record
  end
  read a record
end


This is called a read-ahead loop. You read before doing a loop, and in the loop you process the record. At the end of the loop you read the next record.

You seen there's a similar do-loop construct to process the variable part of the record. Happy coding.


If you want to see how it is done, press the Quote button on this reply. You can code the tags by hand, or use the buttons above the input box of the full editor.

It is not a "read-ahead loop". It is a while-loop. Any attempt to process a record without reading it first would end in failure. That is all you have done, read the record to be processed before processing it. That process doesn't need a "name".

"read-ahead", as I think most people would use it, is when you read a record and it tells you (key change, some indicator, whatever) that you have to now process the record(s)/data that you have stored for that very purpose. Once all that is done, then you deal with the new record (probably storing it or data from it) and read again looking for a subsequent record which will tell you to again process the new set of data that has been stored from previously read records. Always remember that EOF is also going to tell you to finish processing what you have stored.

You might find it picky of me, but your second "determine the position.." is identical to the first. Taken literally (which is what we, and computers, tend to do with code) you have an infinite loop. Here you can only mean one thing, the "new position", but in other code examples the meaning may not be clear. If you are going to post code (after ensuring that it is something addressing the actual problem) then it should be "working" code, even if pseudo-code (ie not open to misinterpretation).