# Problem statement

When I try to apply the \MakeUppercase command to a macro whose value is retrieved from a .csv table via \DTLfetch from the datatool package, I get a compilation error.

I am looking for a solution that overcomes this problem.

# Minimal (non-)working example (MWE)

\documentclass{article}

\usepackage{datatool}

\def\myvariable{\DTLfetch{data}{Key}{Variable}{Value}}%

\begin{document}

\myvariable\\% This works as expected
\MakeUppercase{\myvariable}% TODO: This breaks compilation

\end{document}

with data.csv consisting of:

Key,Value
Variable,1f.45

Trying to compile the above example results in the following error:

! Illegal parameter number in definition of \reserved@a.
3
l.11 \MakeUppercase{\myvariable}
• Problem seems to be specific to \DTLfetch - it seems that it is overcome at tex.stackexchange.com/questions/248965/… by using \DTLassignfirstmatch instead (which does not suit my situation, however). I'll amend the original question accordingly. – Florian H. Jun 2 '18 at 23:15

\DTLfetch is not expandable, so it can not work in the argument of \MakeUppercase, even if hidden inside \myvariable.

Instead, you can use \DTLgetvalueforkey to assign the value to \myvariable, then \myvariable contains the actual value instead of the \DTLfetch command and can be used inside of \MakeUppercase:

\documentclass{article}

\usepackage{datatool}