Eligibility Criteria:
Inclusion criteria:
* Patients ≥18 years of age or over the legal age of consent in countries where that is greater than 18 years at the time of signature of the informed consent form (ICF)
* Cohorts A to K and Cohort O: Documented Human epidermal growth factor receptor 2 overexpressing and/or amplified (HER2+), metastatic breast cancer (mBC) or metastatic gastric adenocarcinoma, gastroesophageal junction adenocarcinoma, or esophageal adenocarcinoma (mGEAC).
* Cohorts L (L-ext), M, and N (metastatic colorectal cancer (mCRC)): Documented Human epidermal growth factor receptor 2 (HER2) overexpression/amplification according to American Society of Clinical Oncology/College of American Pathologists (ASCO/CAP) gastric cancer guidelines and according to the result of local testing.
* For dose optimization and justification (Phase II): Patient must provide tumor tissue from locations not radiated prior to biopsy, if possible, collected through archival tissue
* History of prior treatment lines in palliative setting:
* For cohorts A, B, C, D, E, F, G, H, I, I-ext, J, J-ext, K and O documented investigator assessed progression after HER2-directed treatment for unresectable locally advanced or metastatic disease (For Cohorts D, H, I (I-ext), J (J-ext) - patients must have been pretreated with trastuzumab deruxtecan (T-DXd) and have progressed or have been intolerant to previous T-DXd).
* For cohorts L, L-ext, M and N documented progression or recurrence of disease during or following their latest line of therapy. Patients must have had at least one prior line of therapy for locally advanced unresectable disease or metastatic disease (adjuvant and neoadjuvant therapy excluded) and documented disease progression or recurrence of disease during or following their latest line of therapy. In the opinion of the Investigator, patients must be unlikely to tolerate or derive clinically meaningful benefit from further standard of care therapy known to prolong survival.
* Presence of at least one measurable lesion according to RECIST 1.1
* Eastern Cooperative Oncology Group (ECOG) score of 0 or 1
* Adequate organ function based on laboratory values Further inclusion criteria apply.
Exclusion criteria:
* Previous treatment with:
* Any small molecule HER2 inhibitor in the palliative setting in Cohorts D, E, F, H, L, L-ext, M, and N. In Cohort D allowed in up to 15 patients in each dose level (DL).
* T-DXd in Cohorts E and F. In Cohort E allowed in up to 15 patients in each DL.
* trastuzumab emtansine (T-DM1) in the palliative setting in Cohort D and H. In Cohort H allowed in up to 15 patients in each DL.
* Capecitabine in Cohort D and H. In Cohort D allowed in up to 15 patients in each DL
* Presence of uncontrolled and/or symptomatic brain metastases, or leptomeningeal disease
* Mean resting corrected QT interval (QT interval corrected for heart rate by Fridericia´s formula (QTcF)) \>470 msec.
* Any factors that increase the risk of QT interval corrected for heart rate (QTc) prolongation or risk of arrhythmic events such as heart failure, hypokalemia, congenital long QT syndrome, personal or family history of long QT syndrome or unexplained sudden death under 40 years-of-age.
* Ejection fraction \<50% or the lower limit of normal of the institutional standard within 28 days prior to randomization
* History of (non-infectious) interstitial lung disease (ILD)/pneumonitis that required steroids, current ILD/pneumonitis, or where suspected ILD/pneumonitis cannot be ruled out by imaging at screening Further exclusion criteria apply.