How can I create normal USS text files in assembler?



High Level Assembler(HLASM) for MVS & VM & VSE

How can I create normal USS text files in assembler?

Postby chong_zhou » Mon Jan 27, 2020 4:19 pm

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.
chong_zhou
 
Posts: 30
Joined: Wed Nov 01, 2017 8:59 pm
Has thanked: 12 times
Been thanked: 0 time

Re: How can I create normal USS text files in assembler?

 

Re: How can I create normal USS text files in assembler?

Postby steve-myers » Mon Jan 27, 2020 6:14 pm

  • 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.
I can't really give you examples as I do not use Unix System Services or whatever it's called this week.

These users thanked the author steve-myers for the post:
chong_zhou (Wed Jan 29, 2020 4:38 am)
steve-myers
Global moderator
 
Posts: 2047
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 223 times

Re: How can I create normal USS text files in assembler?

Postby chong_zhou » Mon Jan 27, 2020 6:58 pm

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.
chong_zhou
 
Posts: 30
Joined: Wed Nov 01, 2017 8:59 pm
Has thanked: 12 times
Been thanked: 0 time

Re: How can I create normal USS text files in assembler?

Postby chong_zhou » Tue Jan 28, 2020 2:50 pm

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.
chong_zhou
 
Posts: 30
Joined: Wed Nov 01, 2017 8:59 pm
Has thanked: 12 times
Been thanked: 0 time

Re: How can I create normal USS text files in assembler?

Postby steve-myers » Tue Jan 28, 2020 8:21 pm

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.
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.
         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.
         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'

These users thanked the author steve-myers for the post:
chong_zhou (Wed Jan 29, 2020 4:37 am)
steve-myers
Global moderator
 
Posts: 2047
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 223 times

Re: How can I create normal USS text files in assembler?

Postby chong_zhou » Wed Jan 29, 2020 4:37 am

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.
chong_zhou
 
Posts: 30
Joined: Wed Nov 01, 2017 8:59 pm
Has thanked: 12 times
Been thanked: 0 time

Re: How can I create normal USS text files in assembler?

Postby chong_zhou » Sat Feb 01, 2020 11:33 pm

Hi Steve, your explanation and sample code did resolve my issue quickly. Thank you very much!
chong_zhou
 
Posts: 30
Joined: Wed Nov 01, 2017 8:59 pm
Has thanked: 12 times
Been thanked: 0 time


Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post