So You have a few problems in your code but you need to read the datasheet carfully and understand what options you have.
You must erase before you can write a new value to the chip.
PBP supports block erase and block write but not the ONE WORD write support this device has.
If you do block block write you must write the variables you want to change + dummy writes to complete an entire block and THEN the flash is written.
Read all of chapter 7 in the datasheet especially the Notes in the right side of page 109.
It is not that hard as it seems but it is way more complicated than an EE-prom and remember you can only get 10 000 writes to the flash.. compared to 1 million if you use a standard external Microchip EEprom
Chapter 7.0 in the datasheet
The program memory space is 16 bits wide, while thedata RAM space is 8 bits wide
A read from program memory is executed on 1 byte ata time. A write to program memory is executed onblocks of 64 bytes at a time or 2 bytes at a time.Program memory is erased in blocks of 1024 bytes ata time.
7.4 Erasing Flash Program Memory
The minimum erase block is 512 words or 1024 bytes.
Only through the use of an external programmer, or
through ICSP control, can larger blocks of program
memory be bulk erased. Word erase in the Flash array
is not supported.
7.5.2 FLASH PROGRAM MEMORY WRITE
SEQUENCE (WORD PRORAMMING).
The PIC18F46J11 family of devices has a feature that
allows programming a single word (two bytes). This
feature is enabled when the WPROG bit is set.
Bookmarks