Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nesting Error in runtime in nfjson though not at design time 1

Status
Not open for further replies.

Sng1

Programmer
Aug 3, 2021
58
0
0
IN
Below is the code that is compiled and giving no error but on running below code nesting error is soming. Where am I wrong in the code below.
Code:
Clear
Close All

Local lcJSON, oJSON
TEXT TO jSON
[{"data":{"b2cs":[{"csamt":0,"rt":12,"flag":"N","pos":"24","txval":7500,"typ":"OE","iamt":900,"sply_ty":"INTER"},{"csamt":0,"samt":443.5,"rt":5,"flag":"N","pos":"02","txval":17740,"typ":"OE","camt":443.5,"sply_ty":"INTRA"}]},"status_cd":"1","status_desc":"GSTR request succeeds","header":{"ret_period":"052022"}}]
ENDTEXT
lcJSON = Json

Set Procedure To '.\Utilities\Gst\nfJson-master\nfJson\nfjsonread.prg'
oJSON = nfjsonread(lcJSON)
Close All
Create Cursor CURb2CS (sply_ty c(5),typ c(2),etin c(15),pos c(2),diff_prcnt N(2),rt N(5,2),;
	txval N(12,2),iamt N(10,2),camt N(10,2),samt N(10,2),csamt N(10,2))

tnLevel = 0

btypev='B2CS'
For Each Gstr1Crit In oJSON.Array
	tnLevel = Evl(tnLevel, 0)

	Local lnI, lvMember, laMembers[1]
	For lnI=1 To Amembers(laMembers,Gstr1Crit )
		lvMember = Getpem(Gstr1Crit,laMembers[lnI])
		If Vartype(lvMember)="O" And Upper(laMembers[lnI]) = 'DATA'
			Do B2CS_jSON With lvMember,btypev
		Endif
	Endfor
Endfor
Endproc


Procedure B2CS_jSON(OB2bjson,btypev)
For Each Rowv In OB2bjson.&btypev
	Select CURb2CS
	Append Blank
	Gather Name Rowv
Endfor
Endproc
 
If I change below line
Code:
For Each Rowv In OB2bjson.&btypev
to
Code:
For Each Rowv In OB2bjson.b2cs

Error stops coming. Can problem be traced from this. I want to use btypev as parameter as same procedure would be called for different btypev variable.
 
For sake of finding the actual nesting error it helps to use Beatify in a mode indenting everything.

If the last line then still indented, there is one or more END bracket missing, depending on how far it is still indented. You can easily have wrong pairs nested wrongly.

the other case of course is too many closings, which would be detected when you get back to no indentation too early.

Chriss
 
Chris said:
Code:
Clear
Close All

Local lcJSON, oJSON
TEXT TO jSON
[{"data":{"b2cs":[{"csamt":0,"rt":12,"flag":"N","pos":"24","txval":7500,"typ":"OE","iamt":900,"sply_ty":"INTER"},{"csamt":0,"samt":443.5,"rt":5,"flag":"N","pos":"02","txval":17740,"typ":"OE","camt":443.5,"sply_ty":"INTRA"}]},"status_cd":"1","status_desc":"GSTR request succeeds","header":{"ret_period":"052022"}}]
ENDTEXT
lcJSON = Json

Set Procedure To '.\Utilities\Gst\nfJson-master\nfJson\nfjsonread.prg'
oJSON = nfjsonread(lcJSON)
Close All
Create Cursor CURb2CS (sply_ty c(5),typ c(2),etin c(15),pos c(2),diff_prcnt N(2),rt N(5,2),;
	txval N(12,2),iamt N(10,2),camt N(10,2),samt N(10,2),csamt N(10,2))

tnLevel = 0

btypev='B2CS'
For Each Gstr1Crit In oJSON.Array
	tnLevel = Evl(tnLevel, 0)

	Local lnI, lvMember, laMembers[1]
	For lnI=1 To Amembers(laMembers,Gstr1Crit )
		lvMember = Getpem(Gstr1Crit,laMembers[lnI])
		If Vartype(lvMember)="O" And Upper(laMembers[lnI]) = 'DATA'
			Do B2CS_jSON With lvMember,btypev
		Endif
	Endfor
Endfor



Procedure B2CS_jSON(OB2bjson,btypev)
	For Each Rowv In OB2bjson.&btypev
		Select CURb2CS
		Append Blank
		Gather Name Rowv
	Endfor
Endproc

Do you mean this sort of indentation ?
 
Code:
For Each Rowv In OB2bjson.&btypev
Will be fine in itself. Of course it will depend on correct btypev values at runtime.

For example this compiles unproblmeatically:
Code:
For each oItem in _screen.&lcCollection
 ? oItem.name
EndFor

It works for lcCollection="forms" or "objects", but it compiles without setting that. So that syntax is not problematic.

Try with a manual seperate COMPILE of your prg or scx or vcx or whatever, the COMPILE command has syntaxes for anything and might break a knot, which BUILD may have for whatever reason. You might also use the clean up project option or recompile all in a build.

If you used tools like hackscx in rare cases you could have made a mess of the code memo, which after at least fixing all nestings in source code will mend with a separate COMPILE, too.

Chriss
 
The problem is not nfJson related.

"For each" has trouble when used with macro substitution;
just change it to:

Code:
Procedure B2CS_jSON(OB2bjson,btypev)

local i,rowv

For i = 1 to alen(OB2bjson.&btypev)
	rowv = OB2bjson.&btypev(m.i)
	Select CURb2CS
	Append Blank
	Gather Name m.Rowv
Endfor

and it will be fine.



Marco Plaza
@nfoxProject
 
Thank you Marco, Problem resolved. 'For each ' was creating the problem.
 
Funny, because it works for me, and the compiler can't know that the properties of _screen I would address are collections rather than arrays.

And I always prefer for each to index based loops for arrays, too. Never had a nesting error because of them.

Chriss
 
I belived that too...
( I do like for each also, and with / endwith a lot.. )
but I always remember that ( not always .. but ) nesting
for each inside with / endwith / nested function calls can
trigger weird errors at runtime.








Marco Plaza
@nfoxProject
 
Aha, there is not with..endwith in Sng1's code. I think this points out avoiding For Each on arrays, always.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top