when posting some code, it is a good idea to wrap it into code tag (select part of the message that is code, then click on "#" icon).
code posted by knowledgesharing has some errors but those will be easily find those when start debugging. for example he used '==' for assignment and comparison, double equal is used only for comparison. also your GLOBAL keyword is in wrong place, program names do't match etc.
things i mainly see problem with are:
1. never set tool and base
2. did declare one point as a reference (DECL POS droppoint) but it is not used anywhere in your program. all drop positions should be tied to this position.
3. only open gripper (in several places), but never close it. it looks like product magically appears in the gripper and then robot places it on a pallet. there is no motion to a pick position.
4. program is building structure in space but there are no nested loops. number of loops must match number of dimensions (in this case should be three, not just two).
5. not using any approach point on a way to and from pallet position.
code posted by Forgeur is a good example.
also if i was concerned about resuming operation, i would consider what would be the practial resume options for the application. for example i would say it is enough to provide choice to resume (half finished pallet) or restart (from scratch).
so at the begin of the program i would check if previous run was complete or not. if not complete, i would display dialog asking user to choose between resume and restart. if requested option is restart, i would just initialize Length, Breadth and Height to 1 (if resuming, do nothing).