in z/OS Assembler, can I read a JCL input stream twice? - input

Is there a way to read a z/OS JCL input stream more than once? (one that comes from a //SYSIN DD *). I know I could cache the stream the first time I read it, and then read from the cached data, but I'm not interested in that solution.
Note: the language is Assembler

Depends on the language. This answer provides an example in HLASM and a reference to the 'C' Language reference at the end.
For Assembler you'll need to REWIND when you CLOSE the DCB. See the label at FINISH to see how this is done.
There may be other ways but this worked for me on z/OS 2.4
PRINT NOGEN
* ------------------------------------------------------------------- *
* *
* SYSIN2 *
* *
* #author Hogstrom *
* *
* Test to see if one can re-read SYSIN more than one time. *
* *
* ------------------------------------------------------------------- *
R0 EQU 0
R1 EQU 1
R2 EQU 2
R3 EQU 3 * Number of times to loop
R4 EQU 4
R5 EQU 5
R6 EQU 6
R7 EQU 7
R8 EQU 8
R9 EQU 9
R10 EQU 10
R11 EQU 11
R12 EQU 12 * Base Register
R13 EQU 13
R14 EQU 14
R15 EQU 15
*
SYSIN2 CSECT
STM R14,R12,12(R13)
LR R12,R15
USING SYSIN2,12
*
ST R13,SaveArea+4
LA R0,SaveArea
ST R0,8(R13)
LA R13,SaveArea
*
OPEN (SYSIN,(INPUT))
OPEN (SYSOUT,(OUTPUT))
LA R3,3 Number of times to read SYSIN
*
GETAGAIN DS 0H
GET SYSIN,INREC Read the next rec
PUT SYSOUT,INREC Write that bad boy out
B GETAGAIN
FINISH DS 0H Invoked at End of Data of SYSIN
CLOSE (SYSIN,REWIND) Close SYSIN and rewind
OPEN (SYSIN,(INPUT)) Open it up again
BCT R3,GETAGAIN Repeat the madness
*
CLOSE SYSIN
CLOSE SYSOUT
*
L R13,SaveArea+4
LM R14,R12,12(R13)
XR R15,R15
BR R14
*
SYSIN DCB DSORG=PS,MACRF=(GM),DDNAME=SYSIN,EODAD=FINISH, *
RECFM=FB,LRECL=80,BLKSIZE=0
SYSOUT DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT, *
RECFM=FBA,LRECL=133,BLKSIZE=0
*
INREC DC CL132' '
SaveArea DS 18F
LTORG
END
Assemble the above and execute this JCL
//SYSIN2 JOB (CCCCCCCC),'HOGSTROM',
// MSGLEVEL=(1,1),
// MSGCLASS=O,
// CLASS=A,
// NOTIFY=&SYSUID
//*
//STEP1 EXEC PGM=SYSIN2
//STEPLIB DD DSN=USER1.TEST.LOADLIB,DISP=SHR
//*
//SYSIN DD *
REC 1 OF 3
REC 2 OF 3
REC 3 OF 3
/*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
And you'll get this output
You'll see the same SYSIN data repeated three times.
For a 'C' program this reference in the IBM documentation for the C Compiler provides some hints about rewinding.
To open an in-stream data set, call the fopen() or freopen() library
function and specify the ddname of the data set. You can open an
in-stream data set only for reading. Specifying any of the update,
write, or append modes fails. Once you have opened an in-stream data
set, you cannot acquire or change the file position except by
rewinding. This means that calls to the fseek(), ftell(), fgetpos(),
and fsetpos() for in-stream data sets fail. Calling rewind() causes
z/OS XL C/C++ to reopen the file, leaving the file position at the
beginning.
What you're looking for is possible but the implementation is language dependent.

Related

SAS - Importing variable length Binary records without delimiters

I have a binary data set with no delimiters and no fixed length records. I know each record contains 22 bytes of data then an unknown number of 23 byte blocks, up to 50 blocks. The problem is that it's only reading 1 line of 32767 bytes for a total of 728 obs. I'm expecting 2.7MM output obs. How can I make this read the input file to the end? I've already tried adding an "OBS=" option and "lrecl=" option to the infile line. Adding the "end=" option had no effect on the result.
DATA INFILE.MYDATA (drop= i);
INFILE "&Path./UGLYDATA" end=eof;
INPUT
MY_KEY s370fPD9.
...
OCCURS s370fPD2.
#
;
ARRAY MyData{50} MyData1-MyData50;
...
ARRAY Filler{50} $ Filler1-Filler50;
DO I = 1 TO min(50,OCCURS);
INPUT
MyData{I} s370fPD4.
...
Filler{I} $ebcdic10.
##
;
End;
RUN;
Relevant Log:
NOTE: 1 record was read from the infile "UGLYDATA".
The minimum record length was 32767.
The maximum record length was 32767.
One or more lines were truncated.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set INFILE.MYDATA has 728 observations and 356 variables.
NOTE: Compressing data set INFILE.MYDATA decreased size by 47.06 percent.
Compressed is 9 pages; un-compressed would require 17 pages.
NOTE: DATA statement used (Total process time):
real time 2.69 seconds
user cpu time 0.02 seconds
system cpu time 0.11 seconds
memory 1890.40k
OS Memory 10408.00k
Timestamp 12/07/2021 05:17:34 PM
Step Count 1 Switch Count 0
Page Faults 3
Page Reclaims 1028
Page Swaps 0
Voluntary Context Switches 272
Involuntary Context Switches 1226
Block Input Operations 309648
Block Output Operations 2312
Sounds like the file does not consists of lines of text. So try using RECFM=N on your INFILE statement so that SAS will not be looking for LINEFEED character (or CARRIAGE RETURN and LINEFEED combination) to mark the end of the lines.
INFILE "&Path./UGLYDATA" recfm=n ;
If you are unsure what the file contains just run a simple data step to look at the first few hundred bytes and then figure it out. If any of the bytes in a "line" are not printable characters the LIST command will include the hexcodes for the bytes under the lines when it writes to the SAS log.
data _null_;
INFILE "&Path./UGLYDATA" recfm-=f lrecl=100 obs=10 ;
input;
list;
run;
Per #Tom, indeed RECFM=N.
Example:
Create and read back a binary file.
filename foo '%temp%/foo.bin' recfm=n;
data _null_;
file foo;
call streaminit(2021);
filler = repeat('*', 10);
do recnum = 1001 to 1010;
put recnum s370fPD9. #;
put filler $char11. #;
occurs = rand('integer',1,26);
put occurs s370fPD2. #;
do z = 0 to occurs-1;
record = repeat(byte(rank('A')+z), 22);
put record $ebcdic23.;
end;
putlog 'NOTE: ' recnum= occurs=;
end;
stop;
run;
data want;
infile foo;
* read master;
input recnum s370fPD9. filler $char11. occurs s370fPD2.;
* read details;
do index = 1 to occurs;
input content $ebcdic23.;
output;
end;
run;
dm 'vt want';

Reset Retry Counter, error: "6d00" -> Instruction code not supported or invalid

I have this command as reference:
XX 2C 03 XX
When I send the command: "00 2C 03 01 00" I'm getting error 6d00 (Instruction code not supported or invalid)
Important: I am in a test environment, I am studying the APDU commands.
After testing questions I sent the command to verify the PIN containing an invalid PIN 3 times in a row.
Original PIN: 1574
P1 = 0x15
P2 = 0x15
Commands:
>> 0x00,0x20,0x00,0x80,0x08,0x24,p1,p2,0xFF,0xFF,0xFF,0xFF,0xFF
<< 63c2
>> 0x00,0x20,0x00,0x80,0x08,0x24,p1,p2,0xFF,0xFF,0xFF,0xFF,0xFF
<< 63c1
>> 0x00,0x20,0x00,0x80,0x08,0x24,p1,p2,0xFF,0xFF,0xFF,0xFF,0xFF
<< 63c0
After that, I run the command again:
>> 0x00,0x20,0x00,0x80,0x08,0x24,p1,p2,0xFF,0xFF,0xFF,0xFF,0xFF
<< 6983
I want to reset the counter (Reset Retry Counter), so that I can verify the PIN again, for this purpose I am executing the following command:
>> 00 2C 03 00
<< 6d00
Why am I getting this error: "6d00"?
I was forgetting the PUK code, problem solved!
The correct is:
CL ='00' -
INS='2C' - RESET RETRY COUNTER
P1 = either
'00' - Data contains PUK and new PIN
'01' - Data contains PUK only
P2 ='01' - Key Reference of the PIN (as <01>)
Data = either
PUK | NewPIN, if P1='00'
PUK , if P1='01'

FASM - Boot sector on USB don't work

in first, sorry for my bad english, i'm french.
At the moment, i learn asm with fasm to test boot sector programming.
I have make a simple boot program, i have compiled it and i write boot.bin in first sector of my usb.
But when i boot on my PC or in virtualbox, drive isn't found....
Boot sector code:
;=======================================================================
; a simpliest 1.44 bootable image by shoorick ;)
;=======================================================================
_bs equ 512
_st equ 18
_hd equ 2
_tr equ 80
;=======================================================================
org 7C00h
jmp start
nop
;=====================================================
db "HE-HE OS"; ; 8
dw _bs ; b/s
db 1 ; s/c
dw 1 ; rs
db 2 ; fats
dw 224 ; rde
dw 2880 ; as
db 0F0h ; media
dw 9 ; s/fat
dw _st ; s/t
dw _hd ; h
dd 0 ; hs
dd 0 ; --
db 0 ; drv
db 0 ; --
db 29h ; ebr
dd 0 ; sn
db "NO NAME "; ; 11
db "FAT12 "; ; 8
;=====================================================
start:
mov ax,cs
mov ds,ax
mov cx,count
mov si,hello
mov bx,7
mov ah,0Eh
##:
lodsb
int 10h
loop #B
xor ah,ah
int 16h
int 19h
hello db "Hi! This is disk-invalid!"
count = $ - hello
;=======================================================================
rb 7E00h-2-$
db 055h,0AAh
;=======================================================================
This code is provide by examples of fasm's website.
there are couple of reasons why a bootloader wont work:
the bootloader is not in the first sector of the USB/Floppy/etc.
the bootloader is not EXACTLY 512 bytes long
you are missing the 0xAA55 signature at the last 2 bytes of the bootloader
in your example i assume you have the wrong bootloader size ( it is not 512 bytes )
try replacing
rb 7E00h-2-$
db 055h,0AAh
with
TIMES 510-($-$$) DB 0
DW 0xAA55
this ensures that your file is exactly 512 bytes long and that is has the required bootloader signature

Maximum likelihood programming in Stata

I am trying to learn ml programming in Stata. As a part of this I am running a program myprobit (the code is adopted from Maximum likelihood estimation with Stata by Gould, Pitblado, and Sribney).
capture program drop myprobit
program define myprobit
args todo b lnf g negH g1
tempvar xb lj
mleval `xb'=`b'
quietly{
gen double `lj'=normal(`xb') if $ML_y1==1
replace `lj'=normal(-`xb') if $ML_y1==0
mlsum `lnf'=ln(`lj')
if (`todo'==0|`lnf'>= .) exit
replace `g1'= normalden(`xb')/`lj' if $ML_y1==1
replace `g1'=-normalden(`xb')/`lj' if $ML_y1==0
mlvecsum `lnf' `g'=`g1', eq(1)
if (`todo'==1|`lnf'==>.)exit
mlmatsum `lnf' `negH'=`g1'*(`g1'+`xb'),eq(1,1)
}
end
sysuse cancer, clear
gen drug2=drug==2
gen drug3=drug==3
ml model d1 myprobit (died=drug2 drug3 age)
ml check
ml maximize
But, I got an error varlist required:
Here is a trace of its execution:
------------------------------------------------------------------------------
-> myprobit 1 __000000 __000001 __000002 __000003
- `begin'
= capture noisily version 11: myprobit 1 __000000 __000001 __000002 __000003
---------------------------------------------------------------------------------------------------------------------------------- begin myprobit ---
- args todo b lnf g negH g1
- tempvar xb lj
- mleval `xb'=`b'
= mleval __000005=__000000
- quietly{
- gen double `lj'=normal(`xb') if $ML_y1==1
= gen double __000006=normal(__000005) if died==1
- replace `lj'=normal(-`xb') if $ML_y1==0
= replace __000006=normal(-__000005) if died==0
- mlsum `lnf'=ln(`lj')
= mlsum __000001=ln(__000006)
- if (`todo'==0|`lnf'>= .) exit
= if (1==0|__000001>= .) exit
- replace `g1'= normalden(`xb')/`lj' if $ML_y1==1
= replace = normalden(__000005)/__000006 if died==1
varlist required
replace `g1'=-normalden(`xb')/`lj' if $ML_y1==0
mlvecsum `lnf' `g'=`g1', eq(1)
if (`todo'==1|`lnf'==>.)exit
mlmatsum `lnf' `negH'=`g1'*(`g1'+`xb'),eq(1,1)
}
------------------------------------------------------------------------------------------------------------------------------------ end myprobit ---
- `end'
= set trace off
------------------------------------------------------------------------------
Fix myprobit.
r(100);
end of do-file
Note: The program runs without an error if likelihood evaluator is changed to do.
Any suggestion in this regard will be highly appreciated.
You provided 5 arguments to your program, but 6 are needed. Hence local macro g1 is not defined, which bites when you try to replace the variable it names.
Stata is telling you some of this. The lines
- replace `g1'= normalden(`xb')/`lj' if $ML_y1==1
= replace = normalden(__000005)/__000006 if died==1
show that local macro g1 is interpreted as nothing, i.e. an empty string, so Stata complains because it expects a variable name after replace.
The line
if (`todo'==1|`lnf'==>.)exit
is also problematic, as the operator ==> should be >=.
These are the problems I noticed; there may be others.

Why my rules of bison don't work

Every time I run my parser, it will appear "syntax error in line 1 near <>" (Because there is a subroutine yyerror(char *s)). I think that's because there is something wrong with my rules in bison.
The file (c17.isc) I want to parse.
*c17 iscas example (to test conversion program only)
*---------------------------------------------------
*
*
* total number of lines in the netlist .............. 17
* simplistically reduced equivalent fault set size = 22
* lines from primary input gates ....... 5
* lines from primary output gates ....... 2
* lines from interior gate outputs ...... 4
* lines from ** 3 ** fanout stems ... 6
*
* avg_fanin = 2.00, max_fanin = 2
* avg_fanout = 2.00, max_fanout = 2
*
*
*
*
*
1 1gat inpt 1 0 >sa1
2 2gat inpt 1 0 >sa1
3 3gat inpt 2 0 >sa0 >sa1
8 8fan from 3gat >sa1
9 9fan from 3gat >sa1
6 6gat inpt 1 0 >sa1
7 7gat inpt 1 0 >sa1
10 10gat nand 1 2 >sa1
1 8
11 11gat nand 2 2 >sa0 >sa1
9 6
14 14fan from 11gat >sa1
15 15fan from 11gat >sa1
16 16gat nand 2 2 >sa0 >sa1
2 14
20 20fan from 16gat >sa1
21 21fan from 16gat >sa1
19 19gat nand 1 2 >sa1
15 7
22 22gat nand 0 2 >sa0 >sa1
10 20
23 23gat nand 0 2 >sa0 >sa1
21 19
My flex file is as follows and it is right. You can find some information about how my scanner work here.
Error in the output of my flex file
declare.h
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# define INPT 1
# define NOR 2
# define NAND 3
# define NOT 4
# define XOR 5
# define AND 6
# define BUFF 7
# define FROM 8
flex file is
%{
# include "declare.h"
# include "parse.tab.h"
/*gi=1,it's input;gi=8,it's fanout;otherwise,it's gate*/
static int gi=-1;
static int inum=0;
struct{
char *symbol;
int val;
} symtab[]={
{"inpt", INPT},
{"nor", NOR},
{"nand", NAND},
{"not", NOT},
{"xor", XOR},
{"and", AND},
{"buff", BUFF},
{"from",FROM},
{"0",0}
};
extern FILE *yyin;
extern int yylval;
%}
%start A B C D E
DIGITS [0-9]+
BLANK [ \t\n\r\f\v\b]+
ALPHA [a-z]+
%%
"*".*\n {BEGIN A; return(COMMENT);}
<A>{DIGITS} {yylval=atoi(yytext); BEGIN B; return(NUM);}
<B>{DIGITS}{ALPHA} {yylval=atoi(yytext); BEGIN C; return(GNAME);}
<C>{DIGITS} {yylval=atoi(yytext); BEGIN D; return(OPNUM);}
<C>{DIGITS}{ALPHA} {yylval=atoi(yytext); BEGIN A; return(FR);}
<D>{DIGITS} {inum=atoi(yytext);
yylval=inum;
if(gi==1)
{BEGIN A;}
if(gi!=1)
{BEGIN E;}
return(IPNUM);
}
<E>{DIGITS} {inum--;
yylval=atoi(yytext);
if(inum<0)
{BEGIN B; return(NUM);}
else
{BEGIN E; return(ILIST);}
}
{ALPHA} {yylval=lookup(yytext);
return(GTYPE);
}
">sa"[0-1] {yylval=atoi(&yytext[yyleng-1]);return(FAULT);}
{BLANK} ;
. ;
%%
int lookup(const char *s)
{
int i;
for (i = 0; symtab[i].val != 0; i++)
{
if (strcmp(symtab[i].symbol, s) == 0)
break;
}
return(symtab[i].val);
}
The right rules in bison file are as follows
parto:
| parto COMMENT
| parto parti
;
parti: NUM
{...}
GNAME
{...}
GTYPE
{...}
| parti partii
| parti partiii
;
partii:OPNUM
{...}
IPNUM
{...}
partiv
partv
;
partiii: FR
{...}
partiv
;
partiv:
| partiv FAULT
{...}
;
partv:
| partv ILIST
{...}
;
Transferring the key comments into an answer.
The first edition of the code had a couple of problems. In the scanner code, there were lines like this:
<A>{DIGITS} { yylval=atoi(yytext); return(NUM); BEGIN B; }
You should be getting warnings about unreachable code from the BEGIN operations appearing after return. The BEGIN operations have to be executed. They aren't being executed, so you're not switching into your start states.
Michael commented:
There is no warning. I've modified it as you say and edit my codes in the question. Now I put return after BEGIN. Still, "syntax error in line 1 near <�>".
This probably means you aren't compiling the C code with enough warnings. Assuming you're using GCC, add -Wall to the compilation options for starters. There's a chance the warning requires optimization too.
Have you printed the tokens as they're returned (in the Flex scanner)? Have you compiled the Bison grammar with -DYYDEBUG? You also need to turn the debug on: yydebug = 1; in the main() program. You're probably not getting the tokens you expect when you expect them. I've not tried compiling this code yet. Tracking the tokens is key (in my experience) to getting grammars to work. Otherwise, you're running blind.
The other problem (closely related) is that you need to generate the symbolic names for FAULT etc from the grammar (bison -d grammar.y generates grammar.tab.h). You'll find that COMMENT is assigned the value 258, for example. Your scanner, though, is returning other numbers altogether because they're in declare.h. You'll have to fix this mismatch. One option is to #include "grammar.tab.h" in your scanner; this is more or less normal.
In retrospect, I think this is probably the most important observation; things seemed to revert to normal C debugging after this was resolved.
(People often include 'grammar.h' and only update 'grammar.h' if the content of 'grammar.tab.h' changes, so you don't recompile the scanner all the time).
The significance of this is that the set of tokens used by a grammar tends to be fairly stable while the actions associated with the rules change all the time as the implementation of the grammar evolves. So, if it takes enough time to be worth worrying about, you can create file grammar.h that is a copy of grammar.tab.h, but only update grammar.h when the content of grammar.tab.h changes.
cmp -s grammar.tab.h grammar.h || cp grammar.tab.h grammar.h
You'd include this in the makefile rule that converts that grammar into a C file (or an object file).
If the scanner is small enough and your machine fast enough, it may be simpler not to bother with this refinement; it mattered more in the days of 50 MHz machines with a few MiB of RAM than it does in these days of multiple cores running at 2+ GHz with a few GiB of RAM.