I need to create and write normal text files in the USS filesystem from an HLASM program. Unfortunately, I cannot use BPX1OPN/BPX1WRT for some reason. The OPEN/PUT macros are my only option.
I need to create "normal" text files --- lines are in different lengths and ended with the new-line character. However, using the PUT macro, I can only create files similar to the PS dataset with fix-length records, which makes the lines in the text file have the same length and padded with spaces.
My question is that how I can create text files in the USS just like created by the C funtions fopen/fputs.
I hope I managed to explain my question clearly.
By the way, in the DCB, I only used DDNAME, PATH, PATHOPT, PATHMODE, FILEDATA(TEXT).
Thank you very much.
How can I create normal USS text files in assembler?
-
- Posts: 40
- Joined: Wed Nov 01, 2017 8:59 pm
- Skillset: XL/C, ISPF, USS
- Referer: My colleagues
-
- Global moderator
- Posts: 2105
- Joined: Thu Jun 03, 2010 6:21 pm
- Skillset: Assembler, JCL, utilities
- Referer: zos.efglobe.com
Re: How can I create normal USS text files in assembler?
- Allocation - You can specify path names and the other attributes in dynamic allocation. I'm talking real dynamic allocation here, not BPXWDYN. Obtain MVS Programming: Authorized Assembler Services Guide for your z/OS release.
- PATH, PATHOPT, PATHMODE and FILEDATA(TEXT) are not DCB options. There are equivalent dynamic allocation text keys for them. See Authorized Assembler Services Guide.
- You can write the equivalent of variable length text records using PUT by using z/OS variable length records. PUT will insert real end of line characters at the appropriate place in the output.
-
- Posts: 40
- Joined: Wed Nov 01, 2017 8:59 pm
- Skillset: XL/C, ISPF, USS
- Referer: My colleagues
Re: How can I create normal USS text files in assembler?
Steve, thank you for the quick reply. I am using the DYNALLOC actually. I did not mention it as I wanted to keep the explanation simple. In the RB, I used PATH, POPT PMDE and MDAT (text), just like what you wrote. So I think the RECFM=VB is the key, isn't? OK I'll try it.
-
- Posts: 40
- Joined: Wed Nov 01, 2017 8:59 pm
- Skillset: XL/C, ISPF, USS
- Referer: My colleagues
Re: How can I create normal USS text files in assembler?
I didn't find any intuitive examples and articles explaining the way of writing variable-length records. Moreover, what I need to write if USS files, not MVS data sets. The information is more difficult to find.
Could anyone give me more hints? Thanks.

-
- Global moderator
- Posts: 2105
- Joined: Thu Jun 03, 2010 6:21 pm
- Skillset: Assembler, JCL, utilities
- Referer: zos.efglobe.com
Re: How can I create normal USS text files in assembler?
The format of variable length records is discussed in DFSMS Using Data Sets. If you are writing to a USS file with a PUT macro, PUT will take the text portion of the record, append an end of line character to the line, and write it to the file. You DO NOT present a USS style line to the PUT macro.
Basically, a z/OS variable length record has a 4 byte control area called a Record Descriptor Word (RDW) at the start of the record. The first two bytes contain, in binary, the length of the record and the RDW. The second two bytes contain binary 0s. I write DC statements like these to define a fixed VB record.
Truly variable VB records require a little more code to form the RDW, but it's not back breaking. A more complete example.
Another option might be z/OS U format records.
Basically, a z/OS variable length record has a 4 byte control area called a Record Descriptor Word (RDW) at the start of the record. The first two bytes contain, in binary, the length of the record and the RDW. The second two bytes contain binary 0s. I write DC statements like these to define a fixed VB record.
Code: Select all
VBREC DC AL2(VBRECL,0),C'THE TEXT PORTION OF THE RECORD'
VBRECL EQU *-VBREC
Truly variable VB records require a little more code to form the RDW, but it's not back breaking. A more complete example.
Code: Select all
PUT DCB,VBREC
...
DCB DCB DSORG=PS,MACRF=PM,RECFM=VB,LRECL=nnn,...
...
VBREC DC AL2(VBRECL,0),C'THE TEXT PORTION OF THE RECORD'
VBRECL EQU *-VBREC
Another option might be z/OS U format records.
Code: Select all
LA 0,L'UREC
STH 0,(DCBLRECL-IHADCB)+DCB
PUT DCB,UREC
...
DCB DCB DSORG=PS,MACRF=PM,RECFM=U,BLKSIZE=nnn,...
...
UREC DC C'RECORD TEXT'
-
- Posts: 40
- Joined: Wed Nov 01, 2017 8:59 pm
- Skillset: XL/C, ISPF, USS
- Referer: My colleagues
Re: How can I create normal USS text files in assembler?
Wow! Steve, your explanation is short but the density of information is -> ∞ . One thousand times more helpful than www.ibm.com/support/knowledgecenter !
I believe it will resolve my issue in a minute! A big thanks to you, Steve.
I believe it will resolve my issue in a minute! A big thanks to you, Steve.
-
- Posts: 40
- Joined: Wed Nov 01, 2017 8:59 pm
- Skillset: XL/C, ISPF, USS
- Referer: My colleagues
Re: How can I create normal USS text files in assembler?
Hi Steve, your explanation and sample code did resolve my issue quickly. Thank you very much!
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Converting universal groups to normal Racf group
by aarvalar1 » Thu May 23, 2024 10:15 pm » in Mainframe Security - 5
- 2724
-
by Robert Hansel
View the latest post
Wed Jul 24, 2024 5:12 pm
-
-
-
how to decompress DB2 SMF records in assembler program
by chaat » Fri Feb 19, 2021 9:53 am » in Assembler - 3
- 3463
-
by willy jensen
View the latest post
Sun Feb 21, 2021 4:26 pm
-
-
-
Assembler program accessing IMS DB Database
by gschhatwal1176 » Sat Aug 08, 2020 12:34 pm » in Assembler - 5
- 7165
-
by NicC
View the latest post
Sun Aug 09, 2020 2:53 am
-
-
-
Joining 2 vb files into vsam files ended error
by newbiemainframe » Thu Nov 12, 2020 7:59 am » in JCL - 1
- 1732
-
by NicC
View the latest post
Thu Nov 12, 2020 7:15 pm
-
-
-
Create multiple records based on one record within a file.
by chillmo » Thu Aug 11, 2022 3:54 am » in Syncsort/Synctool - 5
- 7672
-
by sergeyken
View the latest post
Fri Aug 12, 2022 2:23 am
-