It happens that it doesnât work if I reset the #SP and fill the fields #CD, #REF and #IND.
If I donât reset the #F-FACT per se, it doesnât bring the correct result on the read.
This doesnât work:
RESET #SP-REG-CLI-DISCON-EMIS
DECIDE ON FIRST VALUE OF #I-FAT
VALUE 1 #IND-DISCON := 'B'
VALUE 2 #IND-DISCON := 'G'
VALUE 3 #IND-DISCON := 'I'
VALUE 4 #IND-DISCON := 'J'
NONE VALUE #IND-DISCON := 'R'
END-DECIDE
#CD-TIPO-REG := 1
#REF-PENDTE := POL
READ MULTI-FETCH OF 10 SGC-RECI-PENDIENTES
BY SP-REG-CLI-DISCON-EMIS EQ #SP-REG-CLI-DISCON-EMIS
To make it work, I need to reset individually the variable, despite resetting the level 1 field.
Certainly we can help. Because your F-FACT-NUM field is P7, it is causing trouble. When you reset the top level alpha field, it is reset to all spaces (hex â40â) so the packed numeric field contains â40404040â instead of â00000000â. Resetting F-FACT-NUM sets it correctly to â0000000â (the last byte may be something other than zero since that is where the sign is stored).
So I understand that everytime I have a packed field inside a superdescriptor, I need to reset it individually, right? There is other way to do it? Just curious now.
When you RESET #SP-REG-CLI-DISCON-EMIS you were RESETing an A18 field.
As noted by Jerome, this resulted in a string of blanks being placed in #SP-REG-CLI-DISCON-EMIS, when you required #F-FACT-NUM to be a string of zeroes.
What Ralph accomplished by reversing the definition was to RESET #SP-DEF which is NOT a field. As you can see from Ralphâs definition, #SP-DEF is what is called a Group-name in Natural. Note that #SP-DEF does not have a format or length. This is because only fields have format and lengths, not Group-names.
Group-names are basically abbreviations in Natural. At compile time, Natural replaces a Group-name with the name(s) of the component fields in the Group. Thus,
Once I heard someone saying that was necessary to reset each variable always, but with no explanation on why.
The explanation given by Steve is what I understood as default behavior when you reset a variable that has a redefine.
I thought the compiler would automatically reset all of the âinnerâ variables.
I like Jeromeâs technique as a quick fix of a badly defined superdescriptor, but I wouldnât intentionally code it that way. The difference is a minor one, but his version requires at least one RESET GROUP statement to correct the initial contents of #F-FACT-NUM. In mine, all numeric fields start with valid contents and you might not even need to RESET for subsequent uses of the superdescriptor. Additionally, you can INITialize the superdescriptorâs components with default values without resorting to ASSIGN statements.
After all, the first rule of Natural programming is donât code unnecessary statements.