View previous topic :: View next topic
|
Author |
Message |
gauravgupta01
New User
Joined: 29 Nov 2007 Posts: 10 Location: Delhi
|
|
|
|
Hi,
I have a problem where in I need to pack an alphanumeric string to save some space.
For example the below string -
Code: |
ABCDEF
CCCCCC
123456
|
I need to convert it in -
Is this kind of conversion possible in cobol? Keeping in mind that I can use upto A to F alphanumeric characters.
Any help would be much appreciated. |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
Hello,
Are you really asking a COBOL program to compress a data set, so you can save some spaces?
or
Do you want to convert a string to another based on some logic ? |
|
Back to top |
|
|
gauravgupta01
New User
Joined: 29 Nov 2007 Posts: 10 Location: Delhi
|
|
|
|
Hi Suresh,
I am just looking to compress the data to save space. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It can be done, of course. It would seem unlikely that you have sufficient quantity of text with only A-F to make it worthwhile. Perhaps if you explain fully what is going on you can get some suggestions. |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
You can use 'Z' command in front of the data set in 3.4 option.
or
Code: |
Data Set List Actions
Data Set: dataset.name.here
DSLIST Action
1. Edit 14. Print Index
2. View 15. Reset
3. Browse 16. Move
4. Member List 17. Copy
5. Delete 18. Refadd
6. Rename 19. Exclude
7. Info 20. Unexclude 'NX'
8. Short Info 21. Unexclude first 'NXF'
9. Print 22. Unexclude last 'NXL'
10. Catalog 23. SuperC 'SC'
11. Uncatalog 24. SuperCE 'SCE'
12. Compress 25. Search-For 'SF'
13. Free 26. Search-ForE 'SFE'
|
choose option 12 for compress.
Is that different from what are you looking for? |
|
Back to top |
|
|
steve-myers
Active Member
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
|
|
|
|
sureshpathi10 wrote: |
You can use 'Z' command in front of the data set in 3.4 option. ... |
The Z option in ISPF DSLIST is intended to "compress" PDS data sets.
While you are in ISPF EDIT, there is a PACK option that will "compress" the data when it is saved. However, once the data set has been saved, its contents are effectively unreadable by other programs unless they know how to expand the data to its original format. The ISPF edit PACK option performs what is known in the trade as a "run length encoded" compression; for typical text data the "packed" data set is roughly 1/2 the size of the source data set.
The compression you originally proposed will cause the source data to be unreadable. |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
Thanks Steve... I didn't know this trick.
Here is what I found out with HELP
Code: |
TUTORIAL ----------------- EDIT - 'PACK' COMMAND --------------------- TUTORIAL
COMMAND ===>
Use the PACK command to turn PACK mode on or off ("on" is the default) and
save the mode setting in the edit profile. If PACK mode is on when the
data is saved (via a SAVE or END command), the data will be written to the
disk in "packed" format. If PACK mode is off the data will be written in
standard format.
Command ===> pack data will be "packed" when written
(back) to the library or file.
Command ===> pack off data will be written in standard
format.
Packed data is automatically "unpacked" when read in for editing. Whether
or not the data is stored in packed format is transparent to you while
editing data (except as indicated by the profile lines).
Packing of data is intended to save DASD space.
SCLM supplied parsers do not recognize packed data. PACK mode must be off
when data is saved in order for SCLM supplied parsers to generate accurate
statistics.
|
But it showing ("on" is the default) ? |
|
Back to top |
|
|
steve-myers
Active Member
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
|
|
|
|
sureshpathi10 wrote: |
... But it showing ("on" is the default) ? |
When you enter PACK as a primary command the effect is the same as PACK ON. I'm pretty sure that's what the meaning of the help text you copied here.
ISPF PACK is not often used because it renders the data unusable to most other programs.
Several years ago there was talk about eliminating it, but that talk died away shortly afterwards. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
before PACKING things
ask the powers of Your organization ...
a packed anything might break the current behavior of some/few/many JCLs |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
Hi Steve,
When 'PACK' is already on as it is given default... there is no use of using it again rt?
So gauravgupta01 can not use this command for his requirement. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Neither compressing nor packing will do what is wanted.
Possibly a better explanation of the data will help someone provide help.
What kind of data would have alpha fields that only had values from A thru F? |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
Yeah Dick, You are right....
as far as I know, only Hex values would be 0..9..A...F |
|
Back to top |
|
|
gauravgupta01
New User
Joined: 29 Nov 2007 Posts: 10 Location: Delhi
|
|
|
|
Hi All,
Thank you so much for taking time out and helping me. Actually pack is not the option I was looking for since this would render my code unusable. What I am looking is to pack a specific variable.
I have a task to convert an assembler program into a cobol one and PACK is one of the commands being used in there to pack the variable (I believe they must have done it to save some register space) however the logic has been built around the packed parameter and would require changes to a lot of places hence I was looking for an option in cobol which would do this conversion. |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
Are you planning to store these values after conversion, like in a table or file ?
Anyway, As you mentioned in the example.
Your input is:
your expecting output is:
This reminding me of converting HEX to CHAR. You must consider every two Characters as a HEX value and convert into CHAR.
You can search thru internet for "how to convert HEX to CHAR in cobol", you may get many examples. if you can't find any, we will help you out.
Hope this helps |
|
Back to top |
|
|
gauravgupta01
New User
Joined: 29 Nov 2007 Posts: 10 Location: Delhi
|
|
|
|
Agreed with hex conversion but how to push the hex value in a nibble is the problem i am thinking. |
|
Back to top |
|
|
gauravgupta01
New User
Joined: 29 Nov 2007 Posts: 10 Location: Delhi
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You have not yet explained just what this data is.
Long ago (40+ yrs) when i used the PACK instruction it was for taking a zoned decimal number and putting the value in a packed decimal field. Currently the bible (Principles of Operations) says the same thing.
So i am lost with this request/requirement
If you explain what is in the field and the rules for the content of the field, someone here will be able to help. |
|
Back to top |
|
|
gauravgupta01
New User
Joined: 29 Nov 2007 Posts: 10 Location: Delhi
|
|
|
|
The input data is containing numeric as well as alphanumeric characters. Digits can be 0-9 and Alphanumeric can be A-F. Since it was a fairly large x(256) variable hence it was being compressed in a packed format to be contained in X(128) variable. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
This still does not explain why/how there is a data field that contains only 0-9, A-F. What kind of data is this?
I have never seen a "data field" that is limited to that set of values. What are the other fields in the record? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Here's a COBOL sub-program (CHAR2HEX), which will convert from 01 to 30 Bytes of Display-Numeric and Letters A-F into a packed-format.
The compiler option ARITH(EXTEND) must be specified during compilation (as illustrated).
So, for example, you pass a value of '0123456789ABCDEF' in the 31-position character (display) parm (ensure it's padded with low-order EBCDIC zeros), it will be returned in the packed-decimal parm as XL16'0123456789ABCDEF000000000000000F'.
Code: |
CBL LIST,NOOFFSET,OPT(FULL),NOTEST,TRUNC(OPT),ARITH(EXTEND),FLAG(I,I)
IDENTIFICATION DIVISION.
******************************************************************
*----------------------------------------------------------------*
* *
* THIS SUB-PROGRAM IS 'CALLED', PASSING THE FOLLOWING - *
* *
* 03 WS-CHAR2HEX PIC X(08) VALUE 'CHAR2HEX'. *
* 03 WS-CHAR2HEX-PARM-REC. *
* 05 WS-CHAR2HEX-PARMIN-X. *
* 07 WS-CHAR2HEX-PARMIN *
* PIC 9(18). *
* 07 FILLER PIC X(13). *
* 05 WS-CHAR2HEX-PARMOUT-X. *
* 07 WS-CHAR2HEX-PARMOUT *
* PIC 9(16)V9 PACKED-DECIMAL. *
* 07 FILLER PIC X(07). *
* 05 WS-CHAR2HEX-RETURN-CODE *
* PIC 9(02). *
* *
* CALL WS-CHAR2HEX USING WS-CHAR2HEX-PARM-REC. *
* *
* THE VALUE PASSED IN 'PARMIN-X' MUST BE LEFT-JUSTIFIED, UP *
* TO 30-BYTES. BYTE-31 IS USED BY THIS SUB-PROGRAM AS A *
* 'GARBAGE' BYTE AND WILL BE OVERWRITTEN. *
* *
* MOVE ZERO TO WS-CHAR2HEX-PARMIN-X. *
* MOVE '0123456789ABCDEF' TO WS-CHAR2HEX-PARMIN-X (1:16). *
* *
* AFTER THE 'CALL', THE 'PARMOUT-X' VALUE WILL BE - *
* XL16'0123456789ABCDEF000000000000000F' *
* *
* NOTE: ALL NUMERICS MUST BE DEFINED _WITHOUT_ A SIGN. ALSO, *
* THIS SUB-PROGRAM MUST BE COMPILED, USING THE ARITH(EXTEND) *
* COMPILER OPTION, AS NOTED IN THE 'CBL' CARD. *
* *
*----------------------------------------------------------------*
******************************************************************
PROGRAM-ID. CHAR2HEX.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 LS-CHAR2HEX-PARM-REC.
03 LS-DISPLAY-X.
05 LS-DISPLAY-V9 PIC 9(30)V9.
03 LS-PACKED-X.
05 LS-PACKED-V9 PIC 9(30)V9 PACKED-DECIMAL.
03 LS-RETURN-CODE-X.
05 LS-RETURN-CODE PIC 9(02).
PROCEDURE DIVISION USING LS-CHAR2HEX-PARM-REC.
MOVE ZERO TO LS-DISPLAY-X
(LENGTH OF LS-DISPLAY-X:).
*
MOVE 1 TO TALLY.
MOVE ZERO TO LS-RETURN-CODE-X.
*
PERFORM UNTIL TALLY > LENGTH OF LS-DISPLAY-X
IF (LS-DISPLAY-X (TALLY:1) NOT < ZERO
AND LS-DISPLAY-X (TALLY:1) NOT > '9')
OR (LS-DISPLAY-X (TALLY:1) NOT < 'A'
AND LS-DISPLAY-X (TALLY:1) NOT > 'F')
NEXT SENTENCE
ELSE
MOVE ZERO TO LS-DISPLAY-X (TALLY:1)
IF LS-RETURN-CODE-X = ZERO
MOVE TALLY TO LS-RETURN-CODE
END-IF
END-IF
ADD 1 TO TALLY
END-PERFORM.
*
INSPECT LS-DISPLAY-X CONVERTING 'ABCDEF'
TO X'FAFBFCFDFEFF'.
*
MOVE LS-DISPLAY-V9 TO LS-PACKED-V9.
MOVE LS-RETURN-CODE TO RETURN-CODE.
*
GOBACK.
|
|
|
Back to top |
|
|
|