All files / src/objects/tabl zcl_abapgit_object_tabl_ddl.clas.abap

81.25% Statements 2172/2673
79.48% Branches 403/507
93.75% Functions 30/32
81.25% Lines 2172/2673

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 26741x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x   35x 35x 1x           35x 35x 35x 1x           35x 35x 35x 173x 173x 35x 35x 35x 173x   138x                 138x 41x 41x 101x 101x 41x 41x 60x 60x 101x 58x 58x 101x 41x 41x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 35x 35x 35x 35x 35x 35x 41x 97x 97x 97x 97x 97x 97x 173x 35x           35x                   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 131x 131x 1x 1x     1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 8x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 17142x 17142x 7x 7x 7x 7x 7x 1x 1x 7x 7x 7x 17135x 636x 636x 61x 61x 4x 4x 4x 4x 57x 57x 632x 632x 632x 16499x 57x 56x 56x 57x 57x 17142x 1x 1x 1x 1x 1x 16442x 16441x 1x 1x 1x 1x 1x 39x 39x 1x                             1x 16441x 16440x               16440x 2579x 2579x 2579x 16440x 13861x 600x 600x 600x 600x 600x 600x 600x 600x 13261x 1096x 1096x 13261x 13261x 16498x 16498x 1x           1x           1x 1x 1x 1x 1x 1x 1x 1x 3216x 3216x 2063x 2063x 1153x 1153x 1153x 1153x 1153x 1x 1x 1x 36x 36x 36x 36x 36x 36x 36x 36x 36x 213x 213x 36x 36x 177x 177x 177x 33x 33x 33x 177x 177x 177x 213x 177x 177x 177x           177x 177x 177x 177x 177x 177x 177x 34x           34x 34x 34x 34x 18x 18x 11x 11x 1x 1x 1x 1x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 32x 32x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 34x 4x 4x 34x           34x 34x 34x 34x 1x 1x 30x 30x 1x 1x 34x 34x 34x 34x 34x 34x 34x 34x 1x 1x 1x 1x 1x 1x 1x 213x           213x 213x 213x 213x 213x     213x 213x 213x 213x 213x 213x 213x 213x 36x 36x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 138x 138x 138x 138x 138x 138x 138x 138x 138x 138x 138x 138x 198x 198x 138x 138x 60x 60x 60x 60x 60x 198x 58x 58x 58x           58x 58x 58x 60x 60x 60x 60x 2x           2x 2x 2x 2x 2x 2x 2x 2x           2x 2x 2x 2x 2x 2x 2x           2x 2x 2x 10x           10x 10x           10x 10x 10x           10x 9x           9x 9x 6x           6x 6x 6x 6x 6x 2x 6x 2x 2x 2x 2x 6x 23x 21x 23x 2x 2x           23x 198x           198x 198x 198x           198x 198x 198x 198x 198x 198x 198x 198x 138x 138x 1x 1x 1x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x           132x 132x 7x 7x 7x 7x 132x 132x 6x 6x 6x 6x 6x 6x 6x 6x 126x 126x 126x 126x 126x           126x 126x 126x           126x 3x 3x 3x 3x 3x 3x 3x 3x 3x 123x 123x 123x 123x 123x 168x 168x 21x 21x 21x           21x 21x 168x 123x 147x 24x 24x 24x           24x 20x 20x 20x           20x 20x 20x 20x 20x 20x 20x 20x 20x 24x 4x 4x 4x           4x 4x 4x 4x 4x 4x 4x 4x 4x 4x           24x           168x 123x 126x 132x 132x 129x 132x 3x 3x 3x 3x 3x           132x 132x 20x 20x 20x 20x 20x 132x 4x 4x 4x 4x 132x 132x 132x 1x 1x 1x 9x 9x 9x 9x 9x 9x           9x 9x 9x 17x 17x 2x 2x 2x           2x 2x 2x           2x 2x 2x 17x 6x 6x 6x           6x 6x 15x 9x 9x 9x           17x 9x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 32x 32x 32x           32x 32x 32x 32x 1x 1x 1x 26x 26x 26x 26x 26x 26x 26x 26x 26x           26x 23x 23x 23x 23x 23x 23x 23x 23x 23x 26x           26x 26x 26x 26x 14x 14x 20x 20x     20x 20x 20x 20x           20x 20x 20x           20x 20x 20x 20x 20x 20x 2x 2x 18x 18x           18x 18x 18x 20x 20x 10x 10x 20x 20x 20x 20x 20x 14x 14x 6x 6x 14x 26x 26x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x           4x 4x 4x 4x 4x 4x 8x 8x     8x 8x 8x 8x           8x 8x 8x           8x 8x 8x 8x 8x 8x       8x 8x           8x 8x 8x 8x 8x 7x 7x 8x 8x 8x 8x 8x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x           6x 6x 6x 6x           6x 6x 6x 6x 6x 12x 12x 12x 4x 4x 4x 12x 2x 2x 2x 8x                                                                                       6x 6x 6x 6x           6x 6x 6x 6x           6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x                                                   6x           12x 6x           6x 6x 1x 1x 1x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 17x 17x 17x 17x 106x 106x 106x 68x 68x           68x 68x 68x 68x 68x 68x 68x 68x 68x 38x 38x 106x 106x 106x 106x 106x 106x 106x 106x 106x 1x 1x 1x 106x           106x           106x 106x 106x 106x 52x           52x 52x 52x 52x 106x 10x           10x 10x 10x 10x 10x 10x 54x 6x           6x 6x 6x 6x 6x 6x 44x         38x 38x 10x 10x 10x 38x 28x 28x 28x 20x 20x 20x 28x 8x 8x 8x 8x 8x 8x 8x 8x           106x 1x 1x 1x 52x 52x 35x 35x 35x 35x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 2x 2x 2x 2x 52x 52x 52x 52x 52x 52x 52x 52x 52x 1x 1x 1x 10x 10x 10x 10x 10x 10x 1x 1x 1x 10x 10x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 20x 20x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 14x 8x 8x 8x 6x 6x 6x 14x 4x 14x 2x 10x 2x 8x 2x 6x 2x 2x 2x 2x 14x 6x 6x 6x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 110x 110x 110x 7x 7x 110x 110x 110x 107x 107x 3x 3x 110x 38x 38x 110x 1x 116x 116x 9x 9x 116x 116x 3x 3x 116x 63x 63x 63x 63x 116x   116x 9x 6x 6x 9x 9x 2x 2x 2x 9x 6x 6x 3x 3x 9x 9x 9x 9x 5x 5x 4x 4x 4x 9x 9x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 107x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 1x 1x 10x 10x 10x 2x 2x 2x 11x 1x 2x     2x 2x 2x       2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 12x 6x 6x 6x 6x 1x 14x 2x 2x 12x 12x 12x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x     6x 6x 6x 6x 6x 6x                 6x 6x 6x 6x 2x 2x 4x 4x 14x 1x 4x     4x 4x 4x 4x 4x                                   4x 1x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 3x 3x 3x 4x 4x 4x 4x 4x 4x 4x 4x 4x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 3x 7x 3x 3x 7x 1x 1x 9x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 86x 86x 27x 27x 27x 27x 27x 27x 27x 27x 27x 24x 24x 27x 1x 21x 21x 21x 27x 1x 21x 15x 15x 6x 6x 21x 1x 1x 20x 20x 20x 21x 1x 1x 1x 1x 1x 1x 1x 86x 86x 27x 10x 10x 10x 10x 10x 27x 1x 1x 7x 2x 6x 4x 4x       1x 26x 26x 1x 1x 27x 1x 1x 27x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x     1x 1x 1x 21x 21x 11x 11x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 35x 35x 1x 1x 1x 1x 35x 1x 34x       1x 1x 2x 1x 1x 34x 33x 33x       1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 39x 39x 1x 34x 34x 73x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 70x 1x 69x 68x 7x 68x 3x 2x 2x 1x 1x 61x 58x 58x 58x 37x 37x 21x 21x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 103x 103x 4x 1x 8x 8x 8x 4x 1x 8x 4x 4x 4x 4x 8x     8x 8x 8x 8x 1x 1x  
CLASS zcl_abapgit_object_tabl_ddl DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    METHODS read_data
      IMPORTING
        !iv_name       TYPE tadir-obj_name
        !iv_language   TYPE sy-langu DEFAULT 'E'
      RETURNING
        VALUE(rs_data) TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS serialize
      IMPORTING
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS deserialize
      IMPORTING
        !iv_ddl        TYPE string
      RETURNING
        VALUE(rs_data) TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS serialize_adt
      IMPORTING
        !iv_name      TYPE tadir-obj_name
      RETURNING
        VALUE(rv_ddl) TYPE string
      RAISING
        cx_static_check .
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    TYPES: BEGIN OF ty_token,
             value  TYPE string,
             offset TYPE i,
           END OF ty_token.
    TYPES ty_tokens TYPE STANDARD TABLE OF ty_token WITH DEFAULT KEY.
    TYPES ty_fields TYPE STANDARD TABLE OF string WITH DEFAULT KEY.
    TYPES: BEGIN OF ty_cardinality,
             token    TYPE string,
             cardleft TYPE dd08v-cardleft,
             card     TYPE dd08v-card,
           END OF ty_cardinality.
    TYPES ty_cardinalities TYPE STANDARD TABLE OF ty_cardinality WITH DEFAULT KEY.
    TYPES: BEGIN OF ty_reference,
             reftable TYPE dd03p-reftable,
             reffield TYPE dd03p-reffield,
             datatype TYPE dd03p-datatype,
           END OF ty_reference.
    TYPES ty_references TYPE SORTED TABLE OF ty_reference WITH UNIQUE KEY reftable reffield.
 
    " Buffers DDIC lookups for references pointing outside the table being
    " serialized, so a table with many amount or quantity fields does not
    " trigger one DDIF_FIELDINFO_GET per field on every serialize call.
    DATA mt_reference TYPE ty_references.
 
    METHODS tokenize
      IMPORTING
        !iv_ddl          TYPE string
      RETURNING
        VALUE(rt_tokens) TYPE ty_tokens
      RAISING
        zcx_abapgit_exception .
    METHODS flush_token
      IMPORTING
        !iv_offset  TYPE i
      CHANGING
        !cv_current TYPE string
        !ct_tokens  TYPE ty_tokens .
    METHODS parse_error
      IMPORTING
        !iv_context TYPE clike
        !iv_token   TYPE clike
        !iv_offset  TYPE i
      RAISING
        zcx_abapgit_exception .
    METHODS parse_activation_type
      IMPORTING
        !iv_value           TYPE string
      RETURNING
        VALUE(rv_authclass) TYPE dd02v-authclass
      RAISING
        zcx_abapgit_exception .
    METHODS get_replacement_object
      IMPORTING
        !iv_viewref      TYPE clike
      RETURNING
        VALUE(rv_object) TYPE string .
    METHODS get_replacement_view
      IMPORTING
        !iv_entityname     TYPE clike
      RETURNING
        VALUE(rv_viewname) TYPE string .
    METHODS parse_replacement_object
      IMPORTING
        !iv_value TYPE clike
        !iv_name  TYPE clike
      CHANGING
        !cs_data  TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS parse_top_annotations
      IMPORTING
        !it_tokens TYPE ty_tokens
      CHANGING
        !cv_index  TYPE i
        !cs_data   TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS parse_field_annotations
      IMPORTING
        !it_tokens TYPE ty_tokens
      CHANGING
        !cv_index  TYPE i
        !cs_dd03p  TYPE dd03p
        !cs_dd08v  TYPE dd08v
      RAISING
        zcx_abapgit_exception .
    METHODS parse_field
      IMPORTING
        !it_tokens TYPE ty_tokens
      CHANGING
        !cv_index  TYPE i
        !cs_data   TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS parse_include
      IMPORTING
        !it_tokens TYPE ty_tokens
      CHANGING
        !cv_index  TYPE i
        !cs_dd03p  TYPE dd03p
      RAISING
        zcx_abapgit_exception .
    METHODS parse_foreign_key
      IMPORTING
        !it_tokens    TYPE ty_tokens
        !iv_fieldname TYPE clike
      CHANGING
        !cv_index     TYPE i
        !cs_dd08v     TYPE dd08v
        !cs_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS parse_value_help
      IMPORTING
        !it_tokens    TYPE ty_tokens
        !iv_fieldname TYPE clike
      CHANGING
        !cv_index     TYPE i
        !cs_dd35v     TYPE dd35v
        !cs_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RAISING
        zcx_abapgit_exception .
    METHODS parse_extension
      IMPORTING
        !it_tokens TYPE ty_tokens
      CHANGING
        !cv_index  TYPE i
        !cs_data   TYPE zif_abapgit_object_tabl=>ty_internal
        !cs_dd08v  TYPE dd08v
        !cs_dd35v  TYPE dd35v
      RAISING
        zcx_abapgit_exception .
    METHODS is_block_terminator
      IMPORTING
        !iv_token            TYPE clike
      RETURNING
        VALUE(rv_terminator) TYPE abap_bool .
    METHODS get_cardinalities
      RETURNING
        VALUE(rt_cardinalities) TYPE ty_cardinalities .
    METHODS parse_cardinality
      IMPORTING
        !iv_token  TYPE clike
        !iv_offset TYPE i
      CHANGING
        !cs_dd08v  TYPE dd08v
      RAISING
        zcx_abapgit_exception .
    METHODS parse_type
      IMPORTING
        !iv_token TYPE string
      CHANGING
        !cs_dd03p TYPE dd03p
      RAISING
        zcx_abapgit_exception .
    METHODS set_builtin_type
      IMPORTING
        !iv_base     TYPE string
        !iv_length   TYPE string
        !iv_decimals TYPE string
        !iv_offset   TYPE i
      CHANGING
        !cs_dd03p    TYPE dd03p
      RAISING
        zcx_abapgit_exception .
    METHODS set_character_type
      IMPORTING
        !iv_base  TYPE string
      CHANGING
        !cs_dd03p TYPE dd03p .
    METHODS set_numeric_type
      IMPORTING
        !iv_base     TYPE string
        !iv_length   TYPE string
        !iv_decimals TYPE string
      CHANGING
        !cs_dd03p    TYPE dd03p .
    METHODS set_integer_type
      IMPORTING
        !iv_base  TYPE string
      CHANGING
        !cs_dd03p TYPE dd03p .
    METHODS set_date_type
      IMPORTING
        !iv_base  TYPE string
      CHANGING
        !cs_dd03p TYPE dd03p .
    METHODS set_decfloat_type
      IMPORTING
        !iv_base     TYPE string
        !iv_length   TYPE string
        !iv_decimals TYPE string
      CHANGING
        !cs_dd03p    TYPE dd03p .
    METHODS serialize_top
      IMPORTING
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS serialize_extend
      IMPORTING
        !is_dd03p     TYPE dd03p
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS is_foreign_key_extension
      IMPORTING
        !is_dd08v           TYPE dd08v
      RETURNING
        VALUE(rv_extension) TYPE abap_bool .
    METHODS is_value_help_extension
      IMPORTING
        !is_dd35v           TYPE dd35v
      RETURNING
        VALUE(rv_extension) TYPE abap_bool .
    METHODS has_more_extensions
      IMPORTING
        !it_fields     TYPE ty_fields
        !is_data       TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_more) TYPE abap_bool .
    METHODS get_reference_datatype
      IMPORTING
        !is_field          TYPE dd03p
        !is_data           TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_datatype) TYPE dd03p-datatype .
    METHODS serialize_field_annotations
      IMPORTING
        !iv_fieldname TYPE clike
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string .
    METHODS serialize_fkey_annotations
      IMPORTING
        !iv_fieldname TYPE clike
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS serialize_field_foreign_key
      IMPORTING
        !iv_fieldname TYPE clike
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS serialize_value_help
      IMPORTING
        !iv_fieldname TYPE clike
        !is_data      TYPE zif_abapgit_object_tabl=>ty_internal
      RETURNING
        VALUE(rv_ddl) TYPE string .
    METHODS escape_string
      IMPORTING
        !iv_string       TYPE clike
      RETURNING
        VALUE(rv_string) TYPE string .
    METHODS unescape_string
      IMPORTING
        !iv_string       TYPE clike
      RETURNING
        VALUE(rv_string) TYPE string .
    METHODS escape_name
      IMPORTING
        !iv_name       TYPE clike
      RETURNING
        VALUE(rv_name) TYPE string .
    METHODS unescape_name
      IMPORTING
        !iv_name       TYPE clike
      RETURNING
        VALUE(rv_name) TYPE string .
    METHODS serialize_type
      IMPORTING
        !is_dd03p      TYPE dd03p
      RETURNING
        VALUE(rv_type) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS serialize_type_core
      IMPORTING
        !is_dd03p      TYPE dd03p
      RETURNING
        VALUE(rv_type) TYPE string
      RAISING
        zcx_abapgit_exception .
    METHODS serialize_type_special
      IMPORTING
        !is_dd03p      TYPE dd03p
      RETURNING
        VALUE(rv_type) TYPE string
      RAISING
        zcx_abapgit_exception .
ENDCLASS.
 
 
 
CLASS ZCL_ABAPGIT_OBJECT_TABL_DDL IMPLEMENTATION.
 
 
  METHOD deserialize.
 
    DATA lt_tokens TYPE ty_tokens.
    DATA ls_token TYPE ty_token.
    DATA ls_probe TYPE ty_token.
    DATA lv_index TYPE i VALUE 1.
    DATA lv_probe TYPE i.
    DATA lv_end TYPE abap_bool.
    DATA ls_dd03p TYPE dd03p.
    DATA ls_dd08v TYPE dd08v.
    DATA ls_dd35v TYPE dd35v.
 
    lt_tokens = tokenize( iv_ddl ).
    parse_top_annotations(
      EXPORTING
        it_tokens = lt_tokens
      CHANGING
        cv_index = lv_index
        cs_data = rs_data ).
 
    READ TABLE lt_tokens INDEX lv_index INTO ls_token.
    IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'define'.
      parse_error(
        iv_context = 'expected DEFINE TABLE header'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    lv_index = lv_index + 1.
    READ TABLE lt_tokens INDEX lv_index INTO ls_token.
    IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'table'.
      parse_error(
        iv_context = 'expected TABLE after DEFINE'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    lv_index = lv_index + 1.
    READ TABLE lt_tokens INDEX lv_index INTO ls_token.
    IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
      parse_error(
        iv_context = 'expected table name'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    rs_data-dd02v-tabname = to_upper( ls_token-value ).
    lv_index = lv_index + 1.
    READ TABLE lt_tokens INDEX lv_index INTO ls_token.
    IF sy-subrc <> 0 OR ls_token-value <> '{'.
      parse_error(
        iv_context = 'expected opening brace'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    lv_index = lv_index + 1.
 
    WHILE lv_index <= lines( lt_tokens ).
      READ TABLE lt_tokens INDEX lv_index INTO ls_token.
      IF ls_token-value = '}'.
        lv_end = abap_true.
        lv_index = lv_index + 1.
        EXIT.
      ELSEIF ls_token-value = ';'.
        lv_index = lv_index + 1.
      ELSEIF to_lower( ls_token-value ) = 'extend'.
        CLEAR: ls_dd08v, ls_dd35v.
        parse_extension(
          EXPORTING it_tokens = lt_tokens
          CHANGING
            cv_index = lv_index
            cs_data = rs_data
            cs_dd08v = ls_dd08v
            cs_dd35v = ls_dd35v ).
      ELSEIF strlen( ls_token-value ) > 0 AND ls_token-value(1) = '@'.
        lv_probe = lv_index.
        WHILE lv_probe <= lines( lt_tokens ).
          READ TABLE lt_tokens INDEX lv_probe INTO ls_probe.
          IF strlen( ls_probe-value ) = 0 OR ls_probe-value(1) <> '@'.
            EXIT.
          ENDIF.
          lv_probe = lv_probe + 1.
          READ TABLE lt_tokens INDEX lv_probe INTO ls_probe.
          IF sy-subrc = 0 AND ls_probe-value = ':'.
            lv_probe = lv_probe + 2.
          ENDIF.
        ENDWHILE.
        READ TABLE lt_tokens INDEX lv_probe INTO ls_probe.
        IF sy-subrc = 0 AND to_lower( ls_probe-value ) = 'extend'.
          CLEAR: ls_dd03p, ls_dd08v, ls_dd35v.
          parse_field_annotations(
            EXPORTING it_tokens = lt_tokens
            CHANGING
              cv_index = lv_index
              cs_dd03p = ls_dd03p
              cs_dd08v = ls_dd08v ).
          parse_extension(
            EXPORTING it_tokens = lt_tokens
            CHANGING
              cv_index = lv_index
              cs_data = rs_data
              cs_dd08v = ls_dd08v
              cs_dd35v = ls_dd35v ).
        ELSE.
          parse_field(
            EXPORTING it_tokens = lt_tokens
            CHANGING
              cv_index = lv_index
              cs_data = rs_data ).
        ENDIF.
      ELSE.
        parse_field(
          EXPORTING it_tokens = lt_tokens
          CHANGING
            cv_index = lv_index
            cs_data = rs_data ).
      ENDIF.
    ENDWHILE.
    IF lv_end = abap_false.
      parse_error(
        iv_context = 'missing closing brace'
        iv_token = ''
        iv_offset = strlen( iv_ddl ) ).
    ENDIF.
    WHILE lv_index <= lines( lt_tokens ).
      READ TABLE lt_tokens INDEX lv_index INTO ls_token.
      IF ls_token-value <> ';'.
        parse_error(
          iv_context = 'unexpected token after table definition'
          iv_token = ls_token-value
          iv_offset = ls_token-offset ).
      ENDIF.
      lv_index = lv_index + 1.
    ENDWHILE.
 
  ENDMETHOD.
 
 
  METHOD escape_string.
    DATA lv_escaped TYPE string.
    lv_escaped = replace(
      val = iv_string
      sub = |'|
      with = |''|
      occ = 0 ).
    rv_string = |'{ lv_escaped }'|.
  ENDMETHOD.
 
 
  METHOD unescape_string.
    rv_string = iv_string.
    REPLACE FIRST OCCURRENCE OF REGEX |^'| IN rv_string WITH || ##REGEX_POSIX.
    REPLACE FIRST OCCURRENCE OF REGEX |'$| IN rv_string WITH || ##REGEX_POSIX.
    REPLACE ALL OCCURRENCES OF |''| IN rv_string WITH |'|.
  ENDMETHOD.
 
 
  METHOD escape_name.
    CONSTANTS lc_plain TYPE string VALUE 'abcdefghijklmnopqrstuvwxyz0123456789_/'.
    rv_name = to_lower( iv_name ).
    " A name that is not a plain identifier has to be written as a delimited
    " name, for example the %ADMIN group of a draft admin include.
    IF rv_name CN lc_plain.
      rv_name = |"{ rv_name }"|.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD unescape_name.
    DATA lv_length TYPE i.
    DATA lv_last TYPE i.
    rv_name = iv_name.
    lv_length = strlen( rv_name ).
    IF lv_length < 2 OR rv_name(1) <> '"'.
      RETURN.
    ENDIF.
    lv_last = lv_length - 1.
    IF rv_name+lv_last(1) <> '"'.
      RETURN.
    ENDIF.
    lv_length = lv_length - 2.
    rv_name = rv_name+1(lv_length).
  ENDMETHOD.
 
 
  METHOD parse_error.
    zcx_abapgit_exception=>raise( |TABL DDL parse error at offset { iv_offset }: { iv_context } ({ iv_token })| ).
  ENDMETHOD.
 
 
  METHOD is_block_terminator.
    " ADT table DDL omits the semicolon when the next construct already ends
    " the current block, which is the case for a field annotation and for the
    " start of a component extension.
    IF strlen( iv_token ) > 0 AND iv_token(1) = '@'.
      rv_terminator = abap_true.
    ELSEIF to_lower( iv_token ) = 'extend'.
      rv_terminator = abap_true.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD get_replacement_object.
 
    DATA lv_view_name TYPE ddobjname.
    DATA lv_entityname TYPE ddobjname.
 
    lv_view_name = to_upper( iv_viewref ).
    IF lv_view_name IS INITIAL.
      RETURN.
    ENDIF.
 
    TRY.
        " DD02V-VIEWREF contains the database view name. DDL uses the
        " corresponding CDS entity name instead.
        CALL METHOD ('CL_SBD_DDLS_UTILITY')=>('MAP_TO_REPLACEMENT_DDLS')
          EXPORTING
            i_view_name  = lv_view_name
          IMPORTING
            e_entityname = lv_entityname.
        rv_object = lv_entityname.
      CATCH cx_root.
        " The utility is not available on older releases and is also absent
        " from the open-abap test runtime. In that case no annotation is
        " emitted rather than serializing DD02V-VIEWREF with the wrong
        " meaning.
        CLEAR rv_object.
    ENDTRY.
 
  ENDMETHOD.
 
 
  METHOD get_replacement_view.
 
    DATA lv_entityname TYPE ddobjname.
    DATA lv_view_name TYPE ddobjname.
 
    lv_entityname = to_upper( iv_entityname ).
    IF lv_entityname IS INITIAL.
      RETURN.
    ENDIF.
 
    TRY.
        " The reverse mapping is needed when DDL is saved back to TABL:
        " DD02V-VIEWREF must receive the database view name.
        CALL METHOD ('CL_SBD_DDLS_UTILITY')=>('MAP_TO_REPLACEMENT_VIEW')
          EXPORTING
            i_entityname = lv_entityname
          IMPORTING
            e_view_name = lv_view_name.
        rv_viewname = lv_view_name.
      CATCH cx_root.
        " Keep source-only parsing usable on releases without the SAP
        " utility. A SAP system with the utility returns the resolved view
        " name, or initial for an entity that cannot be resolved.
        rv_viewname = lv_entityname.
    ENDTRY.
 
  ENDMETHOD.
 
 
  METHOD parse_replacement_object.
    DATA lv_entityname TYPE string.
 
    lv_entityname = unescape_string( iv_value ).
    IF lv_entityname IS INITIAL.
      parse_error(
        iv_context = 'replacement object is missing'
        iv_token = iv_name
        iv_offset = 0 ).
    ENDIF.
    cs_data-dd02v-viewref = get_replacement_view( lv_entityname ).
    IF cs_data-dd02v-viewref IS INITIAL.
      parse_error(
        iv_context = 'replacement object cannot be resolved'
        iv_token = lv_entityname
        iv_offset = 0 ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD tokenize.
 
    DATA lv_offset TYPE i.
    DATA lv_length TYPE i.
    DATA lv_start TYPE i.
    DATA lv_next TYPE i.
    DATA lv_quoted TYPE abap_bool.
    DATA lv_delimited TYPE abap_bool.
    DATA lv_char TYPE string.
    DATA lv_current TYPE string.
    DATA ls_token TYPE ty_token.
 
    lv_length = strlen( iv_ddl ).
    WHILE lv_offset < lv_length.
      lv_char = iv_ddl+lv_offset(1).
      IF lv_delimited = abap_true.
        " A delimited name runs to the closing double quote. The quotes are
        " kept in the token so the parser can tell a delimited name apart
        " from a keyword.
        lv_current = lv_current && lv_char.
        IF lv_char = '"'.
          lv_delimited = abap_false.
        ENDIF.
        lv_offset = lv_offset + 1.
        CONTINUE.
      ENDIF.
      IF lv_quoted = abap_true.
        lv_current = lv_current && lv_char.
        IF lv_char = |'|.
          lv_next = lv_offset + 1.
          IF lv_next < lv_length AND iv_ddl+lv_next(1) = |'|.
            lv_current = lv_current && |'|.
            lv_offset = lv_offset + 2.
            CONTINUE.
          ENDIF.
          lv_quoted = abap_false.
        ENDIF.
        lv_offset = lv_offset + 1.
        CONTINUE.
      ENDIF.
      IF lv_char = |'|.
        IF lv_current IS INITIAL.
          lv_start = lv_offset.
        ENDIF.
        lv_quoted = abap_true.
        lv_current = lv_current && lv_char.
      ELSEIF lv_char = '"'.
        IF lv_current IS INITIAL.
          lv_start = lv_offset.
        ENDIF.
        lv_delimited = abap_true.
        lv_current = lv_current && lv_char.
      ELSEIF lv_char = '/' AND lv_offset + 1 < lv_length
          AND ( iv_ddl+lv_offset(2) = '//' OR iv_ddl+lv_offset(2) = '/*' ).
        flush_token(
          EXPORTING iv_offset = lv_start
          CHANGING cv_current = lv_current ct_tokens = rt_tokens ).
        IF iv_ddl+lv_offset(2) = '//'.
          WHILE lv_offset < lv_length AND iv_ddl+lv_offset(1) <> |\n|.
            lv_offset = lv_offset + 1.
          ENDWHILE.
        ELSE.
          lv_start = lv_offset.
          lv_offset = lv_offset + 2.
          WHILE lv_offset + 1 < lv_length
              AND iv_ddl+lv_offset(2) <> '*/'.
            lv_offset = lv_offset + 1.
          ENDWHILE.
          IF lv_offset + 1 >= lv_length.
            parse_error(
              iv_context = 'unterminated block comment'
              iv_token = '/*'
              iv_offset = lv_start ).
          ENDIF.
          lv_offset = lv_offset + 2.
        ENDIF.
        CONTINUE.
      ELSEIF lv_char = '-' AND lv_offset + 1 < lv_length
          AND iv_ddl+lv_offset(2) = '--'.
        flush_token(
          EXPORTING iv_offset = lv_start
          CHANGING cv_current = lv_current ct_tokens = rt_tokens ).
        WHILE lv_offset < lv_length AND iv_ddl+lv_offset(1) <> |\n|.
          lv_offset = lv_offset + 1.
        ENDWHILE.
        CONTINUE.
      ELSEIF lv_char = | | OR lv_char = |\n| OR lv_char = |\r| OR lv_char = |\t|.
        flush_token(
          EXPORTING iv_offset = lv_start
          CHANGING cv_current = lv_current ct_tokens = rt_tokens ).
      ELSEIF lv_char = ':' OR lv_char = ';' OR lv_char = '='
          OR lv_char = '{' OR lv_char = '}'.
        flush_token(
          EXPORTING iv_offset = lv_start
          CHANGING cv_current = lv_current ct_tokens = rt_tokens ).
        CLEAR ls_token.
        ls_token-value = lv_char.
        ls_token-offset = lv_offset.
        APPEND ls_token TO rt_tokens.
      ELSE.
        IF lv_current IS INITIAL.
          lv_start = lv_offset.
        ENDIF.
        lv_current = lv_current && lv_char.
      ENDIF.
      lv_offset = lv_offset + 1.
    ENDWHILE.
    IF lv_quoted = abap_true.
      parse_error(
        iv_context = 'unterminated string literal'
        iv_token = lv_current
        iv_offset = lv_start ).
    ENDIF.
    IF lv_delimited = abap_true.
      parse_error(
        iv_context = 'unterminated delimited name'
        iv_token = lv_current
        iv_offset = lv_start ).
    ENDIF.
    flush_token(
      EXPORTING iv_offset = lv_start
      CHANGING cv_current = lv_current ct_tokens = rt_tokens ).
 
  ENDMETHOD.
 
 
  METHOD flush_token.
    DATA ls_token TYPE ty_token.
    IF cv_current IS INITIAL.
      RETURN.
    ENDIF.
    ls_token-value = cv_current.
    ls_token-offset = iv_offset.
    APPEND ls_token TO ct_tokens.
    CLEAR cv_current.
  ENDMETHOD.
 
 
  METHOD parse_top_annotations.
 
    DATA ls_token TYPE ty_token.
    DATA lv_name TYPE string.
    DATA lv_value TYPE string.
    DATA lv_compare TYPE string.
    FIELD-SYMBOLS <lv_is_gtt> TYPE abap_bool.
    FIELD-SYMBOLS <lv_pk_is_invhash> TYPE c.
 
    WHILE cv_index <= lines( it_tokens ).
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF strlen( ls_token-value ) = 0 OR ls_token-value(1) <> '@'.
        EXIT.
      ENDIF.
      lv_name = to_lower( ls_token-value ).
      CONDENSE lv_name NO-GAPS.
      IF lv_name = '@abapcatalog.enhancement.category'.
        " Accept the dotted spelling used by current table DDL.
        lv_name = '@abapcatalog.enhancementcategory'.
      ENDIF.
      cv_index = cv_index + 1.
      CLEAR lv_value.
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF sy-subrc = 0 AND ls_token-value = ':'.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0.
          parse_error(
            iv_context = 'annotation value is missing'
            iv_token = lv_name
            iv_offset = 0 ).
        ENDIF.
        lv_value = ls_token-value.
        cv_index = cv_index + 1.
      ENDIF.
      lv_compare = lv_value.
      CONDENSE lv_compare NO-GAPS.
      CASE lv_name.
        WHEN '@endusertext.label'.
          IF lv_value IS INITIAL.
            parse_error(
              iv_context = 'annotation value is missing'
              iv_token = lv_name
              iv_offset = 0 ).
          ENDIF.
          cs_data-dd02v-ddtext = unescape_string( lv_value ).
        WHEN '@abapcatalog.enhancementcategory'.
          CASE to_upper( lv_compare ).
            WHEN '#NOT_CLASSIFIED'.
              cs_data-dd02v-exclass = '0'.
            WHEN '#NOT_EXTENSIBLE'.
              cs_data-dd02v-exclass = '1'.
            WHEN '#EXTENSIBLE_CHARACTER'.
              cs_data-dd02v-exclass = '2'.
            WHEN '#EXTENSIBLE_CHARACTER_NUMERIC'.
              cs_data-dd02v-exclass = '3'.
            WHEN '#EXTENSIBLE_ANY'.
              cs_data-dd02v-exclass = '4'.
            WHEN OTHERS.
              parse_error(
                iv_context = 'unsupported enhancement category'
                iv_token = lv_value
                iv_offset = 0 ).
          ENDCASE.
        WHEN '@abapcatalog.tablecategory'.
          CASE to_upper( lv_compare ).
            WHEN '#TRANSPARENT'.
              cs_data-dd02v-tabclass = 'TRANSP'.
            WHEN '#GLOBAL_TEMPORARY'.
              cs_data-dd02v-tabclass = 'TRANSP'.
              ASSIGN COMPONENT 'IS_GTT' OF STRUCTURE cs_data-dd02v TO <lv_is_gtt>.
              IF sy-subrc = 0.
                <lv_is_gtt> = abap_true.
              ENDIF.
            WHEN OTHERS.
              parse_error(
                iv_context = 'unsupported table category'
                iv_token = lv_value
                iv_offset = 0 ).
          ENDCASE.
        WHEN '@abapcatalog.activationtype'.
          cs_data-dd02v-authclass = parse_activation_type( lv_value ).
        WHEN '@abapcatalog.deliveryclass'.
          IF strlen( lv_compare ) <> 2 OR lv_compare(1) <> '#'.
            parse_error(
              iv_context = 'invalid delivery class'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          cs_data-dd02v-contflag = to_upper( lv_compare+1 ).
        WHEN '@abapcatalog.datamaintenance'.
          CASE to_upper( lv_compare ).
            WHEN '#ALLOWED'.
              cs_data-dd02v-mainflag = abap_true.
            WHEN '#RESTRICTED'.
              CLEAR cs_data-dd02v-mainflag.
            WHEN '#LIMITED'.
              CLEAR cs_data-dd02v-mainflag.
            WHEN '#NOT_ALLOWED'.
              cs_data-dd02v-mainflag = 'N'.
            WHEN OTHERS.
              parse_error(
                iv_context = 'unsupported data maintenance value'
                iv_token = lv_value
                iv_offset = 0 ).
          ENDCASE.
        WHEN '@abapcatalog.replacementobject'.
          parse_replacement_object(
            EXPORTING
              iv_value = lv_value
              iv_name = lv_name
            CHANGING
              cs_data = cs_data ).
        WHEN '@abapcatalog.primarykey.invertedindividualindex'.
          IF to_lower( lv_compare ) <> 'true' AND to_lower( lv_compare ) <> 'false'.
            parse_error(
              iv_context = 'invalid inverted individual index value'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          ASSIGN COMPONENT 'PK_IS_INVHASH' OF STRUCTURE cs_data-dd02v TO <lv_pk_is_invhash>.
          IF sy-subrc = 0.
            IF to_lower( lv_compare ) = 'true'.
              <lv_pk_is_invhash> = abap_true.
            ELSE.
              CLEAR <lv_pk_is_invhash>.
            ENDIF.
          ENDIF.
        WHEN OTHERS.
          parse_error(
            iv_context = 'unsupported table annotation'
            iv_token = lv_name
            iv_offset = 0 ).
      ENDCASE.
    ENDWHILE.
 
  ENDMETHOD.
 
 
  METHOD parse_activation_type.
    CASE to_upper( iv_value ).
      WHEN '#NAMETAB_GENERATION_OFFLINE'.
        rv_authclass = '01'.
      WHEN '#ADAPT_C_STRUCTURES'.
        rv_authclass = '02'.
      WHEN '#INITIAL_TABLE_REQUIRED'.
        rv_authclass = '10'.
      WHEN OTHERS.
        parse_error(
          iv_context = 'unsupported activation type'
          iv_token = iv_value
          iv_offset = 0 ).
    ENDCASE.
  ENDMETHOD.
 
 
  METHOD parse_field_annotations.
 
    DATA ls_token TYPE ty_token.
    DATA lv_name TYPE string.
    DATA lv_value TYPE string.
    DATA lv_compare TYPE string.
    DATA lv_reference TYPE string.
    DATA lv_table TYPE string.
    DATA lv_field TYPE string.
    DATA lv_keytype TYPE string.
    FIELD-SYMBOLS <lv_outputstyle> TYPE zif_abapgit_aff_doma_v1=>ty_output_style.
 
    WHILE cv_index <= lines( it_tokens ).
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF strlen( ls_token-value ) = 0 OR ls_token-value(1) <> '@'.
        EXIT.
      ENDIF.
      lv_name = to_lower( ls_token-value ).
      CONDENSE lv_name NO-GAPS.
      cv_index = cv_index + 1.
      CLEAR lv_value.
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF sy-subrc = 0 AND ls_token-value = ':'.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0.
          parse_error(
            iv_context = 'field annotation value is missing'
            iv_token = lv_name
            iv_offset = 0 ).
        ENDIF.
        lv_value = ls_token-value.
        cv_index = cv_index + 1.
      ENDIF.
      lv_compare = lv_value.
      CONDENSE lv_compare NO-GAPS.
      CASE lv_name.
        WHEN '@endusertext.label'.
          IF lv_value IS INITIAL.
            parse_error(
              iv_context = 'field annotation value is missing'
              iv_token = lv_name
              iv_offset = 0 ).
          ENDIF.
          cs_dd03p-ddtext = unescape_string( lv_value ).
        WHEN '@abapcatalog.textlanguage'.
          cs_dd03p-languflag = abap_true.
        WHEN '@semantics.amount.currencycode'.
          lv_reference = unescape_string( lv_value ).
          CLEAR: lv_table, lv_field.
          SPLIT lv_reference AT '.' INTO lv_table lv_field.
          IF lv_table IS INITIAL OR lv_field IS INITIAL.
            parse_error(
              iv_context = 'invalid currency reference'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          cs_dd03p-reftable = to_upper( lv_table ).
          cs_dd03p-reffield = to_upper( lv_field ).
        WHEN '@semantics.quantity.unitofmeasure'.
          lv_reference = unescape_string( lv_value ).
          CLEAR: lv_table, lv_field.
          SPLIT lv_reference AT '.' INTO lv_table lv_field.
          IF lv_table IS INITIAL OR lv_field IS INITIAL.
            parse_error(
              iv_context = 'invalid unit reference'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          cs_dd03p-reftable = to_upper( lv_table ).
          cs_dd03p-reffield = to_upper( lv_field ).
        WHEN '@abapcatalog.decfloat.outputstyle'.
          IF strlen( lv_compare ) < 2 OR lv_compare(1) <> '#'.
            parse_error(
              iv_context = 'invalid decfloat output style'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          ASSIGN COMPONENT 'OUTPUTSTYLE' OF STRUCTURE cs_dd03p TO <lv_outputstyle>.
          IF sy-subrc <> 0.
            parse_error(
              iv_context = 'decfloat output style is unavailable'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          IF to_upper( lv_compare+1 ) = 'NORMAL'.
            <lv_outputstyle> = '00'.
          ELSE.
            parse_error(
              iv_context = 'unsupported decfloat output style'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
        WHEN '@abapcatalog.foreignkey.label'.
          IF lv_value IS INITIAL.
            parse_error(
              iv_context = 'foreign key annotation value is missing'
              iv_token = lv_name
              iv_offset = 0 ).
          ENDIF.
          cs_dd08v-ddtext = unescape_string( lv_value ).
        WHEN '@abapcatalog.foreignkey.keytype'.
          IF strlen( lv_compare ) < 2 OR lv_compare(1) <> '#'.
            parse_error(
              iv_context = 'invalid foreign key type'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
          " DD08V-FRKART is CHAR(4), so the DDL keyword has to be mapped
          " before it is assigned, otherwise it is truncated first and no
          " longer matches.
          lv_keytype = to_upper( lv_compare+1 ).
          IF lv_keytype = 'TEXT_KEY'.
            cs_dd08v-frkart = 'TEXT'.
          ELSEIF lv_keytype = 'NON_KEY'.
            cs_dd08v-frkart = 'REF'.
          ELSE.
            cs_dd08v-frkart = lv_keytype.
          ENDIF.
        WHEN '@abapcatalog.foreignkey.screencheck'.
          IF to_lower( lv_compare ) = 'true'.
            CLEAR cs_dd08v-checkflag.
          ELSEIF to_lower( lv_compare ) = 'false'.
            cs_dd08v-checkflag = abap_true.
          ELSE.
            parse_error(
              iv_context = 'invalid foreign key screen check value'
              iv_token = lv_value
              iv_offset = 0 ).
          ENDIF.
        WHEN '@abapcatalog.foreignkey.messageclass'.
          IF lv_value IS INITIAL.
            parse_error(
              iv_context = 'foreign key message class is missing'
              iv_token = lv_name
              iv_offset = 0 ).
          ENDIF.
          cs_dd08v-arbgb = unescape_string( lv_value ).
        WHEN '@abapcatalog.foreignkey.messagenumber'.
          IF lv_value IS INITIAL.
            parse_error(
              iv_context = 'foreign key message number is missing'
              iv_token = lv_name
              iv_offset = 0 ).
          ENDIF.
          cs_dd08v-msgnr = unescape_string( lv_value ).
        WHEN OTHERS.
          parse_error(
            iv_context = 'unsupported field annotation'
            iv_token = lv_name
            iv_offset = 0 ).
      ENDCASE.
    ENDWHILE.
 
  ENDMETHOD.
 
 
  METHOD parse_field.
 
    DATA ls_token TYPE ty_token.
    DATA ls_next TYPE ty_token.
    DATA ls_dd03p TYPE dd03p.
    DATA ls_dd08v TYPE dd08v.
    DATA ls_dd35v TYPE dd35v.
    DATA lv_fieldname TYPE string.
    DATA lv_key TYPE abap_bool.
    DATA lv_is_include TYPE abap_bool.
 
    parse_field_annotations(
      EXPORTING it_tokens = it_tokens
      CHANGING
        cv_index = cv_index
        cs_dd03p = ls_dd03p
        cs_dd08v = ls_dd08v ).
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc <> 0.
      parse_error(
        iv_context = 'field definition is missing'
        iv_token = ''
        iv_offset = 0 ).
    ENDIF.
    READ TABLE it_tokens INDEX cv_index + 1 INTO ls_next.
    IF to_lower( ls_token-value ) = 'key' AND sy-subrc = 0 AND ls_next-value <> ':'.
      lv_key = abap_true.
      cv_index = cv_index + 1.
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
    ENDIF.
    ls_dd03p-keyflag = lv_key.
    IF to_lower( ls_token-value ) = 'include'.
      lv_is_include = abap_true.
      ls_dd03p-fieldname = '.INCLU'.
      cv_index = cv_index + 1.
      parse_include( EXPORTING it_tokens = it_tokens
                    CHANGING
                      cv_index = cv_index
                      cs_dd03p = ls_dd03p ).
    ELSE.
      lv_fieldname = to_upper( unescape_name( ls_token-value ) ).
      ls_dd03p-fieldname = lv_fieldname.
      cv_index = cv_index + 1.
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF sy-subrc <> 0 OR ls_token-value <> ':'.
        parse_error(
          iv_context = 'expected colon after field name'
          iv_token = ls_token-value
          iv_offset = ls_token-offset ).
      ENDIF.
      cv_index = cv_index + 1.
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF sy-subrc <> 0.
        parse_error(
          iv_context = 'field type is missing'
          iv_token = ''
          iv_offset = 0 ).
      ENDIF.
      IF to_lower( ls_token-value ) = 'include'.
        lv_is_include = abap_true.
        ls_dd03p-groupname = lv_fieldname.
        ls_dd03p-fieldname = '.INCLU'.
        cv_index = cv_index + 1.
        parse_include( EXPORTING it_tokens = it_tokens
                      CHANGING
                        cv_index = cv_index
                        cs_dd03p = ls_dd03p ).
      ELSE.
        parse_type( EXPORTING
          iv_token = ls_token-value CHANGING
          cs_dd03p = ls_dd03p ).
        cv_index = cv_index + 1.
        WHILE cv_index <= lines( it_tokens ).
          READ TABLE it_tokens INDEX cv_index INTO ls_token.
          IF to_lower( ls_token-value ) = 'not'.
            cv_index = cv_index + 1.
            READ TABLE it_tokens INDEX cv_index INTO ls_token.
            IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'null'.
              parse_error(
                iv_context = 'expected NULL after NOT'
                iv_token = ls_token-value
                iv_offset = ls_token-offset ).
            ENDIF.
            ls_dd03p-notnull = abap_true.
            cv_index = cv_index + 1.
          ELSEIF ls_token-value = ';'.
            EXIT.
          ELSEIF to_lower( ls_token-value ) = 'with'.
            cv_index = cv_index + 1.
            READ TABLE it_tokens INDEX cv_index INTO ls_token.
            IF sy-subrc <> 0.
              parse_error(
                iv_context = 'relationship kind is missing'
                iv_token = ''
                iv_offset = 0 ).
            ENDIF.
            IF to_lower( ls_token-value ) = 'foreign'.
              cv_index = cv_index + 1.
              READ TABLE it_tokens INDEX cv_index INTO ls_token.
              IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'key'.
                parse_error(
                  iv_context = 'expected KEY after FOREIGN'
                  iv_token = ls_token-value
                  iv_offset = ls_token-offset ).
              ENDIF.
              cv_index = cv_index + 1.
              parse_foreign_key(
                EXPORTING
                  it_tokens = it_tokens
                  iv_fieldname = ls_dd03p-fieldname
                CHANGING
                  cv_index = cv_index
                  cs_dd08v = ls_dd08v
                  cs_data = cs_data ).
            ELSEIF to_lower( ls_token-value ) = 'value'.
              cv_index = cv_index + 1.
              READ TABLE it_tokens INDEX cv_index INTO ls_token.
              IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'help'.
                parse_error(
                  iv_context = 'expected HELP after VALUE'
                  iv_token = ls_token-value
                  iv_offset = ls_token-offset ).
              ENDIF.
              cv_index = cv_index + 1.
              parse_value_help(
                EXPORTING
                  it_tokens = it_tokens
                  iv_fieldname = ls_dd03p-fieldname
                CHANGING
                  cv_index = cv_index
                  cs_dd35v = ls_dd35v
                  cs_data = cs_data ).
            ELSE.
              parse_error(
                iv_context = 'unsupported relationship kind'
                iv_token = ls_token-value
                iv_offset = ls_token-offset ).
            ENDIF.
          ELSE.
            parse_error(
              iv_context = 'unexpected token in field definition'
              iv_token = ls_token-value
              iv_offset = ls_token-offset ).
          ENDIF.
        ENDWHILE.
      ENDIF.
    ENDIF.
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc = 0 AND ls_token-value = ';'.
      cv_index = cv_index + 1.
    ELSEIF lv_is_include = abap_true
        AND sy-subrc = 0
        AND is_block_terminator( ls_token-value ) = abap_true.
      " Some ADT table DDL omits the terminator when an include is
      " immediately followed by its component extensions.
    ELSE.
      parse_error(
        iv_context = 'expected semicolon after field definition'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    ls_dd03p-adminfield = '0'.
    IF ls_dd08v IS NOT INITIAL.
      ls_dd08v-fieldname = ls_dd03p-fieldname.
      ls_dd03p-checktable = ls_dd08v-checktable.
      ls_dd03p-shlporigin = 'P'.
      APPEND ls_dd08v TO cs_data-dd08v.
    ENDIF.
    IF ls_dd35v IS NOT INITIAL.
      ls_dd35v-fieldname = ls_dd03p-fieldname.
      ls_dd03p-shlporigin = 'F'.
      APPEND ls_dd35v TO cs_data-dd35v.
    ENDIF.
    APPEND ls_dd03p TO cs_data-dd03p.
 
  ENDMETHOD.
 
 
  METHOD parse_include.
 
    DATA ls_token TYPE ty_token.
    DATA lv_suffix TYPE string.
 
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
      parse_error(
        iv_context = 'include name is missing'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    cs_dd03p-precfield = to_upper( ls_token-value ).
    cv_index = cv_index + 1.
    WHILE cv_index <= lines( it_tokens ).
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      IF to_lower( ls_token-value ) = 'with'.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'suffix'.
          parse_error(
            iv_context = 'expected SUFFIX after WITH'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
          parse_error(
            iv_context = 'include suffix is missing'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        lv_suffix = to_upper( ls_token-value ).
        cs_dd03p-fieldname = |.INCLU-{ lv_suffix }|.
        cv_index = cv_index + 1.
      ELSEIF to_lower( ls_token-value ) = 'not'.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'null'.
          parse_error(
            iv_context = 'expected NULL after NOT'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        cs_dd03p-notnull = abap_true.
        cv_index = cv_index + 1.
      ELSEIF ls_token-value = ';'
          OR is_block_terminator( ls_token-value ) = abap_true.
        EXIT.
      ELSE.
        parse_error(
          iv_context = 'unexpected token in include definition'
          iv_token = ls_token-value
          iv_offset = ls_token-offset ).
      ENDIF.
    ENDWHILE.
 
  ENDMETHOD.
 
 
  METHOD get_cardinalities.
 
    " Single source of truth for the mapping between the DDL cardinality
    " token and DD08V-CARDLEFT/CARD, read in both directions by
    " parse_cardinality and serialize_field_foreign_key.
    DATA ls_cardinality TYPE ty_cardinality.
 
    ls_cardinality-token = '[1,0..1]'.
    ls_cardinality-cardleft = 'C'.
    ls_cardinality-card = '1'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[0..1,1]'.
    ls_cardinality-cardleft = '1'.
    ls_cardinality-card = 'C'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[1,1]'.
    ls_cardinality-cardleft = '1'.
    ls_cardinality-card = '1'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[1..*,1]'.
    ls_cardinality-cardleft = '1'.
    ls_cardinality-card = 'N'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[0..*,1]'.
    ls_cardinality-cardleft = '1'.
    ls_cardinality-card = 'CN'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[0..*,0..1]'.
    ls_cardinality-cardleft = 'C'.
    ls_cardinality-card = 'CN'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[0..1,0..1]'.
    ls_cardinality-cardleft = 'C'.
    ls_cardinality-card = 'C'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[1..*,]'.
    ls_cardinality-cardleft = 'N'.
    ls_cardinality-card = 'N'.
    APPEND ls_cardinality TO rt_cardinalities.
    ls_cardinality-token = '[1..*,0..1]'.
    ls_cardinality-cardleft = 'C'.
    ls_cardinality-card = 'N'.
    APPEND ls_cardinality TO rt_cardinalities.
 
  ENDMETHOD.
 
 
  METHOD parse_cardinality.
 
    DATA lt_cardinalities TYPE ty_cardinalities.
    DATA ls_cardinality TYPE ty_cardinality.
 
    lt_cardinalities = get_cardinalities( ).
    READ TABLE lt_cardinalities INTO ls_cardinality WITH KEY token = iv_token.
    IF sy-subrc <> 0.
      parse_error(
        iv_context = 'unsupported foreign key cardinality'
        iv_token = iv_token
        iv_offset = iv_offset ).
    ENDIF.
    cs_dd08v-cardleft = ls_cardinality-cardleft.
    cs_dd08v-card = ls_cardinality-card.
 
  ENDMETHOD.
 
 
  METHOD parse_foreign_key.
 
    DATA ls_token TYPE ty_token.
    DATA ls_dd05m TYPE dd05m.
    DATA lv_left TYPE string.
    DATA lv_right TYPE string.
    DATA lv_primpos TYPE i.
 
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc <> 0.
      parse_error(
        iv_context = 'foreign key target is missing'
        iv_token = ''
        iv_offset = 0 ).
    ENDIF.
    IF ls_token-value(1) = '['.
      parse_cardinality(
        EXPORTING
          iv_token = ls_token-value
          iv_offset = ls_token-offset
        CHANGING
          cs_dd08v = cs_dd08v ).
      cv_index = cv_index + 1.
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
    ENDIF.
    IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
      parse_error(
        iv_context = 'foreign key check table is missing'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    cs_dd08v-checktable = to_upper( ls_token-value ).
    cv_index = cv_index + 1.
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc = 0 AND to_lower( ls_token-value ) = 'where'.
      cv_index = cv_index + 1.
      WHILE cv_index <= lines( it_tokens ).
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF ls_token-value = ';' OR to_lower( ls_token-value ) = 'with'.
          EXIT.
        ENDIF.
        lv_left = ls_token-value.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR ls_token-value <> '='.
          parse_error(
            iv_context = 'expected equals in foreign key condition'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
          parse_error(
            iv_context = 'foreign key condition value is missing'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        lv_right = ls_token-value.
        CLEAR ls_dd05m.
        ls_dd05m-fieldname = iv_fieldname.
        ls_dd05m-checktable = cs_dd08v-checktable.
        ls_dd05m-checkfield = to_upper( lv_left ).
        IF lv_right(1) = |'|.
          ls_dd05m-fortable = lv_right.
        ELSE.
          SPLIT lv_right AT '.' INTO ls_dd05m-fortable ls_dd05m-forkey.
          IF ls_dd05m-fortable IS INITIAL OR ls_dd05m-forkey IS INITIAL.
            parse_error(
              iv_context = 'foreign key target must be table.field'
              iv_token = lv_right
              iv_offset = ls_token-offset ).
          ENDIF.
          TRANSLATE ls_dd05m-fortable TO UPPER CASE.
          TRANSLATE ls_dd05m-forkey TO UPPER CASE.
        ENDIF.
        CLEAR lv_primpos.
        LOOP AT cs_data-dd05m TRANSPORTING NO FIELDS WHERE fieldname = iv_fieldname.
          lv_primpos = lv_primpos + 1.
        ENDLOOP.
        ls_dd05m-primpos = lv_primpos + 1.
        APPEND ls_dd05m TO cs_data-dd05m.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'and'.
          EXIT.
        ENDIF.
        cv_index = cv_index + 1.
      ENDWHILE.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD parse_value_help.
 
    DATA ls_token TYPE ty_token.
    DATA ls_dd36m TYPE dd36m.
    DATA lv_left TYPE string.
    DATA lv_right TYPE string.
    DATA lv_position TYPE i.
 
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
      parse_error(
        iv_context = 'value help name is missing'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    cs_dd35v-shlpname = to_upper( ls_token-value ).
    cv_index = cv_index + 1.
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc = 0 AND to_lower( ls_token-value ) = 'where'.
      cv_index = cv_index + 1.
      WHILE cv_index <= lines( it_tokens ).
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF ls_token-value = ';' OR to_lower( ls_token-value ) = 'with'.
          EXIT.
        ENDIF.
        lv_left = ls_token-value.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR ls_token-value <> '='.
          parse_error(
            iv_context = 'expected equals in value help condition'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
          parse_error(
            iv_context = 'value help condition value is missing'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
        lv_right = ls_token-value.
        CLEAR ls_dd36m.
        ls_dd36m-fieldname = iv_fieldname.
        ls_dd36m-shlpname = cs_dd35v-shlpname.
        ls_dd36m-shlpfield = to_upper( lv_left ).
        IF lv_right(1) = |'|.
          ls_dd36m-shtype = 'C'.
          ls_dd36m-shtable = lv_right.
        ELSE.
          SPLIT lv_right AT '.' INTO ls_dd36m-shtable ls_dd36m-shfield.
          IF ls_dd36m-shtable IS INITIAL OR ls_dd36m-shfield IS INITIAL.
            parse_error(
              iv_context = 'value help target must be table.field'
              iv_token = lv_right
              iv_offset = ls_token-offset ).
          ENDIF.
          TRANSLATE ls_dd36m-shtable TO UPPER CASE.
          TRANSLATE ls_dd36m-shfield TO UPPER CASE.
        ENDIF.
        CLEAR lv_position.
        LOOP AT cs_data-dd36m TRANSPORTING NO FIELDS WHERE fieldname = iv_fieldname.
          lv_position = lv_position + 1.
        ENDLOOP.
        ls_dd36m-flposition = lv_position + 1.
        APPEND ls_dd36m TO cs_data-dd36m.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'and'.
          EXIT.
        ENDIF.
        cv_index = cv_index + 1.
      ENDWHILE.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD parse_extension.
 
    DATA ls_token TYPE ty_token.
    DATA ls_dd03p TYPE dd03p.
    DATA ls_dd08v TYPE dd08v.
    DATA ls_dd35v TYPE dd35v.
    DATA lv_fieldname TYPE string.
    DATA lv_keyword TYPE string.
    DATA lv_done TYPE abap_bool.
 
    ls_dd08v = cs_dd08v.
    ls_dd35v = cs_dd35v.
 
    " cv_index points at the EXTEND keyword, which the caller already checked.
    cv_index = cv_index + 1.
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc <> 0 OR ls_token-value IS INITIAL.
      parse_error(
        iv_context = 'extension field is missing'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    lv_fieldname = to_upper( unescape_name( ls_token-value ) ).
    cv_index = cv_index + 1.
    READ TABLE it_tokens INDEX cv_index INTO ls_token.
    IF sy-subrc <> 0 OR ls_token-value <> ':'.
      parse_error(
        iv_context = 'expected colon after extension field'
        iv_token = ls_token-value
        iv_offset = ls_token-offset ).
    ENDIF.
    cv_index = cv_index + 1.
    ls_dd03p-fieldname = lv_fieldname.
    ls_dd03p-adminfield = '1'.
    APPEND ls_dd03p TO cs_data-dd03p.
    WHILE cv_index <= lines( it_tokens ).
      READ TABLE it_tokens INDEX cv_index INTO ls_token.
      lv_keyword = to_lower( ls_token-value ).
      IF ls_token-value = ';'.
        cv_index = cv_index + 1.
        lv_done = abap_true.
        EXIT.
      ELSEIF is_block_terminator( ls_token-value ) = abap_true.
        " Some ADT table DDL omits the terminator between extension blocks.
        lv_done = abap_true.
        EXIT.
      ELSEIF lv_keyword = 'remove'.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0.
          parse_error(
            iv_context = 'remove operation is incomplete'
            iv_token = ''
            iv_offset = 0 ).
        ENDIF.
        IF to_lower( ls_token-value ) = 'foreign'.
          cv_index = cv_index + 1.
          READ TABLE it_tokens INDEX cv_index INTO ls_token.
          IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'key'.
            parse_error(
              iv_context = 'expected KEY after REMOVE FOREIGN'
              iv_token = ls_token-value
              iv_offset = ls_token-offset ).
          ENDIF.
          CLEAR ls_dd08v.
          ls_dd08v-fieldname = lv_fieldname.
          ls_dd08v-checktable = '*'.
          ls_dd08v-noinherit = 'Y'.
          APPEND ls_dd08v TO cs_data-dd08v.
          cv_index = cv_index + 1.
        ELSEIF to_lower( ls_token-value ) = 'value'.
          cv_index = cv_index + 1.
          READ TABLE it_tokens INDEX cv_index INTO ls_token.
          IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'help'.
            parse_error(
              iv_context = 'expected HELP after REMOVE VALUE'
              iv_token = ls_token-value
              iv_offset = ls_token-offset ).
          ENDIF.
          CLEAR ls_dd35v.
          ls_dd35v-fieldname = lv_fieldname.
          ls_dd35v-shlpname = '*'.
          APPEND ls_dd35v TO cs_data-dd35v.
          cv_index = cv_index + 1.
        ELSE.
          parse_error(
            iv_context = 'unsupported remove operation'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
      ELSEIF lv_keyword = 'with'.
        cv_index = cv_index + 1.
        READ TABLE it_tokens INDEX cv_index INTO ls_token.
        IF sy-subrc <> 0.
          parse_error(
            iv_context = 'extension relationship is missing'
            iv_token = ''
            iv_offset = 0 ).
        ENDIF.
        IF to_lower( ls_token-value ) = 'foreign'.
          cv_index = cv_index + 1.
          READ TABLE it_tokens INDEX cv_index INTO ls_token.
          IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'key'.
            parse_error(
              iv_context = 'expected KEY after FOREIGN'
              iv_token = ls_token-value
              iv_offset = ls_token-offset ).
          ENDIF.
          cv_index = cv_index + 1.
          parse_foreign_key(
            EXPORTING
              it_tokens = it_tokens
              iv_fieldname = lv_fieldname
            CHANGING
              cv_index = cv_index
              cs_dd08v = ls_dd08v
              cs_data = cs_data ).
          ls_dd08v-fieldname = lv_fieldname.
          ls_dd08v-noinherit = 'Y'.
          APPEND ls_dd08v TO cs_data-dd08v.
        ELSEIF to_lower( ls_token-value ) = 'value'.
          cv_index = cv_index + 1.
          READ TABLE it_tokens INDEX cv_index INTO ls_token.
          IF sy-subrc <> 0 OR to_lower( ls_token-value ) <> 'help'.
            parse_error(
              iv_context = 'expected HELP after VALUE'
              iv_token = ls_token-value
              iv_offset = ls_token-offset ).
          ENDIF.
          cv_index = cv_index + 1.
          parse_value_help(
            EXPORTING
              it_tokens = it_tokens
              iv_fieldname = lv_fieldname
            CHANGING
              cv_index = cv_index
              cs_dd35v = ls_dd35v
              cs_data = cs_data ).
          ls_dd35v-fieldname = lv_fieldname.
          APPEND ls_dd35v TO cs_data-dd35v.
        ELSE.
          parse_error(
            iv_context = 'unsupported extension relationship'
            iv_token = ls_token-value
            iv_offset = ls_token-offset ).
        ENDIF.
      ELSE.
        parse_error(
          iv_context = 'unexpected token in extension'
          iv_token = ls_token-value
          iv_offset = ls_token-offset ).
      ENDIF.
    ENDWHILE.
    IF lv_done = abap_false.
      parse_error(
        iv_context = 'missing semicolon after extension'
        iv_token = ''
        iv_offset = 0 ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD parse_type.
 
    DATA lv_token TYPE string.
    DATA lv_base TYPE string.
    DATA lv_params TYPE string.
    DATA lv_length TYPE string.
    DATA lv_decimals TYPE string.
    DATA lv_offset TYPE i.
    DATA lv_close TYPE i.
 
    lv_token = to_lower( iv_token ).
    IF lv_token NP 'abap.*'.
      cs_dd03p-rollname = to_upper( iv_token ).
      CLEAR: cs_dd03p-inttype, cs_dd03p-intlen.
      RETURN.
    ENDIF.
    lv_token = lv_token+5.
    FIND FIRST OCCURRENCE OF '(' IN lv_token MATCH OFFSET lv_offset.
    IF sy-subrc = 0.
      lv_close = strlen( lv_token ) - 1.
      IF lv_token+lv_close(1) <> ')'.
        parse_error(
          iv_context = 'type parameter list is not closed'
          iv_token = lv_token
          iv_offset = lv_offset ).
      ENDIF.
      lv_base = lv_token(lv_offset).
      lv_close = lv_offset + 1.
      lv_params = lv_token+lv_close.
      lv_close = strlen( lv_params ) - 1.
      lv_params = lv_params(lv_close).
      SPLIT lv_params AT ',' INTO lv_length lv_decimals.
      CONDENSE lv_length.
      CONDENSE lv_decimals.
    ELSE.
      lv_base = lv_token.
    ENDIF.
    set_builtin_type(
      EXPORTING
        iv_base = lv_base
        iv_length = lv_length
        iv_decimals = lv_decimals
        iv_offset = lv_offset
      CHANGING cs_dd03p = cs_dd03p ).
 
  ENDMETHOD.
 
 
  METHOD set_builtin_type.
    IF iv_length IS NOT INITIAL AND iv_length CN '0123456789'.
      parse_error(
        iv_context = 'type length is not numeric'
        iv_token = iv_length
        iv_offset = iv_offset ).
    ENDIF.
    IF iv_decimals IS NOT INITIAL AND iv_decimals CN '0123456789'.
      parse_error(
        iv_context = 'type decimals are not numeric'
        iv_token = iv_decimals
        iv_offset = iv_offset ).
    ENDIF.
    IF iv_base = 'char' OR iv_base = 'numc' OR iv_base = 'raw'
        OR iv_base = 'lraw' OR iv_base = 'lchr'
        OR iv_base = 'string' OR iv_base = 'rawstring' OR iv_base = 'sstring'
        OR iv_base = 'unit'.
      IF iv_decimals IS NOT INITIAL.
        parse_error(
          iv_context = 'character type accepts one parameter'
          iv_token = iv_base
          iv_offset = iv_offset ).
      ENDIF.
      cs_dd03p-leng = iv_length.
      set_character_type( EXPORTING
        iv_base = iv_base CHANGING
        cs_dd03p = cs_dd03p ).
    ELSEIF iv_base = 'dec' OR iv_base = 'curr' OR iv_base = 'quan'.
      IF iv_length IS INITIAL OR iv_decimals IS INITIAL.
        parse_error(
          iv_context = 'decimal type requires length and decimals'
          iv_token = iv_base
          iv_offset = iv_offset ).
      ENDIF.
      set_numeric_type(
        EXPORTING
          iv_base = iv_base
          iv_length = iv_length
          iv_decimals = iv_decimals
        CHANGING cs_dd03p = cs_dd03p ).
    ELSEIF iv_base = 'df16_dec' OR iv_base = 'df34_dec'.
      IF iv_length IS INITIAL OR iv_decimals IS INITIAL.
        parse_error(
          iv_context = 'decimal floating type requires length and decimals'
          iv_token = iv_base
          iv_offset = iv_offset ).
      ENDIF.
      set_decfloat_type(
        EXPORTING
          iv_base = iv_base
          iv_length = iv_length
          iv_decimals = iv_decimals
        CHANGING cs_dd03p = cs_dd03p ).
    ELSEIF iv_length IS NOT INITIAL OR iv_decimals IS NOT INITIAL.
      parse_error(
        iv_context = 'parameterless built-in type has parameters'
        iv_token = iv_base
        iv_offset = iv_offset ).
    ELSEIF iv_base = 'int1' OR iv_base = 'int2' OR iv_base = 'int4'
        OR iv_base = 'int8' OR iv_base = 'fltp'.
      set_integer_type( EXPORTING
        iv_base = iv_base CHANGING
        cs_dd03p = cs_dd03p ).
    ELSEIF iv_base = 'accp' OR iv_base = 'lang' OR iv_base = 'datn'
        OR iv_base = 'timn' OR iv_base = 'utcl' OR iv_base = 'd16n'
        OR iv_base = 'd34n' OR iv_base = 'cuky' OR iv_base = 'dats'
        OR iv_base = 'tims' OR iv_base = 'clnt'.
      set_date_type( EXPORTING
        iv_base = iv_base CHANGING
        cs_dd03p = cs_dd03p ).
    ELSEIF iv_base = 'df16_raw' OR iv_base = 'df16_scl'
        OR iv_base = 'df34_scl' OR iv_base = 'df34_raw'.
      set_decfloat_type(
        EXPORTING
          iv_base = iv_base
          iv_length = ''
          iv_decimals = ''
        CHANGING cs_dd03p = cs_dd03p ).
    ELSE.
      parse_error(
        iv_context = 'unsupported built-in type'
        iv_token = iv_base
        iv_offset = iv_offset ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD set_character_type.
    CASE iv_base.
      WHEN 'char'.
        cs_dd03p-datatype = 'CHAR'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-intlen = cs_dd03p-leng * 2.
      WHEN 'numc'.
        cs_dd03p-datatype = 'NUMC'.
        cs_dd03p-inttype = 'N'.
        cs_dd03p-intlen = cs_dd03p-leng * 2.
      WHEN 'raw'.
        cs_dd03p-datatype = 'RAW'.
        cs_dd03p-inttype = 'X'.
        cs_dd03p-intlen = cs_dd03p-leng.
      WHEN 'lraw'.
        cs_dd03p-datatype = 'LRAW'.
        cs_dd03p-inttype = 'X'.
        cs_dd03p-intlen = cs_dd03p-leng.
      WHEN 'lchr'.
        cs_dd03p-datatype = 'LCHR'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-intlen = cs_dd03p-leng * 2.
      WHEN 'string'.
        cs_dd03p-datatype = 'STRG'.
        cs_dd03p-inttype = 'g'.
        cs_dd03p-intlen = 8.
      WHEN 'rawstring'.
        cs_dd03p-datatype = 'RSTR'.
        cs_dd03p-inttype = 'x'.
        cs_dd03p-intlen = 8.
      WHEN 'sstring'.
        cs_dd03p-datatype = 'SSTR'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-intlen = cs_dd03p-leng * 2.
      WHEN 'unit'.
        cs_dd03p-datatype = 'UNIT'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-intlen = cs_dd03p-leng * 2.
    ENDCASE.
  ENDMETHOD.
 
 
  METHOD set_numeric_type.
    cs_dd03p-datatype = to_upper( iv_base ).
    cs_dd03p-leng = iv_length.
    cs_dd03p-decimals = iv_decimals.
    cs_dd03p-inttype = 'P'.
    cs_dd03p-intlen = ( cs_dd03p-leng + 2 ) DIV 2.
  ENDMETHOD.
 
 
  METHOD set_integer_type.
    CASE iv_base.
      WHEN 'int1'.
        cs_dd03p-datatype = 'INT1'.
        cs_dd03p-inttype = 'b'.
        cs_dd03p-intlen = 1.
      WHEN 'int2'.
        cs_dd03p-datatype = 'INT2'.
        cs_dd03p-inttype = 's'.
        cs_dd03p-intlen = 2.
      WHEN 'int4'.
        cs_dd03p-datatype = 'INT4'.
        cs_dd03p-inttype = 'I'.
        cs_dd03p-intlen = 4.
      WHEN 'int8'.
        cs_dd03p-datatype = 'INT8'.
        cs_dd03p-inttype = '8'.
        cs_dd03p-intlen = 8.
      WHEN 'fltp'.
        cs_dd03p-datatype = 'FLTP'.
        cs_dd03p-inttype = 'F'.
        cs_dd03p-intlen = 8.
    ENDCASE.
  ENDMETHOD.
 
 
  METHOD set_date_type.
    CASE iv_base.
      WHEN 'accp'.
        cs_dd03p-datatype = 'ACCP'.
        cs_dd03p-inttype = 'N'.
        cs_dd03p-leng = 6.
        cs_dd03p-intlen = 12.
      WHEN 'lang'.
        cs_dd03p-datatype = 'LANG'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-leng = 1.
        cs_dd03p-intlen = 2.
      WHEN 'datn'.
        cs_dd03p-datatype = 'DATN'.
        cs_dd03p-inttype = 'D'.
        cs_dd03p-leng = 8.
        cs_dd03p-intlen = 16.
      WHEN 'timn'.
        cs_dd03p-datatype = 'TIMN'.
        cs_dd03p-inttype = 'T'.
        cs_dd03p-leng = 6.
        cs_dd03p-intlen = 12.
      WHEN 'utcl'.
        cs_dd03p-datatype = 'UTCL'.
        cs_dd03p-inttype = 'P'.
        cs_dd03p-leng = 27.
        cs_dd03p-intlen = 8.
      WHEN 'd16n'.
        cs_dd03p-datatype = 'D16N'.
        cs_dd03p-inttype = 'a'.
        cs_dd03p-intlen = 8.
      WHEN 'd34n'.
        cs_dd03p-datatype = 'D34N'.
        cs_dd03p-inttype = 'e'.
        cs_dd03p-intlen = 16.
      WHEN 'cuky'.
        cs_dd03p-datatype = 'CUKY'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-leng = 5.
        cs_dd03p-intlen = 10.
      WHEN 'dats'.
        cs_dd03p-datatype = 'DATS'.
        cs_dd03p-inttype = 'D'.
        cs_dd03p-leng = 8.
        cs_dd03p-intlen = 16.
      WHEN 'tims'.
        cs_dd03p-datatype = 'TIMS'.
        cs_dd03p-inttype = 'T'.
        cs_dd03p-leng = 6.
        cs_dd03p-intlen = 12.
      WHEN 'clnt'.
        cs_dd03p-datatype = 'CLNT'.
        cs_dd03p-inttype = 'C'.
        cs_dd03p-leng = 3.
        cs_dd03p-intlen = 6.
    ENDCASE.
  ENDMETHOD.
 
 
  METHOD set_decfloat_type.
    IF iv_base = 'df16_dec' OR iv_base = 'df16_raw' OR iv_base = 'df16_scl'.
      cs_dd03p-inttype = 'a'.
      cs_dd03p-intlen = 8.
    ELSE.
      cs_dd03p-inttype = 'e'.
      cs_dd03p-intlen = 16.
    ENDIF.
    IF iv_base = 'df16_dec'.
      cs_dd03p-datatype = 'D16D'.
    ELSEIF iv_base = 'df16_raw'.
      cs_dd03p-datatype = 'D16R'.
    ELSEIF iv_base = 'df16_scl'.
      cs_dd03p-datatype = 'D16S'.
    ELSEIF iv_base = 'df34_dec'.
      cs_dd03p-datatype = 'D34D'.
    ELSEIF iv_base = 'df34_raw'.
      cs_dd03p-datatype = 'D34R'.
    ELSE.
      cs_dd03p-datatype = 'D34S'.
    ENDIF.
    IF iv_length IS NOT INITIAL.
      cs_dd03p-leng = iv_length.
      cs_dd03p-decimals = iv_decimals.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD read_data.
    DATA lv_name TYPE ddobjname.
    lv_name = iv_name.
    " The texts read here end up in the serialized DDL, so the language is a
    " deliberate choice of the caller (the repository master language) and
    " must not default to the logon language, which would make the output
    " differ between developers.
    CALL FUNCTION 'DDIF_TABL_GET'
      EXPORTING name = lv_name langu = iv_language
      IMPORTING dd02v_wa = rs_data-dd02v dd09l_wa = rs_data-dd09l
      TABLES dd03p_tab = rs_data-dd03p dd05m_tab = rs_data-dd05m
             dd08v_tab = rs_data-dd08v dd12v_tab = rs_data-dd12v
             dd17v_tab = rs_data-dd17v dd35v_tab = rs_data-dd35v
             dd36m_tab = rs_data-dd36m
      EXCEPTIONS illegal_input = 1 OTHERS = 2.
    IF sy-subrc <> 0.
      zcx_abapgit_exception=>raise( |error from DDIF_TABL_GET for { lv_name }| ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD serialize.
 
    DATA ls_dd03p LIKE LINE OF is_data-dd03p.
    DATA lv_key TYPE string.
    DATA lv_type TYPE string.
    DATA lv_pre TYPE string.
    DATA lv_int TYPE i.
    DATA lv_suffix TYPE string.
    DATA lv_notnull TYPE string.
    DATA lv_colon TYPE i.
    DATA lv_include TYPE string.
    DATA lv_extend TYPE string.
 
    rv_ddl = serialize_top( is_data ).
    rv_ddl = rv_ddl && |define table { to_lower( is_data-dd02v-tabname ) } \{\n\n|.
    LOOP AT is_data-dd03p INTO ls_dd03p
        WHERE ( fieldname NP '.INCLU*' OR groupname IS NOT INITIAL ) AND adminfield = '0'.
      lv_int = 0.
      IF ls_dd03p-keyflag = abap_true.
        lv_int = 4.
      ENDIF.
      " The delimiting quotes of a non-plain name count towards the column
      " the colons are aligned on.
      IF ls_dd03p-groupname IS INITIAL.
        lv_int = lv_int + strlen( escape_name( ls_dd03p-fieldname ) ).
      ELSE.
        lv_int = lv_int + strlen( escape_name( ls_dd03p-groupname ) ).
      ENDIF.
      IF lv_int > lv_colon.
        lv_colon = lv_int.
      ENDIF.
    ENDLOOP.
    LOOP AT is_data-dd03p INTO ls_dd03p WHERE adminfield = '0'.
      CLEAR: lv_key, lv_notnull, lv_suffix.
      IF ls_dd03p-keyflag = abap_true.
        lv_key = |key |.
      ENDIF.
      lv_pre = |{ lv_key }{ escape_name( ls_dd03p-fieldname ) }|.
      IF ls_dd03p-groupname IS NOT INITIAL.
        lv_pre = |{ lv_key }{ escape_name( ls_dd03p-groupname ) }|.
      ENDIF.
      IF strlen( lv_pre ) < lv_colon.
        lv_pre = lv_pre && repeat(
          val = | |
          occ = lv_colon - strlen( lv_pre ) ).
      ENDIF.
      IF ls_dd03p-fieldname = '.INCLU--AP'.
        CONTINUE.
      ELSEIF ls_dd03p-fieldname CP '.INCLU*'.
        IF ls_dd03p-notnull = abap_true.
          lv_notnull = | not null|.
        ENDIF.
        lv_include = ls_dd03p-fieldname.
        IF lv_include CA '-'.
          SPLIT lv_include AT '-' INTO lv_include lv_suffix.
          lv_suffix = | with suffix { to_lower( lv_suffix ) }|.
        ENDIF.
        IF ls_dd03p-groupname IS INITIAL.
          rv_ddl = rv_ddl && |  { lv_key }include { to_lower( ls_dd03p-precfield ) }{ lv_suffix }{ lv_notnull }|.
        ELSE.
          rv_ddl = rv_ddl && |  { lv_pre } : include { to_lower( ls_dd03p-precfield ) }{ lv_suffix }{ lv_notnull }|.
        ENDIF.
        lv_extend = serialize_extend(
          is_dd03p = ls_dd03p
          is_data = is_data ).
        IF lv_extend IS INITIAL.
          rv_ddl = rv_ddl && |;\n|.
        ELSE.
          " ADT omits the terminator for an include that owns extensions.
          rv_ddl = rv_ddl && lv_extend.
        ENDIF.
        CONTINUE.
      ENDIF.
      rv_ddl = rv_ddl && serialize_field_annotations(
        iv_fieldname = ls_dd03p-fieldname
        is_data = is_data ).
      rv_ddl = rv_ddl && serialize_fkey_annotations(
        iv_fieldname = ls_dd03p-fieldname
        is_data = is_data ).
      lv_type = serialize_type( ls_dd03p ).
      rv_ddl = rv_ddl && |  { lv_pre } : { lv_type }|.
      rv_ddl = rv_ddl && serialize_field_foreign_key(
        iv_fieldname = ls_dd03p-fieldname
        is_data = is_data ).
      rv_ddl = rv_ddl && serialize_value_help(
        iv_fieldname = ls_dd03p-fieldname
        is_data = is_data ).
      rv_ddl = rv_ddl && |;\n|.
    ENDLOOP.
    rv_ddl = rv_ddl && |\n\}|.
  ENDMETHOD.
 
 
  METHOD serialize_adt.
    DATA ls_object_type TYPE wbobjtype.
    DATA lv_object_key TYPE seu_objkey.
    DATA li_object_data TYPE REF TO if_wb_object_data_model.
    DATA lo_operator TYPE REF TO object.
    ls_object_type-objtype_tr = 'TABL'.
    ls_object_type-subtype_wb = 'DT'.
    lv_object_key = iv_name.
    CALL METHOD ('CL_WB_OBJECT_OPERATOR')=>('CREATE_INSTANCE')
      EXPORTING
        object_type = ls_object_type
        object_key = lv_object_key
      RECEIVING
        result = lo_operator.
    CALL METHOD lo_operator->('IF_WB_OBJECT_OPERATOR~READ')
      EXPORTING
        version = 'A'
      IMPORTING
        eo_object_data = li_object_data.
    CALL METHOD li_object_data->('GET_CONTENT')
      IMPORTING
        p_data = rv_ddl.
  ENDMETHOD.
 
 
  METHOD is_foreign_key_extension.
    " A DD08V row describes a component extension when it is not inherited
    " from the include, either because it overrides ('Y') or removes ('*') the
    " inherited foreign key.
    IF ( is_dd08v-noinherit = 'Y' OR is_dd08v-checktable = '*' )
        AND is_dd08v-noinherit <> 'N'.
      rv_extension = abap_true.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD is_value_help_extension.
    IF is_dd35v-shlpinher <> abap_true.
      rv_extension = abap_true.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD has_more_extensions.
 
    DATA ls_dd08v LIKE LINE OF is_data-dd08v.
    DATA ls_dd35v LIKE LINE OF is_data-dd35v.
 
    LOOP AT is_data-dd08v INTO ls_dd08v.
      IF is_foreign_key_extension( ls_dd08v ) = abap_false.
        CONTINUE.
      ENDIF.
      READ TABLE it_fields TRANSPORTING NO FIELDS
        WITH KEY table_line = ls_dd08v-fieldname.
      IF sy-subrc = 0.
        rv_more = abap_true.
        RETURN.
      ENDIF.
    ENDLOOP.
    LOOP AT is_data-dd35v INTO ls_dd35v.
      IF is_value_help_extension( ls_dd35v ) = abap_false.
        CONTINUE.
      ENDIF.
      READ TABLE it_fields TRANSPORTING NO FIELDS
        WITH KEY table_line = ls_dd35v-fieldname.
      IF sy-subrc = 0.
        rv_more = abap_true.
        RETURN.
      ENDIF.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD serialize_extend.
 
    DATA lv_index TYPE i.
    DATA ls_dd03p LIKE LINE OF is_data-dd03p.
    DATA lt_fields TYPE ty_fields.
    DATA lv_field LIKE LINE OF lt_fields.
    DATA ls_dd08v LIKE LINE OF is_data-dd08v.
    DATA ls_dd35v LIKE LINE OF is_data-dd35v.
    DATA lv_more TYPE abap_bool.
 
    READ TABLE is_data-dd03p TRANSPORTING NO FIELDS
      WITH KEY fieldname = is_dd03p-fieldname precfield = is_dd03p-precfield.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    lv_index = sy-tabix + 1.
    LOOP AT is_data-dd03p FROM lv_index INTO ls_dd03p.
      IF ls_dd03p-adminfield = '0'.
        EXIT.
      ENDIF.
      APPEND ls_dd03p-fieldname TO lt_fields.
    ENDLOOP.
    LOOP AT is_data-dd08v INTO ls_dd08v.
      IF is_foreign_key_extension( ls_dd08v ) = abap_false.
        CONTINUE.
      ENDIF.
      READ TABLE lt_fields TRANSPORTING NO FIELDS
        WITH KEY table_line = ls_dd08v-fieldname.
      IF sy-subrc <> 0.
        CONTINUE.
      ENDIF.
      DELETE lt_fields WHERE table_line = ls_dd08v-fieldname.
      IF ls_dd08v-checktable <> '*'.
        rv_ddl = rv_ddl && serialize_fkey_annotations(
          iv_fieldname = ls_dd08v-fieldname
            is_data = is_data ).
      ENDIF.
      rv_ddl = rv_ddl && |  extend { to_lower( ls_dd08v-fieldname ) } :|.
      IF ls_dd08v-checktable = '*'.
        rv_ddl = rv_ddl && |\n    remove foreign key|.
      ELSE.
        rv_ddl = rv_ddl && serialize_field_foreign_key(
          iv_fieldname = ls_dd08v-fieldname
            is_data = is_data ).
      ENDIF.
      READ TABLE is_data-dd35v INTO ls_dd35v WITH KEY fieldname = ls_dd08v-fieldname.
      IF sy-subrc = 0.
        IF ls_dd35v-shlpname = '*'.
          rv_ddl = rv_ddl && |\n    remove value help|.
        ELSEIF ls_dd35v-shlpinher <> abap_true.
          rv_ddl = rv_ddl && serialize_value_help(
            iv_fieldname = ls_dd08v-fieldname
              is_data = is_data ).
        ENDIF.
      ENDIF.
      lv_more = has_more_extensions(
        it_fields = lt_fields
        is_data = is_data ).
      IF lv_more = abap_true.
        rv_ddl = rv_ddl && |\n|.
      ELSE.
        rv_ddl = rv_ddl && |;\n|.
      ENDIF.
    ENDLOOP.
    LOOP AT is_data-dd35v INTO ls_dd35v.
      IF is_value_help_extension( ls_dd35v ) = abap_false.
        CONTINUE.
      ENDIF.
      READ TABLE lt_fields INTO lv_field
        WITH KEY table_line = ls_dd35v-fieldname.
      IF sy-subrc <> 0.
        CONTINUE.
      ENDIF.
      DELETE lt_fields WHERE table_line = ls_dd35v-fieldname.
      rv_ddl = rv_ddl && |  extend { to_lower( lv_field ) } :|.
      IF ls_dd35v-shlpname = '*'.
        rv_ddl = rv_ddl && |\n    remove value help|.
      ELSE.
        rv_ddl = rv_ddl && serialize_value_help(
          iv_fieldname = lv_field
            is_data = is_data ).
      ENDIF.
      lv_more = has_more_extensions(
        it_fields = lt_fields
        is_data = is_data ).
      IF lv_more = abap_true.
        rv_ddl = rv_ddl && |\n|.
      ELSE.
        rv_ddl = rv_ddl && |;\n|.
      ENDIF.
    ENDLOOP.
    IF rv_ddl IS NOT INITIAL.
      " The block always starts on a line of its own. Emitting that newline
      " here instead of in the caller makes the re-indent below cover the
      " first line as well.
      rv_ddl = |\n{ rv_ddl }|.
      REPLACE ALL OCCURRENCES OF |\n  | IN rv_ddl WITH |\n    |.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD get_reference_datatype.
    DATA ls_reference LIKE LINE OF is_data-dd03p.
    DATA ls_buffered TYPE ty_reference.
    DATA ls_dfies TYPE dfies.
 
    " Prefer the field metadata already read for the table. This also keeps
    " serialization independent of DDIC access when the caller supplies it.
    READ TABLE is_data-dd03p INTO ls_reference
      WITH KEY tabname = is_field-reftable fieldname = is_field-reffield.
    IF sy-subrc <> 0 AND is_field-reftable = is_data-dd02v-tabname.
      READ TABLE is_data-dd03p INTO ls_reference
        WITH KEY fieldname = is_field-reffield.
    ENDIF.
    IF sy-subrc = 0.
      rv_datatype = ls_reference-datatype.
      RETURN.
    ENDIF.
 
    " References may point to a different DDIC object, which is not part of
    " the DD03P rows returned for the table being serialized. A table with
    " many amount or quantity fields would otherwise hit DDIC once per field
    " on every serialize call, so the outcome is buffered, including the
    " negative one.
    READ TABLE mt_reference INTO ls_buffered
      WITH TABLE KEY reftable = is_field-reftable reffield = is_field-reffield.
    IF sy-subrc = 0.
      rv_datatype = ls_buffered-datatype.
      RETURN.
    ENDIF.
 
    TRY.
        CALL FUNCTION 'DDIF_FIELDINFO_GET'
          EXPORTING
            tabname    = is_field-reftable
            lfieldname = is_field-reffield
            langu      = sy-langu
          IMPORTING
            dfies_wa   = ls_dfies
          EXCEPTIONS
            not_found      = 1
            internal_error = 2
            OTHERS         = 3.
        IF sy-subrc = 0.
          rv_datatype = ls_dfies-datatype.
        ENDIF.
      CATCH cx_sy_dyn_call_error.
        " The open-abap test runtime does not provide DDIC function modules.
    ENDTRY.
 
    ls_buffered-reftable = is_field-reftable.
    ls_buffered-reffield = is_field-reffield.
    ls_buffered-datatype = rv_datatype.
    INSERT ls_buffered INTO TABLE mt_reference.
  ENDMETHOD.
 
 
  METHOD serialize_field_annotations.
    DATA ls_dd03p LIKE LINE OF is_data-dd03p.
    DATA lv_reference_datatype TYPE dd03p-datatype.
    DATA lv_reference TYPE string.
    READ TABLE is_data-dd03p INTO ls_dd03p WITH KEY fieldname = iv_fieldname.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    IF ( ls_dd03p-rollname IS INITIAL AND ls_dd03p-precfield IS INITIAL
        OR ls_dd03p-comptype = 'R' AND ls_dd03p-reftype = 'B' )
        AND ls_dd03p-ddtext IS NOT INITIAL.
      rv_ddl = rv_ddl && |  @EndUserText.label : { escape_string( ls_dd03p-ddtext ) }\n|.
    ENDIF.
    IF ls_dd03p-languflag = abap_true.
      rv_ddl = rv_ddl && |  @AbapCatalog.textLanguage\n|.
    ENDIF.
    IF ls_dd03p-reftable IS NOT INITIAL AND ls_dd03p-reffield IS NOT INITIAL.
      lv_reference_datatype = get_reference_datatype(
        is_field = ls_dd03p
        is_data  = is_data ).
      lv_reference = |{ to_lower( ls_dd03p-reftable ) }.{ to_lower( ls_dd03p-reffield ) }|.
      " The semantics follow either the field's own type or the type of the
      " referenced field, so decimal floating point amounts and quantities are
      " classified as well. A reference that matches neither carries no
      " semantics and must not produce an annotation.
      IF ls_dd03p-datatype = 'CURR' OR lv_reference_datatype = 'CUKY'.
        rv_ddl = rv_ddl && |  @Semantics.amount.currencyCode : '{ lv_reference }'\n|.
      ELSEIF ls_dd03p-datatype = 'QUAN' OR lv_reference_datatype = 'UNIT'.
        rv_ddl = rv_ddl && |  @Semantics.quantity.unitOfMeasure : '{ lv_reference }'\n|.
      ENDIF.
    ENDIF.
    IF ls_dd03p-rollname IS INITIAL
        AND ( ls_dd03p-datatype(3) = 'D16' OR ls_dd03p-datatype(3) = 'D34' ).
      rv_ddl = rv_ddl && |  @AbapCatalog.decfloat.outputStyle : #NORMAL\n|.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD serialize_field_foreign_key.
 
    DATA ls_dd08v LIKE LINE OF is_data-dd08v.
    DATA ls_dd05m LIKE LINE OF is_data-dd05m.
    DATA lt_dd05m TYPE STANDARD TABLE OF dd05m WITH DEFAULT KEY.
    DATA lt_cardinalities TYPE ty_cardinalities.
    DATA ls_cardinality TYPE ty_cardinality.
    DATA lv_pre TYPE string.
    DATA lv_cardinality TYPE string.
    DATA lv_target TYPE string.
    READ TABLE is_data-dd08v INTO ls_dd08v WITH KEY fieldname = iv_fieldname.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    " Cardinality is optional in table DDL; keep the separator when omitted.
    " DDIC may also contain legacy or incomplete cardinality values which have
    " no direct DDL representation, in which case the foreign key is preserved
    " and only the cardinality is left out.
    lv_cardinality = | |.
    lt_cardinalities = get_cardinalities( ).
    READ TABLE lt_cardinalities INTO ls_cardinality
      WITH KEY cardleft = ls_dd08v-cardleft card = ls_dd08v-card.
    IF sy-subrc = 0.
      lv_cardinality = | { ls_cardinality-token } |.
    ENDIF.
    rv_ddl = rv_ddl && |\n    with foreign key{ lv_cardinality }{ to_lower( ls_dd08v-checktable ) }|.
    LOOP AT is_data-dd05m INTO ls_dd05m
        WHERE fieldname = iv_fieldname AND fortable <> '*'.
      APPEND ls_dd05m TO lt_dd05m.
    ENDLOOP.
    SORT lt_dd05m BY primpos ASCENDING.
    LOOP AT lt_dd05m INTO ls_dd05m.
      IF lv_pre IS INITIAL.
        lv_pre = |\n      where |.
      ELSE.
        lv_pre = |\n        and |.
      ENDIF.
      IF ls_dd05m-fortable(1) = |'|.
        rv_ddl = rv_ddl && |{ lv_pre }{ to_lower( ls_dd05m-checkfield ) } = { ls_dd05m-fortable }|.
      ELSE.
        lv_target = |{ to_lower( ls_dd05m-fortable ) }.{ to_lower( ls_dd05m-forkey ) }|.
        rv_ddl = rv_ddl && |{ lv_pre }{ to_lower( ls_dd05m-checkfield ) } = { lv_target }|.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.
 
 
  METHOD serialize_fkey_annotations.
    DATA ls_dd08v LIKE LINE OF is_data-dd08v.
    READ TABLE is_data-dd08v INTO ls_dd08v WITH KEY fieldname = iv_fieldname.
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    IF ls_dd08v-ddtext IS NOT INITIAL.
      " ADT emits this label without escaping the apostrophes inside it,
      " unlike the other annotations. Match that rather than produce a
      " different serialization than the tool the DDL comes from.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.label : '{ ls_dd08v-ddtext }'\n|.
    ENDIF.
    IF ls_dd08v-frkart IS INITIAL.
    ELSEIF ls_dd08v-frkart = 'TEXT'.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.keyType : #TEXT_KEY\n|.
    ELSEIF ls_dd08v-frkart = 'REF'.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.keyType : #NON_KEY\n|.
    ELSEIF ls_dd08v-frkart = 'KEY'.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.keyType : #KEY\n|.
    ELSE.
      zcx_abapgit_exception=>raise(
        |TABL DDL serialization error: unsupported foreign key type { ls_dd08v-frkart }| ).
    ENDIF.
    IF ls_dd08v-checkflag = abap_false OR ls_dd08v-checkflag = 'N'.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.screenCheck : true\n|.
    ELSE.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.screenCheck : false\n|.
    ENDIF.
    IF ls_dd08v-arbgb IS NOT INITIAL.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.messageClass : { escape_string( ls_dd08v-arbgb ) }\n|.
    ENDIF.
    IF ls_dd08v-msgnr IS NOT INITIAL.
      rv_ddl = rv_ddl && |  @AbapCatalog.foreignKey.messageNumber : { escape_string( ls_dd08v-msgnr ) }\n|.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD serialize_top.
    FIELD-SYMBOLS <lv_pk_is_invhash> TYPE c.
    FIELD-SYMBOLS <lv_is_gtt> TYPE abap_bool.
    DATA lv_replacement_object TYPE string.
    IF is_data-dd02v-exclass NOT BETWEEN '0' AND '4'.
      zcx_abapgit_exception=>raise(
        |TABL DDL serialization error: unsupported enhancement category { is_data-dd02v-exclass }| ).
    ENDIF.
    IF is_data-dd02v-contflag IS INITIAL.
      zcx_abapgit_exception=>raise( 'TABL DDL serialization error: delivery class is missing' ).
    ENDIF.
    rv_ddl = rv_ddl && |@EndUserText.label : { escape_string( is_data-dd02v-ddtext ) }\n|.
    CASE is_data-dd02v-exclass.
      WHEN '0'.
        rv_ddl = rv_ddl && |@AbapCatalog.enhancement.category : #NOT_CLASSIFIED\n|.
      WHEN '1'.
        rv_ddl = rv_ddl && |@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE\n|.
      WHEN '2'.
        rv_ddl = rv_ddl && |@AbapCatalog.enhancement.category : #EXTENSIBLE_CHARACTER\n|.
      WHEN '3'.
        rv_ddl = rv_ddl && |@AbapCatalog.enhancement.category : #EXTENSIBLE_CHARACTER_NUMERIC\n|.
      WHEN '4'.
        rv_ddl = rv_ddl && |@AbapCatalog.enhancement.category : #EXTENSIBLE_ANY\n|.
    ENDCASE.
    IF is_data-dd02v-tabclass <> 'TRANSP'.
      zcx_abapgit_exception=>raise(
        |TABL DDL serialization error: unsupported table category { is_data-dd02v-tabclass }| ).
    ENDIF.
    ASSIGN COMPONENT 'IS_GTT' OF STRUCTURE is_data-dd02v TO <lv_is_gtt>.
    IF sy-subrc = 0 AND <lv_is_gtt> = abap_true.
      rv_ddl = rv_ddl && |@AbapCatalog.tableCategory : #GLOBAL_TEMPORARY\n|.
    ELSE.
      rv_ddl = rv_ddl && |@AbapCatalog.tableCategory : #TRANSPARENT\n|.
    ENDIF.
    IF is_data-dd02v-authclass = '01'.
      rv_ddl = rv_ddl && |@AbapCatalog.activationType : #NAMETAB_GENERATION_OFFLINE\n|.
    ELSEIF is_data-dd02v-authclass = '02'.
      rv_ddl = rv_ddl && |@AbapCatalog.activationType : #ADAPT_C_STRUCTURES\n|.
    ELSEIF is_data-dd02v-authclass = '10'.
      rv_ddl = rv_ddl && |@AbapCatalog.activationType : #INITIAL_TABLE_REQUIRED\n|.
    ELSEIF is_data-dd02v-authclass IS NOT INITIAL.
      zcx_abapgit_exception=>raise(
        |TABL DDL serialization error: unsupported activation type { is_data-dd02v-authclass }| ).
    ENDIF.
    rv_ddl = rv_ddl && |@AbapCatalog.deliveryClass : #{ is_data-dd02v-contflag }\n|.
    IF is_data-dd02v-mainflag = abap_true.
      rv_ddl = rv_ddl && |@AbapCatalog.dataMaintenance : #ALLOWED\n|.
    ELSEIF is_data-dd02v-mainflag = 'N'.
      rv_ddl = rv_ddl && |@AbapCatalog.dataMaintenance : #NOT_ALLOWED\n|.
    ELSEIF is_data-dd02v-mainflag IS INITIAL.
      rv_ddl = rv_ddl && |@AbapCatalog.dataMaintenance : #RESTRICTED\n|.
    ELSE.
      zcx_abapgit_exception=>raise(
        |TABL DDL serialization error: unsupported data maintenance value { is_data-dd02v-mainflag }| ).
    ENDIF.
    lv_replacement_object = get_replacement_object( is_data-dd02v-viewref ).
    IF lv_replacement_object IS NOT INITIAL.
      rv_ddl = rv_ddl && |@AbapCatalog.replacementObject : { escape_string( to_lower( lv_replacement_object ) ) }\n|.
    ENDIF.
    ASSIGN COMPONENT 'PK_IS_INVHASH' OF STRUCTURE is_data-dd02v TO <lv_pk_is_invhash>.
    IF sy-subrc = 0 AND <lv_pk_is_invhash> = abap_true.
      rv_ddl = rv_ddl && |@AbapCatalog.primaryKey.invertedIndividualIndex : true\n|.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD serialize_type.
    DATA lv_notnull TYPE string.
    IF is_dd03p-notnull = abap_true.
      lv_notnull = | not null|.
    ENDIF.
    IF is_dd03p-rollname IS NOT INITIAL.
      rv_type = |{ to_lower( is_dd03p-rollname ) }{ lv_notnull }|.
    ELSE.
      rv_type = serialize_type_core( is_dd03p ).
      rv_type = rv_type && lv_notnull.
    ENDIF.
  ENDMETHOD.
 
 
  METHOD serialize_type_core.
    DATA lv_leng TYPE i.
    DATA lv_decimals TYPE i.
    lv_leng = is_dd03p-leng.
    lv_decimals = is_dd03p-decimals.
    IF is_dd03p-datatype = 'STRG'.
      rv_type = |abap.string({ lv_leng })|.
    ELSEIF is_dd03p-datatype = 'RSTR'.
      rv_type = |abap.rawstring({ lv_leng })|.
    ELSEIF is_dd03p-datatype = 'SSTR'.
      rv_type = |abap.sstring({ lv_leng })|.
    ELSEIF is_dd03p-datatype = 'DEC' OR is_dd03p-datatype = 'CURR'
        OR is_dd03p-datatype = 'QUAN'.
      rv_type = |abap.{ to_lower( is_dd03p-datatype ) }({ lv_leng },{ lv_decimals })|.
    ELSEIF is_dd03p-datatype = 'D16D' OR is_dd03p-datatype = 'D34D'.
      IF is_dd03p-datatype = 'D16D'.
        rv_type = |abap.df16_dec({ lv_leng },{ lv_decimals })|.
      ELSE.
        rv_type = |abap.df34_dec({ lv_leng },{ lv_decimals })|.
      ENDIF.
    ELSEIF is_dd03p-datatype = 'CHAR' OR is_dd03p-datatype = 'NUMC'
        OR is_dd03p-datatype = 'RAW' OR is_dd03p-datatype = 'LRAW'
        OR is_dd03p-datatype = 'LCHR'
        OR is_dd03p-datatype = 'UNIT'.
      rv_type = |abap.{ to_lower( is_dd03p-datatype ) }({ lv_leng })|.
    ELSE.
      rv_type = serialize_type_special( is_dd03p ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD serialize_type_special.
    CASE is_dd03p-datatype.
      WHEN 'INT4'.
        rv_type = |abap.int4|.
      WHEN 'ACCP'.
        rv_type = |abap.accp|.
      WHEN 'LANG'.
        rv_type = |abap.lang|.
      WHEN 'DATN'.
        rv_type = |abap.datn|.
      WHEN 'TIMN'.
        rv_type = |abap.timn|.
      WHEN 'UTCL'.
        rv_type = |abap.utcl|.
      WHEN 'INT8'.
        rv_type = |abap.int8|.
      WHEN 'D16R'.
        rv_type = |abap.df16_raw|.
      WHEN 'D16S'.
        rv_type = |abap.df16_scl|.
      WHEN 'D16N'.
        rv_type = |abap.d16n|.
      WHEN 'D34S'.
        rv_type = |abap.df34_scl|.
      WHEN 'D34R'.
        rv_type = |abap.df34_raw|.
      WHEN 'D34N'.
        rv_type = |abap.d34n|.
      WHEN 'INT2'.
        rv_type = |abap.int2|.
      WHEN 'INT1'.
        rv_type = |abap.int1|.
      WHEN 'CUKY'.
        rv_type = |abap.cuky|.
      WHEN 'DATS'.
        rv_type = |abap.dats|.
      WHEN 'TIMS'.
        rv_type = |abap.tims|.
      WHEN 'FLTP'.
        rv_type = |abap.fltp|.
      WHEN 'CLNT'.
        rv_type = |abap.clnt|.
      WHEN OTHERS.
        zcx_abapgit_exception=>raise(
          |TABL DDL serialization error: unsupported field type { is_dd03p-datatype }| ).
    ENDCASE.
  ENDMETHOD.
 
 
  METHOD serialize_value_help.
    DATA ls_dd35v LIKE LINE OF is_data-dd35v.
    DATA ls_dd36m LIKE LINE OF is_data-dd36m.
    DATA lt_dd36m TYPE STANDARD TABLE OF dd36m WITH DEFAULT KEY.
    DATA lv_pre TYPE string.
    DATA lv_target TYPE string.
    READ TABLE is_data-dd35v INTO ls_dd35v WITH KEY fieldname = iv_fieldname.
    IF sy-subrc <> 0 OR ls_dd35v-shlpname = '*'.
      RETURN.
    ENDIF.
    rv_ddl = rv_ddl && |\n    with value help { to_lower( ls_dd35v-shlpname ) }|.
    LOOP AT is_data-dd36m INTO ls_dd36m
        WHERE fieldname = iv_fieldname AND shlpname = ls_dd35v-shlpname AND shtype <> 'G'.
      APPEND ls_dd36m TO lt_dd36m.
    ENDLOOP.
    SORT lt_dd36m BY shlpfield ASCENDING flposition ASCENDING.
    LOOP AT lt_dd36m INTO ls_dd36m.
      IF lv_pre IS INITIAL.
        lv_pre = |\n      where |.
      ELSE.
        lv_pre = |\n        and |.
      ENDIF.
      IF ls_dd36m-shtype = 'C'.
        rv_ddl = rv_ddl && |{ lv_pre }{ to_lower( ls_dd36m-shlpfield ) } = { ls_dd36m-shtable }|.
      ELSE.
        lv_target = |{ to_lower( ls_dd36m-shtable ) }.{ to_lower( ls_dd36m-shfield ) }|.
        rv_ddl = rv_ddl && |{ lv_pre }{ to_lower( ls_dd36m-shlpfield ) } = { lv_target }|.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.