The Bohl–Bohr–Amerio–Kadets theorem states that the indefinite integral y= Pφ of an almost periodic (ap) φ : R→X is again ap if y is bounded and the Banach space X does not contain a subspace isomorphic to c 0. This is here generalized in several directions: Instead of R it holds also for φ defined only on a half-line J , instead of ap functions abstract classes A with suitable properties are admissible, φ∈ A can be weakened to φ in some “mean” class M q+1 A , then Pφ∈ M q A ; here MA contains all f∈ L 1 loc with (1/h)∫ 0 hf(·+s) ds in A for all h>0 (usually A⊂ MA⊂ M 2 A⊂⋯ strictly); furthermore, instead of boundedness of y mean boundedness, y in some M kL ∞ , or in M k E , E= ergodic functions, suffices. The Loomis–Doss result on the almost periodicity of a bounded Ψ for which all differences Ψ( t+ h)− Ψ( t) are ap for h>0 is extended analogously, also to higher order differences. Studying “difference spaces” Δ A in this connection, we obtain decompositions of the form: Any bounded measurable function is the sum of a bounded ergodic function and the indefinite integral of a bounded ergodic function. The Bohr–Neugebauer result on the almost periodicity of bounded solutions y of linear differential equations P( D) y= φ of degree m with ap φ is extended similarly for φ∈ M q+m A ; then y∈ M q A provided, for example, y is in some M kU with U= L ∞ or is totally ergodic and, for the half-line, Re λ⩾0 for all eigenvalues P( λ)=0. Analogous results hold for systems of linear differential equations. Special case: φ bounded and Pφ ergodic implies Pφ bounded. If all Re λ>0, there exists a unique solution y growing not too fast; this y is in M q A if φ∈ M q+m A , for quite general A .