using craftsReport.Interfaces;

namespace craftsReport.modules
{
	public class rp0452_xbs : IReportModule
	{
		public IReportHost HostObject { set; get; }

		public rp0452_xbs()
		{
		}

		// Kurzfassung
		public bool Execute()
		{

			HostObject.DefineVariable2("Seite", "s,2,0");
			HostObject.DefineVariable2("Zeile", "s,2,0");
			HostObject.DefineVariable2("cyZeile", "d,8,4");
			HostObject.DefineVariable2("ZlMax", "s,2,0");
			HostObject.DefineVariable2("RandX", "d,8,2");
			HostObject.DefineVariable2("RandY", "d,8,2");
			HostObject.DefineVariable2("SizeX", "d,8,2");
			HostObject.DefineVariable2("Heute", "D,10,0");
			HostObject.DefineVariable2("mSumme", "d,8,2");
			HostObject.DefineVariable2("bNeedHdr", "L,1,0");
			HostObject.DefineVariable2("bNeedTHdr", "L,1,0");
			HostObject.DefineVariable2("bTitZus", "L,1,0");

			//  85 Zeilen im Abstand 8 LPI == A4-hoch
			HostObject.Set("ZlMax", @"     63", true);
			HostObject.Set("cyZeile", @" 2,54/6", true);
			HostObject.Set("RandX", @"      1,80", true);
			HostObject.Set("RandY", @"      0,80", true);
			HostObject.Set("SizeX", @"      18,40", true);
			HostObject.Set("Seite", @"      1", true);
			HostObject.Set("Zeile", @"      0", true);
			HostObject.Set("Heute", @"H", true);
			HostObject.Set("bNeedHdr", @"1", true);
			HostObject.Set("bNeedTHdr", @"1", true);
			HostObject.Set("bTitZus", @"0", true);

			if (!HostObject.IsVar("bAufmass"))
				HostObject.DefineVariable2("bAufmass", "L,1,0");
			if (!HostObject.IsVar("bVerdeckt"))
				HostObject.DefineVariable2("bVerdeckt", "L,1,0");
			if (!HostObject.IsVar("mBA"))
				HostObject.DefineVariable2("mBA", "L,1,0");
			if (!HostObject.IsVar("mKurz"))
				HostObject.DefineVariable2("mKurz", "L,1,0");
			if (!HostObject.IsVar("mNurZus"))
				HostObject.DefineVariable2("mNurZus", "L,1,0");
			if (!HostObject.IsVar("mMitZus"))
				HostObject.DefineVariable2("mMitZus", "L,1,0");
			if (!HostObject.IsVar("mBisEbene"))
				HostObject.DefineVariable2("mBisEbene", "N,2,0");
			if (!HostObject.IsVar("mMengen"))
				HostObject.DefineVariable2("mMengen", "L,1,0");
			if (!HostObject.IsVar("mArtnr"))
				HostObject.DefineVariable2("mArtnr", "L,1,0");
			if (!HostObject.IsVar("mGP"))
				HostObject.DefineVariable2("mGP", "L,1,0");
			if (!HostObject.IsVar("mEP"))
				HostObject.DefineVariable2("mEP", "L,1,0");
			if (!HostObject.IsVar("mTSum"))
				HostObject.DefineVariable2("mTSum", "L,1,0");
			if (!HostObject.IsVar("mVerd"))
				HostObject.DefineVariable2("mVerd", "L,1,0");

			if (HostObject.EvalBool("$[mBisEbene] < 2"))
				HostObject.Set("mBisEbene", @"2", true);
			//  Datensatz BELEGVERZEICHNIS

			HostObject.DefineRecord("recPOS", "TMPKALKLIST", 0, 18, HostObject.EvalString(@"$[FltKey<18]"));
			HostObject.DefineRecord("recTIT", "TMPKALKLIST", 0, 18, HostObject.EvalString(@"$[FltKey<18]"));
			HostObject.DefineRecord("recBVZ", "BELEGVERZEICHNIS", 0, 18, HostObject.EvalString(@"$[FltKey<18]"));
			HostObject.DefineRecord("recEXT", "BELEGKOPF_ERWEITERUNG", 0, 18, HostObject.EvalString(@"$[FltKey<18]"));
			HostObject.DefineRecord("recWKZ", "WÄHRUNGEN", 1, 6, HostObject.EvalString(@"$[recBVZ.WAEHRUNG<6]"));
			HostObject.DefineRecord("recSTEURNR", "OPTIONEN", 0, 5, HostObject.EvalString(@" 6110"));
			HostObject.DefineRecord("recUSTIDNR", "OPTIONEN", 0, 5, HostObject.EvalString(@" 6112"));

			//  eigene Anschrift aus Belegvorlauf holen
			HostObject.DefineVariable2("mADRNR", "u,2,0");
			HostObject.Set("mADRNR", @"$[recBVZ.EIGANSCH]", true);
			if (HostObject.EvalBool("$[mADRNR] < 10"))
				HostObject.Set("mADRNR", @"0$[mADRNR>1]", true);
			HostObject.DefineRecord("recEIG", "EIGENE_ANSCHRIFTEN", 0, 2, HostObject.EvalString(@"$[mADRNR>2]"));


			if (HostObject.EvalBool("$[mBauleiter]"))
				HostObject.DefineRecord("recADR1", "BELEGADRESSEN", 0, 19, HostObject.EvalString(@"$[FltKey<18]1"));
			else
				HostObject.DefineRecord("recADR1", "BELEGADRESSEN", 0, 19, HostObject.EvalString(@"$[FltKey<18]0"));
			HostObject.DefineRecord("recADR2", "BELEGADRESSEN", 0, 19, HostObject.EvalString(@"$[FltKey<18]0"));
			HostObject.DefineVariable2("adrZeile1", "C,81,0");
			HostObject.DefineVariable2("adrZeile2", "C,81,0");
			HostObject.DefineVariable2("adrZeile3", "C,81,0");
			HostObject.DefineVariable2("adrZeile4", "C,81,0");
			HostObject.DefineVariable2("adrZeile5", "C,81,0");
			HostObject.DefineVariable2("adrStrasse", "C,40,0");
			HostObject.DefineVariable2("adrPlzOrt", "C,50,0");
			HostObject.Set("adrZeile1", @"$[recADR1.Anrede]", true);
			HostObject.Set("adrZeile2", @"$[recADR1.Name1]", true);
			HostObject.Set("adrZeile3", @"$[recADR1.Name2]", true);
			HostObject.Set("adrZeile4", @"$[recADR1.Branche]", true);
			HostObject.Set("adrZeile5", @"$[recADR1.zuHaenden]", true);
			HostObject.Set("adrStrasse", @"$[recADR1.Strasse]", true);
			HostObject.Set("adrPlzOrt", @"$[recADR1.Plz] $[recADR1.Ort]", true);

			if (!HostObject.IsEmpty("recADR1.Vorname"))
				HostObject.Set("adrZeile2", @"$[recADR1.Vorname] $[adrZeile2]", true);
			SUB_subFmtAdr1();

			HostObject.DefineVariable2("cWKZ", "C,6,0");
			if (HostObject.IsEmpty("recWKZ.Zeichen"))
				HostObject.Set("cWKZ", @"$[recBVZ.WAEHRUNG]", true);
			else
				HostObject.Set("cWKZ", @"$[recWKZ.Zeichen]", true);

			HostObject.DefineVariable2("bTextPrint", "L,1,0");
			HostObject.DefineVariable2("nEndSumme", "N,14,2");
			HostObject.DefineVariable2("bEndShow", "L,1,0");
			HostObject.DefineVariable2("nTitelEbene", "N,12,0");
			HostObject.Set("nTitelEbene", @"0", true);
			HostObject.Set("nEndSumme", @"0", true);
			HostObject.Set("bEndShow", @"0", true);
			HostObject.Set("bTextPrint", @"1", true);


			// --------------------------------------------------
			//  Erste Seite initialisieren und PFD Angaben senden

			//  PDF Options Header
			HostObject.DefineRecord("recPDF", "OPTIONEN", 0, 5, HostObject.EvalString(@"20003"));
			HostObject.DefineVariable2("mJobHead", "C,250,0");
			HostObject.Set("mJobHead", @"@saPS2PDF-c$[recPDF.OptDataC]@ @saPS2PDF-p$[recBVZ.PRJNR]@ @saPS2PDF-a$[recBVZ.KDNR]@", true);
			HostObject.Set("mJobHead", @"@saPS2PDF-dKurfassung $[recBVZ.PRJNR]/$[recBVZ.BELEGART]/$[recBVZ.BELEGNR]@ $[mJobHead]", true);

			HostObject.WriteLine(HostObject.EvalString(@"INITPAGESIZE"));
			HostObject.WriteLine(HostObject.EvalString(@"STARTJOB $[mJobHead]"));
			HostObject.WriteLine(HostObject.EvalString(@"TRANSPARENT"));

			HostObject.WriteLine(HostObject.EvalString(@"STARTPAGE"));
			HostObject.WriteLine(HostObject.EvalString(@"DEVICE $[mDevice1]"));
			HostObject.WriteLine(HostObject.EvalString(@"CALCBORDER"));

			HostObject.Set("Zeile", @"0", true);
			HostObject.ProcessResource("KopfBericht");
			HostObject.ProcessResource("outAdresse1");
			HostObject.Set("adrZeile1", @"$[recADR2.Anrede]", true);
			HostObject.Set("adrZeile2", @"$[recADR2.Name1]", true);
			HostObject.Set("adrZeile3", @"$[recADR2.Name2]", true);
			HostObject.Set("adrZeile4", @"$[recADR2.Branche]", true);
			HostObject.Set("adrZeile5", @"$[recADR2.zuHaenden]", true);
			HostObject.Set("adrStrasse", @"$[recADR2.Strasse]", true);
			HostObject.Set("adrPlzOrt", @"$[recADR2.Plz] $[recADR2.Ort]", true);
			if (!HostObject.IsEmpty("recADR2.Vorname"))
				HostObject.Set("adrZeile2", @"$[recADR2.Vorname] $[adrZeile2]", true);
			SUB_subFmtAdr1();
			if (HostObject.EvalBool("$[mBauleiter]"))
				HostObject.ProcessResource("outAdresse2");

			while(!HostObject.TestEof("recPOS"))
			{
				SUB_loopBELEG();
				HostObject.SkipRecord("recPOS");
			}

			// --------------------------------------------------
			//  letzte Seite abschliessen
			HostObject.Set("Zeile", @"$[ZlMax]", true);
			HostObject.ProcessResource("FussBericht");
			HostObject.WriteLine(HostObject.EvalString(@"ENDPAGE"));
			HostObject.WriteLine(HostObject.EvalString(@"ENDJOB"));

			return true;
		}


		bool SUB_CheckPage()
		{
			HostObject.VariablesPush();

			//  Fussbereich ausgeben, wenn letzte Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] >= $[ZlMax]"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}

		bool SUB_Fuss()
		{
			HostObject.VariablesPush();

			HostObject.Set("Zeile", @"$[ZlMax]", true);
			// OUT ##FussSeite
			HostObject.ProcessResource("FussBericht");
			HostObject.WriteLine(HostObject.EvalString(@"ENDPAGE"));
			//  naechste Seite anfangen
			HostObject.Set("Seite", @"$[Seite]+1", true);
			HostObject.Set("Zeile", @"0", true);
			HostObject.WriteLine(HostObject.EvalString(@"STARTPAGE"));
			HostObject.WriteLine(HostObject.EvalString(@"DEVICE $[mDevice2]"));
			HostObject.WriteLine(HostObject.EvalString(@"CALCBORDER"));

			return HostObject.VariablesPop();
		}

		bool SUB_Kopf()
		{
			HostObject.VariablesPush();

			HostObject.Set("Zeile", @"0", true);
			HostObject.ProcessResource("KopfSeite");
			HostObject.ProcessResource("outAdresse1");
			HostObject.Set("bNeedHdr", @"1", true);
			if (HostObject.EvalBool("$[mSumme]=0"))
				return HostObject.VariablesPop();
			// OUT ##Uebertrag

			return HostObject.VariablesPop();
		}

		bool SUB_subFill()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain
			HostObject.DefineVariable2("mFillStart", "d,8,2");
			HostObject.DefineVariable2("mFillCY", "d,8,2");
			HostObject.Set("mFillStart", @" $[RandY] + ($[cyZeile] * $[Zeile])", true);
			HostObject.Set("mFillCY", @"$[cyZeile]", true);

			HostObject.WriteLine(HostObject.EvalString(@"RGBFILL $[RandX];$[mFillStart];$[SizeX];$[mFillCY];14211288"));

			return HostObject.VariablesPop();
		}

		bool SUB_subFmtAdr1()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain
			if (!HostObject.IsEmpty("adrZeile5"))
				goto Test4;
			HostObject.Set("adrZeile5", @"$[adrZeile4]", true);
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);
			if (!HostObject.IsEmpty("adrZeile5"))
				goto Test4;
			HostObject.Set("adrZeile5", @"$[adrZeile4]", true);
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);
			if (!HostObject.IsEmpty("adrZeile5"))
				goto Test4;
			HostObject.Set("adrZeile5", @"$[adrZeile4]", true);
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);
			if (!HostObject.IsEmpty("adrZeile5"))
				goto Test4;
			HostObject.Set("adrZeile5", @"$[adrZeile4]", true);
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);

			Test4:
			if (!HostObject.IsEmpty("adrZeile4"))
				goto Test3;
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);
			if (!HostObject.IsEmpty("adrZeile4"))
				goto Test3;
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);
			if (!HostObject.IsEmpty("adrZeile4"))
				goto Test3;
			HostObject.Set("adrZeile4", @"$[adrZeile3]", true);
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);

			Test3:
			if (!HostObject.IsEmpty("adrZeile3"))
				goto Test2;
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);
			if (!HostObject.IsEmpty("adrZeile3"))
				goto Test2;
			HostObject.Set("adrZeile3", @"$[adrZeile2]", true);
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);

			Test2:
			if (!HostObject.IsEmpty("adrZeile2"))
				goto Test1;
			HostObject.Set("adrZeile2", @"$[adrZeile1]", true);
			HostObject.Set("adrZeile1", @"", true);

			Test1:

			return HostObject.VariablesPop();
		}

		bool SUB_subT()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			if (!HostObject.EvalBool("$[bTextPrint]"))
				goto EndText;
			SUB_CheckPage();
			HostObject.ProcessResource("outsubT");
			EndText:

			return HostObject.VariablesPop();
		}


		bool SUB_subChkPgH()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subH
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax] - 5)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}

		bool SUB_subH()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			SUB_subChkPgH();
			SUB_subChkHdr();
			if (HostObject.EvalBool("($[recPOS.SATZART]) = (1)"))
				return HostObject.VariablesPop();
			SUB_subFill();
			HostObject.ProcessResource("outsubH");

			return HostObject.VariablesPop();
		}

		bool SUB_subChkPgRab()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subS
			//  Fussbereich ausgeben, wenn letzte Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax]-2)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}

		bool SUB_subS1()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subS
			HostObject.DefineVariable2("cPreis", "C,15,0");
			HostObject.DefineVariable2("nRabattDM", "N,14,2");
			HostObject.DefineVariable2("cRabattDM", "C,15,0");
			HostObject.DefineVariable2("cGP", "C,15,0");

			HostObject.Set("nRabattDM", @"0 - $[recPOS.RABATTDM]", true);
			HostObject.Set("cRabattDM", @"$[nRabattDM!0]", true);
			HostObject.Set("cGP", @"$[recPOS.GP!0]", true);

			HostObject.Set("cPreis", @"$[recPOS.PREIS!0]", true);
			if (HostObject.EvalBool("$[recPOS.NEP]"))
				HostObject.Set("cPreis", @"- N E P -", true);
			if (HostObject.EvalBool("$[recPOS.Entfaellt]"))
				HostObject.Set("cPreis", @"Entfällt", true);
			if (HostObject.EvalBool("$[recPOS.Bedarf]"))
				HostObject.Set("cPreis", @"Bedarf", true);

			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cPreis", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cRabattDM", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cGP", @"..........", true);

			if (HostObject.EvalBool("$[recPOS.RABATTDM] = 0"))
				goto EndRab;
			SUB_subChkPgRab();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubSRab");
			EndRab:

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubSN");

			return HostObject.VariablesPop();
		}

		bool SUB_subS4()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subS

			if (HostObject.EvalBool("$[nTitelEbene] < $[recPOS.Ebene]"))
				HostObject.Set("nTitelEbene", @" $[recPOS.Ebene]", true);

			if (HostObject.EvalBool("$[mNurZus]"))
				return HostObject.VariablesPop();

			if (HostObject.EvalBool("$[mTSum]"))
				return HostObject.VariablesPop();

			HostObject.DefineVariable2("cPreis", "C,15,0");

			HostObject.Set("cPreis", @"$[recPOS.PREIS!0]", true);

			if (HostObject.EvalBool("$[recPOS.NEP]"))
				HostObject.Set("cPreis", @"A ($[cPreis])", true);
			if (HostObject.EvalBool("$[recPOS.Entfaellt]"))
				HostObject.Set("cPreis", @"E ($[cPreis])", true);
			if (HostObject.EvalBool("$[recPOS.Bedarf]"))
				HostObject.Set("cPreis", @"B ($[cPreis])", true);

			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cPreis", @"..........", true);

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubST");

			return HostObject.VariablesPop();
		}

		bool SUB_subS()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG

			if (HostObject.EvalBool("($[recPOS.SATZART]) = (1)"))
				goto SatzArt1;

			if (HostObject.EvalBool("($[recPOS.SATZART]) = (4)"))
				SUB_subS4();

			return HostObject.VariablesPop();

			SatzArt1:
			if (HostObject.EvalBool("$[mNurZus]"))
				goto Zusamenstellung;
			if (HostObject.EvalBool("$[mMitZus]"))
				goto Zusamenstellung;

			goto EndZusammenstellung;

			Zusamenstellung:
			if (HostObject.EvalBool("$[mMitZus]"))
				SUB_Fuss();
			HostObject.Set("bTitZus", @"1", true);
			while(!HostObject.TestEof("recTIT"))
			{
				SUB_loopTITEL();
				HostObject.SkipRecord("recTIT");
			}

			EndZusammenstellung:

			SUB_subS1();

			return HostObject.VariablesPop();
		}

		bool SUB_subJ()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			//  Position oder Jumbo Drucken

			HostObject.DefineVariable2("cMenge", "C,15,0");
			HostObject.DefineVariable2("cEinheit", "C,15,0");
			HostObject.DefineVariable2("cEP", "C,15,0");
			HostObject.DefineVariable2("cGP", "C,15,0");
			HostObject.DefineVariable2("nRabattDM", "N,14,2");
			HostObject.DefineVariable2("cRabattDM", "C,15,0");
			HostObject.DefineVariable2("cText", "C,50,0");

			HostObject.Set("nRabattDM", @"0 - $[recPOS.RABATTDM]", true);
			HostObject.Set("cRabattDM", @"$[nRabattDM!0]", true);
			HostObject.Set("cMenge", @"$[recPOS.MENGE]", true);
			HostObject.Set("cEinheit", @"$[recPOS.EINHEIT]", true);
			HostObject.Set("cEP", @"$[recPOS.EP!0]", true);
			HostObject.Set("cGP", @"$[recPOS.GP!0]", true);
			if (HostObject.EvalBool("$[recPOS.NEP]"))
				HostObject.Set("cGP", @"A ($[cGP])", true);
			if (HostObject.EvalBool("$[recPOS.Entfaellt]"))
				HostObject.Set("cGP", @"E ($[cGP])", true);
			if (HostObject.EvalBool("$[recPOS.Bedarf]"))
				HostObject.Set("cGP", @"B ($[cGP])", true);

			if (HostObject.EvalBool("$[mMengen]"))
				HostObject.Set("cMenge", @"", true);
			if (HostObject.EvalBool("$[mMengen]"))
				HostObject.Set("cEinheit", @"", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEP", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cGP", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cRabattDM", @"..........", true);
			if (HostObject.EvalBool("$[mGP]"))
				HostObject.Set("cGP", @"", true);
			if (HostObject.EvalBool("$[mEP]"))
				HostObject.Set("cEP", @"", true);

			//  ---------------------- 1. Zeile
			if (HostObject.EvalBool("$[mArtnr]"))
				HostObject.Set("cText", @"$[recPOS.ArtNr]", true);
			else
				HostObject.Set("cText", @"$[recPOS.Ktxt1]", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubJ");
			if (HostObject.EvalBool("$[mArtnr]"))
				HostObject.ProcessResource("outsubJ1");


			//  ---------------------- 2. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT2"))
				goto EndKtxt2;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubJ2");
			EndKtxt2:

			//  ---------------------- 3. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT3"))
				goto EndKtxt3;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubJ3");
			EndKtxt3:

			//  ---------------------- Rabattzeile
			if (HostObject.EvalBool("$[recPOS.RABATTDM] = 0"))
				goto EndRab;
			if (HostObject.EvalBool("$[recPOS.NEP]"))
				goto EndRab;
			if (HostObject.EvalBool("$[mGP]"))
				goto EndRab;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubJRab");
			EndRab:

			//  ---------------------- Aufmass
			if (HostObject.EvalBool("$[bAufmass]"))
				SUB_subAufmass();

			return HostObject.VariablesPop();
		}

		bool SUB_subU()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			//  Position oder Jumbo Drucken

			if (!HostObject.EvalBool("$[bUnterpos]"))
				return HostObject.VariablesPop();

			HostObject.DefineVariable2("cMenge", "C,15,0");
			HostObject.DefineVariable2("cEinheit", "C,15,0");
			HostObject.DefineVariable2("cEP", "C,15,0");
			HostObject.DefineVariable2("cText", "C,50,0");

			HostObject.Set("cMenge", @"je $[recPOS.MENGE]", true);
			HostObject.Set("cEinheit", @"$[recPOS.EINHEIT]", true);
			HostObject.Set("cEP", @"$[recPOS.EP!0]", true);
			if (HostObject.EvalBool("$[mMengen]"))
				HostObject.Set("cMenge", @"", true);
			if (HostObject.EvalBool("$[mMengen]"))
				HostObject.Set("cEinheit", @"", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEP", @"..........", true);
			if (HostObject.EvalBool("$[mEP]"))
				HostObject.Set("cEP", @"", true);

			//  ---------------------- 1. Zeile
			if (HostObject.EvalBool("$[mArtnr]"))
				HostObject.Set("cText", @"$[recPOS.ArtNr]", true);
			else
				HostObject.Set("cText", @"$[recPOS.Ktxt1]", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubU");
			if (HostObject.EvalBool("$[mArtnr]"))
				HostObject.ProcessResource("outsubU1");

			//  ---------------------- 2. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT2"))
				goto EndKtxt2;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubU2");
			EndKtxt2:

			//  ---------------------- 3. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT3"))
				goto EndKtxt3;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubU3");
			EndKtxt3:

			//  ---------------------- Aufmass
			if (HostObject.EvalBool("$[bAufmass]"))
				SUB_subAufmass();

			return HostObject.VariablesPop();
		}

		bool SUB_subZ()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			//  Position oder Jumbo Drucken

			if (!HostObject.EvalBool("$[bUnterpos]"))
				return HostObject.VariablesPop();
			if (!HostObject.EvalBool("$[bZubehoer]"))
				return HostObject.VariablesPop();

			HostObject.DefineVariable2("cMenge", "C,15,0");
			HostObject.DefineVariable2("cEinheit", "C,15,0");
			HostObject.DefineVariable2("cText", "C,50,0");

			HostObject.Set("cMenge", @"je $[recPOS.MENGE]", true);
			HostObject.Set("cEinheit", @"$[recPOS.EINHEIT]", true);
			if (HostObject.EvalBool("$[mMengen]"))
				HostObject.Set("cMenge", @"", true);
			if (HostObject.EvalBool("$[mMengen]"))
				HostObject.Set("cEinheit", @"", true);

			//  ---------------------- 1. Zeile
			if (HostObject.EvalBool("$[mArtnr]"))
				HostObject.Set("cText", @"$[recPOS.ArtNr]", true);
			else
				HostObject.Set("cText", @"$[recPOS.Ktxt1]", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubZ");
			if (HostObject.EvalBool("$[mArtnr]"))
				HostObject.ProcessResource("outsubZ1");

			//  ---------------------- 2. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT2"))
				goto EndKtxt2;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubZ2");
			EndKtxt2:

			//  ---------------------- 3. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT3"))
				goto EndKtxt3;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubZ3");
			EndKtxt3:

			return HostObject.VariablesPop();
		}

		bool SUB_subX()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			HostObject.DefineVariable2("cGP", "C,15,0");

			HostObject.Set("cGP", @"$[recPOS.Preis!0]", true);
			if (HostObject.EvalBool("$[recPOS.NEP]"))
				HostObject.Set("cGP", @"- N E P -", true);
			if (HostObject.EvalBool("$[recPOS.Entfaellt]"))
				HostObject.Set("cGP", @"Entfällt", true);
			if (HostObject.EvalBool("$[recPOS.Bedarf]"))
				HostObject.Set("cGP", @"Bedarf", true);

			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cGP", @"..........", true);
			if (HostObject.EvalBool("$[mGP]"))
				HostObject.Set("cGP", @"", true);

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubX");

			return HostObject.VariablesPop();
		}

		bool SUB_loopTXT()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subAufmass/loopMASS
			//  Datensatzschleife recTXT

			HostObject.Set("mZeilen", @"$[mZeilen] + 1", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outMassText");

			return HostObject.VariablesPop();
		}

		bool SUB_loopMASS()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subAufmass
			//  Datensatzschleife recMASS
			HostObject.DefineVariable2("mDetails", "C,50,0");
			HostObject.DefineVariable2("mZeilen", "N,10,0");
			HostObject.Set("mZeilen", @"0", true);
			HostObject.Set("mDetails", @"", true);

			HostObject.DefineRecord("recREF", "BELEGMASSKETTENREFERENZ", 0, 24, HostObject.EvalString(@"$[FltKey<18]$[recMASS.AMREFKEY>6]"));
			HostObject.DefineRecord("recTXT", "BELEGPOSITIONSTEXTE", 0, 25, HostObject.EvalString(@"$[FltKey<18]9$[recMASS.AMREFKEY>6]"));
			HostObject.DefineRecord("recAUF", "BELAUFMASSE", 0, 22, HostObject.EvalString(@"$[FltKey<18]$[recREF.AmNr>4]"));

			//  -------------------------Mit Bauabschnitt
			if (!HostObject.EvalBool("$[mBA]"))
				goto EndeBA;
			if (HostObject.IsEmpty("mDetails"))
				HostObject.Set("mDetails", @"Aufm:", true);
			else
				HostObject.Set("mDetails", @"$[mDetails]  Aufm:", true);
			if (HostObject.IsEmpty("recREF.AmNr"))
				HostObject.Set("mDetails", @"$[mDetails]-/-", true);
			else
				HostObject.Set("mDetails", @"$[mDetails]$[recREF.AmNr]", true);

			if (HostObject.IsEmpty("mDetails"))
				HostObject.Set("mDetails", @"Dat:", true);
			else
				HostObject.Set("mDetails", @"$[mDetails] /", true);
			if (HostObject.CompareString("recMASS.Datum", "=", HostObject.EvalString(@"00.00.0000")))
				HostObject.Set("mDetails", @"$[mDetails] $[recAUF.Datum]", true);
			else
				HostObject.Set("mDetails", @"$[mDetails] $[recMASS.Datum]", true);

			if (HostObject.IsEmpty("mDetails"))
				HostObject.Set("mDetails", @"BA:", true);
			else
				HostObject.Set("mDetails", @"$[mDetails]  BA:", true);
			if (HostObject.IsEmpty("recMASS.BaRef"))
				HostObject.Set("mDetails", @"$[mDetails]-/-", true);
			else
				HostObject.Set("mDetails", @"$[mDetails]$[recMASS.BaRef]", true);

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outMassBA");
			EndeBA:

			//  -------------------------Aufmasslangtext
			if (HostObject.EvalBool("$[mKurz]"))
				goto EndeMassText;
			while(!HostObject.TestEof("recTXT"))
			{
				SUB_loopTXT();
				HostObject.SkipRecord("recTXT");
			}
			HostObject.Set("Zeile", @"$[Zeile] - 1", true);
			HostObject.ProcessResource("outMassMenge");
			goto EndeMassMenge;
			EndeMassText:

			//  -------------------------Aufmassmenge
			if (!HostObject.EvalBool("$[mBA]"))
				goto EndeMassMenge;
			HostObject.Set("Zeile", @"$[Zeile] - 1", true);
			HostObject.ProcessResource("outMassMenge");
			EndeMassMenge:

			HostObject.Set("mMassAnzahl", @"$[mMassAnzahl] + 1", true);
			HostObject.Set("mMassSumme", @"$[mMassSumme] + $[recREF.WERT]", true);

			return HostObject.VariablesPop();
		}

		bool SUB_subAufmass()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG
			HostObject.DefineVariable2("mMassAnzahl", "N,10,0");
			HostObject.DefineVariable2("mMassSumme", "N,10,3");
			HostObject.Set("mMassAnzahl", @"0", true);
			HostObject.Set("mMassSumme", @"0", true);

			HostObject.DefineRecord("recMASS", "AUFMASSREFERENZ", 2, 24, HostObject.EvalString(@"$[FltKey<18]$[recPOS.REFKEY>6]"));
			while(!HostObject.TestEof("recMASS"))
			{
				SUB_loopMASS();
				HostObject.SkipRecord("recMASS");
			}

			if (!HostObject.EvalBool("$[mKurz]"))
				goto EndeMassKurz;
			if (HostObject.EvalBool("$[mBA]"))
				goto EndeMassKurz;
			HostObject.Set("Zeile", @"$[Zeile] - 1", true);
			HostObject.ProcessResource("outMassSumme2");
			goto Ende;
			EndeMassKurz:

			if (!HostObject.EvalBool("$[mMassAnzahl] > 1"))
				goto EndeMassSumme;
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outMassSumme");
			EndeMassSumme:

			Ende:
			return HostObject.VariablesPop();
		}


		bool SUB_subChkPgB12()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB/subB12
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax]-2)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}

		bool SUB_subB12()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB
			HostObject.DefineVariable2("subMSumme", "N,14,2");
			HostObject.DefineVariable2("cEkMat", "C,15,0");
			HostObject.DefineVariable2("cVkMat", "C,15,0");
			HostObject.DefineVariable2("cMSumme", "C,15,0");

			HostObject.Set("cEkMat", @"$[recPOS.EkMat!0]", true);
			HostObject.Set("cVkMat", @"$[recPOS.VkMat!0]", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEkMat", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cVkMat", @"..........", true);

			HostObject.Set("subMSumme", @"$[recPOS.EkMat] + $[recPOS.VkMat]", true);
			HostObject.Set("nEndSumme", @"$[subMSumme]", true);

			HostObject.Set("cMSumme", @"$[subMSumme!0]", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cMSumme", @"..........", true);

			SUB_subChkPgB12();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubM1");
			SUB_subChkPgB12();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubM2");

			return HostObject.VariablesPop();
		}

		bool SUB_subB13()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB
			HostObject.DefineVariable2("subBProz", "N,14,2");
			HostObject.DefineVariable2("subBText", "C,38,0");
			HostObject.DefineVariable2("subBEP", "N,14,2");
			HostObject.DefineVariable2("subBGP", "N,14,2");
			HostObject.DefineVariable2("bNetto", "L,1,0");
			HostObject.DefineVariable2("bAlles", "L,1,0");
			HostObject.DefineVariable2("cEP", "C,15,0");
			HostObject.DefineVariable2("cGP", "C,15,0");

			HostObject.Set("bNetto", @"0", true);
			HostObject.Set("bAlles", @"0", true);

			//  ---------------------- 1. Zeile
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB2");

			//  ---------------------- 2. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT2"))
				goto EndKtxt2;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB3");
			EndKtxt2:

			//  ---------------------- 3. Zeile
			if (HostObject.IsEmpty("recPOS.KTXT3"))
				goto EndKtxt3;

			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB4");
			EndKtxt3:


			if (!HostObject.EvalBool("$[recPOS.VkLohn]=0"))
				HostObject.Set("bNetto", @"1", true);
			if (!HostObject.EvalBool("$[recPOS.VkMat]=0"))
				HostObject.Set("bAlles", @"1", true);

			if (HostObject.EvalBool("$[bNetto]"))
				goto Netto;

			if (HostObject.EvalBool("$[bAlles]"))
				goto Alles;

			goto Ende;


			Netto:
			if (HostObject.EvalBool("$[bAlles]"))
				goto Beides;
			HostObject.Set("Zeile", @"$[Zeile] - 1", true);
			HostObject.Set("subBProz", @"$[recPOS.AufLohn]", true);
			HostObject.Set("subBEP", @"$[recPOS.EkLohn]", true);
			HostObject.Set("subBGP", @"$[recPOS.VkLohn]", true);
			HostObject.Set("nEndSumme", @"$[nEndSumme] + $[subBGP]", true);
			HostObject.Set("cEP", @"$[subBEP!0]", true);
			HostObject.Set("cGP", @"$[subBGP!0]", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEP", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cGP", @"..........", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB1");

			goto Ende;


			Alles:
			if (HostObject.EvalBool("$[bNetto]"))
				goto Beides;
			HostObject.Set("Zeile", @"$[Zeile] - 1", true);
			HostObject.Set("subBText", @"", true);
			HostObject.Set("subBProz", @"$[recPOS.AufMat]", true);
			HostObject.Set("subBEP", @"$[recPOS.EkMat]", true);
			HostObject.Set("subBGP", @"$[recPOS.VkMat]", true);
			HostObject.Set("nEndSumme", @"$[nEndSumme] + $[subBGP]", true);
			HostObject.Set("cEP", @"$[subBEP!0]", true);
			HostObject.Set("cGP", @"$[subBGP!0]", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEP", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cGP", @"..........", true);
			HostObject.ProcessResource("outsubB1");

			goto Ende;


			Beides:
			HostObject.Set("subBText", @"Basis Netto LV-Summe", true);
			HostObject.Set("subBProz", @"$[recPOS.AufLohn]", true);
			HostObject.Set("subBEP", @"$[recPOS.EkLohn]", true);
			HostObject.Set("subBGP", @"$[recPOS.VkLohn]", true);
			HostObject.Set("nEndSumme", @"$[nEndSumme] + $[subBGP]", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB1");
			HostObject.Set("subBText", @"Basis Gesamt-Summe", true);
			HostObject.Set("subBProz", @"$[recPOS.AufMat]", true);
			HostObject.Set("subBEP", @"$[recPOS.EkMat]", true);
			HostObject.Set("subBGP", @"$[recPOS.VkMat]", true);
			HostObject.Set("nEndSumme", @"$[nEndSumme] + $[subBGP]", true);
			HostObject.Set("cEP", @"$[subBEP!0]", true);
			HostObject.Set("cGP", @"$[subBGP!0]", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEP", @"..........", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cGP", @"..........", true);
			SUB_CheckPage();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB1");

			Ende:
			return HostObject.VariablesPop();
		}


		bool SUB_subChkPgB151()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB/subB15
			//  Fussbereich ausgeben, wenn letzte Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax]-2)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}


		bool SUB_subChkPgB152()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB/subB15
			//  Fussbereich ausgeben, wenn letzte Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax]-4)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}

		bool SUB_subB15()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB
			HostObject.DefineVariable2("subRMwst1", "N,14,2");
			HostObject.DefineVariable2("subRMwst2", "N,14,2");

			HostObject.Set("subRMwst1", @"$[recPOS.VkLohn] - $[recPOS.EkLohn]", true);
			HostObject.Set("subRMwst2", @"$[recPOS.VkMat] - $[recPOS.EkMat]", true);

			if (!HostObject.EvalBool("$[bNeedTHdr]"))
				goto EndHeader2;
			SUB_subChkPgB152();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubR1");
			EndHeader2:


			if (HostObject.EvalBool("$[bNeedTHdr]"))
				goto EndHeader;
			SUB_subChkPgB151();
			SUB_subChkHdr();
			EndHeader:

			HostObject.Set("bNeedTHdr", @"0", true);
			HostObject.Set("nEndSumme", @"$[nEndSumme] - $[recPOS.VkMat]", true);
			HostObject.ProcessResource("outsubR2");

			return HostObject.VariablesPop();
		}

		bool SUB_subChkPgB51()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB/subB51
			//  Fussbereich ausgeben, wenn letzte Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax]-2)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();

			return HostObject.VariablesPop();
		}

		bool SUB_subB51()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG/subB

			HostObject.DefineVariable2("cEndSumme", "C,15,0");
			HostObject.Set("cEndSumme", @"$[nEndSumme!0]", true);
			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cEndSumme", @"..........", true);

			SUB_subChkPgB51();
			SUB_subChkHdr();
			HostObject.ProcessResource("outsubB51");

			return HostObject.VariablesPop();
		}

		bool SUB_subB()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopBELEG

			if (HostObject.EvalBool("$[recPOS.SATZART] = 12"))
				SUB_subB12();
			if (HostObject.EvalBool("$[recPOS.SATZART] = 13"))
				SUB_subB13();
			if (HostObject.EvalBool("$[recPOS.SATZART] = 15"))
				SUB_subB15();
			if (HostObject.EvalBool("$[recPOS.SATZART] = 51"))
				SUB_subB51();

			return HostObject.VariablesPop();
		}


		bool SUB_loopBELEG()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain
			//  Datensatzschleife recPOS

			if (HostObject.EvalBool("$[mNurZus]"))
				goto Zusammenstellung;

			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"H")))
				SUB_subH();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"J")))
				SUB_subJ();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"P")))
				SUB_subJ();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"U")))
				SUB_subU();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"Z")))
				SUB_subZ();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"X")))
				SUB_subX();

			Zusammenstellung:
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"B")))
				SUB_subB();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"T")))
				SUB_subT();
			if (HostObject.CompareString("recPOS.VKZ", "=", HostObject.EvalString(@"S")))
				SUB_subS();

			return HostObject.VariablesPop();
		}

		bool SUB_subChkHdr()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain
			if (!HostObject.EvalBool("$[bNeedHdr]"))
				return HostObject.VariablesPop();
			if (HostObject.EvalBool("$[Zeile] >= ($[ZlMax] - 10)"))
				SUB_Fuss();
			//  Kopfbereich ausgeben, wenn erste Zeile erreicht
			if (HostObject.EvalBool("$[Zeile] = 0"))
				SUB_Kopf();
			if (HostObject.EvalBool("$[bTitZus]"))
				HostObject.ProcessResource("outKopfZus");
			else
				HostObject.ProcessResource("KopfDetail");
			HostObject.Set("bNeedHdr", @" 0", true);

			return HostObject.VariablesPop();
		}

		bool SUB_sub4H()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopTITEL
			HostObject.DefineVariable2("mTmp", "N,2,0");
			HostObject.Set("mTmp", @" $[mBisEbene] - 1", true);

			if (HostObject.EvalBool("$[nTitelEbene] = 1"))
				return HostObject.VariablesPop();

			SUB_CheckPage();
			SUB_subChkHdr();

			if (HostObject.EvalBool("$[recTIT.Ebene] = $[mTmp]"))
				HostObject.ProcessResource("outZusH");

			return HostObject.VariablesPop();
		}

		bool SUB_sub4S()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain/loopTITEL
			HostObject.DefineVariable2("cPreis", "C,15,0");
			HostObject.DefineVariable2("mTmp", "N,2,0");
			HostObject.Set("mTmp", @" $[mBisEbene] - 1", true);

			HostObject.Set("cPreis", @"$[recTIT.PREIS!0]", true);
			if (HostObject.EvalBool("$[recTIT.NEP]"))
				HostObject.Set("cPreis", @"A ($[cPreis])", true);
			if (HostObject.EvalBool("$[recTIT.Entfaellt]"))
				HostObject.Set("cPreis", @"E ($[cPreis])", true);
			if (HostObject.EvalBool("$[recTIT.Bedarf]"))
				HostObject.Set("cPreis", @"B ($[cPreis])", true);

			if (HostObject.EvalBool("$[mVerd]"))
				HostObject.Set("cPreis", @"..........", true);

			SUB_CheckPage();
			SUB_subChkHdr();

			if (HostObject.EvalBool("$[nTitelEbene] = 1"))
			{
				HostObject.ProcessResource("outZus");
				return HostObject.VariablesPop();
			}

			if (HostObject.EvalBool("$[recTIT.Ebene] = $[mTmp]"))
				HostObject.ProcessResource("outZusS");
			if (HostObject.EvalBool("$[recTIT.Ebene] = $[mBisEbene]"))
				HostObject.ProcessResource("outZusU");

			return HostObject.VariablesPop();
		}

		bool SUB_loopTITEL()
		{
			HostObject.VariablesPush();

			//  Unterprogramm von ReportMain
			//  Datensatzschleife recTIT

			if (!HostObject.EvalBool("$[recTIT.SATZART]= 4"))
				return HostObject.VariablesPop();

			if (HostObject.CompareString("recTIT.VKZ", "=", HostObject.EvalString(@"H")))
				SUB_sub4H();

			if (HostObject.CompareString("recTIT.VKZ", "=", HostObject.EvalString(@"S")))
				SUB_sub4S();

			return HostObject.VariablesPop();
		}
	}
}
