I'm still new to COBOL and learning about two dimensional tables. Here I'm having difficulty with how to accumulate the total of the two values in rows SOPHOMORE (1,1) = 100 for BSIT and (2,1) = 200 for BSCS with a total of 300.
The input file is: 100200300400500600200300
IDENTIFICATION DIVISION.
PROGRAM-ID. TWODIME.
*AUTHOR..
*INSTALLATION. MANDALUYONG CITY.
*DATE-WRITTEN. SEPTEMBER 9, 2019.
*DATE-COMPILED. SEPTEMBER 10, 2019.
*SECURITY. .
*REMARKS.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. ANGELO-PC.
OBJECT-COMPUTER. ANGELO-PC.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO 'VALSTUD.TXT'.
SELECT OUTFILE ASSIGN TO 'VALOUT.TXT'.
DATA DIVISION.
FILE SECTION.
FD INFILE
LABEL RECORD IS STANDARD
DATA RECORD IS INREC.
01 INREC.
02 YEAR OCCURS 4 TIMES.
03 COURSE OCCURS 2 TIMES PIC 999.
02 TOTALBA PIC 9(5)V99.
FD OUTFILE
LABEL RECORD IS OMITTED
DATA RECORD IS OUTREC.
01 OUTREC.
02 FILLER PIC X(80).
WORKING-STORAGE SECTION.
01 I PIC 9 VALUE IS 0.
01 J PIC 9 VALUE IS 0.
01 EOFSW PIC 9 VALUE IS 0.
01 TYEAR.
02 TS PIC 9999 OCCURS 4 TIMES.
01 HEAD-1.
02 FILLER PIC X(20) VALUE SPACE.
02 FILLER PIC X(23) VALUE 'POLYTECHNIC UNIVERSITY '.
02 FILLER PIC X(18) VALUE 'OF THE PHILIPPINES'.
01 HEAD-2.
02 FILLER PIC X(32) VALUE SPACE.
02 FILLER PIC X(10) VALUE 'STA. MESA,'.
02 FILLER PIC X(7) VALUE ' MANILA'.
01 HEAD-3.
02 FILLER PIC X(31) VALUE SPACE.
02 FILLER PIC X(7) VALUE 'STUDENT'.
02 FILLER PIC X(11) VALUE ' POPULATION'.
01 SUB-1.
02 FILLER PIC X(3) VALUE SPACE.
02 FILLER PIC X(10) VALUE 'YEAR LEVEL'.
02 FILLER PIC X(27) VALUE SPACE.
02 FILLE PIC X(6) VALUE 'COURSE'.
01 SUB-2.
02 FILLER PIC X(20) VALUE SPACE.
02 FILLER PIC X(4) VALUE 'BSCS'.
02 FILLER PIC X(16) VALUE SPACE.
02 FILLER PIC X(4) VALUE 'BSIT'.
02 FILLER PIC X(16) VALUE SPACE.
02 FILLER PIC X(5) VALUE 'TOTAL'.
01 DETAILS.
02 FILLER PIC X(5) VALUE SPACE.
02 P-YEAR PIC X(9).
02 FILLER PIC X(6) VALUE SPACE.
02 P-TAP OCCURS 2 TIMES.
03 P-CTR PIC 999.
03 FILLER PIC X(17) VALUE SPACE.
02 P-TSTUDYEAR PIC 99,999.
01 TOTAL-1.
SCREEN SECTION.
01 SCRE.
02 BLANK SCREEN.
PROCEDURE DIVISION.
MAIN-RTN.
PERFORM INIT-RTN THRU INIT-RTN-END.
PERFORM PROCESS-RTN UNTIL EOFSW = 1.
PERFORM FINISH-RTN.
STOP RUN.
INIT-RTN.
OPEN INPUT INFILE, OUTPUT OUTFILE.
READ INFILE AT END PERFORM END-RTN.
PERFORM HEADING-RTN.
INIT-RTN-END.
END-RTN.
MOVE 1 TO EOFSW.
DISPLAY 'EMPTY FILE' LINE 3 COLUMN 20.
HEADING-RTN.
WRITE OUTREC FROM HEAD-1 AFTER PAGE.
WRITE OUTREC FROM HEAD-2 AFTER 1.
WRITE OUTREC FROM HEAD-3 AFTER 3.
WRITE OUTREC FROM SUB-1 AFTER 2.
WRITE OUTREC FROM SUB-2 AFTER 1.
PROCESS-RTN.
DISPLAY SCRE.
PERFORM ADD-RTN VARYING I FROM 1 BY 1
UNTIL I > 4 AFTER J FROM 1 BY 1 UNTIL
J > 2.
PERFORM MOVE-RTN VARYING I FROM 1 BY 1 UNTIL
I > 4.
READ INFILE AT END MOVE 1 TO EOFSW.
ADD-RTN.
ADD COURSE ( I , J ) TO TS ( I ).
MOVE-RTN.
IF I = 1 MOVE 'FRESHMEN' TO P-YEAR PERFORM A.
IF I = 2 MOVE 'SOPHOMORE' TO P-YEAR PERFORM A.
IF I = 3 MOVE 'JUNIOR' TO P-YEAR PERFORM A.
IF I = 4 MOVE 'SENIOR' TO P-YEAR PERFORM A.
A.
PERFORM MOVE2-RTN VARYING J FROM 1 BY 1 UNTIL
J > 2.
WRITE OUTREC FROM DETAILS AFTER 1.
MOVE2-RTN.
MOVE TS ( I ) TO P-TSTUDYEAR.
MOVE COURSE ( I , J ) TO P-TAP ( J ).
FINISH-RTN.
CLOSE INFILE, OUTFILE.
DISPLAY 'OWARI DA!' LINE 5 COLUMN 20.
I found three problems:
The sample data did not contain data for TOATLBA, though unused. I added seven zeros to the test data.
The item 01 TOTAL-1. had no PICTURE clause. I made it a comment.
TS ( I ) was not zero before adding the values. I added code to zero the data using your style.
IDENTIFICATION DIVISION.
PROGRAM-ID. TWODIME.
*AUTHOR..
*INSTALLATION. MANDALUYONG CITY.
*DATE-WRITTEN. SEPTEMBER 9, 2019.
*DATE-COMPILED. SEPTEMBER 10, 2019.
*SECURITY.
*REMARKS.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. ANGELO-PC.
OBJECT-COMPUTER. ANGELO-PC.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO 'VALSTUD.TXT'.
SELECT OUTFILE ASSIGN TO 'VALOUT.TXT'.
DATA DIVISION.
FILE SECTION.
FD INFILE
LABEL RECORD IS STANDARD
DATA RECORD IS INREC.
01 INREC.
02 YEAR OCCURS 4 TIMES.
03 COURSE OCCURS 2 TIMES PIC 999.
02 TOTALBA PIC 9(5)V99.
FD OUTFILE
LABEL RECORD IS OMITTED
DATA RECORD IS OUTREC.
01 OUTREC.
02 FILLER PIC X(80).
WORKING-STORAGE SECTION.
01 I PIC 9 VALUE IS 0.
01 J PIC 9 VALUE IS 0.
01 EOFSW PIC 9 VALUE IS 0.
01 TYEAR.
02 TS PIC 9999 OCCURS 4 TIMES.
01 HEAD-1.
02 FILLER PIC X(20) VALUE SPACE.
02 FILLER PIC X(23) VALUE 'POLYTECHNIC UNIVERSITY '.
02 FILLER PIC X(18) VALUE 'OF THE PHILIPPINES'.
01 HEAD-2.
02 FILLER PIC X(32) VALUE SPACE.
02 FILLER PIC X(10) VALUE 'STA. MESA,'.
02 FILLER PIC X(7) VALUE ' MANILA'.
01 HEAD-3.
02 FILLER PIC X(31) VALUE SPACE.
02 FILLER PIC X(7) VALUE 'STUDENT'.
02 FILLER PIC X(11) VALUE ' POPULATION'.
01 SUB-1.
02 FILLER PIC X(3) VALUE SPACE.
02 FILLER PIC X(10) VALUE 'YEAR LEVEL'.
02 FILLER PIC X(27) VALUE SPACE.
02 FILLE PIC X(6) VALUE 'COURSE'.
01 SUB-2.
02 FILLER PIC X(20) VALUE SPACE.
02 FILLER PIC X(4) VALUE 'BSCS'.
02 FILLER PIC X(16) VALUE SPACE.
02 FILLER PIC X(4) VALUE 'BSIT'.
02 FILLER PIC X(16) VALUE SPACE.
02 FILLER PIC X(5) VALUE 'TOTAL'.
01 DETAILS.
02 FILLER PIC X(5) VALUE SPACE.
02 P-YEAR PIC X(9).
02 FILLER PIC X(6) VALUE SPACE.
02 P-TAP OCCURS 2 TIMES.
03 P-CTR PIC 999.
03 FILLER PIC X(17) VALUE SPACE.
02 P-TSTUDYEAR PIC 99,999.
*01 TOTAL-1.
SCREEN SECTION.
01 SCRE.
02 BLANK SCREEN.
PROCEDURE DIVISION.
MAIN-RTN.
PERFORM INIT-RTN THRU INIT-RTN-END.
PERFORM PROCESS-RTN UNTIL EOFSW = 1.
PERFORM FINISH-RTN.
STOP RUN.
INIT-RTN.
OPEN INPUT INFILE, OUTPUT OUTFILE.
READ INFILE AT END PERFORM END-RTN.
PERFORM HEADING-RTN.
INIT-RTN-END.
END-RTN.
MOVE 1 TO EOFSW.
DISPLAY 'EMPTY FILE' LINE 3 COLUMN 20.
HEADING-RTN.
WRITE OUTREC FROM HEAD-1 AFTER PAGE.
WRITE OUTREC FROM HEAD-2 AFTER 1.
WRITE OUTREC FROM HEAD-3 AFTER 3.
WRITE OUTREC FROM SUB-1 AFTER 2.
WRITE OUTREC FROM SUB-2 AFTER 1.
PROCESS-RTN.
DISPLAY SCRE.
PERFORM ZERO-RTN VARYING I FROM 1 BY 1
UNTIL I > 4.
PERFORM ADD-RTN VARYING I FROM 1 BY 1
UNTIL I > 4 AFTER J FROM 1 BY 1 UNTIL
J > 2.
PERFORM MOVE-RTN VARYING I FROM 1 BY 1 UNTIL
I > 4.
READ INFILE AT END MOVE 1 TO EOFSW.
ZERO-RTN.
MOVE ZERO TO TS ( I ).
ADD-RTN.
ADD COURSE ( I , J ) TO TS ( I ).
MOVE-RTN.
IF I = 1 MOVE 'FRESHMEN' TO P-YEAR PERFORM A.
IF I = 2 MOVE 'SOPHOMORE' TO P-YEAR PERFORM A.
IF I = 3 MOVE 'JUNIOR' TO P-YEAR PERFORM A.
IF I = 4 MOVE 'SENIOR' TO P-YEAR PERFORM A.
A.
PERFORM MOVE2-RTN VARYING J FROM 1 BY 1 UNTIL
J > 2.
WRITE OUTREC FROM DETAILS AFTER 1.
MOVE2-RTN.
MOVE TS ( I ) TO P-TSTUDYEAR.
MOVE COURSE ( I , J ) TO P-TAP ( J ).
FINISH-RTN.
CLOSE INFILE, OUTFILE.
DISPLAY 'OWARI DA!' LINE 5 COLUMN 20.
Note that MOVE-RTN is inefficient. It would be better to place the text values in a table and move only the entry ( I ) TO P-YEAR.
Also MOVE TS ( I ) TO P-TSTUDYEAR. is done twice. The statement could be moved to before WRITE OUTREC ....
Related
In COBOL I need to replace each char within random alphanumeric string of 149 char with numbers.
1 needs to be replaced with 4,
2 with 7 etc...
The complexity comes with few char needs to be replaced by digit in tens:
'A' needs to be replaced with 19,
'B' needs to be replaced with 21 etc...
Could someone please help? The following code not quite works. I am not sure how to resolve problem with positions.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG211.
**************************************************
* DEFINE FILES TO BE BE USED
**************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO INFILE
FILE STATUS IS WS-IN-STATUS.
SELECT TOTALS-FILE ASSIGN TO OUTTOT
FILE STATUS IS WS-TOTALS-STATUS.
DATA DIVISION.
**************************************************
* DEFINE FILE LAYOUTS
**************************************************
FILE SECTION.
FD IN-FILE RECORDING MODE IS F.
01 IN-REC.
03 IN-BODY PIC X(149).
03 IN-CRLF PIC XX.
FD TOTALS-FILE RECORDING MODE IS F.
*** TOTALS-REC TWICE THE SIZE IN CASE CONVERTING ALL TO TENS DIGITS ***
01 TOTALS-REC.
03 TOTALS-BODY PIC X(298).
03 TOTALS-CRLF PIC XX.
WORKING-STORAGE SECTION.
01 WS-IN-STATUS PIC XX.
88 IN-OK VALUE '00'.
88 IN-EOF VALUE '10'.
88 IN-VALID VALUE '00', '10'.
01 WS-TOTALS-STATUS PIC XX.
88 TOTALS-OK VALUE '00'.
01 WS-POS-IN PIC 999.
01 WS-POS-TOT PIC 999.
01 WS-CHARACTERS.
04 BF PIC X(24) VALUE '0123456789EFGHIKMNPQTUVZ'.
04 AF PIC X(24) VALUE '534916820717906256478310'.
PROCEDURE DIVISION.
MAIN-PROCESS SECTION.
PERFORM A-100-INIT
PERFORM B-100-PROCESS UNTIL IN-EOF
PERFORM C-100-TERM
DISPLAY 'PROGRAM FINISHED'
STOP RUN
.
***************************************************
* INITIAL PROCESSING - OPEN FILES
***************************************************
A-100-INIT SECTION.
OPEN INPUT IN-FILE
OUTPUT TOTALS-FILE
IF IN-OK AND TOTALS-OK
CONTINUE
ELSE
DISPLAY 'COULD NOT OPEN FILES'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
PERFORM Y-100-READ-IN
IF IN-EOF
DISPLAY 'IN FILE IS EMPTY'
END-IF
.
A-100-INIT-RETURN.
EXIT.
***************************************************
* PROCESS EACH RECORD
***************************************************
B-100-PROCESS SECTION.
INSPECT IN-REC
CONVERTING BF
TO AF
MOVE IN-REC TO TOTALS-BODY
MOVE 0 TO WS-POS-IN
MOVE 0 TO WS-POS-TOT
PERFORM VARYING WS-POS-IN FROM 1 BY 1 UNTIL WS-POS-IN > 149
EVALUATE IN-BODY (WS-POS-IN: )
WHEN 'A'
MOVE 21 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'B'
MOVE 17 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'C'
MOVE 13 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'D'
MOVE 15 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'J'
MOVE 11 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'L'
MOVE 31 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'O'
MOVE 23 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'R'
MOVE 19 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'S'
MOVE 10 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'W'
MOVE 16 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'X'
MOVE 18 TO TOTALS-BODY (WS-POS-TOT: )
WHEN 'Y'
MOVE 20 TO TOTALS-BODY (WS-POS-TOT: )
END-EVALUATE
END-PERFORM
MOVE X'0D0A' TO TOTALS-CRLF
PERFORM Y-200-WRITE-TOTALS
PERFORM Y-100-READ-MOO
.
B-100-PROCESS-RETURN.
EXIT.
***************************************************
* TERMINATION PROCESSING - CLOSE FILES
***************************************************
C-100-TERM SECTION.
CLOSE IN-FILE
TOTALS-FILE
IF IN-OK AND TOTALS-OK
CONTINUE
ELSE
DISPLAY 'COULD NOT CLOSE FILES'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
.
C-100-TERM-RETURN.
EXIT.
***************************************************
* READ RECORD
***************************************************
Y-100-READ-IN SECTION.
READ IN-FILE
IF NOT IN-VALID
DISPLAY 'COULD NOT READ IN RECORD'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
.
Y-100-READ-IN-RETURN.
EXIT.
***************************************************
* WRITE IN RECORD
***************************************************
Y-200-WRITE-TOTALS SECTION.
WRITE TOTALS-REC
IF NOT TOTALS-OK
DISPLAY 'COULD NOT WRITE TOTALS RECORD'
PERFORM Z-100-UNEXPECTED-ERROR
END-IF
.
Y-200-WRITE-TOTALS-RETURN.
EXIT.
***************************************************
* UNEXPECTED ERROR SECTION
***************************************************
Z-100-UNEXPECTED-ERROR SECTION.
DISPLAY 'IN STATUS IS ' WS-IN-STATUS
DISPLAY 'TOTALS STATUS IS ' WS-TOTALS-STATUS
STOP RUN
.
Z-100-TERM-RETURN.
EXIT.
I chose to use a common technique to place the one and two character translations into the output. To that end, I created a table defining all the translations in one place, used SEARCH to locate the specific translation, and INSTRING to place the translation into the output.
To test the code, I reduced the size of the fields to 9 and 18 positions.
I used lower-case for all significant changes included in this minimal working example (MWE).
WORKING-STORAGE SECTION.
01 IN-REC.
03 IN-BODY PIC X(9).
88 test-1 value "012345678".
88 test-2 value "9ABCDEFGH".
88 test-3 value "IJKLMNOPQ".
88 test-4 value "RSTUVWXYZ".
*** TOTALS-REC TWICE THE SIZE IN CASE CONVERTING ALL TO TENS DIGITS ***
01 TOTALS-REC.
03 TOTALS-BODY PIC X(18).
01 WS-POS-IN PIC 999.
01 WS-POS-TOT PIC 999.
01 WS-CHARACTERS.
03 translations-defined.
05 pic x value "0". 05 pic xx value "5 ".
05 pic x value "1". 05 pic xx value "3 ".
05 pic x value "2". 05 pic xx value "4 ".
05 pic x value "3". 05 pic xx value "9 ".
05 pic x value "4". 05 pic xx value "1 ".
05 pic x value "5". 05 pic xx value "6 ".
05 pic x value "6". 05 pic xx value "8 ".
05 pic x value "7". 05 pic xx value "2 ".
05 pic x value "8". 05 pic xx value "0 ".
05 pic x value "9". 05 pic xx value "7 ".
05 pic x value "A". 05 pic xx value "21".
05 pic x value "B". 05 pic xx value "17".
05 pic x value "C". 05 pic xx value "13".
05 pic x value "D". 05 pic xx value "15".
05 pic x value "E". 05 pic xx value "1 ".
05 pic x value "F". 05 pic xx value "7 ".
05 pic x value "G". 05 pic xx value "9 ".
05 pic x value "H". 05 pic xx value "0 ".
05 pic x value "I". 05 pic xx value "6 ".
05 pic x value "J". 05 pic xx value "11".
05 pic x value "K". 05 pic xx value "2 ".
05 pic x value "L". 05 pic xx value "31".
05 pic x value "M". 05 pic xx value "5 ".
05 pic x value "N". 05 pic xx value "6 ".
05 pic x value "O". 05 pic xx value "23".
05 pic x value "P". 05 pic xx value "4 ".
05 pic x value "Q". 05 pic xx value "7 ".
05 pic x value "R". 05 pic xx value "19".
05 pic x value "S". 05 pic xx value "10".
05 pic x value "T". 05 pic xx value "8 ".
05 pic x value "U". 05 pic xx value "3 ".
05 pic x value "V". 05 pic xx value "1 ".
05 pic x value "W". 05 pic xx value "16".
05 pic x value "X". 05 pic xx value "18".
05 pic x value "Y". 05 pic xx value "20".
05 pic x value "Z". 05 pic xx value "0 ".
03 redefines translations-defined.
05 translate-entry occurs 36 indexed by search-pos.
07 search-char pic x.
07 translate-char pic xx.
01 character-count comp pic 9(4).
procedure division.
begin.
set test-1 to true
perform translate-test
set test-2 to true
perform translate-test
set test-3 to true
perform translate-test
set test-4 to true
perform translate-test
stop run
.
translate-test.
display IN-BODY
perform B-100-PROCESS
display TOTALS-BODY
display space
.
***************************************************
* PROCESS EACH RECORD
***************************************************
B-100-PROCESS SECTION.
move 1 to WS-POS-TOT
move space to TOTALS-BODY
PERFORM VARYING WS-POS-IN FROM 1 BY 1 UNTIL WS-POS-IN > 9
set search-pos to 1
search translate-entry varying search-pos
when IN-BODY (WS-POS-IN:1) = search-char (search-pos)
unstring translate-char (search-pos)
delimited space
into TOTALS-BODY (WS-POS-TOT:2)
count in character-count
add character-count to WS-POS-TOT
END-PERFORM
.
Output:
012345678
534916820
9ABCDEFGH
7211713151790
IJKLMNOPQ
611231562347
RSTUVWXYZ
19108311618200
Continue from: EMV Reading PAN Code
I'm working in C, so I havn't Java tools and all the functions that parse automatically the response of APDU command.
I want to read all types of smart cards.
I have to parse the response of an GET PROCESSING OPTIONS and get the AFL (Access File Locator) of every card.
I have three cards with three different situation:
A) HelloBank: 77 12 82 2 38 0 94 c 10 2 4 1 18 1 1 0 20 1 1 0 90
B) PayPal: 77 12 82 2 39 0 94 c 18 1 1 0 20 1 1 0 28 1 3 1 90
C) PostePay: 80 a 1c 0 8 1 1 0 18 1 2 0 90
Case A)
I've got three different AFL: 10 2 4 1, 18 1 1 0, 20 1 1 0
So I send 00 B2 SFI P2 00 where SFI was 10>>3 (10 was first byte of first AFL) and P2 was SFI<<3|4 and this way I got the correct PAN Code of my card.
Case B)
I've got three different AFL: 18 1 1 0, 20 1 1 0, 28 1 3 1.
So I send 00 B2 SFI P2 00 builded in the same way as Case A, but I got the response 6A 83 for every AFL.
Case C)
I've got two different AFL: 8 1 1 0, 18 1 2 0 but I cannot parse those automatically because there isn't the same TAG of previous response.
If I use those AFL it worked and I can get the PAN Code of the card.
How can I make an universal way to read the correct AFL and how can I make the correct command with those AFL?
Here is the decoding of AFL:
You will get the AFL in multiple of 4 Bytes normally. Divide your complete AFL in a chunk of 4 Bytes. Lets take an example of 1 Chunk:
AABBCCDD
AA -> SFI (Decoding is described below)
BB -> First Record under this SFI
CC -> Last Record under this SFI
DD -> Record involved for Offline Data Authentication (Not for your use for the moment)
Taking your example 10 02 04 01 18 01 01 00 20 01 10 00
Chunks are 10 02 04 01, 18 01 01 00, 20 01 10 00
10 02 04 01 -->
Taking 1st Byte 10 : 00010000 Take initial 5 bits from MSB --> 00010 means 2 : Means SFI 2
Taking 2nd Byte 02 : First Record under SFI 2 is 02
Taking 3rd Byte 04 : Last Record under SFI 2 is 04
Excluding 4 Byte explanation since no use
Summary : SFI 2 contains record 2 to 4
How Read Record command will form :
APDU structure : CLA INS P1 P2 LE
CLA 00
INS B2
P1 (Rec No)02 (SInce in this SFI 2 inital record is 02)
P2 (SFI) SFI 02 : Represent the SFI in 5 binay digit 00010 and then append 100 in the end : 00010100 : In Hex 14
So P2 is 14
LE 00
APDU to Read SFI 2 Rec 2 : 00 B2 02 14 00
APDU to Read SFI 2 Rec 3 : 00 B2 03 14 00
APDU to Read SFI 2 Rec 4 : 00 B2 04 14 00
Now if you will try to Read Rec 5, Since this Rec is not present you will get SW 6A83 in this case.
Use the same procedure for all chunk to identify the available Records and SFIs
BY this mechanisam you can write the function to parse the AFL
I have a card support T0 protocol with an applet is installed on it. The host send a "multi-records reading" command to get records data. Records are read which are specified by record identifiers in this data field of this command. These are steps that I did:
Select DF
Send a command to read sequence of records
00 B2 00 06 16 73 0A 51 02 40 01 54 04 00 10 00 04 73 08 51 02 40 02 54 02 00 01 00
The meaning of the command is as bellow:
INS = 'B2': read record(s)
P1 = '00': references the current record (ISO 7814-4, 7.3.3, table 48)
P2 = '07' = '00000 110' :
'0000' indicate current short EF id (ISO 7814-4, 7.3.2, table 47)
'111' mean read all records from the last up to P1 (ISO 7814-4, 7.3.3, table 49)
Le = 16 : data length
Data field follow the BER-TLV, for example:
73 0A 51 02 40 01 54 04 00 10 00 04
Tag'73' indicate that sequence of bytes above consist hierarchy data object structure in data filed (length = '0A')
Tag'51' reference to 2-byte EF identifier = '40 01'
Tag'54' reference to one or more record identifiers, in this case are '00 10' and '00 04'
Le = '00'
This is expect respond from card:
53 |length of data| record data| 53| length of data| record data|......
I test this command with the card, the card return 'Unknown Error' message.
Could you tell me what is wrong with the command? Am I misunderstood at any points?
Thanks.
This cannot be answered without knowing the actual implementation. 6F00 - the status word indicating an unknown error - should only be returned when the implementation has an internal error. For Java Card implementations - for instance - the 6F00 is returned for uncaught exceptions in the process method handling the APDU's.
But just like the rest of ISO/IEC 7816-4, nothing is set in stone. It's not even defined when a specific error should be returned, so even the above is unsure. ISO/IEC 7816-4 is thoroughly useless in that regard.
Thank you for your answer. My problem is solved
Actually the return SW = 61 XY is not error message. According to ISO 7814-3 it mean:
Process completed normally (SW2 encodes N x , i.e., the number of extra data bytes still available). In cases 1 and 3, the
card should not use such a value. In cases 2 and 4, for transferring response data bytes, the card shall be ready to receive
a GET RESPONSE command with P3 set to the minimum of N x and N e .
So just need to send a GET RESPONSE command to get response data:
00 C0 00 00 XY
XY: the number of extra data bytes still available
I have a list of times which i want to add to a string
0900 1730
0900 1730
1000 1700
0930 1700
i need to break these up to hours and minutes like so
09 00 17 30
09 00 17 30
10 00 17 00
09 30 17 00
to do this i am using the MID() function to get the first two characters from the cell and then the last two. But when i do this for numbers that start with 0 of have 00 it drops the first 0 like so
0930 = ",MID(B2,1,2),",",MID(B2,3,2)," output - 93 0 what i want = 09 30
0900 = ",MID(B2,1,2),",",MID(B2,3,2)," output - 90 0 what i want = 09 00
1000 = ",MID(B2,1,2),",",MID(B2,3,2)," output - 10 0 what i want = 10 00
is there a way to solve this?
You can use a mid of a pre-formatted block:
=MID(RIGHT("0000"&B2,4),1,2) =MID(RIGHT("0000"&B2,4),3,2)
This should give you two strings like 09 & 30.
If you want two numeric values you can add a value function:
=VALUE(MID(RIGHT("0000"&B2,4),1,2))
One way is place Single Quote(') before the 0 then it will store the 0930 as text in cell
and your formula will also work, No need to change in the formula.
So the value 0930 will be '0930
I have a binary file , the definition of its content is as below : ( all data is stored
in little endian (ie. least significant byte first)) . The example numbers below are HEX
11 63 39 46 --- Time, UTC in seconds since 1 Jan 1970.
01 00 --- 0001 = No Fix, 0002 = SPS
97 85 ff e0 7b db 4c 40 --- Latitude, as double
a1 d5 ce 56 8d 26 28 40 --- Longitude, as double
f0 37 e1 42 --- Height in meters, as float
fe 2b f0 3a --- Speed in km/h, as float
00 00 00 00 --- Heading (degrees ?), as float
01 00 --- RCR, log reason. 0001=Time, 0004=Distance
59 20 6a f3 4a 26 e3 3f --- Distance in meters, as double,
2a --- ? Don't know
a8 --- Checksum, xor of all bytes above not including 0x2a
the data from the Binary file "in HEX" is as below
"F25D39460200269652F5032445401F4228D79BCC54C09A3A2743B4ADE73F2A83"
I appreciate if you can support me to translate this data line based on the instruction before.
Probably wrong, but here's a shot at it using Ruby:
hex = "F25D39460200269652F5032445401F4228D79BCC54C09A3A2743B4ADE73F2A83"
ints = hex.scan(/../).map{ |s| s.to_i(16) }
raw = ints.pack('C*')
fields = raw.unpack( 'VvEEVVVvE')
p fields
#=> [1178164722, 2, 42.2813707974677, -83.1970117467067, 1126644378, 1072147892, nil, 33578, nil]
p Time.at( fields.first )
#=> 2007-05-02 21:58:42 -0600
I'd appreciate it if someone well-versed in #pack and #unpack would show me a better way to accomplish the first three lines.
My Cygnus Hex Editor could load such a file and, using structure templates, display the data in its native formats.
Beyond that, it's just a matter of doing through each value and working out the translation for each byte.