'Affirmative' action

In the old TV series “Lost in Space” and “Star Trek,” The Robot and Spock respectively typically answered “Yes” as “Affirmative.”

Was that something invented for the screen, or is that a common response in the military or some other circles?

US Military jargon from forties and fifties originally as part of radio communication- yes and no being short and indistinct, negative and affirmative being less open to mistakes.

And we still use 'em today.