Q:

how to write a macro on multiplication table?

There is an example on macro of MultTable in the manual of Pstricks. I just copied the codes and pasted into the tex file, but it doesn't work. who can help me modify it? 
\documentclass[pstricks,margin=1mm]{standalone}
\usepackage{pstricks,pst-poly,pst-text,pst-key}

\begin{document}

\begin{pspicture*}(12,3)

% “Start”, “End” and “Value” parameters
\define@key{psset}{Start}{\pst@getint{#1}{\MultTable@Start}}
\define@key{psset}{End}{\pst@getint{#1}{\MultTable@End}}
\define@key{psset}{Value}{\pst@getint{#1}{\MultTable@Value}}
\setkeys{psset}{Start=1,End=5,Value=2}% Default values

% Main macro for “multiplication table” object
\def\MultTable{\def\pst@par{}\pst@object{MultTable}}

 \def\MultTable@i{{%
 \use@par% Assignment of local parameters
 \pst@cnth=\MultTable@End
 \advance\pst@cnth-\MultTable@Start
 \advance\pst@cnth\@ne
 \multido{\iValue=\MultTable@Start+\@ne}{\pst@cnth}{%
 \pst@cntg=\iValue
 \multiply\pst@cntg\MultTable@Value
 \iValue$\times$\MultTable@Value = \the\pst@cntg
 \ifnum\multidocount=\pst@cnth\else; \fi}}}

 \MultTable

\MultTable[Value=9]

\setkeys{psset}{Value=6}

\MultTable[Start=6,End=11]

\MultTable[Start=19742,End=19742]
\end{pspicture}
\end{document} 

A:

The documentation is a bit scanty about the code; the preliminary definitions should go between \makeatletter and \makeatother, preferably before \begin{document}. In this case there's no need to use a pspicture, because you aren't really drawing.
\documentclass{article}
\usepackage{pstricks,pst-poly,pst-text,pst-key}

\makeatletter
% “Start”, “End” and “Value” parameters
\define@key{psset}{Start}{\pst@getint{#1}{\MultTable@Start}}
\define@key{psset}{End}{\pst@getint{#1}{\MultTable@End}}
\define@key{psset}{Value}{\pst@getint{#1}{\MultTable@Value}}
\setkeys{psset}{Start=1,End=5,Value=2}% Default values

% Main macro for “multiplication table” object
\def\MultTable{\def\pst@par{}\pst@object{MultTable}}

 \def\MultTable@i{{%
 \use@par% Assignment of local parameters
 \pst@cnth=\MultTable@End
 \advance\pst@cnth-\MultTable@Start
 \advance\pst@cnth\@ne
 \multido{\iValue=\MultTable@Start+\@ne}{\pst@cnth}{%
 \pst@cntg=\iValue
 \multiply\pst@cntg\MultTable@Value
 \iValue$\times$\MultTable@Value = \the\pst@cntg
 \ifnum\multidocount=\pst@cnth\else; \fi}}}
\makeatother

\begin{document}

\MultTable

\MultTable[Value=9]

\setkeys{psset}{Value=6}

\MultTable[Start=6,End=11]

\MultTable[Start=19742,End=19742]

\end{document} 

How a multtable.sty package should be written? Here it is
\ProvidesPackage{multtab}[2017/01/14 v. 0]
\RequirePackage{pstricks,pst-poly,pst-text,pst-key}
% “Start”, “End” and “Value” parameters
\define@key{psset}{Start}{\pst@getint{#1}{\MultTable@Start}}
\define@key{psset}{End}{\pst@getint{#1}{\MultTable@End}}
\define@key{psset}{Value}{\pst@getint{#1}{\MultTable@Value}}
\setkeys{psset}{Start=1,End=5,Value=2}% Default values

% Main macro for “multiplication table” object
\def\MultTable{\def\pst@par{}\pst@object{MultTable}}

 \def\MultTable@i{{%
 \use@par% Assignment of local parameters
 \pst@cnth=\MultTable@End
 \advance\pst@cnth-\MultTable@Start
 \advance\pst@cnth\@ne
 \multido{\iValue=\MultTable@Start+\@ne}{\pst@cnth}{%
 \pst@cntg=\iValue
 \multiply\pst@cntg\MultTable@Value
 \iValue$\times$\MultTable@Value = \the\pst@cntg
 \ifnum\multidocount=\pst@cnth\else; \fi}}}

\endinput

Save this as multtable.sty and then after \usepackage{multtable} the command \MultTable will do its job:
\documentclass{article}
\usepackage{multtable}

\begin{document}

\MultTable

\MultTable[Value=9]

\setkeys{psset}{Value=6}

\MultTable[Start=6,End=11]

\MultTable[Start=19742,End=19742]

\end{document}

